Skip to content

Commit 6421a7c

Browse files
committed
Inject the template compiler via main parameter
This is very hacky. When packaged as a PyPI wheel, the module path to the template.py file is ".template", but when importing in a pyz file, just "template" works. Now, the importing of the template file is done at the entrypoint and is injected into the main function of the cmake_init.py file.
1 parent 26b2dd5 commit 6421a7c

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

cmake-init/__main__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
import zipfile
2121

2222
from cmake_init import main
23+
from template import compile_template
2324

2425
if __name__ == "__main__":
2526
zip = zipfile.ZipFile(os.path.dirname(__file__), "r")
2627
try:
2728
# open a dummy fd to keep the zip from being closed
2829
with zip.open("__main__.py") as dummy_fp:
29-
main(zip)
30+
main(zip, compile_template)
3031
except KeyboardInterrupt:
3132
pass

cmake-init/cmake_init.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
import sys
3232
import zipfile
3333

34-
from template import compile_template
35-
3634
__version__ = "0.26.1"
3735

3836
is_windows = os.name == "nt"
3937

38+
compile_template = None
39+
4040

4141
class Language:
4242
def __init__(self, name, types, options, default):
@@ -455,7 +455,10 @@ def get_argv(index):
455455
return ""
456456

457457

458-
def main(zip):
458+
def main(zip, template_compiler):
459+
global compile_template
460+
compile_template = template_compiler
461+
459462
# I guess this is similar to how cmake switches modes on the first flag in
460463
# the CLI, like cmake --build and cmake --install, but how to include that
461464
# in argparse's help output?

package/setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import zipfile
3131
3232
from .cmake_init import main
33+
from .template import compile_template
3334
3435
def pypi_main():
3536
zip = zipfile.ZipFile(
@@ -39,7 +40,7 @@ def pypi_main():
3940
try:
4041
# open a dummy fd to keep the zip from being closed
4142
with zip.open("templates/common/.gitignore") as dummy_fp:
42-
main(zip)
43+
main(zip, compile_template)
4344
except KeyboardInterrupt:
4445
pass
4546
""")

0 commit comments

Comments
 (0)