mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1666883: install-moz-phab should use pip CLI, not internal file r=firefox-build-system-reviewers,rstewart
Programmatically detecting the moz-phab location by looking at pip egg/dist files is easily subject to breakage if pip changes its internal file structure, as it did from pip 19 to pip 20. So, instead, call the (more stable) pip CLI directly and parse the output. Differential Revision: https://phabricator.services.mozilla.com/D91199
This commit is contained in:
parent
dd6fb44016
commit
0d40573061
@ -25,9 +25,9 @@ class PhabricatorCommandProvider(MachCommandBase):
|
||||
def install_moz_phab(self, force=False):
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import pkg_resources
|
||||
|
||||
existing = mozfile.which("moz-phab")
|
||||
if existing and not force:
|
||||
@ -92,13 +92,17 @@ class PhabricatorCommandProvider(MachCommandBase):
|
||||
self.log(logging.INFO, "run", {}, "Installing moz-phab")
|
||||
subprocess.run(command)
|
||||
|
||||
dist = pkg_resources.get_distribution('mozphab')
|
||||
# There isn't an elegant way of determining the CLI location of a pip-installed package.
|
||||
# The viable mechanism used here is to:
|
||||
# 1. Get the list of info about the installed package via pip
|
||||
# 2. Parse out the install location. This gives us the python environment in which the
|
||||
# package is installed
|
||||
# 3. Parse out the relative location of the cli script
|
||||
# 4. Join the two paths, and execute the script at that location
|
||||
|
||||
# "get_metadata_lines('RECORD')" shows us all the files (paths and hashes) used by this
|
||||
# package. Fetch them and strip off the hash.
|
||||
package_files = [file.split(',')[0] for file in dist.get_metadata_lines('RECORD')]
|
||||
potential_cli_paths = [file for file in package_files
|
||||
if os.path.basename(file) in ('moz-phab.exe', 'moz-phab')]
|
||||
info = subprocess.check_output([pip3, "show", "-f", "MozPhab"], universal_newlines=True)
|
||||
mozphab_package_location = re.compile(r"Location: (.*)").search(info).group(1)
|
||||
potential_cli_paths = re.compile(r"([^\s]*moz-phab(?:\.exe)?)").findall(info)
|
||||
|
||||
if len(potential_cli_paths) != 1:
|
||||
self.log(
|
||||
@ -109,5 +113,6 @@ class PhabricatorCommandProvider(MachCommandBase):
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
console_script = os.path.realpath(os.path.join(dist.location, potential_cli_paths[0]))
|
||||
console_script = os.path.realpath(os.path.join(mozphab_package_location,
|
||||
potential_cli_paths[0]))
|
||||
subprocess.run([console_script, 'install-certificate'])
|
||||
|
Loading…
Reference in New Issue
Block a user