Skip to content

Commit 9e05155

Browse files
committed
Merge tag 'v1.96.4' into threadsafe_gc
[Diff since v1.96.3](JuliaPy/PyCall.jl@v1.96.3...v1.96.4) **Merged pull requests:** - Rename `distutils.sysconfig` to `sysconfig` (JuliaPy#1068) (@MilesCranmer) - bump to 1.96.4 (JuliaPy#1070) (@stevengj)
2 parents c707032 + e54c4ee commit 9e05155

24 files changed

+851
-101
lines changed

.github/workflows/TagBot.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
name: TagBot
22
on:
3-
schedule:
4-
- cron: 0 * * * *
3+
issue_comment:
4+
types:
5+
- created
6+
workflow_dispatch:
57
jobs:
68
TagBot:
9+
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
710
runs-on: ubuntu-latest
811
steps:
912
- uses: JuliaRegistries/TagBot@v1

.github/workflows/aot.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ jobs:
1616
os:
1717
- ubuntu-latest
1818
architecture: [x64]
19-
python-version: ['3.8']
20-
julia-version: ['1.5', 'nightly']
19+
python-version: ['3.x']
20+
julia-version:
21+
- '1'
22+
- '1.6'
23+
# - 'nightly' # TODO: reenable
2124
fail-fast: false
2225
env:
2326
PYTHON: python${{ matrix.python-version }}
@@ -34,6 +37,9 @@ jobs:
3437
architecture: ${{ matrix.architecture }}
3538
- run: python --version
3639
- run: python -m pip install --user numpy
40+
- name: Install libpython2.7 for `find_libpython` test
41+
run: sudo apt-get install python2.7-dev
42+
if: ${{ matrix.python-version != '2.7' && matrix.os == 'ubuntu-latest' }}
3743
- name: Setup julia
3844
uses: julia-actions/setup-julia@v1
3945
with:

.github/workflows/conda.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ jobs:
1818
- macos-latest
1919
- windows-latest
2020
architecture: [x64]
21-
julia-version: ['1.5']
21+
julia-version: ['1']
2222
include:
2323
- os: windows-latest
2424
architecture: x86
25-
julia-version: '1.5'
25+
julia-version: '1'
2626
fail-fast: false
2727
env:
2828
PYTHON: ""
@@ -32,6 +32,9 @@ jobs:
3232
${{ matrix.os }} ${{ matrix.architecture }}
3333
steps:
3434
- uses: actions/checkout@v1
35+
- name: Install libpython2.7 for `find_libpython` test
36+
run: sudo apt-get install python2.7-dev
37+
if: ${{ matrix.python-version != '2.7' && matrix.os == 'ubuntu-latest' }}
3538
- name: Setup julia
3639
uses: julia-actions/setup-julia@v1
3740
with:

.github/workflows/system.yml

+31-8
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,39 @@ jobs:
1818
- macos-latest
1919
- windows-latest
2020
architecture: [x64]
21-
python-version: ['2.7', '3.8']
22-
julia-version: ['1.0', '1.5', 'nightly']
21+
python-version: ['3.x']
22+
julia-version:
23+
- '1'
24+
- 'nightly'
2325
include:
26+
# 32 bit Windows:
2427
- os: windows-latest
2528
architecture: x86
26-
python-version: '3.8'
27-
julia-version: '1.5'
29+
python-version: '3.x'
30+
julia-version: '1'
31+
# Sweep python-version and julia-version only on Ubuntu:
32+
- os: ubuntu-latest
33+
architecture: x64
34+
python-version: '3.9'
35+
julia-version: '1'
2836
- os: ubuntu-latest
2937
architecture: x64
30-
python-version: '3.7'
38+
python-version: '3.x'
3139
julia-version: '1.5'
3240
- os: ubuntu-latest
3341
architecture: x64
34-
python-version: '3.8'
42+
python-version: '3.x'
3543
julia-version: '1.4'
44+
# Test Python 2.7 only with a few combinations (TODO: drop 2.7).
45+
# Note that it does not work in macOS:
3646
- os: ubuntu-latest
3747
architecture: x64
38-
python-version: '3.8'
39-
julia-version: '1.3'
48+
python-version: '2.7'
49+
julia-version: '1'
50+
- os: windows-2019
51+
architecture: x64
52+
python-version: '2.7'
53+
julia-version: '1'
4054
fail-fast: false
4155
name: Test
4256
Julia ${{ matrix.julia-version }}
@@ -56,6 +70,9 @@ jobs:
5670
if: ${{ matrix.python-version != '2.7' }}
5771
- run: virtualenv --version
5872
if: ${{ matrix.python-version != '2.7' }}
73+
- name: Install libpython2.7 for `find_libpython` test
74+
run: sudo apt-get install python2.7-dev
75+
if: ${{ matrix.python-version != '2.7' && matrix.os == 'ubuntu-latest' }}
5976
- name: Setup julia
6077
uses: julia-actions/setup-julia@v1
6178
with:
@@ -67,6 +84,12 @@ jobs:
6784
PYTHON: python
6885
- run: julia test/check_deps_version.jl ${{ matrix.python-version }}
6986
- uses: julia-actions/julia-runtest@v1
87+
env:
88+
# Windows temp directories break the CI:
89+
# https://github.com/actions/runner-images/issues/712
90+
# so, we use
91+
# https://docs.github.com/en/actions/learn-github-actions/contexts#runner-context
92+
_TMP_DIR: ${{ runner.temp }}
7093
- uses: julia-actions/julia-processcoverage@v1
7194
- uses: codecov/codecov-action@v1
7295
with:

Project.toml

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PyCall"
22
uuid = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
33
authors = ["Steven G. Johnson <[email protected]>", "Yichao Yu <[email protected]>", "Takafumi Arakaki <[email protected]>", "Simon Kornblith <[email protected]>", "Páll Haraldsson <[email protected]>", "Jon Malmaud <[email protected]>", "Jake Bolewski <[email protected]>", "Keno Fischer <[email protected]>", "Joel Mason <[email protected]>", "Jameson Nash <[email protected]>", "The JuliaPy development team"]
4-
version = "1.92.2"
4+
version = "1.96.4"
55

66
[deps]
77
Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d"
@@ -13,13 +13,19 @@ Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
1313
VersionParsing = "81def892-9a0e-5fdd-b105-ffc91e053289"
1414

1515
[compat]
16-
Conda = "1.0"
16+
Conda = "1.9"
1717
MacroTools = "0.4, 0.5"
1818
VersionParsing = "1.0"
19-
julia = "0.7, 1.0"
19+
20+
julia = "1.4"
21+
Dates = "<0.0.1, 1"
22+
Libdl = "<0.0.1, 1"
23+
LinearAlgebra = "<0.0.1, 1"
24+
Serialization = "<0.0.1, 1"
2025

2126
[extras]
2227
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
28+
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
2329

2430
[targets]
25-
test = ["Test"]
31+
test = ["Test", "REPL"]

README.md

+20-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ install the files. Julia 0.7 or later is required.
2020

2121
The latest development version of PyCall is available from
2222
<https://github.com/JuliaPy/PyCall.jl>. If you want to switch to
23-
this after installing the package, run `Pkg.checkout("PyCall"); Pkg.build("PyCall")`.
23+
this after installing the package, run:
24+
25+
```julia
26+
Pkg.add(PackageSpec(name="PyCall", rev="master"))
27+
Pkg.build("PyCall")
28+
```
2429

2530
By default on Mac and Windows systems, `Pkg.add("PyCall")`
2631
or `Pkg.build("PyCall")` will use the
@@ -48,9 +53,9 @@ to the path of the `python` (or `python3` etc.) executable and then re-running `
4853
In Julia:
4954

5055
ENV["PYTHON"] = "... path of the python executable ..."
51-
# ENV["PYTHON"] = raw"C:\Python37-x64\python.exe" # example for Windows, "raw" to not have to escape: "C:\\Python37-x64\\python.exe"
56+
# ENV["PYTHON"] = raw"C:\Python310-x64\python.exe" # example for Windows, "raw" to not have to escape: "C:\\Python310-x64\\python.exe"
5257

53-
# ENV["PYTHON"] = "/usr/bin/python3.7" # example for *nix
58+
# ENV["PYTHON"] = "/usr/bin/python3.10" # example for *nix
5459
Pkg.build("PyCall")
5560

5661
Note also that you will need to re-run `Pkg.build("PyCall")` if your
@@ -160,6 +165,8 @@ def sinpi(x):
160165
py"sinpi"(1)
161166
```
162167

168+
You can also execute a whole script `"foo.py"` via `@pyinclude("foo.py")` as if you had pasted it into a `py"""..."""` string.
169+
163170
When creating a Julia module, it is a useful pattern to define Python
164171
functions or classes in Julia's `__init__` and then use it in Julia
165172
function with `py"..."`.
@@ -192,7 +199,7 @@ cannot be accessed outside `MyModule`.
192199

193200
Here are solutions to some common problems:
194201

195-
* By default, PyCall [doesn't include the current directory in the Python search path](https://github.com/JuliaPy/PyCall.jl/issues/48). If you want to do that (in order to load a Python module from the current directory), just run `pushfirst!(PyVector(pyimport("sys")."path"), "")`.
202+
* By default, PyCall [doesn't include the current directory in the Python search path](https://github.com/JuliaPy/PyCall.jl/issues/48). If you want to do that (in order to load a Python module from the current directory), just run `pushfirst!(pyimport("sys")."path", "")`.
196203

197204
## Python object interfaces
198205

@@ -298,7 +305,7 @@ use `PyDict` as the return type of a `pycall` returning a dictionary,
298305
or call `PyDict(o::PyObject)` on a dictionary object `o`. By
299306
default, a `PyDict` is an `Any => Any` dictionary (or actually `PyAny
300307
=> PyAny`) that performs runtime type inference, but if your Python
301-
dictionary has known, fixed types you can insteady use `PyDict{K,V}` given
308+
dictionary has known, fixed types you can instead use `PyDict{K,V}` given
302309
the key and value types `K` and `V` respectively.
303310

304311
Currently, passing Julia dictionaries to Python makes a copy of the Julia
@@ -359,7 +366,8 @@ and also by providing more type information to the Julia compiler.
359366
Python's [`eval`](https://docs.python.org/3/library/functions.html#eval) function, and returns the result
360367
converted to `PyAny`. Alternatively, `py"..."o` returns the raw `PyObject`
361368
(which can then be manually converted if desired). You can interpolate
362-
Julia variables and other expressions into the Python code with `$`,
369+
Julia variables and other expressions into the Python code (except for into
370+
Python strings contained in Python code), with `$`,
363371
which interpolates the *value* (converted to `PyObject`) of the given
364372
expression---data is not passed as a string, so this is different from
365373
ordinary Julia string interpolation. e.g. `py"sum($([1,2,3]))"` calls the
@@ -384,10 +392,15 @@ and also by providing more type information to the Julia compiler.
384392
`__init__`. Side-effect in Python occurred at top-level Julia scope
385393
cannot be used at run-time for precompiled modules.
386394

395+
You can also execute a Python script file `"foo.py"` by running `@pyinclude("foo.py")`, and it will be as if you had pasted the
396+
script into a `py"..."` string. (`@pyinclude` does not support
397+
interpolating Julia variables with `$var`, however — the script
398+
must be pure Python.)
399+
387400
* `pybuiltin(s)`: Look up `s` (a string or symbol) among the global Python
388401
builtins. If `s` is a string it returns a `PyObject`, while if `s` is a
389402
symbol it returns the builtin converted to `PyAny`. (You can also use `py"s"`
390-
to look up builtins or other Python globas.)
403+
to look up builtins or other Python globals.)
391404

392405
Occasionally, you may need to pass a keyword argument to Python that
393406
is a [reserved word](https://en.wikipedia.org/wiki/Reserved_word) in Julia.

deps/build.jl

+8-13
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ mkpath(dirname(prefsfile))
4343
try # make sure deps.jl file is removed on error
4444
python = try
4545
let py = get(ENV, "PYTHON", isfile(prefsfile) ? readchomp(prefsfile) :
46-
(Sys.isunix() && !Sys.isapple()) || Sys.ARCH (:i686, :x86_64) ?
46+
(Sys.isunix() && !Sys.isapple()) ?
4747
whichfirst("python3", "python") : "Conda"),
4848
vers = isempty(py) || py == "Conda" ? v"0.0" : vparse(pyconfigvar(py,"VERSION","0.0"))
4949
if vers < v"2.7"
@@ -64,24 +64,19 @@ try # make sure deps.jl file is removed on error
6464
py
6565
end
6666
catch e1
67-
if Sys.ARCH in (:i686, :x86_64)
68-
if isa(e1, UseCondaPython)
69-
@info string("Using the Python distribution in the Conda package by default.\n",
70-
"To use a different Python version, set ENV[\"PYTHON\"]=\"pythoncommand\" and re-run Pkg.build(\"PyCall\").")
71-
else
72-
@info string( "No system-wide Python was found; got the following error:\n",
73-
"$e1\nusing the Python distribution in the Conda package")
74-
end
75-
abspath(Conda.PYTHONDIR, "python" * (Sys.iswindows() ? ".exe" : ""))
67+
if isa(e1, UseCondaPython)
68+
@info string("Using the Python distribution in the Conda package by default.\n",
69+
"To use a different Python version, set ENV[\"PYTHON\"]=\"pythoncommand\" and re-run Pkg.build(\"PyCall\").")
7670
else
77-
error("No system-wide Python was found; got the following error:\n",
78-
"$e1")
71+
@info string("No system-wide Python was found; got the following error:\n",
72+
"$e1\nusing the Python distribution in the Conda package")
7973
end
74+
abspath(Conda.PYTHONDIR, "python" * (Sys.iswindows() ? ".exe" : ""))
8075
end
8176

8277
use_conda = dirname(python) == abspath(Conda.PYTHONDIR)
8378
if use_conda
84-
Conda.add("numpy")
79+
Conda.add("numpy"; satisfied_skip_solve=true)
8580
end
8681

8782
(libpython, libpy_name) = find_libpython(python)

deps/buildutils.jl

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ import Conda, Libdl
55

66
pyvar(python::AbstractString, mod::AbstractString, var::AbstractString) = chomp(read(pythonenv(`$python -c "import $mod; print($mod.$(var))"`), String))
77

8-
pyconfigvar(python::AbstractString, var::AbstractString) = pyvar(python, "distutils.sysconfig", "get_config_var('$(var)')")
8+
function pyconfigvar(python::AbstractString, var::AbstractString)
9+
try
10+
pyvar(python, "sysconfig", "get_config_var('$(var)')")
11+
catch e
12+
emsg = sprint(showerror, e)
13+
@warn "Encountered error on using `sysconfig`: $emsg. Falling back to `distutils.sysconfig`."
14+
pyvar(python, "distutils.sysconfig", "get_config_var('$(var)')")
15+
end
16+
end
917
pyconfigvar(python, var, default) = let v = pyconfigvar(python, var)
1018
v == "None" ? default : v
1119
end

deps/depsutils.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ function _preserveas!(dest::Vector{UInt8}, ::Type{Cstring}, x::AbstractString)
6464
end
6565

6666
function _preserveas!(dest::Vector{UInt8}, ::Type{Cwstring}, x::AbstractString)
67-
s = reinterpret(UInt8, Base.cconvert(Cwstring, x))
68-
copyto!(resize!(dest, length(s)), s)
67+
s = reinterpret(UInt8, transcode(Cwchar_t, String(x)))
68+
len = length(s)
69+
copyto!(resize!(dest, len + sizeof(Cwchar_t)), s)
70+
dest[len + 1:len + sizeof(Cwchar_t)] .= 0
6971
return pointer(dest)
7072
end
7173

deps/find_libpython.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def normalize_path(path, suffix=SHLIB_SUFFIX, is_apple=is_apple):
264264
265265
Parameters
266266
----------
267-
path : str ot None
267+
path : str or None
268268
A candidate path to a shared library.
269269
"""
270270
if not path:

0 commit comments

Comments
 (0)