diff --git a/.gitignore b/.gitignore index 69bf918..5169b4b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ venv/ .hypothesis/ .mutmut-cache -NewLang.pyz +dist/ +src/NewLang.egg-info/ diff --git a/Jenkinsfile b/Jenkinsfile index 42dc97f..c53b688 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,8 +16,8 @@ sh "python ./build.py" echo "Testing for Linux" sh ". ./env.sh; dobuild && domut_ci && dotest_ci" - sh "mv NewLang.pyz NewLang.linux.pyz" - archiveArtifacts artifacts: 'NewLang.linux.pyz', fingerprint: true + sh "mv dist dist.linux" + archiveArtifacts artifacts: 'dist.linux', fingerprint: true cleanWs cleanWhenAborted: false, cleanWhenFailure: false, cleanWhenNotBuilt: false, cleanWhenUnstable: false } } @@ -30,8 +30,8 @@ pwsh "python .\\build.py" echo "Testing for Windows" pwsh ".\\env.ps1; dobuild; domut_ci; dotest_ci" - pwsh "mv NewLang.pyz NewLang.windows.pyz" - archiveArtifacts artifacts: 'NewLang.windows.pyz', fingerprint: true + pwsh "mv dist dist.windows" + archiveArtifacts artifacts: 'dist.windows', fingerprint: true cleanWs cleanWhenAborted: false, cleanWhenFailure: false, cleanWhenNotBuilt: false, cleanWhenUnstable: false } } diff --git a/build.py b/build.py deleted file mode 100644 index a04a5c1..0000000 --- a/build.py +++ /dev/null @@ -1,101 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1 -# Copyright 2022 Jookia - -import pathlib -import zipfile - - -def reproducible_date(): - return (2000, 1, 1, 1, 1, 1) - - -def open_new_file(path): - path.unlink(missing_ok=True) - file = path.open("xb") - mode = path.stat().st_mode - new_mode = mode | 0o100 # Executable - path.chmod(new_mode) - return file - - -def write_shebang(file): - shebang = "#!/usr/bin/env python3\n" - file.write(shebang.encode("utf-8")) - - -def open_zip(file): - return zipfile.ZipFile( - file, mode="a", compression=zipfile.ZIP_DEFLATED, compresslevel=9 - ) - - -def close_zip(zip): - zip.close() - - -def close_file(file): - file.close() - - -def find_all_src(srcpath): - paths = srcpath.rglob("*") - new_paths = [srcpath] - for p in paths: - if "__pycache__" in p.as_posix(): - continue - if p.name[0] == ".": - continue - new_paths.append(p) - return new_paths - - -def write_zip_entry(zip, name, data, date): - info = zipfile.ZipInfo(filename=name, date_time=date) - info.create_system = 3 # UNIX - zip.writestr(info, data, compress_type=zipfile.ZIP_DEFLATED, compresslevel=9) - - -def write_main(zip, date): - name = "__main__.py" - data = "import newlang.main\nnewlang.main.wait_main(None)" - write_zip_entry(zip, name, data, date) - - -def write_dir(zip, path, name, date): - # For some reason Python needs empty files with the names of directories ending in / - name = name + "/" - data = "" - write_zip_entry(zip, name, data, date) - - -def write_file(zip, path, name, date): - file = path.open("rb") - data = file.read() - new_data = data.replace(b"\r\n", b"\n") - file.close() - write_zip_entry(zip, name, new_data, date) - - -def write_src(zip, date): - srcs = sorted(find_all_src(pathlib.Path("src/newlang"))) - for p in srcs: - name = p.relative_to("src").as_posix() - if p.is_dir(): - write_dir(zip, p, name, date) - else: - write_file(zip, p, name, date) - - -def main(): - date = reproducible_date() - file = open_new_file(pathlib.Path("NewLang.pyz")) - write_shebang(file) - zip = open_zip(file) - write_src(zip, date) - write_main(zip, date) - close_zip(zip) - close_file(file) - - -if __name__ == "__main__": - main() diff --git a/env.ps1 b/env.ps1 index d77d1a7..836f13c 100644 --- a/env.ps1 +++ b/env.ps1 @@ -37,8 +37,8 @@ # See https://github.com/PowerShell/PowerShell/issues/12218 Function Global:resetenv { rm -r venv; .\env.ps1 } -Function Global:dotidy { black src tests build.py } -Function Global:dolint { flake8 src tests build.py } +Function Global:dotidy { black src tests } +Function Global:dolint { flake8 src tests } Function Global:dotest { pytest -q -n auto -x -l --sw --hypothesis-profile=dev $args } Function Global:dotest_dev { pytest -vv -n 0 -x -l --sw --hypothesis-profile=dev $args } Function Global:dotest_ci { pytest -q -n auto --hypothesis-profile=ci } @@ -47,4 +47,4 @@ Function Global:_envps1_domut { mutmut run --paths-to-mutate "src/parse2,src/i18n.py" $args } Function Global:domut { _envps1_domut } Function Global:domut_ci { _envps1_domut --no-progress || mutmut results } -Function Global:dobuild { python build.py } +Function Global:dobuild { python -m build } diff --git a/env.sh b/env.sh index 82cbf79..c622292 100644 --- a/env.sh +++ b/env.sh @@ -28,8 +28,8 @@ unset -f activate die setup resetenv() { rm -r venv; . ./env.sh; } -dotidy() { black src tests build.py; } -dolint() { flake8 src tests build.py; } +dotidy() { black src tests; } +dolint() { flake8 src tests; } dotest() { pytest -q -n auto -x -l --sw --hypothesis-profile=dev $@; } dotest_dev() { pytest -vv -n 0 -x -l --sw --hypothesis-profile=dev $@; } dotest_ci() { pytest -q -n auto --hypothesis-profile=ci; } @@ -38,4 +38,4 @@ _envsh_domut() { mutmut run --paths-to-mutate "src/parse2,src/i18n.py" $@; } domut() { _envsh_domut; } domut_ci() { _envsh_domut --no-progress || (mutmut results; exit 1); } -dobuild() { python build.py; } +dobuild() { python -m build; } diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..ffbb977 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,16 @@ +[project] +name = "NewLang" +version = "0.0.0" +description = "A simple programming language" +readme = "README.md" +license = {text = "LGPL-2.1-only"} + +[project.urls] +homepage = "https://git.lumina-sensum.com/LuminaSensum/NewLang" + +[project.scripts] +newlang = "newlang:__main__" + +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" diff --git a/requirements.txt b/requirements.txt index 56b26bb..0e684ac 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +build black pytest pytest-randomly