Skip to content

Commit 573dc13

Browse files
authored
Use Base.require instead of using in more places (#407)
This way, PyJulia can work in more strict setup (e.g., customized `JULIA_LOAD_PATH`).
1 parent d0e2f0c commit 573dc13

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

src/julia/core.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from .libjulia import UNBOXABLE_TYPES, LibJulia, get_inprocess_libjulia, get_libjulia
3333
from .options import JuliaOptions, options_docs
3434
from .release import __version__
35-
from .utils import is_windows
35+
from .utils import IMPORT_PYCALL, is_windows
3636

3737
try:
3838
from shutil import which
@@ -500,7 +500,8 @@ def __init__(self, init_julia=True, jl_init_path=None, runtime=None,
500500

501501
# Currently, PyJulia assumes that `Main.PyCall` exsits. Thus, we need
502502
# to import `PyCall` again here in case `init_julia=False` is passed:
503-
self._call(u"using PyCall")
503+
self._call(IMPORT_PYCALL)
504+
self._call(u"using .PyCall")
504505

505506
# Whether we initialized Julia or not, we MUST create at least one
506507
# instance of PyObject and the convert function. Since these will be

src/julia/install-packagecompiler.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ if VERSION < v"0.7-"
44
error("Unsupported Julia version $VERSION")
55
end
66

7-
using Pkg
7+
const Pkg =
8+
Base.require(Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg"))
89

910
function cat_build_log(pkg)
1011
modpath = Base.locate_package(pkg)
@@ -22,7 +23,7 @@ Pkg.activate(compiler_env)
2223
@info "Installing PackageCompiler..."
2324

2425
Pkg.add([
25-
PackageSpec(
26+
Pkg.PackageSpec(
2627
name = "PackageCompiler",
2728
uuid = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d",
2829
version = "1",

src/julia/install.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ if VERSION < v"0.7.0"
99
error("Unsupported Julia version $VERSION")
1010
end
1111

12-
using Pkg
13-
using InteractiveUtils
12+
const Pkg =
13+
Base.require(Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg"))
14+
const InteractiveUtils = Base.require(Base.PkgId(
15+
Base.UUID("b77e0a4c-d291-57a0-90e8-8db25a27a240"),
16+
"InteractiveUtils",
17+
))
1418

1519
@info "Julia version info"
16-
versioninfo(verbose=true)
20+
InteractiveUtils.versioninfo(verbose=true)
1721

1822
@info "Julia executable: $(Base.julia_cmd().exec[1])"
1923

@@ -29,7 +33,7 @@ end
2933

3034
try
3135
# `import PyCall` cannot be caught?
32-
global PyCall = Base.require(Main, :PyCall)
36+
global PyCall = Base.require(pkgid)
3337
catch err
3438
@error "`import PyCall` failed" exception=(err, catch_backtrace())
3539
global PyCall = DummyPyCall

src/julia/pyjulia_helper.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
module _PyJuliaHelper
22

3-
import REPL
4-
using PyCall
5-
using PyCall: pyeval_, Py_eval_input, Py_file_input
6-
using PyCall.MacroTools: isexpr, walk
3+
const REPL =
4+
Base.require(Base.PkgId(Base.UUID("3fa0cd96-eef1-5676-8a61-b3b8758bbffb"), "REPL"))
5+
const PyCall =
6+
Base.require(Base.PkgId(Base.UUID("438e738f-606a-5dbb-bf0a-cddfbfd45ab0"), "PyCall"))
7+
const MacroTools = Base.require(Base.PkgId(
8+
Base.UUID("1914dd2f-81c6-5fcd-8719-6d5c9610ff09"),
9+
"MacroTools",
10+
))
11+
12+
using .PyCall
13+
using .PyCall: Py_eval_input, Py_file_input, pyeval_
14+
using .MacroTools: isexpr, walk
715

816
"""
917
fullnamestr(m)

src/julia/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ def _execprog_subprocess(cmd):
2222
execprog = _execprog_subprocess
2323
else:
2424
execprog = _execprog_os
25+
26+
27+
PYCALL_PKGID = """\
28+
Base.PkgId(Base.UUID("438e738f-606a-5dbb-bf0a-cddfbfd45ab0"), "PyCall")"""
29+
30+
IMPORT_PYCALL = "const PyCall = Base.require({})".format(PYCALL_PKGID)

0 commit comments

Comments
 (0)