-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move package configuration to declarative config (#557)
* Add pyproject.toml declaring build dependency on setuptools. * Reformat using ruff (to avoid diffs for editors with ruff autosave). * Fix typo in package_data * Move Description to setup.cfg * Remove 'license' field, which is redundant and recommended against. * Move 'version' to setup.cfg * Move the remaining metadata into setup.cfg. * Remove build_py cmdclass as it's the default.
- Loading branch information
Showing
3 changed files
with
86 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[build-system] | ||
requires = ["setuptools>=61.2"] | ||
build-backend = "setuptools.build_meta" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,47 @@ | ||
[metadata] | ||
name = comtypes | ||
description = Pure Python COM package | ||
author = Thomas Heller | ||
author_email = [email protected] | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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,55 +50,36 @@ 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) | ||
|
||
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 | ||
# the working solution was found here: | ||
# 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="[email protected]", | ||
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'] | ||
|