style: activate string normalization
This commit is contained in:
committed by
Henry Schreiner
parent
d1900f6a05
commit
bda76b21cb
@@ -8,42 +8,42 @@ from pathlib import Path
|
||||
|
||||
def main():
|
||||
parser = ArgumentParser(
|
||||
prog="python -m test.test_projects", description='Generate a test project to check it out'
|
||||
prog="python -m test.test_projects", description="Generate a test project to check it out"
|
||||
)
|
||||
parser.add_argument(
|
||||
'--open',
|
||||
action='store_true',
|
||||
help='Open the generated project in a file explorer',
|
||||
"--open",
|
||||
action="store_true",
|
||||
help="Open the generated project in a file explorer",
|
||||
)
|
||||
parser.add_argument(
|
||||
'PROJECT',
|
||||
help='Python path to a project object. E.g. test.test_0_basic.basic_project',
|
||||
"PROJECT",
|
||||
help="Python path to a project object. E.g. test.test_0_basic.basic_project",
|
||||
)
|
||||
parser.add_argument(
|
||||
'OUTPUT',
|
||||
nargs='?',
|
||||
help='Path to output dir. If no dir is passed, a tempdir will be generated.',
|
||||
"OUTPUT",
|
||||
nargs="?",
|
||||
help="Path to output dir. If no dir is passed, a tempdir will be generated.",
|
||||
)
|
||||
options = parser.parse_args()
|
||||
|
||||
module, _, name = options.PROJECT.rpartition('.')
|
||||
module, _, name = options.PROJECT.rpartition(".")
|
||||
|
||||
project = getattr(importlib.import_module(module), name)
|
||||
|
||||
project_dir = Path(options.OUTPUT or tempfile.mkdtemp())
|
||||
project.generate(project_dir)
|
||||
|
||||
print('Project generated at', project_dir)
|
||||
print("Project generated at", project_dir)
|
||||
print()
|
||||
|
||||
if options.open:
|
||||
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)
|
||||
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)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -8,12 +8,12 @@ TemplateContext = Dict[str, Any]
|
||||
|
||||
|
||||
class TestProject:
|
||||
'''
|
||||
"""
|
||||
An object that represents a project that can be built by cibuildwheel.
|
||||
Can be manipulated in tests by changing `files` and `template_context`.
|
||||
|
||||
Write out to the filesystem using `generate`.
|
||||
'''
|
||||
"""
|
||||
|
||||
__test__ = False # Have pytest ignore this class on `from .test_projects import TestProject`
|
||||
|
||||
@@ -29,7 +29,7 @@ class TestProject:
|
||||
file_path = path / filename
|
||||
file_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
with file_path.open('w', encoding='utf8') as f:
|
||||
with file_path.open("w", encoding="utf8") as f:
|
||||
if isinstance(content, jinja2.Template):
|
||||
content = content.render(self.template_context)
|
||||
|
||||
|
||||
+19
-19
@@ -2,7 +2,7 @@ import jinja2
|
||||
|
||||
from .base import TestProject
|
||||
|
||||
SPAM_C_TEMPLATE = r'''
|
||||
SPAM_C_TEMPLATE = r"""
|
||||
#include <Python.h>
|
||||
|
||||
{{ spam_c_top_level_add }}
|
||||
@@ -57,9 +57,9 @@ MOD_INIT(spam)
|
||||
|
||||
MOD_RETURN(m)
|
||||
}
|
||||
'''
|
||||
"""
|
||||
|
||||
SETUP_PY_TEMPLATE = r'''
|
||||
SETUP_PY_TEMPLATE = r"""
|
||||
import sys
|
||||
from setuptools import setup, Extension
|
||||
|
||||
@@ -77,42 +77,42 @@ setup(
|
||||
)],
|
||||
{{ setup_py_setup_args_add | indent(4) }}
|
||||
)
|
||||
'''
|
||||
"""
|
||||
|
||||
SETUP_CFG_TEMPLATE = r'''
|
||||
SETUP_CFG_TEMPLATE = r"""
|
||||
[metadata]
|
||||
name = spam
|
||||
version = 0.1.0
|
||||
|
||||
{{ setup_cfg_add }}
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
def new_c_project(
|
||||
*,
|
||||
spam_c_top_level_add='',
|
||||
spam_c_function_add='',
|
||||
setup_py_add='',
|
||||
setup_py_setup_args_add='',
|
||||
setup_cfg_add='',
|
||||
spam_c_top_level_add="",
|
||||
spam_c_function_add="",
|
||||
setup_py_add="",
|
||||
setup_py_setup_args_add="",
|
||||
setup_cfg_add="",
|
||||
):
|
||||
project = TestProject()
|
||||
|
||||
project.files.update(
|
||||
{
|
||||
'spam.c': jinja2.Template(SPAM_C_TEMPLATE),
|
||||
'setup.py': jinja2.Template(SETUP_PY_TEMPLATE),
|
||||
'setup.cfg': jinja2.Template(SETUP_CFG_TEMPLATE),
|
||||
"spam.c": jinja2.Template(SPAM_C_TEMPLATE),
|
||||
"setup.py": jinja2.Template(SETUP_PY_TEMPLATE),
|
||||
"setup.cfg": jinja2.Template(SETUP_CFG_TEMPLATE),
|
||||
}
|
||||
)
|
||||
|
||||
project.template_context.update(
|
||||
{
|
||||
'spam_c_top_level_add': spam_c_top_level_add,
|
||||
'spam_c_function_add': spam_c_function_add,
|
||||
'setup_py_add': setup_py_add,
|
||||
'setup_py_setup_args_add': setup_py_setup_args_add,
|
||||
'setup_cfg_add': setup_cfg_add,
|
||||
"spam_c_top_level_add": spam_c_top_level_add,
|
||||
"spam_c_function_add": spam_c_function_add,
|
||||
"setup_py_add": setup_py_add,
|
||||
"setup_py_setup_args_add": setup_py_setup_args_add,
|
||||
"setup_cfg_add": setup_cfg_add,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user