Skip to content

Commit

Permalink
Add version 1.0.3 and isolated-environment dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
zackees committed Feb 23, 2024
1 parent 33a1dca commit b636603
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ Run `./lint.sh` to find linting errors using `pylint`, `flake8` and `mypy`.
* Cross compiler toolchain images in linux:
* https://github.com/dockcross/dockcross
* MacOS images
* https://hub.docker.com/r/sickcodes/docker-osx
* https://hub.docker.com/r/sickcodes/docker-osx

# Releases

* 1.0.3: Native windows compile is available if the host is also windows.
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ keywords = ["template-python-cmd"]
license = { text = "BSD 3-Clause License" }
classifiers = ["Programming Language :: Python :: 3"]
dependencies = [
"docker-run-cmd~=1.0.10"
"docker-run-cmd~=1.0.10",
"isolated-environment"
]
# Change this with the version number bump.
version = "1.0.2"
version = "1.0.3"

[tool.setuptools]
package-dir = {"" = "src"}
Expand Down
14 changes: 12 additions & 2 deletions src/python_compile/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

from docker_run_cmd.api import docker_run

from python_compile.native_windows_build import run_native_windows_build

HERE = Path(__file__).parent
ASSETS = HERE / "assets"

Expand All @@ -31,7 +33,7 @@ def parse_args() -> argparse.Namespace:
parser.add_argument(
"--platform",
type=str,
help="If specified, then the docker platform will be used",
help="If specified, then the docker platform will be used, like linux/amd64",
required=False,
)
parser.add_argument(
Expand All @@ -51,11 +53,19 @@ def parse_args() -> argparse.Namespace:
def main() -> int:
"""Main entry point for the template_python_cmd package."""
args = parse_args()
print(args)
os_system = args.os
if not os_system:
print("You must provide an os")
return 1
if os_system == "windows":
if os.name != "nt":
print("You must run this on a windows machine")
return 1
rtn = run_native_windows_build(
app_py=args.input, requirements_txt=args.requirements
)
return rtn

dockerpath: Path = DOCKER_FILE_MAP[os_system]
assert dockerpath.exists(), f"dockerpath {dockerpath} does not exist"
py_path = args.input
Expand Down
51 changes: 51 additions & 0 deletions src/python_compile/native_windows_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import subprocess
import tempfile
from pathlib import Path

from isolated_environment import IsolatedEnvironment, Requirements

HERE = Path(__file__).parent
VENV_PATH = HERE / "nuitka_venv"

REQUIREMENTS = [
"nuitka==2.0.1",
"zstandard==0.17.0",
"chardet==5.2.0",
"ordered-set==4.1.0",
"python-dotenv==1.0.0",
"tqdm==4.66.1",
]

REQS = Requirements(REQUIREMENTS)


def run_native_windows_build(app_py: Path, requirements_txt: Path) -> int:
"""Run the native windows build."""
print("Running native windows build")
with tempfile.TemporaryDirectory() as tmp_dir:
print(f"Creating temporary directory: {tmp_dir}")
env_path = Path(tmp_dir) / "nuitka_venv"
iso_env = IsolatedEnvironment(env_path, REQS)
subprocess.run(
["pip", "install", "-r", requirements_txt],
env=iso_env.environment(),
check=True,
)
# python -m nuitka --standalone --follow-imports --onefile --lto=yes --python-flag=-OO "$@"'
subprocess.run(
[
"python",
"-m",
"nuitka",
"--mingw",
"--standalone",
"--follow-imports",
"--onefile",
"--lto=yes",
"--python-flag=-OO",
app_py,
],
env=iso_env.environment(),
check=True,
)
return 0

0 comments on commit b636603

Please sign in to comment.