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

Implement a custom distutils command to symlink data_files #592

Merged
merged 7 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
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

Check warning on line 5 in colcon_core/distutils/commands/symlink_data.py

View check run for this annotation

Codecov / codecov/patch

colcon_core/distutils/commands/symlink_data.py#L4-L5

Added lines #L4 - L5 were not covered by tests


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

Check warning on line 11 in colcon_core/distutils/commands/symlink_data.py

View check run for this annotation

Codecov / codecov/patch

colcon_core/distutils/commands/symlink_data.py#L11

Added line #L11 was not covered by tests
if kwargs.get('link'):
return super().copy_file(src, dst, **kwargs)

Check warning on line 13 in colcon_core/distutils/commands/symlink_data.py

View check run for this annotation

Codecov / codecov/patch

colcon_core/distutils/commands/symlink_data.py#L13

Added line #L13 was not covered by tests

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))

Check warning on line 18 in colcon_core/distutils/commands/symlink_data.py

View check run for this annotation

Codecov / codecov/patch

colcon_core/distutils/commands/symlink_data.py#L18

Added line #L18 was not covered by tests
else:
target = dst

Check warning on line 20 in colcon_core/distutils/commands/symlink_data.py

View check run for this annotation

Codecov / codecov/patch

colcon_core/distutils/commands/symlink_data.py#L20

Added line #L20 was not covered by tests
if os.path.exists(dst) and not os.path.islink(dst):
os.remove(target)

Check warning on line 22 in colcon_core/distutils/commands/symlink_data.py

View check run for this annotation

Codecov / codecov/patch

colcon_core/distutils/commands/symlink_data.py#L22

Added line #L22 was not covered by tests

kwargs['link'] = 'sym'
src = os.path.abspath(src)
return super().copy_file(src, dst, **kwargs)

Check warning on line 26 in colcon_core/distutils/commands/symlink_data.py

View check run for this annotation

Codecov / codecov/patch

colcon_core/distutils/commands/symlink_data.py#L24-L26

Added lines #L24 - L26 were not covered by tests
13 changes: 11 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 @@
# 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']

Check warning on line 122 in colcon_core/task/python/build.py

View check run for this annotation

Codecov / codecov/patch

colcon_core/task/python/build.py#L122

Added line #L122 was not covered by tests
if rc is not None:
cmd += ['--force']

Check warning on line 124 in colcon_core/task/python/build.py

View check run for this annotation

Codecov / codecov/patch

colcon_core/task/python/build.py#L124

Added line #L124 was not covered by tests
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

Check warning on line 133 in colcon_core/task/python/build.py

View check run for this annotation

Codecov / codecov/patch

colcon_core/task/python/build.py#L133

Added line #L133 was not covered by tests
temp_symlinks = self._symlinks_in_build(args, setup_py_data)

# invoke `setup.py develop` step in build space
Expand All @@ -142,7 +148,9 @@
'--no-deps',
]
if setup_py_data.get('data_files'):
cmd += ['install_data']
cmd += ['symlink_data']

Check warning on line 151 in colcon_core/task/python/build.py

View check run for this annotation

Codecov / codecov/patch

colcon_core/task/python/build.py#L151

Added line #L151 was not covered by tests
if rc is not None:
cottsay marked this conversation as resolved.
Show resolved Hide resolved
cmd += ['--force']

Check warning on line 153 in colcon_core/task/python/build.py

View check run for this annotation

Codecov / codecov/patch

colcon_core/task/python/build.py#L153

Added line #L153 was not covered by tests
completed = await run(
self.context, cmd, cwd=args.build_base, env=env)
finally:
Expand Down Expand Up @@ -246,6 +254,7 @@
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
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,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