未验证 提交 1a23305c 编写于 作者: F Frost Ming

feat. Build the wheel to find the name

上级 72c24cc6
When importing requirments from a `requirments.txt` file, build the package to find the name if not given in the URL.
import hashlib
import urllib.parse
from distlib.wheel import Wheel
from pdm.formats.base import make_array
from pdm.iostream import stream
from pdm.models.markers import Marker
from pdm.models.pip_shims import parse_requirements
from pdm.models.requirements import parse_requirement
from pdm.utils import get_finder
......@@ -26,7 +30,7 @@ def _requirement_to_str_lowercase_name(requirement):
return "".join(parts)
def ireq_as_line(ireq):
def ireq_as_line(ireq, environment):
"""Formats an `InstallRequirement` instance as a
PEP 508 dependency string.
......@@ -40,6 +44,11 @@ def ireq_as_line(ireq):
if ireq.editable:
line = "-e {}".format(ireq.link)
else:
if not ireq.req:
ireq.req = parse_requirement("dummy @" + ireq.link.url)
wheel = Wheel(environment.build(ireq))
ireq.req.name = wheel.name
line = _requirement_to_str_lowercase_name(ireq.req)
if str(ireq.req.marker) != str(ireq.markers):
......@@ -85,7 +94,8 @@ def convert_url_to_source(url, name=None):
def convert(project, filename):
ireqs, finder = parse_requirement_file(str(filename))
reqs = [ireq_as_line(ireq) for ireq in ireqs]
with stream.logging("build"):
reqs = [ireq_as_line(ireq, project.environment) for ireq in ireqs]
data = {"dependencies": make_array(reqs, True)}
settings = {}
......
......@@ -389,8 +389,6 @@ class VcsRequirement(FileRequirement):
self.url = add_ssh_scheme_to_git_uri(self.url)
if not self.name:
self._parse_name_from_url()
if not self.name:
raise RequirementError("VCS requirement must provide a 'egg=' fragment.")
repo = url_without_fragments(self.url)
ref = None
parsed = urlparse.urlparse(repo)
......
......@@ -33,6 +33,17 @@ def test_convert_requirements_file(project):
)
def test_convert_requirements_file_without_name(project, vcs):
req_file = project.root.joinpath("reqs.txt")
project.root.joinpath("reqs.txt").write_text(
"git+https://github.com/test-root/demo.git\n"
)
assert requirements.check_fingerprint(project, str(req_file))
result, _ = requirements.convert(project, str(req_file))
assert result["dependencies"] == ["demo@ git+https://github.com/test-root/demo.git"]
def test_convert_poetry(project):
golden_file = FIXTURES / "pyproject-poetry.toml"
assert poetry.check_fingerprint(project, golden_file)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册