Skip to content

Commit

Permalink
ignore yanked versions
Browse files Browse the repository at this point in the history
  • Loading branch information
wimglenn committed Mar 14, 2024
1 parent 34f323d commit d1f75de
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
30 changes: 24 additions & 6 deletions luddite.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from concurrent.futures import ThreadPoolExecutor

from packaging.requirements import Requirement, InvalidRequirement
from packaging.version import Version
from packaging.version import Version, InvalidVersion

try:
from urllib2 import Request, urlopen
Expand All @@ -23,7 +23,7 @@
sys.stdout = codecs.getwriter("utf8")(sys.stdout)


__version__ = "1.0.2"
__version__ = "1.0.4"


DEFAULT_FNAME = "requirements.txt"
Expand Down Expand Up @@ -94,10 +94,23 @@ def get_data_pypi(name, index=DEFAULT_INDEX):
return data


def _safe_version(v):
try:
return Version(v)
except InvalidVersion:
pass


def get_versions_pypi(name, index=DEFAULT_INDEX):
data = get_data_pypi(name, index)
version_numbers = sorted(data["releases"], key=Version)
return tuple(version_numbers)
versions = []
for raw_version, details in data["releases"].items():
version = _safe_version(raw_version)
if version is not None:
if any(not d.get("yanked", False) for d in details):
versions.append((version, raw_version))
versions.sort()
return tuple(v for (_, v) in versions)


def get_version_pypi(name, index=DEFAULT_INDEX):
Expand All @@ -122,8 +135,13 @@ def get_data_devpi(name, index):

def get_versions_devpi(name, index):
data = get_data_devpi(name, index)
version_numbers = sorted(data["result"], key=Version)
return tuple(version_numbers)
versions = []
for raw_version, details in data["result"].items():
version = _safe_version(raw_version)
if version is not None:
versions.append((version, raw_version))
versions.sort()
return tuple(v for (_, v) in versions)


def get_version_devpi(name, index):
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="luddite",
version="1.0.3",
version="1.0.4",
author="Wim Glenn",
author_email="hey@wimglenn.com",
url="https://github.com/jumptrading/luddite",
Expand All @@ -29,7 +29,6 @@
"pytest-cov",
"pytest-mock",
"pytest-socket",
"coveralls",
],
},
options={"bdist_wheel": {"universal": True}},
Expand Down
28 changes: 27 additions & 1 deletion test_luddite.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding: utf-8
from __future__ import unicode_literals

import json
import sys
from subprocess import CalledProcessError

Expand Down Expand Up @@ -219,7 +220,14 @@ def test_integration(tmpdir, capsys, mocker, monkeypatch):
mock_response = mocker.MagicMock()
mock_response.code = 200
mock_response.headers.get_content_charset.return_value = "utf-8"
mock_response.read.return_value = b'{"releases": ["1.0", "1.1", "1.4"]}'
releases = {
"releases": {
"1.0": [{"yanked": False}],
"1.1": [{"yanked": False}],
"1.4": [{"yanked": False}],
}
}
mock_response.read.return_value = json.dumps(releases).encode()
mocker.patch("luddite.urlopen", return_value=mock_response)
mocker.patch("sys.argv", "luddite -i http://index-from-cmdline".split())

Expand Down Expand Up @@ -264,3 +272,21 @@ def test_integration(tmpdir, capsys, mocker, monkeypatch):
distextra[x,y]==1.2.3 ! distextra 1.2.3 is not in the index (from versions: 1.0, 1.1, 1.4)
"""
)


def test_yanked_versions_skipped(mocker):
mock_response = mocker.MagicMock()
mock_response.code = 200
releases = {
"releases": {
"1.1": [{}],
"1.4": [{"yanked": False}],
"1.3": [{"yanked": True}],
"1.2": [{"yanked": False}],
}
}
mock_response.read.return_value = json.dumps(releases).encode()
mocker.patch("luddite.urlopen", return_value=mock_response)
mocker.patch("luddite.get_charset", return_value="utf-8")
vs = luddite.get_versions_pypi("dist", "http://myindex/+simple/")
assert vs == ("1.1", "1.2", "1.4")

0 comments on commit d1f75de

Please sign in to comment.