Skip to content

Commit 605492c

Browse files
author
Matthias Koeppe
committed
Merge #34434
2 parents 6d31aad + b0f638d commit 605492c

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

build/sage_bootstrap/app.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,22 @@ def update_latest(self, package_name, commit=False):
148148
"""
149149
Update a package to the latest version. This modifies the Sage sources.
150150
"""
151+
pkg = Package(package_name)
152+
dist_name = pkg.distribution_name
153+
if dist_name is None:
154+
log.debug('%s does not have Python distribution info in install-requires.txt' % pkg)
155+
return
156+
if pkg.tarball_pattern.endswith('.whl'):
157+
source = 'wheel'
158+
else:
159+
source = 'pypi'
151160
try:
152-
pypi = PyPiVersion(package_name)
161+
pypi = PyPiVersion(dist_name, source=source)
153162
except PyPiNotFound:
154-
log.debug('%s is not a pypi package', package_name)
163+
log.debug('%s is not a pypi package', dist_name)
155164
return
156165
else:
157-
pypi.update(Package(package_name))
166+
pypi.update(pkg)
158167
if commit:
159168
self.commit(package_name)
160169

build/sage_bootstrap/package.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def __init__(self, package_name):
4646
self._init_checksum()
4747
self._init_version()
4848
self._init_type()
49+
self._init_install_requires()
4950

5051
def __repr__(self):
5152
return 'Package {0}'.format(self.name)
@@ -229,6 +230,21 @@ def type(self):
229230
"""
230231
return self.__type
231232

233+
@property
234+
def distribution_name(self):
235+
"""
236+
Return the Python distribution name or ``None`` for non-Python packages
237+
"""
238+
if self.__install_requires is None:
239+
return None
240+
for line in self.__install_requires.split('\n'):
241+
line = line.strip()
242+
if line.startswith('#'):
243+
continue
244+
for part in line.split():
245+
return part
246+
return None
247+
232248
def __eq__(self, other):
233249
return self.tarball == other.tarball
234250

@@ -312,3 +328,10 @@ def _init_type(self):
312328
'base', 'standard', 'optional', 'experimental'
313329
]
314330
self.__type = package_type
331+
332+
def _init_install_requires(self):
333+
try:
334+
with open(os.path.join(self.path, 'install-requires.txt')) as f:
335+
self.__install_requires = f.read().strip()
336+
except IOError:
337+
self.__install_requires = None

0 commit comments

Comments
 (0)