Skip to content

Commit

Permalink
Merge pull request #667 from leocardao/mr/cardao/e3-pypi-closure-mana…
Browse files Browse the repository at this point in the history
…ge-yanked

e3-pypi-closure: Add yanked management
  • Loading branch information
leocardao authored Jan 18, 2024
2 parents 966eeed + 7cc70c6 commit 24f081f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
18 changes: 18 additions & 0 deletions src/e3/python/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def url(self) -> str:
"""Return the download url."""
return self.data["url"]

@property
def is_yanked(self) -> bool:
"""Return whether the package is yanked."""
return self.data.get("yanked", False)

@property
def is_wheel(self) -> bool:
"""Return whether the package is a wheel."""
Expand Down Expand Up @@ -191,6 +196,7 @@ def __init__(
for version in self.data.get("releases", {}):
try:
v = packaging.version.parse(version)

if (not v.is_prerelease and not v.is_devrelease) or (
v.is_prerelease and self.name in pypi.allowed_prerelease
):
Expand Down Expand Up @@ -236,9 +242,15 @@ def latest_release(self) -> list[PackageFile]:
for f in all_files
if f.is_compatible_with_cpython3(self.pypi.python3_version)
and f.is_compatible_with_platforms(self.pypi.platforms)
and (not f.is_yanked or self.name in self.pypi.allowed_yanked)
]
if any((f.is_generic_wheel for f in all_files)):
all_files = [f for f in all_files if f.is_wheel]

if not all_files:
self.versions.remove(packaging.version.parse(self.latest_version))
return self.latest_release

self.releases[self.latest_version] = all_files

return self.releases[self.latest_version]
Expand Down Expand Up @@ -365,6 +377,7 @@ def __init__(
cache_file: str | None = None,
pypi_url: str = "https://pypi.org/pypi",
allowed_prerelease: list[str] | None = None,
allowed_yanked: list[str] | None = None,
) -> None:
"""Initialize a PyPI session.
Expand All @@ -375,6 +388,10 @@ def __init__(
data is cached a maximum of 24h. The cache contains results of requests to
PyPI.
:param pypi_url: set Python package registry URL. Default is PyPI
:param allowed_prerelease: list of package names authorized to be into
pre-release.
:param allowed_yanked: list of package names authorized to have yanked flags set
to true (see: PEP_592).
"""
self.cache_file = cache_file
self.cache_dir = cache_dir
Expand All @@ -385,6 +402,7 @@ def __init__(
self.requirements: set[Requirement] = set()
self.explicit_requirements: set[Requirement] = set()
self.allowed_prerelease = allowed_prerelease or []
self.allowed_yanked = allowed_yanked or []

self.platforms = platforms
self.sys_platforms = set()
Expand Down
24 changes: 18 additions & 6 deletions src/e3/python/pypiscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,40 @@ def main() -> None:
m.argument_parser.description = DESCRIPTION.strip()
m.argument_parser.add_argument("config_file", help="configuration files")
m.argument_parser.add_argument(
"--python3-version", help="Python 3 version (default:10)", type=int, default=10
"--python3-version",
type=int,
default=10,
help="python 3 version (default: %(default)s)",
)
m.argument_parser.add_argument("target_dir", help="target directory")
m.argument_parser.add_argument(
"--cache-dir", help="cache directory (default ./cache)", default="./cache"
"--cache-dir", help="cache directory (default: %(default)s)", default="./cache"
)
m.argument_parser.add_argument(
"--skip-repo-updates",
action="store_true",
help="Don't update clones in the cache",
help="don't update clones in the cache",
)
m.argument_parser.add_argument(
"--local-clones",
help="Use local clones. When set look for git clones in a directory",
help="use local clones. When set look for git clones in a directory",
default=None,
)
m.argument_parser.add_argument(
"--allow-prerelease",
dest="allowed_prerelease",
metavar="REQUIREMENT",
metavar="PACKAGE",
nargs="*",
default=None,
help="Allow to use pre-release version for some requirements",
help="allow to use pre-release version for some requirements",
)
m.argument_parser.add_argument(
"--allow-yanked",
dest="allowed_yanked",
metavar="PACKAGE",
nargs="*",
default=None,
help="allow to use yanked version for some requirements (See: PEP_592)",
)
m.parse_args()
assert m.args is not None
Expand Down Expand Up @@ -162,6 +173,7 @@ def main() -> None:
python3_version=m.args.python3_version,
platforms=config["platforms"],
allowed_prerelease=m.args.allowed_prerelease,
allowed_yanked=m.args.allowed_yanked,
) as pypi:
for wheel in local_wheels:
logging.info(f"Register wheel {wheel.path}")
Expand Down

0 comments on commit 24f081f

Please sign in to comment.