diff options
| author | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-06-19 11:58:56 +0100 |
|---|---|---|
| committer | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-06-19 12:06:41 +0100 |
| commit | 207da8caa9e2673ab8470f78dc10901e0d60a96f (patch) | |
| tree | 3fc05e273731e15187db28c7ec044b53c0679e42 /setuptools/command | |
| parent | 84d5133b63dd6c2f64cc38ced7ec8f93f1725cac (diff) | |
| download | python-setuptools-git-207da8caa9e2673ab8470f78dc10901e0d60a96f.tar.gz | |
Make it possible for build_py to export the output mapping
Diffstat (limited to 'setuptools/command')
| -rw-r--r-- | setuptools/command/build_py.py | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index dab81327..3163752f 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -11,6 +11,8 @@ import itertools import stat import warnings from pathlib import Path +from typing import Dict, Iterator, List, Optional, Tuple + from setuptools._deprecation_warning import SetuptoolsDeprecationWarning from setuptools.extern.more_itertools import unique_everseen @@ -28,8 +30,13 @@ class build_py(orig.build_py): Also, this version of the 'build_py' command allows you to specify both 'py_modules' and 'packages' in the same setup operation. """ + editable_mode: bool = False + existing_egg_info_dir: Optional[str] = None #: Private API, internal use only. - existing_egg_info_dir = None #: Private API, setuptools internal use only. + def initialize_options(self): + super().initialize_options() + self.editable_mode = False + self.existing_egg_info_dir = None def finalize_options(self): orig.build_py.finalize_options(self) @@ -52,7 +59,8 @@ class build_py(orig.build_py): def run(self): """Build modules, packages, and copy data files to build directory""" - if not self.py_modules and not self.packages: + # if self.editable_mode or not (self.py_modules and self.packages): + if not (self.py_modules or self.packages) or self.editable_mode: return if self.py_modules: @@ -125,16 +133,41 @@ class build_py(orig.build_py): ) return self.exclude_data_files(package, src_dir, files) - def build_package_data(self): - """Copy data files into build directory""" + def get_outputs(self, include_bytecode=1) -> List[str]: + """See :class:`setuptools.commands.build.SubCommand`""" + if self.editable_mode: + return list(self.get_output_mapping().keys()) + return super().get_outputs(include_bytecode) + + def get_output_mapping(self) -> Dict[str, str]: + """See :class:`setuptools.commands.build.SubCommand`""" + mapping = itertools.chain( + self._get_package_data_output_mapping(), + self._get_module_mapping(), + ) + return dict(sorted(mapping, key=lambda x: x[0])) + + def _get_module_mapping(self) -> Iterator[Tuple[str, str]]: + """Iterate over all modules producing (dest, src) pairs.""" + for (package, module, module_file) in self.find_all_modules(): + package = package.split('.') + filename = self.get_module_outfile(self.build_lib, package, module) + yield (filename, module_file) + + def _get_package_data_output_mapping(self) -> Iterator[Tuple[str, str]]: + """Iterate over package data producing (dest, src) pairs.""" for package, src_dir, build_dir, filenames in self.data_files: for filename in filenames: target = os.path.join(build_dir, filename) - self.mkpath(os.path.dirname(target)) srcfile = os.path.join(src_dir, filename) - outf, copied = self.copy_file(srcfile, target) - make_writable(target) - srcfile = os.path.abspath(srcfile) + yield (target, srcfile) + + def build_package_data(self): + """Copy data files into build directory""" + for target, srcfile in self._get_package_data_output_mapping(): + self.mkpath(os.path.dirname(target)) + _outf, _copied = self.copy_file(srcfile, target) + make_writable(target) def analyze_manifest(self): self.manifest_files = mf = {} |
