Skip to content

Commit

Permalink
Add an option for fast init and bump version "0.4.0" (#61)
Browse files Browse the repository at this point in the history
* Add an experimental option to init julia with custom sysimage which includes TyPython

* bump version "0.4.0"
  • Loading branch information
songjhaha committed Sep 16, 2022
1 parent ed5b9f9 commit 87a15e9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/simple_add.py
/jimages.py
jnumpy/TyPython
jnumpy/JNumPyEnv/Project.toml
jnumpy/JNumPyEnv/Manifest.toml

# Julia
# Files generated by invoking Julia with --code-coverage
Expand Down
2 changes: 2 additions & 0 deletions jnumpy/JNumPyEnv/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[deps]
TyPython = "9c4566a2-237d-4c69-9a5e-9d27b7d0881b"
4 changes: 4 additions & 0 deletions jnumpy/envars.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations
import pathlib
import argparse

CF_TYPY_MODE = "TYPY_MODE"
CF_TYPY_PY_APIPTR = "TYPY_PY_APIPTR"
Expand Down Expand Up @@ -28,3 +29,6 @@ class SessionCtx:
JULIA_EXE: str
DEFAULT_PROJECT_DIR: str
JULIA_START_OPTIONS: list[str]

jl_opts_parse = argparse.ArgumentParser()
jl_opts_parse.add_argument("-J", "--sysimage", type=str, default=None)
42 changes: 30 additions & 12 deletions jnumpy/init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations
import io
import os
import pathlib
import sys
import subprocess
import ctypes
Expand All @@ -18,6 +19,7 @@
TyPython_directory,
InitTools_path,
SessionCtx,
jl_opts_parse,
)

# XXX: adding an environment variable for fast debugging:
Expand Down Expand Up @@ -95,7 +97,8 @@ class JuliaError(Exception):
pass


def init_jl():
def init_jl(experimental_fast_init=False):
# if experimental_fast_init is True, assume TyPython is included in sysimage
global _eval_jl
if os.getenv(CF_TYPY_MODE) == CF_TYPY_MODE_JULIA:
return
Expand All @@ -120,22 +123,37 @@ def init_jl():
setup_julia_exe_()
jl_opts = shlex.split(os.getenv(CF_TYPY_JL_OPTS, ""))
jl_opts_proj = get_project_args()
cmd = [
SessionCtx.JULIA_EXE,
jl_opts_proj,
*jl_opts,
"--startup-file=no",
"-O0",
"--compile=min",
"-e",
julia_info_query,
]
opts, unkown_opts = jl_opts_parse.parse_known_args([jl_opts_proj, *jl_opts]) # parse arg --sysimage or -J
if experimental_fast_init:
cmd = [
SessionCtx.JULIA_EXE,
*unkown_opts,
"--startup-file=no",
"-O0",
"--compile=min",
"-e",
julia_info_query,
]
else:
cmd = [
SessionCtx.JULIA_EXE,
jl_opts_proj,
*jl_opts,
"--startup-file=no",
"-O0",
"--compile=min",
"-e",
julia_info_query,
]
bindir, libpath, sysimage, default_project_dir = subprocess.run(
cmd, check=True, capture_output=True, encoding="utf8"
).stdout.splitlines()
SessionCtx.JULIA_START_OPTIONS = [jl_opts_proj, *jl_opts]
SessionCtx.JULIA_START_OPTIONS = unkown_opts
SessionCtx.DEFAULT_PROJECT_DIR = default_project_dir

if experimental_fast_init and opts.sysimage:
sysimage_abs_paths = pathlib.Path(opts.sysimage).absolute().as_posix()
sysimage = sysimage_abs_paths
old_cwd = os.getcwd()
try:
os.chdir(os.path.dirname(os.path.abspath(libpath)))
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "julia-numpy"
version = "0.3.0"
version = "0.4.0"
description = "Writing Python C extensions in Julia within 5 minutes."
authors = ["thautwarm <twshere@outlook.com>"]
maintainers = ["songjhaha <songjh96@foxmail.com>"]
Expand Down

0 comments on commit 87a15e9

Please sign in to comment.