From 46a49a2499156bca345c9fa5e8c68d081b3c95fc Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Wed, 13 Apr 2022 10:04:53 +0100 Subject: [PATCH 1/5] Add dist_info_dir param to dist_info command --- setuptools/command/dist_info.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/setuptools/command/dist_info.py b/setuptools/command/dist_info.py index ca540ad119..5e38c96c26 100644 --- a/setuptools/command/dist_info.py +++ b/setuptools/command/dist_info.py @@ -24,23 +24,24 @@ class dist_info(Command): def initialize_options(self): self.egg_base = None + self.dist_info_dir = None def finalize_options(self): - pass - - def run(self): egg_info = self.get_finalized_command('egg_info') egg_info.egg_base = self.egg_base egg_info.finalize_options() - egg_info.run() name = _safe(self.distribution.get_name()) - version = _version(self.distribution.get_version()) base = self.egg_base or os.curdir - dist_info_dir = os.path.join(base, f"{name}-{version}.dist-info") - log.info("creating '{}'".format(os.path.abspath(dist_info_dir))) + 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 + def run(self): + self.egg_info.run() + log.info("creating '{}'".format(os.path.abspath(self.dist_info_dir))) bdist_wheel = self.get_finalized_command('bdist_wheel') - bdist_wheel.egg2dist(egg_info.egg_info, dist_info_dir) + bdist_wheel.egg2dist(self.egg_info.egg_info, self.dist_info_dir) def _safe(component: str) -> str: From 23790daf0787cb19e5316f6353cf725fd11234bb Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Sun, 3 Apr 2022 23:08:34 +0100 Subject: [PATCH 2/5] Change dist_info to better control output directory --- setuptools/command/dist_info.py | 35 ++++++++++++++++++++++-------- setuptools/tests/test_dist_info.py | 9 ++++++++ 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/setuptools/command/dist_info.py b/setuptools/command/dist_info.py index 5e38c96c26..b948763d5a 100644 --- a/setuptools/command/dist_info.py +++ b/setuptools/command/dist_info.py @@ -11,6 +11,7 @@ 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 813ef51d32..eb41a66775 100644 --- a/setuptools/tests/test_dist_info.py +++ b/setuptools/tests/test_dist_info.py @@ -91,6 +91,15 @@ def test_invalid_version(self, tmp_path): 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 From 225bf0d35e9b1d8535eadd63cdc088c99f72ca36 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Sun, 3 Apr 2022 23:10:06 +0100 Subject: [PATCH 3/5] Change build_meta to use --output-dir instead of --egg-base for dist-info --- setuptools/build_meta.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setuptools/build_meta.py b/setuptools/build_meta.py index 8b592fadfe..66e2602f44 100644 --- a/setuptools/build_meta.py +++ b/setuptools/build_meta.py @@ -185,7 +185,7 @@ def get_requires_for_build_sdist(self, config_settings=None): def prepare_metadata_for_build_wheel(self, metadata_directory, config_settings=None): sys.argv = sys.argv[:1] + [ - 'dist_info', '--egg-base', metadata_directory] + 'dist_info', '--output-dir', metadata_directory] with no_install_setup_requires(): self.run_setup() From 28e5cec3886c16fc457a23a42766db4dee965233 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Mon, 4 Apr 2022 01:01:06 +0100 Subject: [PATCH 4/5] Make sure output_dir exists with dist_info --- setuptools/command/dist_info.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/setuptools/command/dist_info.py b/setuptools/command/dist_info.py index b948763d5a..79647bc7fc 100644 --- a/setuptools/command/dist_info.py +++ b/setuptools/command/dist_info.py @@ -7,6 +7,7 @@ import re import warnings from inspect import cleandoc +from pathlib import Path from distutils.core import Command from distutils import log @@ -40,10 +41,11 @@ def finalize_options(self): dist = self.distribution project_dir = dist.src_root or os.curdir - self.output_dir = self.output_dir or project_dir + self.output_dir = Path(self.output_dir or project_dir) + self.output_dir.mkdir(parents=True, exist_ok=True) egg_info = self.reinitialize_command('egg_info') - egg_info.egg_base = self.output_dir + egg_info.egg_base = str(self.output_dir) egg_info.finalize_options() self.egg_info = egg_info From 84171a89335f0e4820af377a908e7585db4a0c43 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Wed, 13 Apr 2022 10:00:49 +0100 Subject: [PATCH 5/5] Avoid creating dist_info_dir before the command runs --- setuptools/command/dist_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setuptools/command/dist_info.py b/setuptools/command/dist_info.py index 79647bc7fc..aa7af48c1a 100644 --- a/setuptools/command/dist_info.py +++ b/setuptools/command/dist_info.py @@ -42,7 +42,6 @@ def finalize_options(self): dist = self.distribution project_dir = dist.src_root or os.curdir self.output_dir = Path(self.output_dir or project_dir) - self.output_dir.mkdir(parents=True, exist_ok=True) egg_info = self.reinitialize_command('egg_info') egg_info.egg_base = str(self.output_dir) @@ -55,6 +54,7 @@ def finalize_options(self): self.dist_info_dir = os.path.join(self.output_dir, f"{self.name}.dist-info") def run(self): + self.output_dir.mkdir(parents=True, exist_ok=True) self.egg_info.run() egg_info_dir = self.egg_info.egg_info log.info("creating '{}'".format(os.path.abspath(self.dist_info_dir)))