Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move package configuration to declarative config #557

Merged
merged 8 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pyproject.toml
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"
45 changes: 45 additions & 0 deletions setup.cfg
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
132 changes: 38 additions & 94 deletions setup.py
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):
Expand All @@ -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"]

Expand All @@ -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):
Expand All @@ -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']
Expand Down