Skip to content

Commit eb42e5c

Browse files
committed
Update _vcs_split_rev_from_url to use modern constructs.
1 parent 35ee2b4 commit eb42e5c

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

setuptools/package_index.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,8 @@ def _download_svn(self, url, _filename):
865865
@staticmethod
866866
def _vcs_split_rev_from_url(url):
867867
"""
868+
Given a possible VCS URL, return a clean URL and resolved revision if any.
869+
868870
>>> vsrfu = PackageIndex._vcs_split_rev_from_url
869871
>>> vsrfu('git+https://github.com/pypa/[email protected]#egg-info=setuptools')
870872
('https://github.com/pypa/setuptools', 'v69.0.0')
@@ -873,21 +875,24 @@ def _vcs_split_rev_from_url(url):
873875
>>> vsrfu('http://foo/bar')
874876
('http://foo/bar', None)
875877
"""
876-
scheme, netloc, path, query, frag = urllib.parse.urlsplit(url)
878+
parts = urllib.parse.urlsplit(url)
877879

878-
scheme = scheme.split('+', 1)[-1]
880+
clean_scheme = parts.scheme.split('+', 1)[-1]
879881

880882
# Some fragment identification fails
881-
path = path.split('#', 1)[0]
883+
no_fragment_path, _, _ = parts.path.partition('#')
882884

883-
rev = None
884-
if '@' in path:
885-
path, rev = path.rsplit('@', 1)
885+
pre, sep, post = no_fragment_path.rpartition('@')
886+
clean_path, rev = (pre, post) if sep else (post, None)
886887

887-
# Also, discard fragment
888-
url = urllib.parse.urlunsplit((scheme, netloc, path, query, ''))
888+
resolved = parts._replace(
889+
scheme=clean_scheme,
890+
path=clean_path,
891+
# discard the fragment
892+
fragment='',
893+
).geturl()
889894

890-
return url, rev
895+
return resolved, rev
891896

892897
def _download_git(self, url, filename):
893898
filename = filename.split('#', 1)[0]

0 commit comments

Comments
 (0)