Skip to content

Commit

Permalink
Ad method to access the raw project name
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Jul 13, 2021
1 parent e11c182 commit b6e2355
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
2 changes: 0 additions & 2 deletions news/9825.process.rst

This file was deleted.

8 changes: 4 additions & 4 deletions src/pip/_internal/commands/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ def output_package_listing(self, packages, options):
elif options.list_format == 'freeze':
for dist in packages:
if options.verbose >= 1:
write_output("%s==%s (%s)", dist.canonical_name,
write_output("%s==%s (%s)", dist.raw_name,
dist.version, dist.location)
else:
write_output("%s==%s", dist.canonical_name, dist.version)
write_output("%s==%s", dist.raw_name, dist.version)
elif options.list_format == 'json':
write_output(format_for_json(packages, options))

Expand Down Expand Up @@ -297,7 +297,7 @@ def format_for_columns(pkgs, options):
for proj in pkgs:
# if we're working on the 'outdated' list, separate out the
# latest_version and type
row = [proj.canonical_name, str(proj.version)]
row = [proj.raw_name, str(proj.version)]

if running_outdated:
row.append(str(proj.latest_version))
Expand All @@ -318,7 +318,7 @@ def format_for_json(packages, options):
data = []
for dist in packages:
info = {
'name': dist.canonical_name,
'name': dist.raw_name,
'version': str(dist.version),
}
if options.verbose >= 1:
Expand Down
6 changes: 3 additions & 3 deletions src/pip/_internal/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def search_packages_info(query: List[str]) -> Iterator[_PackageInfo]:

def _get_requiring_packages(current_dist: BaseDistribution) -> List[str]:
return [
dist.canonical_name
for dist in env.iter_distributions()
dist.metadata["Name"] or "UNKNOWN"
for dist in installed.values()
if current_dist.canonical_name in {
canonicalize_name(d.name) for d in dist.iter_dependencies()
}
Expand Down Expand Up @@ -132,7 +132,7 @@ def _files_from_installed_files(dist: BaseDistribution) -> Optional[Iterator[str
metadata = dist.metadata

yield _PackageInfo(
name=dist.canonical_name,
name=dist.raw_name,
version=str(dist.version),
location=dist.location or "",
requires=[req.name for req in dist.iter_dependencies()],
Expand Down
9 changes: 8 additions & 1 deletion src/pip/_internal/metadata/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,16 @@ def metadata(self) -> email.message.Message:

@property
def metadata_version(self) -> Optional[str]:
"""Value of "Metadata-Version:" in the distribution, if available."""
"""Value of "Metadata-Version:" in distribution metadata, if available."""
return self.metadata.get("Metadata-Version")

@property
def raw_name(self) -> str:
"""Value of "Name:" in distribution metadata."""
# The metadata should NEVER be missing the Name: key, but if it somehow
# does not, fall back to the known canonical name.
return self.metadata.get("Name", self.canonical_name)

def iter_dependencies(self, extras: Collection[str] = ()) -> Iterable[Requirement]:
raise NotImplementedError()

Expand Down
14 changes: 7 additions & 7 deletions tests/functional/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ def test_local_columns_flag(simple_script):

def test_multiple_exclude_and_normalization(script, tmpdir):
req_path = wheel.make_wheel(
name="Normalizable_Name", version="1.0").save_to_dir(tmpdir)
name="Normalizable-Name", version="1.0").save_to_dir(tmpdir)
script.pip("install", "--no-index", req_path)
result = script.pip("list")
print(result.stdout)
assert "normalizable-name" in result.stdout
assert "Normalizable-Name" in result.stdout
assert "pip" in result.stdout
result = script.pip("list", "--exclude", "normalizablE-namE", "--exclude", "pIp")
assert "normalizable-name" not in result.stdout
assert "Normalizable-Name" not in result.stdout
assert "pip" not in result.stdout


Expand Down Expand Up @@ -477,10 +477,10 @@ def test_not_required_flag(script, data):
'install', '-f', data.find_links, '--no-index', 'TopoRequires4'
)
result = script.pip('list', '--not-required', expect_stderr=True)
assert 'toporequires4 ' in result.stdout, str(result)
assert 'toporequires ' not in result.stdout
assert 'toporequires2 ' not in result.stdout
assert 'toporequires3 ' not in result.stdout
assert 'TopoRequires4 ' in result.stdout, str(result)
assert 'TopoRequires ' not in result.stdout
assert 'TopoRequires2 ' not in result.stdout
assert 'TopoRequires3 ' not in result.stdout


def test_list_freeze(simple_script):
Expand Down

0 comments on commit b6e2355

Please sign in to comment.