def test_tox(): """Test requirements via tox.""" utils.print_title('Testing via tox') host_python = get_host_python('tox') req_path = os.path.join(REQ_DIR, 'requirements-tox.txt') with tempfile.TemporaryDirectory() as tmpdir: venv_dir = os.path.join(tmpdir, 'venv') tox_workdir = os.path.join(tmpdir, 'tox-workdir') venv_python = os.path.join(venv_dir, 'bin', 'python') init_venv(host_python, venv_dir, req_path) list_proc = subprocess.run([venv_python, '-m', 'tox', '--listenvs'], check=True, stdout=subprocess.PIPE, universal_newlines=True) environments = list_proc.stdout.strip().split('\n') for env in environments: with utils.gha_group('tox for {}'.format(env)): utils.print_subtitle(env) utils.print_col('venv$ tox -e {} --notest'.format(env), 'blue') subprocess.run([ venv_python, '-m', 'tox', '--workdir', tox_workdir, '-e', env, '--notest' ], check=True)
def build_requirements(name): """Build a requirements file.""" utils.print_subtitle("Building") filename = os.path.join(REQ_DIR, 'requirements-{}.txt-raw'.format(name)) host_python = get_host_python(name) with open(filename, 'r', encoding='utf-8') as f: comments = read_comments(f) with tempfile.TemporaryDirectory() as tmpdir: init_venv(host_python=host_python, venv_dir=tmpdir, requirements=filename, pre=comments['pre']) with utils.gha_group('Freezing requirements'): proc = run_pip(tmpdir, 'freeze', stdout=subprocess.PIPE) reqs = proc.stdout.decode('utf-8') if utils.ON_CI: print(reqs.strip()) outfile = get_outfile(name) with open(outfile, 'w', encoding='utf-8') as f: f.write("# This file is automatically generated by " "scripts/dev/recompile_requirements.py\n\n") for line in reqs.splitlines(): if line.startswith('qutebrowser=='): continue f.write(convert_line(line, comments) + '\n') for line in comments['add']: f.write(line + '\n') return outfile
def print_changed_files(): """Output all changed files from this run.""" diff = git_diff() if utils.ON_CI: with utils.gha_group('Raw diff'): print('\n'.join(diff)) changed_files = _get_changed_files() files_text = '\n'.join('- ' + line for line in changed_files) changes = _get_changes(diff) changes_text = '\n'.join(str(change) for change in changes) utils.print_subtitle('Files') print(files_text) print() utils.print_subtitle('Changes') print(changes_text) if utils.ON_CI: print() print('::set-output name=changed::' + files_text.replace('\n', '%0A')) table_header = [ '| Requirement | old | new |', '|-------------|-----|-----|', ] diff_table = '%0A'.join(table_header + [change.table_str() for change in changes]) print('::set-output name=diff::' + diff_table)
def init_venv(host_python, venv_dir, requirements, pre=False): """Initialize a new virtualenv and install the given packages.""" with utils.gha_group('Creating virtualenv'): utils.print_col('$ python3 -m venv {}'.format(venv_dir), 'blue') subprocess.run([host_python, '-m', 'venv', venv_dir], check=True) run_pip(venv_dir, 'install', '-U', 'pip') run_pip(venv_dir, 'install', '-U', 'setuptools', 'wheel') install_command = ['install', '-r', requirements] if pre: install_command.append('--pre') with utils.gha_group('Installing requirements'): run_pip(venv_dir, *install_command) run_pip(venv_dir, 'check')
import os.path sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) from scripts import utils code = subprocess.run( ['git', '--no-pager', 'diff', '--exit-code', '--stat', '--', 'doc'], check=False).returncode if os.environ.get('GITHUB_REF', 'refs/heads/master') != 'refs/heads/master': if code != 0: print("Docs changed but ignoring change as we're building a PR") sys.exit(0) if code != 0: print() print('The autogenerated docs changed, please run this to update them:') print(' tox -e docs') print(' git commit -am "Update docs"') print() print('(Or you have uncommitted changes, in which case you can ignore ' 'this.)') if utils.ON_CI: utils.gha_error('The autogenerated docs changed') print() with utils.gha_group('Diff'): subprocess.run(['git', '--no-pager', 'diff'], check=True) sys.exit(code)