Skip to content

Commit b740a1e

Browse files
committed
Fix most of 0.7 depwarns
1 parent 0550f89 commit b740a1e

File tree

10 files changed

+139
-122
lines changed

10 files changed

+139
-122
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
julia 0.5
2-
Compat 0.27.0
2+
Compat 0.30.0
33
Conda 0.2
44
MacroTools 0.3

deps/build.jl

Lines changed: 82 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import Conda
1010

1111
immutable UseCondaPython <: Exception end
1212

13-
try # make sure deps.jl file is removed on error
14-
1513
#########################################################################
1614

1715
# Fix the environment for running `python`, and setts IO encoding to UTF-8.
@@ -36,7 +34,7 @@ function pythonenv(cmd::Cmd)
3634
setenv(cmd, env)
3735
end
3836

39-
pyvar(python::AbstractString, mod::AbstractString, var::AbstractString) = chomp(readstring(pythonenv(`$python -c "import $mod; print($mod.$var)"`)))
37+
pyvar(python::AbstractString, mod::AbstractString, var::AbstractString) = chomp(read(pythonenv(`$python -c "import $mod; print($mod.$var)"`), String))
4038

4139
pyconfigvar(python::AbstractString, var::AbstractString) = pyvar(python, "distutils.sysconfig", "get_config_var('$var')")
4240
pyconfigvar(python, var, default) = let v = pyconfigvar(python, var)
@@ -113,7 +111,7 @@ function find_libpython(python::AbstractString)
113111
print(s, "\n\n")
114112
end
115113
println(STDERR, "---------------------------------- get_config_vars ---------------------------------------")
116-
print(STDERR, readstring(`python -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_vars())"`))
114+
print(STDERR, read(`python -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_vars())"`, String))
117115
println(STDERR, "--------------------------------- directory contents -------------------------------------")
118116
for libpath in libpaths
119117
if isdir(libpath)
@@ -142,76 +140,6 @@ include("depsutils.jl")
142140

143141
#########################################################################
144142

145-
const python = try
146-
let py = get(ENV, "PYTHON", isfile("PYTHON") ? readchomp("PYTHON") :
147-
Compat.Sys.islinux() || Sys.ARCH (:i686, :x86_64) ? "python" : ""),
148-
vers = isempty(py) ? v"0.0" : convert(VersionNumber, pyconfigvar(py,"VERSION","0.0"))
149-
if vers < v"2.7"
150-
if isempty(py)
151-
throw(UseCondaPython())
152-
else
153-
error("Python version $vers < 2.7 is not supported")
154-
end
155-
end
156-
157-
# check word size of Python via sys.maxsize, since a common error
158-
# on Windows is to link a 64-bit Julia to a 32-bit Python.
159-
pywordsize = parse(UInt64, pysys(py, "maxsize")) > (UInt64(1)<<32) ? 64 : 32
160-
if pywordsize != Sys.WORD_SIZE
161-
error("$py is $(pywordsize)-bit, but Julia is $(Sys.WORD_SIZE)-bit")
162-
end
163-
164-
py
165-
end
166-
catch e1
167-
if Sys.ARCH in (:i686, :x86_64)
168-
if isa(e1, UseCondaPython)
169-
info("Using the Python distribution in the Conda package by default.\n",
170-
"To use a different Python version, set ENV[\"PYTHON\"]=\"pythoncommand\" and re-run Pkg.build(\"PyCall\").")
171-
else
172-
info( "No system-wide Python was found; got the following error:\n",
173-
"$e1\nusing the Python distribution in the Conda package")
174-
end
175-
abspath(Conda.PYTHONDIR, "python" * (Compat.Sys.iswindows() ? ".exe" : ""))
176-
else
177-
error("No system-wide Python was found; got the following error:\n",
178-
"$e1")
179-
end
180-
end
181-
182-
use_conda = dirname(python) == abspath(Conda.PYTHONDIR)
183-
if use_conda
184-
Conda.add("numpy")
185-
end
186-
187-
const (libpython, libpy_name) = find_libpython(python)
188-
const programname = pysys(python, "executable")
189-
190-
# Get PYTHONHOME, either from the environment or from Python
191-
# itself (if it is not in the environment or if we are using Conda)
192-
PYTHONHOME = if !haskey(ENV, "PYTHONHOME") || use_conda
193-
# PYTHONHOME tells python where to look for both pure python
194-
# and binary modules. When it is set, it replaces both
195-
# `prefix` and `exec_prefix` and we thus need to set it to
196-
# both in case they differ. This is also what the
197-
# documentation recommends. However, they are documented
198-
# to always be the same on Windows, where it causes
199-
# problems if we try to include both.
200-
exec_prefix = pysys(python, "exec_prefix")
201-
Compat.Sys.iswindows() ? exec_prefix : pysys(python, "prefix") * ":" * exec_prefix
202-
else
203-
ENV["PYTHONHOME"]
204-
end
205-
206-
# cache the Python version as a Julia VersionNumber
207-
const pyversion = VersionNumber(pyvar(python, "platform", "python_version()"))
208-
209-
info("PyCall is using $python (Python $pyversion) at $programname, libpython = $libpy_name")
210-
211-
if pyversion < v"2.7"
212-
error("Python 2.7 or later is required for PyCall")
213-
end
214-
215143
# A couple of key strings need to be stored as constants so that
216144
# they persist throughout the life of the program. In Python 3,
217145
# they need to be wchar_t* data.
@@ -221,15 +149,86 @@ wstringconst(s) = string("Base.cconvert(Cwstring, \"", escape_string(s), "\")")
221149
# to prevent unnecessary recompilation and to minimize
222150
# problems in the unlikely event of read-only directories.
223151
function writeifchanged(filename, str)
224-
if !isfile(filename) || readstring(filename) != str
152+
if !isfile(filename) || read(filename, String) != str
225153
info(abspath(filename), " has been updated")
226154
write(filename, str)
227155
else
228156
info(abspath(filename), " has not changed")
229157
end
230158
end
231159

