Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editable rework dist_info to use --output-dir instead of --egg-base #9

Merged
merged 5 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setuptools/build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
44 changes: 32 additions & 12 deletions setuptools/command/dist_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import re
import warnings
from inspect import cleandoc
from pathlib import Path

from distutils.core import Command
from distutils import log
from setuptools.extern import packaging
from setuptools._deprecation_warning import SetuptoolsDeprecationWarning


class dist_info(Command):
Expand All @@ -19,28 +21,46 @@ 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):
pass
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

def run(self):
egg_info = self.get_finalized_command('egg_info')
egg_info.egg_base = self.egg_base
dist = self.distribution
project_dir = dist.src_root or os.curdir
self.output_dir = Path(self.output_dir or project_dir)

egg_info = self.reinitialize_command('egg_info')
egg_info.egg_base = str(self.output_dir)
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)))
self.egg_info = egg_info

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.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)))
bdist_wheel = self.get_finalized_command('bdist_wheel')
bdist_wheel.egg2dist(egg_info.egg_info, 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:
Expand Down
9 changes: 9 additions & 0 deletions setuptools/tests/test_dist_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down