summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnderson Bravalheri <andersonbravalheri@gmail.com>2022-04-03 23:08:34 +0100
committerAnderson Bravalheri <andersonbravalheri@gmail.com>2022-06-15 16:43:42 +0100
commitad803aeaeb3aa36d615193e627219c813cae16b6 (patch)
treed89c3599007f3d2f86e45369de9f811a0792c71f
parentc6106b7b5eac56f6f84174ede07aa221d5aa635d (diff)
downloadpython-setuptools-git-ad803aeaeb3aa36d615193e627219c813cae16b6.tar.gz
Change dist_info to better control output directory
-rw-r--r--setuptools/command/dist_info.py35
-rw-r--r--setuptools/tests/test_dist_info.py9
2 files changed, 35 insertions, 9 deletions
diff --git a/setuptools/command/dist_info.py b/setuptools/command/dist_info.py
index 5e38c96c..b948763d 100644
--- a/setuptools/command/dist_info.py
+++ b/setuptools/command/dist_info.py
@@ -11,6 +11,7 @@ from inspect import cleandoc
from distutils.core import Command
from distutils import log
from setuptools.extern import packaging
+from setuptools._deprecation_warning import SetuptoolsDeprecationWarning
class dist_info(Command):
@@ -19,29 +20,45 @@ class dist_info(Command):
user_options = [
('egg-base=', 'e', "directory containing .egg-info directories"
- " (default: top of the source tree)"),
+ " (default: top of the source tree)"
+ " DEPRECATED: use --output-dir."),
+ ('output-dir=', 'o', "directory inside of which the .dist-info will be"
+ "created (default: top of the source tree)"),
]
def initialize_options(self):
self.egg_base = None
+ self.output_dir = None
+ self.name = None
self.dist_info_dir = None
def finalize_options(self):
- egg_info = self.get_finalized_command('egg_info')
- egg_info.egg_base = self.egg_base
+ if self.egg_base:
+ msg = "--egg-base is deprecated for dist_info command. Use --output-dir."
+ warnings.warn(msg, SetuptoolsDeprecationWarning)
+ self.output_dir = self.egg_base or self.output_dir
+
+ dist = self.distribution
+ project_dir = dist.src_root or os.curdir
+ self.output_dir = self.output_dir or project_dir
+
+ egg_info = self.reinitialize_command('egg_info')
+ egg_info.egg_base = self.output_dir
egg_info.finalize_options()
- name = _safe(self.distribution.get_name())
- base = self.egg_base or os.curdir
- version = _version(self.distribution.get_version())
- self.dist_info_dir = os.path.join(base, f"{name}-{version}.dist-info")
self.egg_info = egg_info
- self.egg_base = egg_info.egg_base
+
+ name = _safe(dist.get_name())
+ version = _version(dist.get_version())
+ self.name = f"{name}-{version}"
+ self.dist_info_dir = os.path.join(self.output_dir, f"{self.name}.dist-info")
def run(self):
self.egg_info.run()
+ egg_info_dir = self.egg_info.egg_info
log.info("creating '{}'".format(os.path.abspath(self.dist_info_dir)))
bdist_wheel = self.get_finalized_command('bdist_wheel')
- bdist_wheel.egg2dist(self.egg_info.egg_info, self.dist_info_dir)
+ bdist_wheel.egg2dist(egg_info_dir, self.dist_info_dir)
+ assert os.path.exists(egg_info_dir) is False
def _safe(component: str) -> str:
diff --git a/setuptools/tests/test_dist_info.py b/setuptools/tests/test_dist_info.py
index 813ef51d..eb41a667 100644
--- a/setuptools/tests/test_dist_info.py
+++ b/setuptools/tests/test_dist_info.py
@@ -91,6 +91,15 @@ class TestDistInfo:
dist_info = next(tmp_path.glob("*.dist-info"))
assert dist_info.name.startswith("proj-42")
+ def test_output_dir(self, tmp_path):
+ config = "[metadata]\nname=proj\nversion=42\n"
+ (tmp_path / "setup.cfg").write_text(config, encoding="utf-8")
+ out = (tmp_path / "__out")
+ out.mkdir()
+ run_command("dist_info", "--output-dir", str(out), cwd=tmp_path)
+ assert len(list(out.glob("*.dist-info"))) == 1
+ assert len(list(tmp_path.glob("*.dist-info"))) == 0
+
class TestWheelCompatibility:
"""Make sure the .dist-info directory produced with the ``dist_info`` command