Files
cibuildwheel/test/test_projects/__main__.py
T

52 lines
1.4 KiB
Python
Raw Normal View History

from __future__ import annotations
import importlib
import subprocess
2020-07-12 12:35:30 +01:00
import sys
import tempfile
from argparse import ArgumentParser
from pathlib import Path
2024-10-22 10:16:59 -04:00
def main() -> None:
parser = ArgumentParser(
2021-05-03 11:45:43 -04:00
prog="python -m test.test_projects", description="Generate a test project to check it out"
)
2021-04-30 17:56:34 -04:00
parser.add_argument(
2021-05-03 11:45:43 -04:00
"--open",
action="store_true",
help="Open the generated project in a file explorer",
2021-04-30 17:56:34 -04:00
)
parser.add_argument(
2021-05-03 11:45:43 -04:00
"PROJECT",
help="Python path to a project object. E.g. test.test_0_basic.basic_project",
2021-04-30 17:56:34 -04:00
)
parser.add_argument(
2021-05-03 11:45:43 -04:00
"OUTPUT",
nargs="?",
help="Path to output dir. If no dir is passed, a tempdir will be generated.",
2021-04-30 17:56:34 -04:00
)
options = parser.parse_args()
2021-05-03 11:45:43 -04:00
module, _, name = options.PROJECT.rpartition(".")
project = getattr(importlib.import_module(module), name)
project_dir = Path(options.OUTPUT or tempfile.mkdtemp())
project.generate(project_dir)
2021-05-03 11:45:43 -04:00
print("Project generated at", project_dir)
print()
if options.open:
2021-05-03 11:45:43 -04:00
if sys.platform == "darwin":
subprocess.run(["open", "--", project_dir], check=True)
elif sys.platform == "linux2":
subprocess.run(["xdg-open", "--", project_dir], check=True)
elif sys.platform == "win32":
subprocess.run(["explorer", project_dir], check=True)
2021-05-03 11:45:43 -04:00
if __name__ == "__main__":
main()