Skip to content
Open
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
46 changes: 25 additions & 21 deletions morgan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,20 @@ def _mirror(
if self._processed_pkgs.check(requirement):
return None

# Check if requirement is relevant for any environment
if not is_requirement_relevant(requirement, self.envs.values()):
print(f"\tSkipping {requirement}, not relevant for any environment")
self._processed_pkgs.add(requirement) # Mark as processed
return None

# Display the cause of 'Skipping...'
extras = None
if required_by:
extras = required_by.extras
print(f"[{required_by}]: {requirement}")
else:
print(f"{requirement}")

# Check if requirement is relevant for any environment
if not is_requirement_relevant(requirement, self.envs.values(), extras=extras):
print("\tSkipping, not relevant for any environment")
self._processed_pkgs.add(requirement) # Mark as processed
return None

data: dict = None

# get information about this package from the Simple API in JSON
Expand Down Expand Up @@ -278,7 +281,9 @@ def _filter_files(

# Now we only have files that satisfy the requirement, and we need to
# filter out files that do not match our environments.
files = list(filter(lambda file: self._matches_environments(file), files))
files = list(
filter(self._matches_environments, files)
) # fix: unnecessary-lambda

if len(files) == 0:
print(f"Skipping {requirement}, no file matches environments")
Expand All @@ -293,7 +298,8 @@ def _filter_files(
return files

def _matches_environments(self, fileinfo: dict) -> bool:
if req := fileinfo.get("requires-python"):
req = fileinfo.get("requires-python") # python3.7
if req:
# The Python versions in all of our environments must be supported
# by this file in order to match.
# Some packages specify their required Python versions with a simple
Expand Down Expand Up @@ -330,7 +336,7 @@ def _matches_environments(self, fileinfo: dict) -> bool:
# only skip it if it does not match any.
intrp_ver_matched = any(
map(
lambda supported_python: intrp_set.contains(supported_python),
intrp_set.contains, # fix: unnecessary-lambda
self._supported_pyversions,
)
)
Expand Down Expand Up @@ -577,18 +583,16 @@ def my_url(arg):
action="store_true",
help="Skip server copy in mirror command (default: False)",
)
(
parser.add_argument(
"-a",
"--mirror-all-versions",
dest="mirror_all_versions",
action="store_true",
help=(
"For packages listed in the [requirements] section, mirror every release "
"that matches their version specifiers. "
"Transitive dependencies still mirror only the latest matching release. "
"(Default: only the latest matching release)"
),
parser.add_argument( # fix: del unnecessary parens
"-a",
"--mirror-all-versions",
dest="mirror_all_versions",
action="store_true",
help=(
"For packages listed in the [requirements] section, mirror every release "
"that matches their version specifiers. "
"Transitive dependencies still mirror only the latest matching release. "
"(Default: only the latest matching release)"
),
)
parser.add_argument(
Expand Down
19 changes: 19 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import argparse
import hashlib
import os
import urllib.error

import packaging.requirements
import pytest
Expand Down Expand Up @@ -266,3 +267,21 @@ def test_filter_files_with_latest_version_mirrored(
)

assert self.extract_versions(filtered_files) == expected_versions

def test_skipping(self, make_mirrorer):
"""Test that requirement not skipping."""
mirrorer = make_mirrorer(mirror_all_versions=False)
required_by = packaging.requirements.Requirement("pyjwt[crypto]==2.10.1")
requirement = packaging.requirements.Requirement(
"cryptography>=3.4.0; extra == \"crypto\""
)

res = {}
try:
# if skipping then None
res = mirrorer._mirror(requirement=requirement, required_by=required_by)
except urllib.error.HTTPError as e:
# if not skipping then HTTPError
pass

assert res != None