232-
writeifchanged("deps.jl", """
160+
try # make sure deps.jl file is removed on error
161+
python = try
162+
let py = get(ENV, "PYTHON", isfile("PYTHON") ? readchomp("PYTHON") :
163+
Compat.Sys.islinux() || Sys.ARCH (:i686, :x86_64) ? "python" : ""),
164+
vers = isempty(py) ? v"0.0" : convert(VersionNumber, pyconfigvar(py,"VERSION","0.0"))
165+
if vers < v"2.7"
166+
if isempty(py)
167+
throw(UseCondaPython())
168+
else
169+
error("Python version $vers < 2.7 is not supported")
170+
end
171+
end
172+
173+
# check word size of Python via sys.maxsize, since a common error
174+
# on Windows is to link a 64-bit Julia to a 32-bit Python.
175+
pywordsize = parse(UInt64, pysys(py, "maxsize")) > (UInt64(1)<<32) ? 64 : 32
176+
if pywordsize != Sys.WORD_SIZE
177+
error("$py is $(pywordsize)-bit, but Julia is $(Sys.WORD_SIZE)-bit")
178+
end
179+
180+
py
181+
end
182+
catch e1
183+
if Sys.ARCH in (:i686, :x86_64)
184+
if isa(e1, UseCondaPython)
185+
info("Using the Python distribution in the Conda package by default.\n",
186+
"To use a different Python version, set ENV[\"PYTHON\"]=\"pythoncommand\" and re-run Pkg.build(\"PyCall\").")
187+
else
188+
info( "No system-wide Python was found; got the following error:\n",
189+
"$e1\nusing the Python distribution in the Conda package")
190+
end
191+
abspath(Conda.PYTHONDIR, "python" * (Compat.Sys.iswindows() ? ".exe" : ""))
192+
else
193+
error("No system-wide Python was found; got the following error:\n",
194+
"$e1")
195+
end
196+
end
197+
198+
use_conda = dirname(python) == abspath(Conda.PYTHONDIR)
199+
if use_conda
200+
Conda.add("numpy")
201+
end
202+
203+
(libpython, libpy_name) = find_libpython(python)
204+
programname = pysys(python, "executable")
205+
206+
# Get PYTHONHOME, either from the environment or from Python
207+
# itself (if it is not in the environment or if we are using Conda)
208+
PYTHONHOME = if !haskey(ENV, "PYTHONHOME") || use_conda
209+
# PYTHONHOME tells python where to look for both pure python
210+
# and binary modules. When it is set, it replaces both
211+
# `prefix` and `exec_prefix` and we thus need to set it to
212+
# both in case they differ. This is also what the
213+
# documentation recommends. However, they are documented
214+
# to always be the same on Windows, where it causes
215+
# problems if we try to include both.
216+
exec_prefix = pysys(python, "exec_prefix")
217+
Compat.Sys.iswindows() ? exec_prefix : pysys(python, "prefix") * ":" * exec_prefix
218+
else
219+
ENV["PYTHONHOME"]
220+
end
221+
222+
# cache the Python version as a Julia VersionNumber
223+
pyversion = VersionNumber(pyvar(python, "platform", "python_version()"))
224+
225+
info("PyCall is using $python (Python $pyversion) at $programname, libpython = $libpy_name")
226+
227+
if pyversion < v"2.7"
228+
error("Python 2.7 or later is required for PyCall")
229+
end
230+
231+
writeifchanged("deps.jl", """
233232
const python = "$(escape_string(python))"
234233
const libpython = "$(escape_string(libpy_name))"
235234
const pyprogramname = "$(escape_string(programname))"
@@ -242,16 +241,16 @@ writeifchanged("deps.jl", """
242241
const conda = $use_conda
243242
""")
244243

245-
# Make subsequent builds (e.g. Pkg.update) use the same Python by default:
246-
writeifchanged("PYTHON", isfile(programname) ? programname : python)
244+
# Make subsequent builds (e.g. Pkg.update) use the same Python by default:
245+
writeifchanged("PYTHON", isfile(programname) ? programname : python)
247246

248-
#########################################################################
247+
#########################################################################
249248

250249
catch
251250

252-
# remove deps.jl (if it exists) on an error, so that PyCall will
253-
# not load until it is properly configured.
254-
isfile("deps.jl") && rm("deps.jl")
255-
rethrow()
251+
# remove deps.jl (if it exists) on an error, so that PyCall will
252+
# not load until it is properly configured.
253+
isfile("deps.jl") && rm("deps.jl")
254+
rethrow()
256255

257256
end

src/PyCall.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,15 @@ end
462462
macro pyimport(name, optional_varname...)
463463
mname = modulename(name)
464464
Name = pyimport_name(name, optional_varname)
465+
quoteName = Expr(:quote, Name)
466+
# VERSION 0.7
467+
@static if isdefined(Base, Symbol("@isdefined"))
468+
isdef_check = :(isdefined($__module__, $quoteName))
469+
else
470+
isdef_check = :(isdefined($quoteName))
471+
end
465472
quote
466-
if !isdefined($(Expr(:quote, Name)))
473+
if !$isdef_check
467474
const $(esc(Name)) = pywrap(pyimport($mname))
468475
elseif !isa($(esc(Name)), Module)
469476
error("@pyimport: ", $(Expr(:quote, Name)), " already defined")

src/io.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function pyio_initialize()
108108
String(read(pyio_jl(self), nb < 0 ? typemax(Int) : nb)) :
109109
pybytes(read(pyio_jl(self), nb < 0 ? typemax(Int) : nb)))
110110
readall(self) =
111-
@with_ioraise(self[:istextio] ? readstring(pyio_jl(self)) :
111+
@with_ioraise(self[:istextio] ? read(pyio_jl(self), String) :
112112
pybytes(read(pyio_jl(self))))
113113
readinto(self, b) = @with_ioraise(pybytes(readbytes!(pyio_jl(self), b)))
114114
write(self, b) = @with_ioraise(write(pyio_jl(self), b))

src/numpy.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function npyinitialize()
7474
# Parse __multiarray_api.h to obtain length and meaning of PyArray_API
7575
try
7676
hdrfile = open(joinpath(inc, "numpy", "__multiarray_api.h"))
77-
hdr = readstring(hdrfile);
77+
hdr = read(hdrfile, String)
7878
close(hdrfile)
7979
catch e
8080
error("could not read __multiarray_api.h to parse PyArray_API ", e)

src/pybuffer.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ end
4040
function pydecref(o::PyBuffer)
4141
# note that PyBuffer_Release sets o.obj to NULL, and
4242
# is a no-op if o.obj is already NULL
43-
ccall(@pysym(:PyBuffer_Release), Void, (Ptr{PyBuffer},), &o)
43+
# TODO change to `Ref{PyBuffer}` when 0.6 is dropped.
44+
ccall(@pysym(:PyBuffer_Release), Void, (Any,), o)
4445
o
4546
end
4647

@@ -85,9 +86,10 @@ function Base.stride(b::PyBuffer, d::Integer)
8586
return Int(unsafe_load(b.buf.strides, d))
8687
end
8788

89+
# TODO change to `Ref{PyBuffer}` when 0.6 is dropped.
8890
iscontiguous(b::PyBuffer) =
8991
1 == ccall((@pysym :PyBuffer_IsContiguous), Cint,
90-
(Ptr{PyBuffer}, Cchar), &b, 'A')
92+
(Any, Cchar), b, 'A')
9193

