diff options
| author | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-08-02 18:11:45 +0100 |
|---|---|---|
| committer | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-08-03 20:49:49 +0100 |
| commit | da5af04f0a8c2ab79454e0670039e19b54f5eddc (patch) | |
| tree | 36fa3cd11677de7743c0000f657c49598c723af9 /setuptools/command | |
| parent | 0d3cf53483fb6be3a4f85d592098f75b134b5f7a (diff) | |
| download | python-setuptools-git-da5af04f0a8c2ab79454e0670039e19b54f5eddc.tar.gz | |
Add compat mode to editable install
This is only a transitional measure that can be temporarily used by
users to help them to adapt to the PEP 660 implementation.
In this commit the argument for the `editable_wheel` command is changed
from the flag form `--strict` to `--mode=strict`.
Diffstat (limited to 'setuptools/command')
| -rw-r--r-- | setuptools/command/editable_wheel.py | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/setuptools/command/editable_wheel.py b/setuptools/command/editable_wheel.py index 5e205a4d..2fb4b07d 100644 --- a/setuptools/command/editable_wheel.py +++ b/setuptools/command/editable_wheel.py @@ -18,6 +18,7 @@ import sys import traceback import warnings from contextlib import suppress +from enum import Enum from inspect import cleandoc from itertools import chain from pathlib import Path @@ -54,34 +55,57 @@ _P = TypeVar("_P", bound=_Path) _logger = logging.getLogger(__name__) +class _EditableMode(Enum): + """ + Possible editable installation modes: + a) `lenient` (new files automatically added to the package - DEFAULT) + b) `strict` (requires a new installation when files are added/removed) + c) `compat` (attempts to replicate `python setup.py develop` - DEPRECATED) + """ + STRICT = "strict" + LENIENT = "lenient" + COMPAT = "compat" # TODO: Remove `compat` after Dec/2022. + + @classmethod + def convert(cls, mode: Optional[str]) -> "_EditableMode": + if not mode: + return _EditableMode.LENIENT # default + + _mode = mode.upper() + if _mode not in _EditableMode.__members__: + raise errors.OptionError(f"Invalid editable mode: {mode!r}. Try: 'strict'.") + + return _EditableMode[_mode] + + _STRICT_WARNING = """ New or renamed files may not be automatically picked up without a new installation. """ -_LAX_WARNING = """ +_LENIENT_WARNING = """ Options like `package-data`, `include/exclude-package-data` or `packages.find.exclude/include` may have no effect. """ class editable_wheel(Command): - """Build 'editable' wheel for development""" + """Build 'editable' wheel for development. + (This command is reserved for internal use of setuptools). + """ description = "create a PEP 660 'editable' wheel" user_options = [ ("dist-dir=", "d", "directory to put final built distributions in"), ("dist-info-dir=", "I", "path to a pre-build .dist-info directory"), - ("strict", None, "perform an strict installation"), + ("mode=", None, cleandoc(_EditableMode.__doc__ or "")), ] - boolean_options = ["strict"] - def initialize_options(self): self.dist_dir = None self.dist_info_dir = None self.project_dir = None - self.strict = False + self.mode = None def finalize_options(self): dist = self.distribution @@ -267,16 +291,18 @@ class editable_wheel(Command): """Decides which strategy to use to implement an editable installation.""" build_name = f"__editable__.{name}-{tag}" project_dir = Path(self.project_dir) + mode = _EditableMode.convert(self.mode) - if self.strict or os.getenv("SETUPTOOLS_EDITABLE", None) == "strict": + if mode is _EditableMode.STRICT: auxiliary_dir = _empty_dir(Path(self.project_dir, "build", build_name)) return _LinkTree(self.distribution, name, auxiliary_dir, build_lib) packages = _find_packages(self.distribution) has_simple_layout = _simple_layout(packages, self.package_dir, project_dir) - if set(self.package_dir) == {""} and has_simple_layout: + is_compat_mode = mode is _EditableMode.COMPAT + if set(self.package_dir) == {""} and has_simple_layout or is_compat_mode: # src-layout(ish) is relatively safe for a simple pth file - src_dir = self.package_dir[""] + src_dir = self.package_dir.get("", ".") return _StaticPth(self.distribution, name, [Path(project_dir, src_dir)]) # Use a MetaPathFinder to avoid adding accidental top-level packages/modules @@ -310,7 +336,7 @@ class _StaticPth: Editable install will be performed using .pth file to extend `sys.path` with: {self.path_entries!r} """ - _logger.warning(msg + _LAX_WARNING) + _logger.warning(msg + _LENIENT_WARNING) return self def __exit__(self, _exc_type, _exc_value, _traceback): @@ -414,7 +440,7 @@ class _TopLevelFinder: def __enter__(self): msg = "Editable install will be performed using a meta path finder.\n" - _logger.warning(msg + _LAX_WARNING) + _logger.warning(msg + _LENIENT_WARNING) return self def __exit__(self, _exc_type, _exc_value, _traceback): |
