diff --git a/.gitignore b/.gitignore index a864e06..e6d5c5f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ venv/ .hypothesis/ .mutmut-cache +NewLang.pyz diff --git a/build.py b/build.py new file mode 100644 index 0000000..a969153 --- /dev/null +++ b/build.py @@ -0,0 +1,54 @@ +# SPDX-License-Identifier: LGPL-2.1 +# Copyright 2022 Jookia + +import shutil +import os +import os.path +import zipapp + + +def clean_dir(zipdir): + if os.path.exists(zipdir): + shutil.rmtree(zipdir) + + +def clean_pyz(filename): + if os.path.exists(filename): + os.remove(filename) + + +def create_dir(zipdir): + os.mkdir(zipdir) + + +def copy_src(zipdir): + ignored = shutil.ignore_patterns("__pycache__", ".*") + shutil.copytree("src", zipdir + "/src", ignore=ignored) + + +def write_main(zipdir): + file = open(zipdir + "/__main__.py", "w+") + file.write("import src.main\n") + file.write("src.main.main()") + file.close() + + +def make_zip(zipdir, filename): + interp = "/usr/bin/env python3" + zipapp.create_archive(zipdir, filename, interpreter=interp, compressed=True) + + +def main(): + zipdir = "zip" + filename = "NewLang.pyz" + clean_dir(zipdir) + clean_pyz(filename) + create_dir(zipdir) + copy_src(zipdir) + write_main(zipdir) + make_zip(zipdir, filename) + clean_dir(zipdir) + + +if __name__ == "__main__": + main() diff --git a/env.ps1 b/env.ps1 index d56c423..56ce8bb 100644 --- a/env.ps1 +++ b/env.ps1 @@ -25,10 +25,11 @@ If (Test-Path -Path venv\.stamp) { Activate } Else { Setup } -Function Global:dotidy { black src tests } -Function Global:dolint { flake8 src tests } +Function Global:dotidy { black src tests build.py } +Function Global:dolint { flake8 src tests build.py } Function Global:dotest { pytest -q -n auto --hypothesis-profile=dev } Function Global:dotest_ci { pytest -q -n auto --hypothesis-profile=ci } Function Global:dotest_long { pytest -q -n auto --hypothesis-profile=long } Function Global:docheck { dotidy && dolint && dotest } Function Global:domut { mutmut run --paths-to-mutate "src/syntax.py src/tokenize.py src/parse.py" } +Function Global:dobuild { python build.py } diff --git a/env.sh b/env.sh index a80d98a..effe121 100644 --- a/env.sh +++ b/env.sh @@ -24,10 +24,11 @@ if test -e venv/.stamp; then activate; else setup; fi -dotidy() { black src tests; } -dolint() { flake8 src tests; } +dotidy() { black src tests build.py; } +dolint() { flake8 src tests build.py; } dotest() { pytest -q -n auto --hypothesis-profile=dev; } dotest_ci() { pytest -q -n auto --hypothesis-profile=ci; } dotest_long() { pytest -q -n auto --hypothesis-profile=long; } docheck() { dotidy && dolint && dotest; } domut() { mutmut run --paths-to-mutate "src/syntax.py src/tokenize.py src/parse.py"; } +dobuild() { python build.py; }