Skip to content

Commit cf18f71

Browse files
committed
Consolidated all _download_vcs methods into one.
1 parent 4d54fa7 commit cf18f71

File tree

1 file changed

+23
-45
lines changed

1 file changed

+23
-45
lines changed

setuptools/package_index.py

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""PyPI and direct package downloading."""
22

3-
import contextlib
43
import sys
54
import os
65
import re
@@ -853,10 +852,30 @@ def _resolve_vcs(url):
853852
allowed = set(['svn', 'git'] + ['hg'] * bool(sep))
854853
return next(iter({pre} & allowed), None)
855854

856-
def _download_vcs(self, url, filename):
855+
def _download_vcs(self, url, spec_filename):
857856
vcs = self._resolve_vcs(url)
858-
with contextlib.suppress(AttributeError):
859-
return getattr(self, f'_download_{vcs}')(url, filename)
857+
if not vcs:
858+
return
859+
if vcs == 'svn':
860+
raise DistutilsError(
861+
f"Invalid config, SVN download is not supported: {url}"
862+
)
863+
864+
filename, _, _ = spec_filename.partition('#')
865+
url, rev = self._vcs_split_rev_from_url(url)
866+
867+
self.info(f"Doing {vcs} clone from {url} to {filename}")
868+
os.system(f"{vcs} clone --quiet {url} {filename}")
869+
870+
co_commands = dict(
871+
git=f"git -C {filename} checkout --quiet {rev}",
872+
hg=f"hg --cwd {filename} up -C -r {rev} -q",
873+
)
874+
if rev is not None:
875+
self.info(f"Checking out {rev}")
876+
os.system(co_commands[vcs])
877+
878+
return filename
860879

861880
def _download_other(self, url, filename):
862881
scheme = urllib.parse.urlsplit(url).scheme
@@ -880,9 +899,6 @@ def _invalid_download_html(self, url, headers, filename):
880899
os.unlink(filename)
881900
raise DistutilsError(f"Unexpected HTML page found at {url}")
882901

883-
def _download_svn(self, url, _filename):
884-
raise DistutilsError(f"Invalid config, SVN download is not supported: {url}")
885-
886902
@staticmethod
887903
def _vcs_split_rev_from_url(url):
888904
"""
@@ -915,44 +931,6 @@ def _vcs_split_rev_from_url(url):
915931

916932
return resolved, rev
917933

918-
def _download_git(self, url, filename):
919-
filename = filename.split('#', 1)[0]
920-
url, rev = self._vcs_split_rev_from_url(url)
921-
922-
self.info("Doing git clone from %s to %s", url, filename)
923-
os.system("git clone --quiet %s %s" % (url, filename))
924-
925-
if rev is not None:
926-
self.info("Checking out %s", rev)
927-
os.system(
928-
"git -C %s checkout --quiet %s"
929-
% (
930-
filename,
931-
rev,
932-
)
933-
)
934-
935-
return filename
936-
937-
def _download_hg(self, url, filename):
938-
filename = filename.split('#', 1)[0]
939-
url, rev = self._vcs_split_rev_from_url(url)
940-
941-
self.info("Doing hg clone from %s to %s", url, filename)
942-
os.system("hg clone --quiet %s %s" % (url, filename))
943-
944-
if rev is not None:
945-
self.info("Updating to %s", rev)
946-
os.system(
947-
"hg --cwd %s up -C -r %s -q"
948-
% (
949-
filename,
950-
rev,
951-
)
952-
)
953-
954-
return filename
955-
956934
def debug(self, msg, *args):
957935
log.debug(msg, *args)
958936

0 commit comments

Comments
 (0)