9294
#############################################################################
9395
# pybuffer constant values from Include/object.h
@@ -105,8 +107,9 @@ const PyBUF_INDIRECT = convert(Cint, 0x0100) | PyBUF_STRIDES
105107
# construct a PyBuffer from a PyObject, if possible
106108
function PyBuffer(o::Union{PyObject,PyPtr}, flags=PyBUF_SIMPLE)
107109
b = PyBuffer()
110+
# TODO change to `Ref{PyBuffer}` when 0.6 is dropped.
108111
@pycheckz ccall((@pysym :PyObject_GetBuffer), Cint,
109-
(PyPtr, Ptr{PyBuffer}, Cint), o, &b, flags)
112+
(PyPtr, Any, Cint), o, b, flags)
110113
return b
111114
end
112115

src/pyinit.jl

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ const pyxrange = Ref{PyPtr}(0)
2323

2424
#########################################################################
2525

26+
type EmptyStringList
27+
x::Int32
28+
ptr::Ptr{Int32}
29+
function EmptyStringList()
30+
obj = new(0)
31+
obj.ptr = pointer_from_objref(obj)
32+
return obj
33+
end
34+
end
35+
Base.unsafe_convert(::Type{Ptr{UInt32}}, x::EmptyStringList) =
36+
Ptr{UInt32}(pointer_from_objref(x) + fieldoffset(EmptyStringList, 2))
37+
2638
function __init__()
2739
# issue #189
2840
libpy_handle = libpython === nothing ? C_NULL :
@@ -87,15 +99,7 @@ function __init__()
8799

