mirror of
https://github.com/pypiserver/pypiserver
synced 2024-11-09 16:45:51 +01:00
guess package names from filenames and match on those.
previously we just matched string prefixes and it could happen that pip/easy_install did install the wrong package, e.g. 'pip install zope' installed zope.interface.
This commit is contained in:
parent
9db76f7e98
commit
b651d15f36
@ -1,7 +1,7 @@
|
|||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
"""minimal PyPI like server for use with pip/easy_install"""
|
"""minimal PyPI like server for use with pip/easy_install"""
|
||||||
|
|
||||||
import os, sys, getopt, mimetypes
|
import os, sys, getopt, re, mimetypes
|
||||||
try:
|
try:
|
||||||
# get rid of "UserWarning: Module bottle was already imported from..."
|
# get rid of "UserWarning: Module bottle was already imported from..."
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
@ -17,28 +17,42 @@ mimetypes.add_type("application/octet-stream", ".egg")
|
|||||||
packages = None
|
packages = None
|
||||||
|
|
||||||
|
|
||||||
|
def guess_pkgname(path):
|
||||||
|
pkgname = re.split(r"-\d+\.", os.path.basename(path))[0]
|
||||||
|
return pkgname
|
||||||
|
|
||||||
|
|
||||||
class pkgset(object):
|
class pkgset(object):
|
||||||
def __init__(self, root):
|
def __init__(self, root):
|
||||||
self.root = root
|
self.root = root
|
||||||
|
|
||||||
|
def listdir(self):
|
||||||
|
res = []
|
||||||
|
for x in os.listdir(self.root):
|
||||||
|
if not x.startswith("."):
|
||||||
|
res.append(os.path.join(self.root, x))
|
||||||
|
return res
|
||||||
|
|
||||||
def find_packages(self, prefix=""):
|
def find_packages(self, prefix=""):
|
||||||
prefix = prefix.lower()
|
prefix = prefix.lower()
|
||||||
files = []
|
files = []
|
||||||
for x in os.listdir(self.root):
|
for x in self.listdir():
|
||||||
if not x.lower().startswith(prefix):
|
pkgname = guess_pkgname(x)
|
||||||
|
if prefix and pkgname.lower() != prefix:
|
||||||
continue
|
continue
|
||||||
fn = os.path.join(self.root, x)
|
if os.path.isfile(x):
|
||||||
if os.path.isfile(fn):
|
files.append(x[len(self.root) + 1:])
|
||||||
files.append(x)
|
|
||||||
return files
|
return files
|
||||||
|
|
||||||
def find_prefixes(self):
|
def find_prefixes(self):
|
||||||
files = self.find_packages()
|
|
||||||
prefixes = set()
|
prefixes = set()
|
||||||
for x in files:
|
for x in self.listdir():
|
||||||
parts = x.split("-")[:-1]
|
if not os.path.isfile(x):
|
||||||
for i in range(len(parts)):
|
continue
|
||||||
prefixes.add("-".join(parts[:i + 1]))
|
|
||||||
|
pkgname = guess_pkgname(x)
|
||||||
|
if pkgname:
|
||||||
|
prefixes.add(pkgname)
|
||||||
return prefixes
|
return prefixes
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user