Skip to content

Commit

Permalink
Add e3-pypi-closure yanked tests
Browse files Browse the repository at this point in the history
Related to #671
  • Loading branch information
leocardao committed Jan 24, 2024
1 parent cb8ca76 commit 865e620
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 16 deletions.
6 changes: 5 additions & 1 deletion src/e3/python/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,11 @@ 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)
and (
not f.is_yanked
or self.name in self.pypi.allowed_yanked
or self.name.replace("-", "_") 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]
Expand Down
4 changes: 2 additions & 2 deletions src/e3/python/pypiscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ def main() -> None:
"--allow-prerelease",
dest="allowed_prerelease",
metavar="PACKAGE",
nargs="*",
nargs="+",
default=None,
help="allow to use pre-release version for some requirements",
)
m.argument_parser.add_argument(
"--allow-yanked",
dest="allowed_yanked",
metavar="PACKAGE",
nargs="*",
nargs="+",
default=None,
help="allow to use yanked version for some requirements (See: PEP_592)",
)
Expand Down
76 changes: 63 additions & 13 deletions tests/tests_e3/python/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
from e3.python.wheel import Wheel
from e3.os.process import Run
from e3.sys import python_script
from e3.fs import mkdir
from e3.fs import mkdir, rm
from e3.python.pypi import PyPIClosure, PyPIError

import yaml
import os
from os import listdir
from os.path import join as path_join, isfile, basename
import pytest


Expand All @@ -16,26 +17,26 @@ def generate_py_pkg_source(
mkdir(name)
if requires:
requires_str = ",".join([f'"{el}"' for el in requires])
with open(os.path.join(name, "setup.py"), "w") as fd:
with open(path_join(name, "setup.py"), "w") as fd:
fd.write("from setuptools import setup, find_packages\n")
fd.write(f"setup(name='{name}',\n")
fd.write(f" version='{version}',\n")
if requires:
fd.write(f" install_requires=[{requires_str}],\n")
fd.write(" packages=find_packages())\n")
mkdir(os.path.join(name, name))
with open(os.path.join(name, name, "__init__.py"), "w") as fd:
mkdir(path_join(name, name))
with open(path_join(name, name, "__init__.py"), "w") as fd:
fd.write(f"# This is package {name}")
return Wheel.build(source_dir=name, dest_dir=".")


def test_wheel():
wheel1 = generate_py_pkg_source("src1")
assert os.path.isfile(wheel1.path)
assert isfile(wheel1.path)
assert not wheel1.requirements

wheel2 = generate_py_pkg_source("src2", requires=["src1<=2.0.0"])
assert os.path.isfile(wheel2.path)
assert isfile(wheel2.path)
assert len(wheel2.requirements) == 1

mkdir(".cache")
Expand Down Expand Up @@ -100,7 +101,7 @@ def test_pypi_closure_tool():
+ ["--python3-version=10", "--local-clones=.", "config.yml", "dist"]
)
assert p.status == 0, p.out
file_list = set(os.listdir("dist"))
file_list = set(listdir("dist"))
assert file_list == {
"requirements.txt",
"src1-1.0.0-py3-none-any.whl",
Expand All @@ -111,15 +112,15 @@ def test_pypi_closure_tool():
def test_star_requirements():
"""Test package requirements ending with * with != operator."""
wheel1 = generate_py_pkg_source("src1", version="1.0.4")
assert os.path.isfile(wheel1.path)
assert isfile(wheel1.path)
assert not wheel1.requirements

wheel2 = generate_py_pkg_source("src2", requires=["src1!=1.0.*"])
assert os.path.isfile(wheel2.path)
assert isfile(wheel2.path)
assert len(wheel2.requirements) == 1

wheel3 = generate_py_pkg_source("src1", version="1.1.4")
assert os.path.isfile(wheel3.path)
assert isfile(wheel3.path)
assert not wheel3.requirements

mkdir(".cache")
Expand Down Expand Up @@ -153,5 +154,54 @@ def test_star_requirements():

def test_yanked(pypi_server):
with pypi_server:
print("OK")
raise AssertionError("Expected")
mkdir("cache")

with PyPIClosure(
python3_version=11,
platforms=[
"x86_64-linux",
],
cache_dir="cache",
cache_file="pypi.cache",
) as pypi:
pypi.add_requirement("setuptools_scm >= 6.2, <= 8")
all_filenames = [basename(f) for f in pypi.file_closure()]
assert "setuptools_scm-7.1.0-py3-none-any.whl" in all_filenames

rm("cache", recursive=True)
rm("pypi.cache", recursive=True)
rm("test-wheels", recursive=True)

mkdir("cache")

with PyPIClosure(
python3_version=11,
platforms=[
"x86_64-linux",
],
cache_dir="cache",
cache_file="pypi.cache",
allowed_yanked=["setuptools-scm"],
) as pypi:
pypi.add_requirement("setuptools_scm >= 6.2, <= 8")
all_filenames = [basename(f) for f in pypi.file_closure()]
assert "setuptools_scm-8.0.0-py3-none-any.whl" in all_filenames

rm("cache", recursive=True)
rm("pypi.cache", recursive=True)
rm("test-wheels", recursive=True)

mkdir("cache")

with PyPIClosure(
python3_version=11,
platforms=[
"x86_64-linux",
],
cache_dir="cache",
cache_file="pypi.cache",
allowed_yanked=["setuptools_scm"],
) as pypi:
pypi.add_requirement("setuptools_scm >= 6.2, <= 8")
all_filenames = [basename(f) for f in pypi.file_closure()]
assert "setuptools_scm-8.0.0-py3-none-any.whl" in all_filenames

0 comments on commit 865e620

Please sign in to comment.