diff options
author | Florian Bruhin <me@the-compiler.org> | 2020-11-25 14:28:18 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2020-11-25 14:30:18 +0100 |
commit | 7b35974a40d84aacdaa2028c89104649a4b88da9 (patch) | |
tree | d21ffbc94b5b192d001ecaf00893974124cdf07f | |
parent | ab2b01d2c097eb6bc2340d332f8e86e6e8e80372 (diff) | |
download | qutebrowser-7b35974a40d84aacdaa2028c89104649a4b88da9.tar.gz qutebrowser-7b35974a40d84aacdaa2028c89104649a4b88da9.zip |
scripts: Add print_command to mkvenv
-rw-r--r-- | scripts/mkvenv.py | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/scripts/mkvenv.py b/scripts/mkvenv.py index 391d75f00..271d73b93 100644 --- a/scripts/mkvenv.py +++ b/scripts/mkvenv.py @@ -28,9 +28,9 @@ import re import os import os.path import shutil -import venv +import venv as pyvenv import subprocess -from typing import List, Optional, Tuple, Dict +from typing import List, Optional, Tuple, Dict, Union sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir)) from scripts import utils, link_pyqt @@ -48,6 +48,12 @@ class Error(Exception): self.code = code +def print_command(*cmd: Union[str, pathlib.Path], venv: bool) -> None: + """Print a command being run.""" + prefix = 'venv$ ' if venv else '$ ' + utils.print_col(prefix + ' '.join([str(e) for e in cmd]), 'blue') + + def parse_args(argv: List[str] = None) -> argparse.Namespace: """Parse commandline arguments.""" parser = argparse.ArgumentParser(description=__doc__) @@ -136,7 +142,7 @@ def run_venv( def pip_install(venv_dir: pathlib.Path, *args: str) -> None: """Run a pip install command inside the virtualenv.""" arg_str = ' '.join(str(arg) for arg in args) - utils.print_col('venv$ pip install {}'.format(arg_str), 'blue') + print_command('pip install', arg_str, venv=True) run_venv(venv_dir, 'python', '-m', 'pip', 'install', *args) @@ -156,22 +162,22 @@ def delete_old_venv(venv_dir: pathlib.Path) -> None: raise Error('{} does not look like a virtualenv, cowardly refusing to ' 'remove it.'.format(venv_dir)) - utils.print_col('$ rm -r {}'.format(venv_dir), 'blue') + print_command('rm -r', venv_dir, venv=False) shutil.rmtree(str(venv_dir)) def create_venv(venv_dir: pathlib.Path, use_virtualenv: bool = False) -> None: """Create a new virtualenv.""" if use_virtualenv: - utils.print_col('$ python3 -m virtualenv {}'.format(venv_dir), 'blue') + print_command('python3 -m virtualenv', venv_dir, venv=False) try: subprocess.run([sys.executable, '-m', 'virtualenv', venv_dir], check=True) except subprocess.CalledProcessError as e: raise Error("virtualenv failed, exiting", e.returncode) else: - utils.print_col('$ python3 -m venv {}'.format(venv_dir), 'blue') - venv.create(str(venv_dir), with_pip=True) + print_command('python3 -m venv', venv_dir, venv=False) + pyvenv.create(str(venv_dir), with_pip=True) def upgrade_seed_pkgs(venv_dir: pathlib.Path) -> None: @@ -282,7 +288,7 @@ def apply_xcb_util_workaround( # This gives us a nicer path to print, and also conveniently makes sure we # didn't accidentally end up with a path outside the venv. rel_link_path = venv_dir / link_path.relative_to(venv_dir.resolve()) - utils.print_col(f'$ ln -s {libxcb_util_path} {rel_link_path}', 'blue') + print_command('ln -s', libxcb_util_path, rel_link_path, venv=False) link_path.symlink_to(libxcb_util_path) @@ -375,8 +381,7 @@ def regenerate_docs(venv_dir: pathlib.Path, a2h_args = [] script_path = pathlib.Path(__file__).parent / 'asciidoc2html.py' - utils.print_col('venv$ python3 scripts/asciidoc2html.py {}' - .format(' '.join(a2h_args)), 'blue') + print_command('python3 scripts/asciidoc2html.py', *a2h_args, venv=True) run_venv(venv_dir, 'python', str(script_path), *a2h_args) |