diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 46eba0d4..75aa1048 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,7 @@ jobs: strategy: ${{steps.load.outputs.strategy}} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: repository: colcon/ci - id: load @@ -24,7 +24,7 @@ jobs: runs-on: ${{matrix.os}} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-python@v4 with: python-version: ${{matrix.python}} @@ -37,7 +37,7 @@ jobs: runs-on: ${{matrix.os}} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-python@v4 with: python-version: ${{matrix.python}} diff --git a/colcon_core/__init__.py b/colcon_core/__init__.py index 21c54fc4..4654486c 100644 --- a/colcon_core/__init__.py +++ b/colcon_core/__init__.py @@ -1,4 +1,4 @@ # Copyright 2016-2020 Dirk Thomas # Licensed under the Apache License, Version 2.0 -__version__ = '0.15.0' +__version__ = '0.15.2' diff --git a/colcon_core/executor/__init__.py b/colcon_core/executor/__init__.py index bba60f3d..aca03575 100644 --- a/colcon_core/executor/__init__.py +++ b/colcon_core/executor/__init__.py @@ -244,7 +244,7 @@ def add_executor_arguments(parser): group.add_argument( '--executor', type=str, choices=keys, default=default, help=f'The executor to process all packages (default: {default})' - f'{descriptions}') + f'{descriptions}') # noqa: E131 for priority in extensions.keys(): extensions_same_prio = extensions[priority] diff --git a/colcon_core/extension_point.py b/colcon_core/extension_point.py index ff348ba5..c724d221 100644 --- a/colcon_core/extension_point.py +++ b/colcon_core/extension_point.py @@ -37,6 +37,15 @@ EXTENSION_POINT_GROUP_NAME = 'colcon_core.extension_point' +def _get_unique_distributions(): + seen = set() + for dist in distributions(): + dist_name = dist.metadata['Name'] + if dist_name not in seen: + seen.add(dist_name) + yield dist + + def get_all_extension_points(): """ Get all extension points related to `colcon` and any of its extensions. @@ -51,12 +60,7 @@ def get_all_extension_points(): colcon_extension_points.setdefault(EXTENSION_POINT_GROUP_NAME, None) entry_points = defaultdict(dict) - seen = set() - for dist in distributions(): - dist_name = dist.metadata['Name'] - if dist_name in seen: - continue - seen.add(dist_name) + for dist in _get_unique_distributions(): for entry_point in dist.entry_points: # skip groups which are not registered as extension points if entry_point.group not in colcon_extension_points: @@ -70,7 +74,7 @@ def get_all_extension_points(): f"from '{dist._path}' " f"overwriting '{previous}'") entry_points[entry_point.group][entry_point.name] = \ - (entry_point.value, dist_name, dist.version) + (entry_point.value, dist.metadata['Name'], dist.version) return entry_points @@ -87,7 +91,11 @@ def get_extension_points(group): # Python 3.10 and newer query = entry_points(group=group) except TypeError: - query = entry_points().get(group, ()) + query = ( + entry_point + for dist in _get_unique_distributions() + for entry_point in dist.entry_points + if entry_point.group == group) for entry_point in query: if entry_point.name in extension_points: previous_entry_point = extension_points[entry_point.name] diff --git a/colcon_core/task/python/test/__init__.py b/colcon_core/task/python/test/__init__.py index ef5298bc..74a5ed2b 100644 --- a/colcon_core/task/python/test/__init__.py +++ b/colcon_core/task/python/test/__init__.py @@ -73,6 +73,9 @@ async def test(self, *, additional_hooks=None): # noqa: D102 logger.log(1, f"test.step() by extension '{key}'") try: + if 'PYTHONDONTWRITEBYTECODE' not in env: + env = dict(env) + env['PYTHONDONTWRITEBYTECODE'] = '1' return await extension.step(self.context, env, setup_py_data) except Exception as e: # noqa: F841 # catch exceptions raised in python testing step extension diff --git a/setup.cfg b/setup.cfg index 2c9fe567..e935db42 100644 --- a/setup.cfg +++ b/setup.cfg @@ -29,7 +29,7 @@ python_requires = >=3.6 install_requires = coloredlogs; sys_platform == 'win32' distlib - EmPy + EmPy<4 importlib-metadata; python_version < "3.8" packaging # the pytest dependency and its extensions are provided for convenience @@ -44,7 +44,7 @@ zip_safe = false [options.extras_require] test = - flake8>=3.6.0,<6 + flake8>=3.6.0,<7 flake8-blind-except flake8-builtins flake8-class-newline @@ -68,8 +68,9 @@ exclude = filterwarnings = error # Suppress deprecation warnings in other packages + ignore:Deprecated call to `pkg_resources.declare_namespace\('paste'\)`:: ignore:lib2to3 package is deprecated::scspell - ignore:pkg_resources is deprecated as an API::colcon_core.entry_point + ignore:pkg_resources is deprecated as an API:: ignore:SelectableGroups dict interface is deprecated::flake8 ignore:The loop argument is deprecated::asyncio ignore:Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated::pydocstyle diff --git a/stdeb.cfg b/stdeb.cfg index 9c4793cd..08bafc8e 100644 --- a/stdeb.cfg +++ b/stdeb.cfg @@ -1,6 +1,6 @@ [colcon-core] No-Python2: -Depends3: python3-distlib, python3-empy, python3-packaging, python3-pytest, python3-setuptools, python3 (>= 3.8) | python3-importlib-metadata +Depends3: python3-distlib, python3-empy (<4), python3-packaging, python3-pytest, python3-setuptools, python3 (>= 3.8) | python3-importlib-metadata Recommends3: python3-pytest-cov Suggests3: python3-pytest-repeat, python3-pytest-rerunfailures Suite: focal jammy bullseye bookworm diff --git a/test/spell_check.words b/test/spell_check.words index a1cb3d99..d44f7a23 100644 --- a/test/spell_check.words +++ b/test/spell_check.words @@ -47,6 +47,7 @@ hookimpl hookwrapper https importlib +importorskip isatty iterdir junit @@ -56,6 +57,7 @@ lineno linter linux lstrip +minversion mkdtemp monkeypatch namedtuple @@ -79,6 +81,7 @@ purelib pydocstyle pytest pytests +pythondontwritebytecode pythonpath pythonscriptspath pythonwarnings diff --git a/test/test_build_python.py b/test/test_build_python.py index 27060ef1..7780a567 100644 --- a/test/test_build_python.py +++ b/test/test_build_python.py @@ -45,17 +45,32 @@ def monkey_patch_put_event_into_queue(monkeypatch): ) -def _test_build_package(tmp_path_str, *, symlink_install): +def _test_build_package( + tmp_path_str, *, symlink_install, setup_cfg, libexec_pattern, data_files +): + assert not libexec_pattern or setup_cfg, \ + 'The libexec pattern requires use of setup.cfg' + + if setup_cfg and data_files: + pytest.importorskip('setuptools', minversion='40.5.0') + event_loop = new_event_loop() asyncio.set_event_loop(event_loop) try: tmp_path = Path(tmp_path_str) python_build_task = PythonBuildTask() package = PackageDescriptor(tmp_path / 'src') - package.name = 'test_package' + package.name = 'test-package' package.type = 'python' package.metadata['get_python_setup_options'] = lambda _: { 'packages': ['my_module'], + **( + { + 'data_files': [ + ('share/test_package', ['test-resource']), + ] + } if data_files else {} + ) } context = TaskContext( @@ -73,15 +88,56 @@ def _test_build_package(tmp_path_str, *, symlink_install): pkg = python_build_task.context.pkg pkg.path.mkdir(exist_ok=True) - (pkg.path / 'setup.py').write_text( - 'from setuptools import setup\n' - 'setup(\n' - ' name="test_package",\n' - ' packages=["my_module"],\n' - ')\n' - ) + if setup_cfg: + (pkg.path / 'setup.py').write_text( + 'from setuptools import setup\n' + 'setup()\n' + ) + (pkg.path / 'setup.cfg').write_text( + '[metadata]\n' + 'name = test-package\n' + '[options]\n' + 'packages = find:\n' + '[options.entry_points]\n' + 'console_scripts =\n' + ' my_command = my_module:main\n' + + ( + '[develop]\n' + 'script-dir=$base/lib/test_package\n' + '[install]\n' + 'install-scripts=$base/lib/test_package\n' + if libexec_pattern else '' + ) + ( + '[options.data_files]\n' + 'share/test_package = test-resource\n' + if data_files else '' + ) + ) + else: + (pkg.path / 'setup.py').write_text( + 'from setuptools import setup\n' + 'setup(\n' + ' name="test-package",\n' + ' packages=["my_module"],\n' + ' entry_points={\n' + ' "console_scripts": ["my_command = my_module:main"],\n' + ' },\n' + + ( + ' data_files=[\n' + ' ("share/test_package", [\n' + ' "test-resource",\n' + ' ]),\n' + ' ],\n' + if data_files else '' + ) + + ')\n' + ) (pkg.path / 'my_module').mkdir(exist_ok=True) - (pkg.path / 'my_module' / '__init__.py').touch() + (pkg.path / 'test-resource').touch() + (pkg.path / 'my_module' / '__init__.py').write_text( + 'def main():\n' + ' print("Hello, World!")\n' + ) src_base = Path(python_build_task.context.args.path) @@ -94,108 +150,44 @@ def _test_build_package(tmp_path_str, *, symlink_install): build_base = Path(python_build_task.context.args.build_base) assert build_base.rglob('my_module/__init__.py') - return Path(python_build_task.context.args.install_base) + install_base = Path(python_build_task.context.args.install_base) + assert symlink_install == any(install_base.rglob( + 'test-package.egg-link')) + assert symlink_install != any(install_base.rglob( + 'PKG-INFO')) + assert libexec_pattern == any(install_base.rglob( + 'lib/test_package/my_command*')) + assert libexec_pattern != ( + any(install_base.rglob('bin/my_command*')) or + any(install_base.rglob('Scripts/my_command*'))) + assert data_files == any(install_base.rglob( + 'share/test_package/test-resource')) + + if not symlink_install: + pkg_info, = install_base.rglob('PKG-INFO') + assert 'Name: test-package' in pkg_info.read_text().splitlines() finally: event_loop.close() -def test_build_package(): - with TemporaryDirectory(prefix='test_colcon_') as tmp_path_str: - install_base = _test_build_package(tmp_path_str, symlink_install=False) - - assert 1 == len(list(install_base.rglob('my_module/__init__.py'))) - - pkg_info, = install_base.rglob('PKG-INFO') - assert 'Name: test-package' in pkg_info.read_text().splitlines() - - -def test_build_package_symlink(): - with TemporaryDirectory(prefix='test_colcon_') as tmp_path_str: - install_base = _test_build_package(tmp_path_str, symlink_install=True) - - assert 1 == len(list(install_base.rglob('test-package.egg-link'))) - - -def test_build_package_symlink_first(): +@pytest.mark.parametrize( + 'data_files', + [False, True]) +@pytest.mark.parametrize( + 'setup_cfg,libexec_pattern', + [(False, False), (True, False), (True, True)]) +@pytest.mark.parametrize( + 'symlink_first', + [False, True]) +def test_build_package(symlink_first, setup_cfg, libexec_pattern, data_files): with TemporaryDirectory(prefix='test_colcon_') as tmp_path_str: - install_base = _test_build_package(tmp_path_str, symlink_install=True) - - assert 1 == len(list(install_base.rglob('test-package.egg-link'))) - assert 0 == len(list(install_base.rglob('PKG-INFO'))) - - install_base = _test_build_package(tmp_path_str, symlink_install=False) - - assert 0 == len(list(install_base.rglob('test-package.egg-link'))) - assert 1 == len(list(install_base.rglob('PKG-INFO'))) - - -def test_build_package_symlink_second(): - with TemporaryDirectory(prefix='test_colcon_') as tmp_path_str: - install_base = _test_build_package(tmp_path_str, symlink_install=False) - - assert 0 == len(list(install_base.rglob('test-package.egg-link'))) - assert 1 == len(list(install_base.rglob('PKG-INFO'))) - - install_base = _test_build_package(tmp_path_str, symlink_install=True) - - assert 1 == len(list(install_base.rglob('test-package.egg-link'))) - assert 0 == len(list(install_base.rglob('PKG-INFO'))) - - -def test_build_package_libexec_pattern(): - event_loop = new_event_loop() - asyncio.set_event_loop(event_loop) - try: - with TemporaryDirectory(prefix='test_colcon_') as tmp_path_str: - tmp_path = Path(tmp_path_str) - python_build_task = PythonBuildTask() - package = PackageDescriptor(tmp_path / 'src') - package.name = 'test_package' - package.type = 'python' - - context = TaskContext( - pkg=package, - args=SimpleNamespace( - path=str(tmp_path / 'src'), - build_base=str(tmp_path / 'build'), - install_base=str(tmp_path / 'install'), - symlink_install=False, - ), - dependencies={} - ) - python_build_task.set_context(context=context) - - pkg = python_build_task.context.pkg - - pkg.path.mkdir(exist_ok=True) - (pkg.path / 'setup.py').write_text( - 'from setuptools import setup\n' - 'setup()\n' - ) - (pkg.path / 'setup.cfg').write_text( - '[metadata]\n' - 'name = test_package\n' - '[options]\n' - 'packages = find:\n' - '[options.entry_points]\n' - 'console_scripts =\n' - ' my_command = my_module:main\n' - '[develop]\n' - 'script-dir=$base/lib/test_package\n' - '[install]\n' - 'install-scripts=$base/lib/test_package\n' - ) - (pkg.path / 'my_module').mkdir(exist_ok=True) - (pkg.path / 'my_module' / '__init__.py').write_text( - 'def main():\n' - ' print("Hello, World!")\n' - ) - - rc = event_loop.run_until_complete(python_build_task.build()) - assert not rc - - install_base = Path(python_build_task.context.args.install_base) - assert list(install_base.rglob( - '**/lib/test_package/my_command*')) - finally: - event_loop.close() + _test_build_package( + tmp_path_str, symlink_install=symlink_first, + setup_cfg=setup_cfg, libexec_pattern=libexec_pattern, + data_files=data_files) + + # Test again with the symlink flag inverted to validate cleanup + _test_build_package( + tmp_path_str, symlink_install=not symlink_first, + setup_cfg=setup_cfg, libexec_pattern=libexec_pattern, + data_files=data_files) diff --git a/test/test_extension_point.py b/test/test_extension_point.py index 7111b796..96e58a0d 100644 --- a/test/test_extension_point.py +++ b/test/test_extension_point.py @@ -54,8 +54,8 @@ def iter_entry_points(*, group=None): def distributions(): return [ - Dist(iter_entry_points(group='group1')), - Dist([EntryPoint('extC', 'eC', Group2.name)]), + Dist([Group1, ExtA, ExtB]), + Dist([Group2, EntryPoint('extC', 'eC', Group2.name)]), Dist([EntryPoint('extD', 'eD', 'groupX')]), ] @@ -71,7 +71,11 @@ def test_all_extension_points(): ): # successfully load a known entry point extension_points = get_all_extension_points() - assert set(extension_points.keys()) == {'group1', 'group2'} + assert set(extension_points.keys()) == { + EXTENSION_POINT_GROUP_NAME, + 'group1', + 'group2', + } assert set(extension_points['group1'].keys()) == {'extA', 'extB'} assert extension_points['group1']['extA'][0] == 'eA'