mirror of
https://github.com/pypiserver/pypiserver
synced 2025-02-22 19:19:37 +01:00
better handling for wheel files
use pip's wheel regex. this should fix #44.
This commit is contained in:
parent
95f24b0a99
commit
af62cfbf3e
@ -45,9 +45,31 @@ def parse_version(s):
|
||||
|
||||
_archive_suffix_rx = re.compile(r"(\.zip|\.tar\.gz|\.tgz|\.tar\.bz2|-py[23]\.\d-.*|\.win-amd64-py[23]\.\d\..*|\.win32-py[23]\.\d\..*)$", re.IGNORECASE)
|
||||
|
||||
wheel_file_re = re.compile(
|
||||
r"""^(?P<namever>(?P<name>.+?)-(?P<ver>\d.*?))
|
||||
((-(?P<build>\d.*?))?-(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?)
|
||||
\.whl|\.dist-info)$""",
|
||||
re.VERBOSE)
|
||||
|
||||
|
||||
def _guess_pkgname_and_version_wheel(basename):
|
||||
m = wheel_file_re.match(basename)
|
||||
if not m:
|
||||
return None, None
|
||||
name = m.group("name")
|
||||
ver = m.group("ver")
|
||||
build = m.group("build")
|
||||
if build:
|
||||
return name, ver + "-" + build
|
||||
else:
|
||||
return name, ver
|
||||
|
||||
|
||||
def guess_pkgname_and_version(path):
|
||||
path = os.path.basename(path)
|
||||
if path.endswith(".whl"):
|
||||
return _guess_pkgname_and_version_wheel(path)
|
||||
|
||||
path = _archive_suffix_rx.sub('', path)
|
||||
if '-' not in path:
|
||||
pkgname, version = path, ''
|
||||
@ -90,10 +112,11 @@ def listdir(root):
|
||||
if not is_allowed_path(x) or not os.path.isfile(fn):
|
||||
continue
|
||||
pkgname, version = guess_pkgname_and_version(x)
|
||||
yield pkgfile(fn=fn, root=root, relfn=fn[len(root) + 1:],
|
||||
pkgname=pkgname,
|
||||
version=version,
|
||||
parsed_version=parse_version(version))
|
||||
if pkgname:
|
||||
yield pkgfile(fn=fn, root=root, relfn=fn[len(root) + 1:],
|
||||
pkgname=pkgname,
|
||||
version=version,
|
||||
parsed_version=parse_version(version))
|
||||
|
||||
|
||||
def find_packages(pkgs, prefix=""):
|
||||
|
@ -32,6 +32,7 @@ files = [
|
||||
("package-123-20000101.zip", "package-123", "20000101"),
|
||||
("pyelasticsearch-0.5-brainbot-1-20130712.zip", "pyelasticsearch", "0.5-brainbot-1-20130712"),
|
||||
("pywin32-217-cp27-none-win32.whl", "pywin32", "217"),
|
||||
("pywin32-217-55-cp27-none-win32.whl", "pywin32", "217-55"),
|
||||
("pywin32-217.1-cp27-none-win32.whl", "pywin32", "217.1"),
|
||||
("package.zip", "package", ""),
|
||||
]
|
||||
@ -40,3 +41,9 @@ files = [
|
||||
@pytest.mark.parametrize(("filename", "pkgname", "version"), files)
|
||||
def test_guess_pkgname_and_version(filename, pkgname, version):
|
||||
assert core.guess_pkgname_and_version(filename) == (pkgname, version)
|
||||
|
||||
|
||||
def test_listdir_bad_name(tmpdir):
|
||||
tmpdir.join("foo.whl").ensure()
|
||||
res = list(core.listdir(tmpdir.strpath))
|
||||
assert res == []
|
||||
|
Loading…
Reference in New Issue
Block a user