88100
if !already_inited
89101
# some modules (e.g. IPython) expect sys.argv to be set
90-
if pyversion.major < 3
91-
argv_s = ""
92-
argv = unsafe_convert(Ptr{UInt8}, argv_s)
93-
ccall(@pysym(:PySys_SetArgvEx), Void, (Cint,Ptr{Ptr{UInt8}},Cint), 1, &argv, 0)
94-
else
95-
argv_s = Cwchar_t[0]
96-
argv = unsafe_convert(Ptr{Cwchar_t}, argv_s)
97-
ccall(@pysym(:PySys_SetArgvEx), Void, (Cint, Ptr{Ptr{Cwchar_t}}, Cint), 1, &argv, 0)
98-
end
102+
ccall(@pysym(:PySys_SetArgvEx), Void, (Cint, Ptr{UInt32}, Cint), 1, EmptyStringList(), 0)
99103

100104
# Some Python code checks sys.ps1 to see if it is running
101105
# interactively, and refuses to be interactive otherwise.

src/pyiterator.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ const jlWrapIteratorType = PyTypeObject()
4949
function jlwrap_iterator(o::Any)
5050
if jlWrapIteratorType.tp_name == C_NULL # lazily initialize
5151
pyjlwrap_type!(jlWrapIteratorType, "PyCall.jlwrap_iterator") do t
52-
t.tp_iter = cfunction(pyincref_, PyPtr, (PyPtr,)) # new reference to same object
53-
t.tp_iternext = cfunction(pyjlwrap_iternext, PyPtr, (PyPtr,))
52+
t.tp_iter = cfunction(pyincref_, PyPtr, Tuple{PyPtr}) # new reference to same object
53+
t.tp_iternext = cfunction(pyjlwrap_iternext, PyPtr, Tuple{PyPtr})
5454
end
5555
end
5656
return pyjlwrap_new(jlWrapIteratorType, (o, Ref(start(o))))

0 commit comments

Comments
 (0)