-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a custom distutils command to symlink data_files (#592)
The default implementation of install_data will always copy files into the destination directory. When we use the 'develop' command, we actually need to specifically tell setuptools to do something with the data_files or they will be ignored. Instead of telling setuptools to use install_data as-is, we can implement a custom version of install_data that will try to symlink the files instead.
- Loading branch information
Showing
5 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
Empty file.
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,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) |
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
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