diff options
| author | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-06-24 12:30:30 +0100 |
|---|---|---|
| committer | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-06-24 13:53:03 +0100 |
| commit | 5b7498ba18599b0ecfea2a6541ec4a64ae8c2bae (patch) | |
| tree | 91d27bf33bd8365f36c7fd39fd258b93334e9e43 /setuptools/command | |
| parent | 7a9bc7601925b2e5743c8d821d2d1ef82277c22a (diff) | |
| download | python-setuptools-git-5b7498ba18599b0ecfea2a6541ec4a64ae8c2bae.tar.gz | |
editable_wheel: Move warnings/logging inside the strategy classes
Diffstat (limited to 'setuptools/command')
| -rw-r--r-- | setuptools/command/editable_wheel.py | 58 |
1 files changed, 40 insertions, 18 deletions
diff --git a/setuptools/command/editable_wheel.py b/setuptools/command/editable_wheel.py index c1726efb..6cfdefdd 100644 --- a/setuptools/command/editable_wheel.py +++ b/setuptools/command/editable_wheel.py @@ -280,8 +280,6 @@ class editable_wheel(Command): output_mapping: Dict[str, str], ): """Populate wheel using the "strict" ``link tree`` strategy.""" - msg = "Strict editable install will be performed using a link tree.\n" - _logger.warning(msg + _STRICT_WARNING) auxiliary_dir = _empty_dir(Path(self.project_dir, "build", build_name)) populate = _LinkTree( self.distribution, @@ -291,31 +289,21 @@ class editable_wheel(Command): outputs, output_mapping, ) - populate(wheel) - - msg = f"""\n - Strict editable installation performed using the auxiliary directory: - {auxiliary_dir} - - Please be careful to not remove this directory, otherwise you might not be able - to import/use your package. - """ - warnings.warn(msg, InformationOnly) + with populate: + populate(wheel) def _populate_static_pth(self, name: str, project_dir: Path, wheel: "WheelFile"): """Populate wheel using the "lax" ``.pth`` file strategy, for ``src-layout``.""" src_dir = self.package_dir[""] - msg = f"Editable install will be performed using .pth file to {src_dir}.\n" - _logger.warning(msg + _LAX_WARNING) populate = _StaticPth(self.distribution, name, [Path(project_dir, src_dir)]) - populate(wheel) + with populate: + populate(wheel) def _populate_finder(self, name: str, wheel: "WheelFile"): """Populate wheel using the "lax" MetaPathFinder strategy.""" - msg = "Editable install will be performed using a meta path finder.\n" - _logger.warning(msg + _LAX_WARNING) populate = _TopLevelFinder(self.distribution, name) - populate(wheel) + with populate: + populate(wheel) class _StaticPth: @@ -329,6 +317,17 @@ class _StaticPth: contents = bytes(f"{entries}\n", "utf-8") wheel.writestr(f"__editable__.{self.name}.pth", contents) + def __enter__(self): + msg = f""" + Editable install will be performed using .pth file to extend `sys.path` with: + {self.path_entries!r} + """ + _logger.warning(msg + _LAX_WARNING) + return self + + def __exit__(self, _exc_type, _exc_value, _traceback): + ... + class _LinkTree(_StaticPth): """ @@ -388,6 +387,21 @@ class _LinkTree(_StaticPth): for relative, src in mappings.items(): self._create_file(relative, src, link=link_type) + def __enter__(self): + msg = "Strict editable install will be performed using a link tree.\n" + _logger.warning(msg + _STRICT_WARNING) + return self + + def __exit__(self, _exc_type, _exc_value, _traceback): + msg = f"""\n + Strict editable installation performed using the auxiliary directory: + {self.auxiliary_dir} + + Please be careful to not remove this directory, otherwise you might not be able + to import/use your package. + """ + warnings.warn(msg, InformationOnly) + class _TopLevelFinder: def __init__(self, dist: Distribution, name: str): @@ -413,6 +427,14 @@ class _TopLevelFinder: content = bytes(f"import {finder}; {finder}.install()", "utf-8") wheel.writestr(f"__editable__.{self.name}.pth", content) + def __enter__(self): + msg = "Editable install will be performed using a meta path finder.\n" + _logger.warning(msg + _LAX_WARNING) + return self + + def __exit__(self, _exc_type, _exc_value, _traceback): + ... + def _can_symlink_files() -> bool: with TemporaryDirectory() as tmp: |
