mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
Cherry-pick requirementslib@dae7cb2
This commit is contained in:
+36
-17
@@ -168,11 +168,7 @@ class FileRequirement(BaseRequirement):
|
||||
relpath = get_converted_relative_path(path)
|
||||
except ValueError:
|
||||
relpath = None
|
||||
if link.is_artifact or link.is_wheel:
|
||||
prefer = 'file'
|
||||
else:
|
||||
prefer = 'path'
|
||||
return LinkInfo(None, prefer, relpath, path, uri, link)
|
||||
return LinkInfo(None, 'path', relpath, path, uri, link)
|
||||
|
||||
# This is an URI. We'll need to perform some elaborated parsing.
|
||||
|
||||
@@ -337,27 +333,50 @@ class FileRequirement(BaseRequirement):
|
||||
arg_dict["name"] = Wheel(link.filename).name
|
||||
elif link.egg_fragment:
|
||||
arg_dict["name"] = link.egg_fragment
|
||||
print(arg_dict)
|
||||
created = cls(**arg_dict)
|
||||
return created
|
||||
|
||||
@classmethod
|
||||
def from_pipfile(cls, name, pipfile):
|
||||
uri_key = first((k for k in ["uri", "file"] if k in pipfile))
|
||||
path = pipfile.get("path")
|
||||
uri = pipfile.get(uri_key, path)
|
||||
parsed = urlparse(uri)
|
||||
if not parsed.scheme:
|
||||
path = parsed.path
|
||||
abs_path = Path(uri).absolute().as_posix()
|
||||
uri = path_to_url(abs_path)
|
||||
link = Link(unquote(uri)) if uri else None
|
||||
# Parse the values out. After this dance we should have two variables:
|
||||
# path - Local filesystem path.
|
||||
# uri - Absolute URI that is parsable with urlsplit.
|
||||
# One of these will be a string; the other would be None.
|
||||
uri = pipfile.get('uri')
|
||||
fil = pipfile.get('file')
|
||||
path = pipfile.get('path')
|
||||
if path and uri:
|
||||
raise ValueError("do not specify both 'path' and 'uri'")
|
||||
if path and fil:
|
||||
raise ValueError("do not specify both 'path' and 'file'")
|
||||
uri = uri or fil
|
||||
if uri:
|
||||
uri = unquote(uri)
|
||||
|
||||
# Decide that scheme to use.
|
||||
# 'path' - local filesystem path.
|
||||
# 'file' - A file:// URI (possibly with VCS prefix).
|
||||
# 'uri' - Any other URI.
|
||||
if path:
|
||||
uri_scheme = 'path'
|
||||
else:
|
||||
scheme = urllib_parse.urlsplit(uri).scheme
|
||||
if not scheme or scheme.split('+', 1)[-1] == 'file':
|
||||
uri_scheme = 'file'
|
||||
else:
|
||||
uri_scheme = 'uri'
|
||||
|
||||
if not uri:
|
||||
uri = path_to_url(path)
|
||||
link = Link(uri)
|
||||
|
||||
arg_dict = {
|
||||
"name": name,
|
||||
"path": path,
|
||||
"uri": unquote(link.url_without_fragment if link else uri),
|
||||
"editable": pipfile.get("editable"),
|
||||
"uri": unquote(link.url_without_fragment),
|
||||
"editable": pipfile.get("editable", False),
|
||||
"link": link,
|
||||
"uri_scheme": uri_scheme,
|
||||
}
|
||||
return cls(**arg_dict)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user