Skip to content

Commit

Permalink
Merge branch 'master' into update-deb-platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
cottsay committed Feb 5, 2024
2 parents e92700f + f7dfec7 commit 461ca3b
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 116 deletions.
2 changes: 1 addition & 1 deletion colcon_core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2020 Dirk Thomas
# Licensed under the Apache License, Version 2.0

__version__ = '0.15.1'
__version__ = '0.15.2'
Empty file.
Empty file.
26 changes: 26 additions & 0 deletions colcon_core/distutils/commands/symlink_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2023 Open Source Robotics Foundation, Inc.
# Licensed under the Apache License, Version 2.0

from distutils.command.install_data import install_data
import os


class symlink_data(install_data): # noqa: N801
"""Like install_data, but symlink files instead of copying."""

def copy_file(self, src, dst, **kwargs): # noqa: D102
if kwargs.get('link'):
return super().copy_file(src, dst, **kwargs)

if self.force:
# os.symlink fails if the destination exists as a regular file
if os.path.isdir(dst):
target = os.path.join(dst, os.path.basename(src))
else:
target = dst
if os.path.exists(dst) and not os.path.islink(dst):
os.remove(target)

kwargs['link'] = 'sym'
src = os.path.abspath(src)
return super().copy_file(src, dst, **kwargs)
2 changes: 1 addition & 1 deletion colcon_core/executor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
25 changes: 23 additions & 2 deletions colcon_core/task/python/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,19 @@ async def build(self, *, additional_hooks=None): # noqa: D102
# prevent installation of dependencies specified in setup.py
cmd.append('--single-version-externally-managed')
self._append_install_layout(args, cmd)
if setup_py_data.get('data_files'):
cmd += ['install_data']
if rc is not None:
cmd += ['--force']
completed = await run(
self.context, cmd, cwd=args.path, env=env)
if completed.returncode:
return completed.returncode

else:
self._undo_install(pkg, args, setup_py_data, python_lib)
rc = self._undo_install(pkg, args, setup_py_data, python_lib)
if rc:
return rc
temp_symlinks = self._symlinks_in_build(args, setup_py_data)

# invoke `setup.py develop` step in build space
Expand All @@ -142,7 +148,9 @@ async def build(self, *, additional_hooks=None): # noqa: D102
'--no-deps',
]
if setup_py_data.get('data_files'):
cmd += ['install_data']
cmd += ['symlink_data']
if rc is not None:
cmd += ['--force']
completed = await run(
self.context, cmd, cwd=args.build_base, env=env)
finally:
Expand Down Expand Up @@ -189,6 +197,12 @@ async def _get_available_commands(self, path, env):
return commands

async def _undo_develop(self, pkg, args, env):
"""
Undo a previously run 'develop' command.
:returns: None if develop was not previously detected, otherwise
an integer return code where zero indicates success.
"""
# undo previous develop if .egg-info is found and develop symlinks
egg_info = os.path.join(
args.build_base, '%s.egg-info' % pkg.name.replace('-', '_'))
Expand All @@ -207,6 +221,12 @@ async def _undo_develop(self, pkg, args, env):
return completed.returncode

def _undo_install(self, pkg, args, setup_py_data, python_lib):
"""
Undo a previously run 'install' command.
:returns: None if install was not previously detected, otherwise
an integer return code where zero indicates success.
"""
# undo previous install if install.log is found
install_log = os.path.join(args.build_base, 'install.log')
if not os.path.exists(install_log):
Expand Down Expand Up @@ -246,6 +266,7 @@ def _undo_install(self, pkg, args, setup_py_data, python_lib):
with suppress(OSError):
os.rmdir(d)
os.remove(install_log)
return 0

def _symlinks_in_build(self, args, setup_py_data):
items = ['setup.py']
Expand Down
3 changes: 3 additions & 0 deletions colcon_core/task/python/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -144,6 +145,8 @@ colcon_core.verb =
test = colcon_core.verb.test:TestVerb
console_scripts =
colcon = colcon_core.command:main
distutils.commands =
symlink_data = colcon_core.distutils.commands.symlink_data:symlink_data
pytest11 =
colcon_core_warnings_stderr = colcon_core.pytest.hooks

Expand Down
3 changes: 3 additions & 0 deletions test/spell_check.words
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ hookimpl
hookwrapper
https
importlib
importorskip
isatty
iterdir
junit
Expand All @@ -56,6 +57,7 @@ lineno
linter
linux
lstrip
minversion
mkdtemp
monkeypatch
namedtuple
Expand All @@ -79,6 +81,7 @@ purelib
pydocstyle
pytest
pytests
pythondontwritebytecode
pythonpath
pythonscriptspath
pythonwarnings
Expand Down
Loading

0 comments on commit 461ca3b

Please sign in to comment.