summaryrefslogtreecommitdiff
path: root/ci/bootstrap.py
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2023-06-28 22:44:06 +0100
committerColin Watson <cjwatson@debian.org>2023-06-28 22:44:06 +0100
commit0f96ae90f194236823aa97e709f6b4935fbd69b3 (patch)
tree6558626ee51d81a80475a45ec809d8b0cabfbe50 /ci/bootstrap.py
parentbe15a5ec8a45c072c2262e3a7ce598004f8739cf (diff)
New upstream version 2.0.0
Diffstat (limited to 'ci/bootstrap.py')
-rwxr-xr-xci/bootstrap.py78
1 files changed, 36 insertions, 42 deletions
diff --git a/ci/bootstrap.py b/ci/bootstrap.py
index 2597983..f3c9a7e 100755
--- a/ci/bootstrap.py
+++ b/ci/bootstrap.py
@@ -1,64 +1,57 @@
#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-from __future__ import absolute_import
-from __future__ import print_function
-from __future__ import unicode_literals
-
import os
+import pathlib
import subprocess
import sys
-from os.path import abspath
-from os.path import dirname
-from os.path import exists
-from os.path import join
-base_path = dirname(dirname(abspath(__file__)))
+base_path: pathlib.Path = pathlib.Path(__file__).resolve().parent.parent
+templates_path = base_path / 'ci' / 'templates'
def check_call(args):
- print("+", *args)
+ print('+', *args)
subprocess.check_call(args)
def exec_in_env():
- env_path = join(base_path, ".tox", "bootstrap")
- if sys.platform == "win32":
- bin_path = join(env_path, "Scripts")
+ env_path = base_path / '.tox' / 'bootstrap'
+ if sys.platform == 'win32':
+ bin_path = env_path / 'Scripts'
else:
- bin_path = join(env_path, "bin")
- if not exists(env_path):
+ bin_path = env_path / 'bin'
+ if not env_path.exists():
import subprocess
- print("Making bootstrap env in: {0} ...".format(env_path))
+ print(f'Making bootstrap env in: {env_path} ...')
try:
- check_call([sys.executable, "-m", "venv", env_path])
+ check_call([sys.executable, '-m', 'venv', env_path])
except subprocess.CalledProcessError:
try:
- check_call([sys.executable, "-m", "virtualenv", env_path])
+ check_call([sys.executable, '-m', 'virtualenv', env_path])
except subprocess.CalledProcessError:
- check_call(["virtualenv", env_path])
- print("Installing `jinja2` into bootstrap environment...")
- check_call([join(bin_path, "pip"), "install", "jinja2", "tox"])
- python_executable = join(bin_path, "python")
- if not os.path.exists(python_executable):
- python_executable += '.exe'
+ check_call(['virtualenv', env_path])
+ print('Installing `jinja2` into bootstrap environment...')
+ check_call([bin_path / 'pip', 'install', 'jinja2', 'tox'])
+ python_executable = bin_path / 'python'
+ if not python_executable.exists():
+ python_executable = python_executable.with_suffix('.exe')
+
+ print(f'Re-executing with: {python_executable}')
+ print('+ exec', python_executable, __file__, '--no-env')
+ os.execv(python_executable, [python_executable, __file__, '--no-env'])
- print("Re-executing with: {0}".format(python_executable))
- print("+ exec", python_executable, __file__, "--no-env")
- os.execv(python_executable, [python_executable, __file__, "--no-env"])
def main():
import jinja2
- print("Project path: {0}".format(base_path))
+ print(f'Project path: {base_path}')
jinja = jinja2.Environment(
- loader=jinja2.FileSystemLoader(join(base_path, "ci", "templates")),
+ loader=jinja2.FileSystemLoader(str(templates_path)),
trim_blocks=True,
lstrip_blocks=True,
- keep_trailing_newline=True
+ keep_trailing_newline=True,
)
-
tox_environments = [
line.strip()
# 'tox' need not be installed globally, but must be importable
@@ -69,21 +62,22 @@ def main():
for line in subprocess.check_output([sys.executable, '-m', 'tox', '--listenvs'], universal_newlines=True).splitlines()
]
tox_environments = [line for line in tox_environments if line.startswith('py')]
+ for template in templates_path.rglob('*'):
+ if template.is_file():
+ template_path = template.relative_to(templates_path).as_posix()
+ destination = base_path / template_path
+ destination.parent.mkdir(parents=True, exist_ok=True)
+ destination.write_text(jinja.get_template(template_path).render(tox_environments=tox_environments))
+ print(f'Wrote {template_path}')
+ print('DONE.')
- for name in os.listdir(join("ci", "templates")):
- with open(join(base_path, name), "w") as fh:
- fh.write(jinja.get_template(name).render(tox_environments=tox_environments))
- print("Wrote {}".format(name))
- print("DONE.")
-
-if __name__ == "__main__":
+if __name__ == '__main__':
args = sys.argv[1:]
- if args == ["--no-env"]:
+ if args == ['--no-env']:
main()
elif not args:
exec_in_env()
else:
- print("Unexpected arguments {0}".format(args), file=sys.stderr)
+ print(f'Unexpected arguments: {args}', file=sys.stderr)
sys.exit(1)
-