From 033b8c4dc9aae249c1cfa20d59e0416b99306c53 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 7 Jun 2024 10:26:45 -0400 Subject: [PATCH 1/8] Add pyproject.toml declaring build dependency on setuptools. --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 pyproject.toml 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" From 82f13d1a8226bd60c5a2ec9628462754159b0e05 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 7 Jun 2024 10:28:42 -0400 Subject: [PATCH 2/8] Reformat using ruff (to avoid diffs for editors with ruff autosave). --- setup.py | 63 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/setup.py b/setup.py index 0bf9ba55..8d8f5b19 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ """comtypes package install script""" + import sys import os import subprocess @@ -18,14 +19,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 +55,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,12 +63,12 @@ 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 @@ -73,7 +80,7 @@ def run(self): 'Programming Language :: Python', 'Programming Language :: Python :: 3', 'Topic :: Software Development :: Libraries :: Python Modules', - ] +] def read_version(): @@ -88,7 +95,6 @@ def read_version(): 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 +102,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,7 +121,12 @@ 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!") @@ -135,25 +149,20 @@ def run(self): "TestDispServer.tlb", "mytypelib.idl", "mylib.idl", - "mylib.tlb" - "urlhist.tlb", + "mylib.tlb" "urlhist.tlb", "test_jscript.js", ], - "comtypes": [ - "hints.pyi" - ]}, + "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", From 6c43db8770be249e7deb38326f55b60ee492fcf4 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 7 Jun 2024 10:29:16 -0400 Subject: [PATCH 3/8] Fix typo in package_data --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 8d8f5b19..6f219302 100644 --- a/setup.py +++ b/setup.py @@ -149,7 +149,8 @@ def run(self): "TestDispServer.tlb", "mytypelib.idl", "mylib.idl", - "mylib.tlb" "urlhist.tlb", + "mylib.tlb", + "urlhist.tlb", "test_jscript.js", ], "comtypes": ["hints.pyi"], From 21a5359df51420fc288de70842ac4b48c0587b3d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 7 Jun 2024 10:33:01 -0400 Subject: [PATCH 4/8] Move Description to setup.cfg --- setup.cfg | 4 ++++ setup.py | 6 ------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/setup.cfg b/setup.cfg index afa65060..a34cf6a9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,6 @@ +[metadata] +long_description = file:README.md +long_description_content_type = text/markdown + [options] python_requires = >=3.7 diff --git a/setup.py b/setup.py index 6f219302..42b92162 100644 --- a/setup.py +++ b/setup.py @@ -9,10 +9,6 @@ from setuptools.command.build_py import build_py -with open('README.md') as readme_stream: - readme = readme_stream.read() - - class test(Command): # Original version of this class posted # by Berthold Hoellmann to distutils-sig@python.org @@ -134,8 +130,6 @@ def run(self): 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", From b48c58a0aa6f04ee0aedccac0540576a7366f029 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 7 Jun 2024 10:34:50 -0400 Subject: [PATCH 5/8] Remove 'license' field, which is redundant and recommended against. --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index 42b92162..77d90f7a 100644 --- a/setup.py +++ b/setup.py @@ -134,7 +134,6 @@ def run(self): 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", From 0d07dd28939c9d18f0a28ec8d8b6f88f6098b4f0 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 7 Jun 2024 10:36:43 -0400 Subject: [PATCH 6/8] Move 'version' to setup.cfg --- setup.cfg | 1 + setup.py | 12 ------------ 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/setup.cfg b/setup.cfg index a34cf6a9..0bef1b13 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,4 +1,5 @@ [metadata] +version = attr:comtypes.__version__ long_description = file:README.md long_description_content_type = text/markdown diff --git a/setup.py b/setup.py index 77d90f7a..d0e95fe0 100644 --- a/setup.py +++ b/setup.py @@ -79,17 +79,6 @@ def run(self): ] -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: @@ -157,7 +146,6 @@ def run(self): 'build_py': build_py, 'install': post_install, }, - version=read_version(), packages=[ "comtypes", "comtypes.client", From f6062154618dddf2723468fcd724dc8277558318 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 7 Jun 2024 10:44:59 -0400 Subject: [PATCH 7/8] Move the remaining metadata into setup.cfg. --- setup.cfg | 40 +++++++++++++++++++++++++++++++++++++ setup.py | 59 +++++++------------------------------------------------ 2 files changed, 47 insertions(+), 52 deletions(-) diff --git a/setup.cfg b/setup.cfg index 0bef1b13..55811cea 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +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 d0e95fe0..d8e5be90 100644 --- a/setup.py +++ b/setup.py @@ -68,17 +68,6 @@ def run(self): 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', -] - - 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: @@ -116,48 +105,14 @@ def run(self): print("Failed to run post install script!") -setup_params = dict( - 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", - 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, - }, - 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, + 'build_py': build_py, + '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'] From 22ace79335fea3d4ddae738411d751e994bf2e54 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 7 Jun 2024 10:45:35 -0400 Subject: [PATCH 8/8] Remove build_py cmdclass as it's the default. --- setup.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/setup.py b/setup.py index d8e5be90..407cdfcb 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,6 @@ from setuptools import Command, setup from setuptools.command.install import install -from setuptools.command.build_py import build_py class test(Command): @@ -109,7 +108,6 @@ def run(self): dist = setup( cmdclass={ 'test': test, - 'build_py': build_py, 'install': post_install, }, )