Skip to content

Commit

Permalink
Make MLStyle.jl & MacroTools.jl development-time only dependencies (#83)
Browse files Browse the repository at this point in the history
* MLStyle is devonly

* make MacroTools.@q as development-only dependency

* requires Julia > 1.6
  • Loading branch information
thautwarm committed Oct 19, 2023
1 parent 8ec802c commit 1123af4
Show file tree
Hide file tree
Showing 17 changed files with 722 additions and 528 deletions.
7 changes: 2 additions & 5 deletions TyPython/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ version = "0.2.5"
IOCapture = "b5f81e59-6552-4d32-b1f0-c071b021bf89"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
IOCapture = "0.2"
MLStyle = "0.4.13"
MacroTools = "0.5"
julia = "1"
julia = "1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
24 changes: 24 additions & 0 deletions TyPython/run_devonly.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# remove *.compiled.jl in src/
import TOML
ProjName = TOML.parsefile("Project.toml")["name"]

julia_compiler = "julia"
directory = "src"

for (root, dirs, files) in walkdir(directory)
for file in files
if endswith(file, ".log")
rm(joinpath(root, file))
end
if endswith(file, ".compiled.jl")
rm(joinpath(root, file))
end
end
end

run(
Cmd(
`$julia_compiler --compile=min -O0 --project=. -e "using $ProjName"`;
env = Dict("JULIA_DEVONLY_COMPILE" => "1")
)
)
13 changes: 13 additions & 0 deletions TyPython/src/CPython.Dev.DevOnly.compiled.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This file is automatically generated by DevOnly.jl
import Serialization
import SHA
let
expected_sign = b"\xe2\xd6\xd2\xd0\xca\x7c\xf8\x2b\x76\xc3\x86\x8e\x4e\x95\x26\xe1\x17\x49\x88\x43\x1a\x94\x94\x59\x6d\x3d\xbe\x6b"
data = b"\x37\x4a\x4c\x0d\x04\x00\x00\x00\x16\x02\x01\x08\x74\x6f\x70\x6c\x65\x76\x65\x6c\x17\xe0\x01\x3b\x45\x3a\x5c\x50\x72\x6f\x6a\x65\x63\x74\x73\x5c\x47\x69\x74\x34\x5c\x6a\x6e\x75\x6d\x70\x79\x5c\x54\x79\x50\x79\x74\x68\x6f\x6e\x5c\x73\x72\x63\x5c\x43\x50\x79\x74\x68\x6f\x6e\x2e\x44\x65\x76\x2e\x44\x65\x76\x4f\x6e\x6c\x79\x2e\x6a\x6c\x16\x02\x01\x05\x6d\x61\x63\x72\x6f\x16\x03\x56\x01\x0f\x65\x78\x70\x6f\x72\x74\x5f\x70\x79\x6d\x6f\x64\x75\x6c\x65\x16\x02\x57\x01\x04\x6e\x61\x6d\x65\x01\x06\x53\x79\x6d\x62\x6f\x6c\x01\x02\x65\x78\x16\x13\x01\x05\x62\x6c\x6f\x63\x6b\x17\xe0\x2c\x02\x00\x17\xe1\x2c\x02\x00\x16\x09\x01\x05\x62\x6c\x6f\x63\x6b\x16\x01\x01\x05\x62\x6c\x6f\x63\x6b\x16\x02\x59\x01\x0b\x23\x23\x63\x61\x63\x68\x65\x23\x37\x34\x34\x01\x07\x6e\x6f\x74\x68\x69\x6e\x67\x16\x02\x59\x01\x05\x23\x23\x37\x34\x33\x01\x02\x65\x78\x17\xe2\x2c\x02\x00\x16\x02\x01\x02\x69\x66\x16\x02\x01\x02\x26\x26\x16\x03\x56\x01\x03\x69\x73\x61\x01\x05\x23\x23\x37\x34\x33\x00\x16\x16\x02\x01\x02\x26\x26\x16\x03\x01\x05\x62\x6c\x6f\x63\x6b\x16\x02\x01\x02\x69\x66\x16\x03\x56\x5b\x2c\x0b\x00\x01\x07\x6e\x6f\x74\x68\x69\x6e\x67\x16\x02\x59\x2c\x0b\x00\x16\x02\x56\x01\x04\x53\x6f\x6d\x65\x16\x02\xa4\x16\x02\x01\x01\x2e\x01\x05\x23\x23\x37\x34\x33\x1a\x01\x04\x68\x65\x61\x64\x16\x02\x01\x01\x2e\x01\x05\x23\x23\x37\x34\x33\x1a\x01\x04\x61\x72\x67\x73\x16\x02\x59\x01\x05\x23\x23\x37\x34\x35\x16\x02\x01\x01\x2e\x2c\x0b\x00\x1a\x01\x05\x76\x61\x6c\x75\x65\x16\x03\x56\x01\x03\x69\x73\x61\x01\x05\x23\x23\x37\x34\x35\x12\x00\x1c\x01\x04\x76\x61\x72\x32\x47\x12\x01\x02\x00\x10\x01\x0d\x41\x62\x73\x74\x72\x61\x63\x74\x41\x72\x72\x61\x79\x1f\x4e\x9b\x44\x00\x00\x00\x00\x10\x53\x1f\x4e\x9b\x44\x02\x00\x00\x00\x00\x01\x2c\x1c\x00\x16\x02\x01\x02\x26\x26\x16\x03\x56\x5a\x16\x02\x01\x03\x72\x65\x66\x01\x05\x23\x23\x37\x34\x35\xe0\x1a\x01\x05\x62\x6c\x6f\x63\x6b\x16\x02\x01\x02\x26\x26\x16\x02\x01\x05\x62\x6c\x6f\x63\x6b\x16\x02\x59\x01\x05\x23\x23\x37\x34\x36\x16\x02\x01\x03\x72\x65\x66\x01\x05\x23\x23\x37\x34\x35\xe1\x16\x03\x56\x01\x03\x69\x73\x61\x01\x05\x23\x23\x37\x34\x36\x12\x01\x02\x00\x2c\x1d\x00\x16\x02\x01\x02\x26\x26\x16\x02\x01\x02\x26\x26\x16\x03\x56\x5b\x16\x02\x56\x01\x05\x6e\x64\x69\x6d\x73\x01\x05\x23\x23\x37\x34\x36\xe0\x16\x03\x56\x01\x02\x3e\x3d\x16\x02\x56\x01\x06\x6c\x65\x6e\x67\x74\x68\x01\x05\x23\x23\x37\x34\x36\xdf\x16\x02\x01\x05\x62\x6c\x6f\x63\x6b\x16\x02\x59\x01\x05\x23\x23\x37\x34\x37\x16\x03\x56\x12\x01\x05\x00\x10\x01\x08\x53\x75\x62\x41\x72\x72\x61\x79\x1f\x4e\x9e\x44\x00\x00\x00\x00\x01\x05\x23\x23\x37\x34\x36\x16\x01\xa4\x16\x03\x56\x01\x01\x3a\xe0\x16\x02\x56\x01\x06\x6c\x65\x6e\x67\x74\x68\x01\x05\x23\x23\x37\x34\x36\x4d\x16\x03\x01\x05\x62\x6c\x6f\x63\x6b\x16\x02\x59\x01\x05\x73\x75\x69\x74\x65\x01\x05\x23\x23\x37\x34\x37\x16\x02\x59\x01\x0c\x23\x23\x72\x65\x74\x75\x72\x6e\x23\x37\x34\x31\x16\x00\x01\x05\x62\x6c\x6f\x63\x6b\x16\x01\x01\x0c\x73\x79\x6d\x62\x6f\x6c\x69\x63\x67\x6f\x74\x6f\x01\x11\x23\x23\x23\x23\x66\x69\x6e\x61\x6c\x23\x37\x34\x32\x23\x37\x34\x38\x17\xe3\x2c\x02\x00\x16\x02\x01\x05\x62\x6c\x6f\x63\x6b\x16\x02\x59\x2c\x39\x00\x16\x02\x01\x05\x62\x6c\x6f\x63\x6b\x17\xe4\x2c\x02\x00\x16\x02\x56\x01\x05\x65\x72\x72\x6f\x72\x39\x21\x2a\x40\x65\x78\x70\x6f\x72\x74\x5f\x70\x79\x6d\x6f\x64\x75\x6c\x65\x20\x65\x78\x70\x65\x63\x74\x73\x20\x61\x20\x62\x65\x67\x69\x6e\x2d\x65\x6e\x64\x20\x62\x6c\x6f\x63\x6b\x16\x01\x2c\x3c\x00\x2c\x3d\x00\x16\x02\x56\x34\x10\x01\x06\x23\x65\x72\x72\x6f\x72\x1f\x4e\x9e\x44\x39\x21\x5f\x6d\x61\x74\x63\x68\x69\x6e\x67\x20\x6e\x6f\x6e\x2d\x65\x78\x68\x61\x75\x73\x74\x69\x76\x65\x2c\x20\x61\x74\x20\x23\x3d\x20\x45\x3a\x5c\x50\x72\x6f\x6a\x65\x63\x74\x73\x5c\x47\x69\x74\x34\x5c\x6a\x6e\x75\x6d\x70\x79\x5c\x54\x79\x50\x79\x74\x68\x6f\x6e\x5c\x73\x72\x63\x5c\x43\x50\x79\x74\x68\x6f\x6e\x2e\x44\x65\x76\x2e\x44\x65\x76\x4f\x6e\x6c\x79\x2e\x6a\x6c\x3a\x32\x20\x3d\x23\x16\x01\x01\x0d\x73\x79\x6d\x62\x6f\x6c\x69\x63\x6c\x61\x62\x65\x6c\x2c\x3d\x00\x2c\x39\x00\x17\xe6\x2c\x02\x00\x16\x02\x59\x01\x04\x62\x6f\x64\x79\x16\x02\x56\x01\x04\x45\x78\x70\x72\x1a\x01\x05\x62\x6c\x6f\x63\x6b\x17\xe7\x2c\x02\x00\x16\x02\x59\x01\x03\x6f\x75\x74\x16\x04\x56\x01\x04\x45\x78\x70\x72\x1a\x01\x03\x6c\x65\x74\x16\x02\x56\x01\x04\x45\x78\x70\x72\x1a\x01\x05\x62\x6c\x6f\x63\x6b\x01\x04\x62\x6f\x64\x79\x17\xe8\x2c\x02\x00\x16\x02\x59\x01\x0a\x73\x79\x6d\x5f\x6d\x6f\x64\x75\x6c\x65\x16\x02\x56\x01\x06\x67\x65\x6e\x73\x79\x6d\x16\x02\x01\x06\x73\x74\x72\x69\x6e\x67\x21\x04\x6d\x6f\x64\x5f\x01\x04\x6e\x61\x6d\x65\x17\xe9\x2c\x02\x00\x16\x02\x59\x01\x0b\x6d\x6f\x64\x75\x6c\x65\x5f\x6e\x61\x6d\x65\x16\x02\x56\x01\x06\x73\x74\x72\x69\x6e\x67\x01\x04\x6e\x61\x6d\x65\x17\xea\x2c\x02\x00\x16\x03\x56\x01\x05\x70\x75\x73\x68\x21\x16\x02\x01\x01\x2e\x01\x04\x62\x6f\x64\x79\x1a\x01\x04\x61\x72\x67\x73\x16\x03\x56\x24\x1f\x4e\x9b\x44\x01\x05\x5f\x65\x78\x70\x72\x1a\x01\x05\x6c\x6f\x63\x61\x6c\x16\x04\x56\x24\x1f\x4e\x9b\x44\x01\x05\x5f\x65\x78\x70\x72\x1a\x59\x2c\x4f\x00\x16\x03\x56\x24\x1f\x4e\x9b\x44\x01\x05\x5f\x65\x78\x70\x72\x1a\x56\x16\x04\x56\x24\x1f\x4e\x9b\x44\x01\x05\x5f\x65\x78\x70\x72\x1a\x01\x01\x2e\x16\x04\x56\x24\x1f\x4e\x9b\x44\x01\x05\x5f\x65\x78\x70\x72\x1a\x56\x16\x04\x56\x24\x1f\x4e\x9b\x44\x01\x05\x5f\x65\x78\x70\x72\x1a\x01\x01\x2e\x16\x04\x56\x24\x1f\x4e\x9b\x44\x01\x05\x5f\x65\x78\x70\x72\x1a\x01\x01\x2e\x01\x07\x43\x50\x79\x74\x68\x6f\x6e\x16\x01\x01\x07\x63\x6f\x70\x79\x61\x73\x74\x1a\x1a\x01\x0b\x47\x5f\x50\x79\x42\x75\x69\x6c\x74\x69\x6e\x16\x01\x01\x07\x63\x6f\x70\x79\x61\x73\x74\x1a\x1a\x01\x0a\x5f\x5f\x69\x6d\x70\x6f\x72\x74\x5f\x5f\x16\x05\x56\x24\x1f\x4e\x9b\x44\x01\x05\x5f\x65\x78\x70\x72\x1a\x56\x01\x07\x70\x79\x5f\x63\x61\x73\x74\x01\x02\x50\x79\x21\x05\x74\x79\x70\x65\x73\x16\x01\x01\x07\x63\x6f\x70\x79\x61\x73\x74\x1a\x1a\x01\x0f\x53\x69\x6d\x70\x6c\x65\x4e\x61\x6d\x65\x73\x70\x61\x63\x65\x17\xeb\x2c\x02\x00\x16\x02\x01\x03\x66\x6f\x72\x16\x02\x59\x01\x03\x61\x72\x67\x01\x05\x73\x75\x69\x74\x65\x16\x02\x01\x05\x62\x6c\x6f\x63\x6b\x17\xec\x2c\x02\x00\x16\x09\x01\x05\x62\x6c\x6f\x63\x6b\x16\x01\x01\x05\x62\x6c\x6f\x63\x6b\x16\x02\x59\x01\x0b\x23\x23\x63\x61\x63\x68\x65\x23\x37\x35\x32\x01\x07\x6e\x6f\x74\x68\x69\x6e\x67\x16\x02\x59\x01\x05\x23\x23\x37\x35\x31\x01\x03\x61\x72\x67\x16\x02\x01\x02\x69\x66\x16\x03\x56\x01\x03\x69\x73\x61\x01\x05\x23\x23\x37\x35\x31\x00\x16\x16\x02\x01\x05\x62\x6c\x6f\x63\x6b\x17\xed\x2c\x02\x00\x16\x02\x01\x02\x69\x66\x16\x02\x01\x02\x26\x26\x16\x03\x01\x05\x62\x6c\x6f\x63\x6b\x16\x02\x01\x02\x69\x66\x16\x03\x56\x5b\x2c\x6b\x00\x01\x07\x6e\x6f\x74\x68\x69\x6e\x67\x16\x02\x59\x2c\x6b\x00\x16\x02\x56\x01\x04\x53\x6f\x6d\x65\x16\x02\xa4\x16\x02\x01\x01\x2e\x01\x05\x23\x23\x37\x35\x31\x1a\x01\x04\x68\x65\x61\x64\x16\x02\x01\x01\x2e\x01\x05\x23\x23\x37\x35\x31\x1a\x01\x04\x61\x72\x67\x73\x16\x02\x59\x01\x05\x23\x23\x37\x35\x33\x16\x02\x01\x01\x2e\x2c\x6b\x00\x1a\x01\x05\x76\x61\x6c\x75\x65\x16\x03\x56\x01\x03\x69\x73\x61\x01\x05\x23\x23\x37\x35\x33\x12\x00\x1c\x01\x04\x76\x61\x72\x32\x47\x12\x01\x02\x00\x2c\x1d\x00\x10\x53\x1f\x4e\x9b\x44\x02\x00\x00\x00\x00\x01\x2c\x7d\x00\x16\x02\x01\x02\x26\x26\x16\x03\x56\x5a\x16\x02\x01\x03\x72\x65\x66\x01\x05\x23\x23\x37\x35\x33\xe0\x1a\x59\x16\x02\x01\x02\x26\x26\x16\x02\x01\x05\x62\x6c\x6f\x63\x6b\x16\x02\x59\x01\x05\x23\x23\x37\x35\x34\x16\x02\x01\x03\x72\x65\x66\x01\x05\x23\x23\x37\x35\x33\xe1\x16\x03\x56\x01\x03\x69\x73\x61\x01\x05\x23\x23\x37\x35\x34\x12\x01\x02\x00\x2c\x1d\x00\x16\x02\x01\x02\x26\x26\x16\x03\x56\x5b\x16\x02\x56\x01\x06\x6c\x65\x6e\x67\x74\x68\x01\x05\x23\x23\x37\x35\x34\xe1\x16\x03\x01\x05\x62\x6c\x6f\x63\x6b\x16\x02\x59\x01\x05\x23\x23\x37\x35\x35\x16\x02\x01\x03\x72\x65\x66\x01\x05\x23\x23\x37\x35\x34\xe0\x16\x02\x59\x01\x05\x23\x23\x37\x35\x36\x16\x02\x01\x03\x72\x65\x66\x01\x05\x23\x23\x37\x35\x34\xe1\x4d\x16\x04\x01\x05\x62\x6c\x6f\x63\x6b\x16\x02\x59\x01\x05\x76\x61\x6c\x75\x65\x01\x05\x23\x23\x37\x35\x36\x16\x02\x59\x01\x04\x6e\x61\x6d\x65\x01\x05\x23\x23\x37\x35\x35\x16\x02\x59\x01\x0c\x23\x23\x72\x65\x74\x75\x72\x6e\x23\x37\x34\x39\x16\x02\x01\x05\x62\x6c\x6f\x63\x6b\x17\xee\x2c\x02\x00\x16\x03\x56\x01\x05\x70\x75\x73\x68\x21\x16\x02\x01\x01\x2e\x01\x04\x62\x6f\x64\x79\x1a\x01\x04\x61\x72\x67\x73\x16\x04\x56\x24\x1f\x4e\x9b\x44\x01\x05\x5f\x65\x78\x70\x72\x1a\x59\x16\x04\x56\x24\x1f\x4e\x9b\x44\x01\x05\x5f\x65\x78\x70\x72\x1a\x01\x01\x2e\x2c\x4f\x00\x16\x02\x56\x24\x1f\x4e\x9b\x44\x01\x09\x51\x75\x6f\x74\x65\x4e\x6f\x64\x65\x01\x04\x6e\x61\x6d\x65\x16\x05\x56\x24\x1f\x4e\x9b\x44\x01\x05\x5f\x65\x78\x70\x72\x1a\x56\x01\x07\x70\x79\x5f\x63\x61\x73\x74\x01\x02\x50\x79\x01\x05\x76\x61\x6c\x75\x65\x16\x01\x2c\x3c\x00\x01\x11\x23\x23\x23\x23\x66\x69\x6e\x61\x6c\x23\x37\x35\x30\x23\x37\x35\x37\x16\x02\x01\x02\x69\x66\x16\x03\x56\x01\x03\x69\x73\x61\x01\x05\x23\x23\x37\x35\x31\x00\x17\x16\x02\x01\x05\x62\x6c\x6f\x63\x6b\x17\xef\x2c\x02\x00\x16\x02\x01\x05\x62\x6c\x6f\x63\x6b\x16\x02\x59\x2c\x93\x00\x16\x02\x01\x05\x62\x6c\x6f\x63\x6b\x17\xf0\x2c\x02\x00\x16\x03\x56\x01\x05\x70\x75\x73\x68\x21\x16\x02\x01\x01\x2e\x01\x04\x62\x6f\x64\x79\x1a\x01\x04\x61\x72\x67\x73\x01\x03\x61\x72\x67\x16\x01\x2c\x3c\x00\x2c\x9d\x00\x17\xf1\x2c\x02\x00\x16\x02\x01\x05\x62\x6c\x6f\x63\x6b\x16\x02\x59\x2c\x93\x00\x16\x02\x01\x05\x62\x6c\x6f\x63\x6b\x17\xf2\x2c\x02\x00\x16\x02\x56\x01\x05\x65\x72\x72\x6f\x72\x39\x21\x3d\x40\x65\x78\x70\x6f\x72\x74\x5f\x70\x79\x6d\x6f\x64\x75\x6c\x65\x20\x65\x78\x70\x65\x63\x74\x73\x20\x61\x20\x62\x6c\x6f\x63\x6b\x20\x6f\x66\x20\x60\x6e\x61\x6d\x65\x20\x3d\x20\x76\x61\x6c\x75\x65\x60\x20\x73\x74\x61\x74\x65\x6d\x65\x6e\x74\x73\x16\x01\x2c\x3c\x00\x2c\x9d\x00\x16\x02\x56\x34\x2c\x45\x00\x39\x21\x60\x6d\x61\x74\x63\x68\x69\x6e\x67\x20\x6e\x6f\x6e\x2d\x65\x78\x68\x61\x75\x73\x74\x69\x76\x65\x2c\x20\x61\x74\x20\x23\x3d\x20\x45\x3a\x5c\x50\x72\x6f\x6a\x65\x63\x74\x73\x5c\x47\x69\x74\x34\x5c\x6a\x6e\x75\x6d\x70\x79\x5c\x54\x79\x50\x79\x74\x68\x6f\x6e\x5c\x73\x72\x63\x5c\x43\x50\x79\x74\x68\x6f\x6e\x2e\x44\x65\x76\x2e\x44\x65\x76\x4f\x6e\x6c\x79\x2e\x6a\x6c\x3a\x31\x33\x20\x3d\x23\x16\x01\x2c\x48\x00\x2c\x9d\x00\x2c\x93\x00\x17\xf5\x2c\x02\x00\x16\x03\x56\x01\x05\x70\x75\x73\x68\x21\x16\x02\x01\x01\x2e\x01\x04\x62\x6f\x64\x79\x1a\x01\x04\x61\x72\x67\x73\x16\x04\x56\x24\x1f\x4e\x9b\x44\x01\x05\x5f\x65\x78\x70\x72\x1a\x59\x16\x04\x56\x24\x1f\x4e\x9b\x44\x01\x05\x5f\x65\x78\x70\x72\x1a\x01\x03\x72\x65\x66\x16\x04\x56\x24\x1f\x4e\x9b\x44\x01\x05\x5f\x65\x78\x70\x72\x1a\x01\x01\x2e\x16\x04\x56\x24\x1f\x4e\x9b\x44\x01\x05\x5f\x65\x78\x70\x72\x1a\x56\x16\x04\x56\x24\x1f\x4e\x9b\x44\x01\x05\x5f\x65\x78\x70\x72\x1a\x01\x01\x2e\x16\x04\x56\x24\x1f\x4e\x9b\x44\x01\x05\x5f\x65\x78\x70\x72\x1a\x01\x01\x2e\x01\x07\x43\x50\x79\x74\x68\x6f\x6e\x16\x01\x01\x07\x63\x6f\x70\x79\x61\x73\x74\x1a\x1a\x2c\x5f\x00\x16\x01\x01\x07\x63\x6f\x70\x79\x61\x73\x74\x1a\x1a\x2c\x61\x00\x16\x05\x56\x24\x1f\x4e\x9b\x44\x01\x05\x5f\x65\x78\x70\x72\x1a\x56\x01\x07\x70\x79\x5f\x63\x61\x73\x74\x01\x02\x50\x79\x21\x03\x73\x79\x73\x16\x01\x01\x07\x63\x6f\x70\x79\x61\x73\x74\x1a\x1a\x01\x07\x6d\x6f\x64\x75\x6c\x65\x73\x16\x05\x56\x24\x1f\x4e\x9b\x44\x01\x05\x5f\x65\x78\x70\x72\x1a\x56\x01\x07\x70\x79\x5f\x63\x61\x73\x74\x01\x02\x50\x79\x2c\x53\x00\x2c\x4f\x00\x17\xf6\x2c\x02\x00\x16\x02\x56\x01\x03\x65\x73\x63\x01\x03\x6f\x75\x74"
sign_data = SHA.sha224(data)
if sign_data != expected_sign
error("The compiled data file", "E:\\Projects\\Git4\\jnumpy\\TyPython\\src\\CPython.Dev.DevOnly.compiled.jl", "is not verified. Please recompile it.")
end
buf = IOBuffer(data)
Base.eval(@__MODULE__(), Serialization.deserialize(buf))
end
24 changes: 24 additions & 0 deletions TyPython/src/CPython.Dev.DevOnly.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
macro export_pymodule(name::Symbol, ex)
@switch ex begin
@case Expr(:block, suite...)
@case _
error("@export_pymodule expects a begin-end block")
end
body = Expr(:block)
out = Expr(:let, Expr(:block), body)
sym_module = gensym("mod_$name")
module_name = string(name)
push!(body.args, :(local $sym_module = $CPython.G_PyBuiltin.__import__($py_cast($Py, "types")).SimpleNamespace()))
for arg in suite
@switch arg begin
@case :($name = $value)
push!(body.args, :($sym_module.$name = $py_cast($Py, $value)))
@case ::LineNumberNode
push!(body.args, arg)
@case _
error("@export_pymodule expects a block of `name = value` statements")
end
end
push!(body.args, :($CPython.G_PyBuiltin.__import__($py_cast($Py, "sys")).modules[$py_cast($Py, $module_name)] = $sym_module))
esc(out)
end
27 changes: 2 additions & 25 deletions TyPython/src/CPython.Dev.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ implementing necessary utilities to create CPython extensions.
using TyPython.Reflection
import TyPython
import TyPython.Utils
import MacroTools: @q

export @export_py, @export_pymodule, Pyfunc

const refl = Reflection
Expand Down Expand Up @@ -153,27 +153,4 @@ function export_py(__module__::Module, __source__::LineNumberNode, fi::FuncInfo)
end
end

macro export_pymodule(name::Symbol, ex)
@switch ex begin
@case Expr(:block, suite...)
@case _
error("@export_pymodule expects a begin-end block")
end
body = Expr(:block)
out = Expr(:let, Expr(:block), body)
sym_module = gensym("mod_$name")
module_name = string(name)
push!(body.args, :(local $sym_module = $CPython.G_PyBuiltin.__import__($py_cast($Py, "types")).SimpleNamespace()))
for arg in suite
@switch arg begin
@case :($name = $value)
push!(body.args, :($sym_module.$name = $py_cast($Py, $value)))
@case ::LineNumberNode
push!(body.args, arg)
@case _
error("@export_pymodule expects a block of `name = value` statements")
end
end
push!(body.args, :($CPython.G_PyBuiltin.__import__($py_cast($Py, "sys")).modules[$py_cast($Py, $module_name)] = $sym_module))
esc(out)
end
DevOnly.@staticinclude("CPython.Dev.DevOnly.jl")
13 changes: 13 additions & 0 deletions TyPython/src/CPython.NumPy.DevOnly.compiled.jl

Large diffs are not rendered by default.

95 changes: 95 additions & 0 deletions TyPython/src/CPython.NumPy.DevOnly.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
"""
from_ndarray(x::Py)
Convert numpy ndarray to julia array,
ndarray with F-contiguous could be converted to Array without copy,
ndarray with C-contiguous could be converted to Transpose of Array(2D) or PermutedDimsArray of Array(high dimensions) without copy,
other ndarray will first be copied to f-contiguous ndarray, then converted to Array.
"""
function from_ndarray(x::Py)
np = get_numpy()
if PyAPI.PyObject_HasAttr(x, attribute_symbol_to_pyobject(:__array_struct__)) != 1
error("from_ndarray: $x has no __array_struct__")
end
__array_struct__ = x.__array_struct__
ptr = C.Ptr{PyArrayInterface}(_get_capsule_ptr(__array_struct__))
info = ptr[] :: PyArrayInterface
info.typekind in supported_kinds || error("unsupported numpy dtype: $(Char(ptr.typekind))")
flags = info.flags
if (!(checkbit(flags, NPY_ARRAY_F_CONTIGUOUS) || checkbit(flags, NPY_ARRAY_C_CONTIGUOUS)) ||
!checkbit(flags, TYPY_SUPPORTED_NO_COPY_NP_FLAG))
x = np.copy(x, order=py_cast(Py, "F"))
__array_struct__ = x.__array_struct__
ptr = C.Ptr{PyArrayInterface}(_get_capsule_ptr(__array_struct__))
info = ptr[] :: PyArrayInterface
flags = info.flags
end

# TODO: exception check
shape = Tuple(Int(i)
for i in unsafe_wrap(Array, convert(Ptr{Py_intptr_t}, info.shape), Int(info.nd); own=false)) :: ShapeType

if checkbit(flags, NPY_ARRAY_C_CONTIGUOUS) && !(checkbit(flags, NPY_ARRAY_F_CONTIGUOUS))
shape = reverse(shape)
end

arr = @switch (Char(info.typekind), Int(info.itemsize)) begin
@case ('b', 1)
register_root(x,
unsafe_wrap(Array, convert(Ptr{Bool}, info.data), shape; own=false))
@case ('i', 1)
register_root(x,
unsafe_wrap(Array, convert(Ptr{Int8}, info.data), shape; own=false))
@case ('i', 2)
register_root(x,
unsafe_wrap(Array, convert(Ptr{Int16}, info.data), shape; own=false))
@case ('i', 4)
register_root(x,
unsafe_wrap(Array, convert(Ptr{Int32}, info.data), shape; own=false))
@case ('i', 8)
register_root(x,
unsafe_wrap(Array, convert(Ptr{Int64}, info.data), shape; own=false))
@case ('f', 2)
register_root(x,
unsafe_wrap(Array, convert(Ptr{Float16}, info.data), shape; own=false))
@case ('f', 4)
register_root(x,
unsafe_wrap(Array, convert(Ptr{Float32}, info.data), shape; own=false))
@case ('f', 8)
register_root(x,
unsafe_wrap(Array, convert(Ptr{Float64}, info.data), shape; own=false))
@case ('u', 1)
register_root(x,
unsafe_wrap(Array, convert(Ptr{UInt8}, info.data), shape; own=false))
@case ('u', 2)
register_root(x,
unsafe_wrap(Array, convert(Ptr{UInt16}, info.data), shape; own=false))
@case ('u', 4)
register_root(x,
unsafe_wrap(Array, convert(Ptr{UInt32}, info.data), shape; own=false))
@case ('u', 8)
register_root(x,
unsafe_wrap(Array, convert(Ptr{UInt64}, info.data), shape; own=false))
@case ('c', 4)
register_root(x,
unsafe_wrap(Array, convert(Ptr{ComplexF16}, info.data), shape; own=false))
@case ('c', 8)
register_root(x,
unsafe_wrap(Array, convert(Ptr{ComplexF32}, info.data), shape; own=false))
@case ('c', 16)
register_root(x,
unsafe_wrap(Array, convert(Ptr{ComplexF64}, info.data), shape; own=false))
@case (code, nbytes)
throw(error("unsupported numpy dtype: $(code) $(nbytes)"))
end

if checkbit(flags, NPY_ARRAY_C_CONTIGUOUS) && !(checkbit(flags, NPY_ARRAY_F_CONTIGUOUS))
if info.nd == 2
arr = transpose(arr)
elseif info.nd > 2
perm = Tuple(reverse(1:info.nd))
arr = PermutedDimsArray(arr, perm)
end
end
return arr
end
Loading

0 comments on commit 1123af4

Please sign in to comment.