Skip to content

Commit

Permalink
Generate pypi data from version-qualified installs
Browse files Browse the repository at this point in the history
In case a PyPI package being processed is not the "current" version
listed in the PyPI catalog, make sure to `pip install` an older release
of the package corresponding to the parsed content version string.

Fixes clearlinux#652

Signed-off-by: Patrick McCarty <[email protected]>
  • Loading branch information
phmccarty committed Sep 9, 2021
1 parent 7519b26 commit e41a94a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion autospec/autospec.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def package(args, url, name, archives, workingdir):
license.scan_for_licenses(os.path.dirname(_dir), conf, name)
exit(0)

requirements.scan_for_configure(_dir, content.name, conf)
requirements.scan_for_configure(_dir, content.name, conf, content)
specdescription.scan_for_description(content.name, _dir, conf.license_translations, conf.license_blacklist)
# Start one directory higher so we scan *all* versions for licenses
license.scan_for_licenses(os.path.dirname(_dir), conf, content.name)
Expand Down
4 changes: 2 additions & 2 deletions autospec/buildreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ def parse_catkin_deps(self, cmakelists_file, conf32):
self.extra_cmake.add("-DCATKIN_BUILD_BINARY_PACKAGE=ON")
self.extra_cmake.add("-DSETUPTOOLS_DEB_LAYOUT=OFF")

def scan_for_configure(self, dirn, tname, config):
def scan_for_configure(self, dirn, tname, config, content):
"""Scan the package directory for build files to determine build pattern."""
if config.default_pattern == "distutils36":
self.add_buildreq("buildreq-distutils36")
Expand Down Expand Up @@ -902,7 +902,7 @@ def scan_for_configure(self, dirn, tname, config):
if config.alias:
tname = config.alias
pypi_name = pypidata.get_pypi_name(tname)
pypi_json = pypidata.get_pypi_metadata(pypi_name)
pypi_json = pypidata.get_pypi_metadata(pypi_name, content.version)
if pypi_json:
try:
package_pypi = json.loads(pypi_json)
Expand Down
8 changes: 6 additions & 2 deletions autospec/pypidata.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,19 @@ def get_pypi_name(name):
return name


def get_pypi_metadata(name):
def get_pypi_metadata(name, version=None):
"""Get metadata for a pypi package."""
show = []
# Create virtenv to do the pip install (needed for pip show)
with tempfile.TemporaryDirectory() as tdir:
proc = subprocess.run(["virtualenv", "--no-periodic-update", tdir], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
if proc.returncode != 0:
return ""
proc = subprocess.run(f"source bin/activate && pip install {name}", cwd=tdir, shell=True,
if version:
target = f"{name}=={version}"
else:
target = name
proc = subprocess.run(f"source bin/activate && pip install {target}", cwd=tdir, shell=True,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
env=pip_env())
if proc.returncode != 0:
Expand Down

0 comments on commit e41a94a

Please sign in to comment.