@@ -164,11 +164,7 @@ def from_req_dict(cls, name: str, req_dict: RequirementDict) -> "Requirement":
164
164
for vcs in VCS_SCHEMA :
165
165
if vcs in req_dict :
166
166
repo = cast (str , req_dict .pop (vcs , None ))
167
- url = (
168
- vcs
169
- + "+"
170
- + VcsRequirement ._build_url_from_req_dict (name , repo , req_dict )
171
- )
167
+ url = vcs + "+" + repo
172
168
return VcsRequirement .create (name = name , vcs = vcs , url = url , ** req_dict )
173
169
if "path" in req_dict or "url" in req_dict :
174
170
return FileRequirement .create (name = name , ** req_dict )
@@ -366,33 +362,39 @@ def __post_init__(self) -> None:
366
362
if not self .vcs :
367
363
self .vcs = self .url .split ("+" , 1 )[0 ]
368
364
369
- def as_ireq (self , ** kwargs : Any ) -> InstallRequirement :
370
- ireq = super ().as_ireq (** kwargs )
371
- if not self .editable and self .revision :
372
- # For non-editable VCS requirements, commit-hash should be used as the
373
- # rev-options for InstallRequirement to consume.
374
- parsed = urlparse .urlparse (cast (Link , ireq .link ).url )
375
- new_path = "@" .join ((parsed .path .split ("@" , 1 )[0 ], self .revision ))
376
- new_url = urlparse .urlunparse (parsed ._replace (path = new_path ))
377
- ireq .link = Link (new_url )
378
- return ireq
365
+ def as_line (self ) -> str :
366
+ project_name = f"{ self .project_name } " if self .project_name else ""
367
+ extras = f"[{ ',' .join (sorted (self .extras ))} ]" if self .extras else ""
368
+ marker = self ._format_marker ()
369
+ url = url_without_fragments (self .url )
370
+ if self .revision and not self .editable :
371
+ url += f"@{ self .revision } "
372
+ elif self .ref :
373
+ url += f"@{ self .ref } "
374
+ if self .editable or self .subdirectory :
375
+ fragments = f"egg={ project_name } { extras } "
376
+ if self .subdirectory :
377
+ fragments = f"{ fragments } &subdirectory={ self .subdirectory } "
378
+ return f"{ '-e ' if self .editable else '' } { url } #{ fragments } { marker } "
379
+ delimiter = " @ " if project_name else ""
380
+ return f"{ project_name } { extras } { delimiter } { url } { marker } "
379
381
380
382
def _parse_url (self ) -> None :
381
383
vcs , url_no_vcs = self .url .split ("+" , 1 )
382
384
if url_no_vcs .startswith ("git@" ):
383
385
url_no_vcs = add_ssh_scheme_to_git_uri (url_no_vcs )
384
- self .url = f"{ vcs } +{ url_no_vcs } "
385
386
if not self .name :
386
387
self ._parse_name_from_url ()
387
- repo = url_without_fragments (url_no_vcs )
388
- ref : str | None = None
388
+ ref = self .ref
389
389
parsed = urlparse .urlparse (url_no_vcs )
390
+ path = parsed .path
390
391
fragments = dict (urlparse .parse_qsl (parsed .fragment ))
391
392
if "subdirectory" in fragments :
392
393
self .subdirectory = fragments ["subdirectory" ]
393
394
if "@" in parsed .path :
394
395
path , ref = parsed .path .split ("@" , 1 )
395
- repo = urlparse .urlunparse (parsed ._replace (path = path ))
396
+ repo = urlparse .urlunparse (parsed ._replace (path = path , fragment = "" ))
397
+ self .url = f"{ vcs } +{ repo } "
396
398
self .repo , self .ref = repo , ref # type: ignore
397
399
398
400
@staticmethod
0 commit comments