diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..c02b2718 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools>=61.2"] +build-backend = "setuptools.build_meta" diff --git a/setup.cfg b/setup.cfg index afa65060..55811cea 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,47 @@ +[metadata] +name = comtypes +description = Pure Python COM package +author = Thomas Heller +author_email = theller@python.net +url = https://github.com/enthought/comtypes +download_url = https://github.com/enthought/comtypes/releases +version = attr:comtypes.__version__ +long_description = file:README.md +long_description_content_type = text/markdown +classifiers = + Development Status :: 5 - Production/Stable + Intended Audience :: Developers + License :: OSI Approved :: MIT License + Operating System :: Microsoft :: Windows + Programming Language :: Python + Programming Language :: Python :: 3 + Topic :: Software Development :: Libraries :: Python Modules + [options] python_requires = >=3.7 + +packages = + comtypes + comtypes.client + comtypes.server + comtypes.tools + comtypes.tools.codegenerator + comtypes.test + +[options.package_data] +comtypes.test = + TestComServer.idl + TestComServer.tlb + TestDispServer.idl + TestDispServer.tlb + mytypelib.idl + mylib.idl + mylib.tlb + urlhist.tlb + test_jscript.js +comtypes = + hints.pyi + +[options.entry_points] +console_scripts = + clear_comtypes_cache = comtypes.clear_cache:main diff --git a/setup.py b/setup.py index 0bf9ba55..407cdfcb 100644 --- a/setup.py +++ b/setup.py @@ -1,15 +1,11 @@ """comtypes package install script""" + import sys import os import subprocess from setuptools import Command, setup from setuptools.command.install import install -from setuptools.command.build_py import build_py - - -with open('README.md') as readme_stream: - readme = readme_stream.read() class test(Command): @@ -18,14 +14,19 @@ class test(Command): description = "run tests" user_options = [ - ('tests=', 't', - "comma-separated list of packages that contain test modules"), - ('use-resources=', 'u', - "resources to use - resource names are defined by tests"), - ('refcounts', 'r', - "repeat tests to search for refcount leaks (requires " - "'sys.gettotalrefcount')"), - ] + ('tests=', 't', "comma-separated list of packages that contain test modules"), + ( + 'use-resources=', + 'u', + "resources to use - resource names are defined by tests", + ), + ( + 'refcounts', + 'r', + "repeat tests to search for refcount leaks (requires " + "'sys.gettotalrefcount')", + ), + ] boolean_options = ["refcounts"] @@ -49,6 +50,7 @@ def run(self): # Register our ATL COM tester dll import comtypes.test + script_path = os.path.dirname(__file__) source_dir = os.path.abspath(os.path.join(script_path, "source")) comtypes.test.register_server(source_dir) @@ -56,39 +58,16 @@ def run(self): comtypes.test.use_resources.extend(self.use_resources) for name in self.tests: package = __import__(name, globals(), locals(), ['*']) - sys.stdout.write("Testing package %s %s\n" - % (name, (sys.version, sys.platform, os.name))) - package_failure = comtypes.test.run_tests(package, - "test_*.py", - self.verbose, - self.refcounts) + sys.stdout.write( + "Testing package %s %s\n" % (name, (sys.version, sys.platform, os.name)) + ) + package_failure = comtypes.test.run_tests( + package, "test_*.py", self.verbose, self.refcounts + ) self.failure = self.failure or package_failure -classifiers = [ - 'Development Status :: 5 - Production/Stable', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'Operating System :: Microsoft :: Windows', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Topic :: Software Development :: Libraries :: Python Modules', - ] - - -def read_version(): - # Determine the version number by reading it from the file - # 'comtypes\__init__.py'. We cannot import this file (with py3, - # at least) because it is in py2.x syntax. - for line in open("comtypes/__init__.py"): - if line.startswith("__version__ = "): - var, value = line.split('=') - return value.strip().strip('"').strip("'") - raise NotImplementedError("__version__ is not found in __init__.py") - - class post_install(install): - # both this static variable and method initialize_options() help to avoid # weird setuptools error with "pip install comtypes", details are here: # https://github.com/enthought/comtypes/issues/155 @@ -96,8 +75,11 @@ class post_install(install): # https://github.com/pypa/setuptools/blob/3b90be7bb6323eb44d0f28864509c1d47aa098de/setuptools/command/install.py user_options = install.user_options + [ ('old-and-unmanageable', None, "Try not to use this!"), - ('single-version-externally-managed', None, - "used by system package builders to create 'flat' eggs"), + ( + 'single-version-externally-managed', + None, + "used by system package builders to create 'flat' eggs", + ), ] def initialize_options(self): @@ -112,61 +94,23 @@ def run(self): print("Executing post install script...") print(f'"{sys.executable}" -m comtypes.clear_cache -y') try: - subprocess.check_call([sys.executable, "-m", "comtypes.clear_cache", '-y']) + subprocess.check_call([ + sys.executable, + "-m", + "comtypes.clear_cache", + '-y', + ]) except subprocess.CalledProcessError: print("Failed to run post install script!") -setup_params = dict( - name="comtypes", - description="Pure Python COM package", - long_description=readme, - long_description_content_type="text/markdown", - author="Thomas Heller", - author_email="theller@python.net", - url="https://github.com/enthought/comtypes", - download_url="https://github.com/enthought/comtypes/releases", - license="MIT License", - package_data={ - "comtypes.test": [ - "TestComServer.idl", - "TestComServer.tlb", - "TestDispServer.idl", - "TestDispServer.tlb", - "mytypelib.idl", - "mylib.idl", - "mylib.tlb" - "urlhist.tlb", - "test_jscript.js", - ], - "comtypes": [ - "hints.pyi" - ]}, - classifiers=classifiers, - - entry_points={ - "console_scripts": ["clear_comtypes_cache=comtypes.clear_cache:main"] - }, - - cmdclass={ - 'test': test, - 'build_py': build_py, - 'install': post_install, - }, - - version=read_version(), - packages=[ - "comtypes", - "comtypes.client", - "comtypes.server", - "comtypes.tools", - "comtypes.tools.codegenerator", - "comtypes.test", - ], -) - if __name__ == '__main__': - dist = setup(**setup_params) + dist = setup( + cmdclass={ + 'test': test, + 'install': post_install, + }, + ) # Exit with a failure code if only running the tests and they failed if dist.commands == ['test']: command = dist.command_obj['test']