Skip to content

Commit

Permalink
drop 0.6 support (JuliaPy#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj authored Jan 11, 2019
1 parent 093342b commit 45cbcee
Show file tree
Hide file tree
Showing 21 changed files with 218 additions and 343 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ language: julia
os:
- linux
julia:
- 0.6
- 0.7
- 1.0
- nightly
addons:
apt:
Expand All @@ -23,7 +23,7 @@ matrix:
language: julia
os: osx
env: PYTHON=python
julia: 0.6
julia: 1.0
- &test-macos-py3
<<: *test-macos-py2
before_install:
Expand All @@ -35,9 +35,9 @@ matrix:
- &test-macos-conda
<<: *test-macos-py2
env: PYTHON=Conda
- {<<: *test-macos-py2, julia: 0.7}
- {<<: *test-macos-py3, julia: 0.7}
- {<<: *test-macos-conda, julia: 0.7}
- {<<: *test-macos-py2, julia: 1.0}
- {<<: *test-macos-py3, julia: 1.0}
- {<<: *test-macos-conda, julia: 1.0}
- {<<: *test-macos-py2, julia: nightly}
- {<<: *test-macos-py3, julia: nightly}
- {<<: *test-macos-conda, julia: nightly}
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
[![Build status](https://ci.appveyor.com/api/projects/status/ycvukpk4ujq987pm?svg=true)](https://ci.appveyor.com/project/StevenGJohnson/pycall-jl-nu3aa)
[![Coverage Status](https://coveralls.io/repos/JuliaPy/PyCall.jl/badge.svg?branch=master)](https://coveralls.io/r/JuliaPy/PyCall.jl?branch=master)

[![PyCall](http://pkg.julialang.org/badges/PyCall_0.5.svg)](http://pkg.julialang.org/?pkg=PyCall&ver=0.5)
[![PyCall](http://pkg.julialang.org/badges/PyCall_0.6.svg)](http://pkg.julialang.org/?pkg=PyCall&ver=0.6)
[![PyCall](http://pkg.julialang.org/badges/PyCall_0.7.svg)](http://pkg.julialang.org/?pkg=PyCall&ver=0.7)


Expand All @@ -20,7 +18,7 @@ without copying them.
## Installation

Within Julia, just use the package manager to run `Pkg.add("PyCall")` to
install the files. Julia 0.5 or later is required.
install the files. Julia 0.7 or later is required.

The latest development version of PyCall is available from
<https://github.com/stevengj/PyCall.jl>. If you want to switch to
Expand Down
3 changes: 1 addition & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
julia 0.6
Compat 0.68.0
julia 0.7
Conda 0.2
MacroTools 0.3
VersionParsing
7 changes: 0 additions & 7 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
environment:
matrix:
- julia_version: 0.6
python_version: "27"
- julia_version: 0.6
python_version: "37"
- julia_version: 0.6
python_version: "Conda"

- julia_version: 0.7
python_version: "27"
- julia_version: 0.7
Expand Down
26 changes: 13 additions & 13 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# As a result, if you switch to a different version or path of Python, you
# will probably need to re-run Pkg.build("PyCall").

using Compat, VersionParsing
import Conda, Compat.Libdl
using VersionParsing
import Conda, Libdl

struct UseCondaPython <: Exception end

Expand Down Expand Up @@ -45,7 +45,7 @@ pysys(python::AbstractString, var::AbstractString) = pyvar(python, "sys", var)

#########################################################################

const dlprefix = Compat.Sys.iswindows() ? "" : "lib"
const dlprefix = Sys.iswindows() ? "" : "lib"

# print out extra info to help with remote debugging
const PYCALL_DEBUG_BUILD = "yes" == get(ENV, "PYCALL_DEBUG_BUILD", "no")
Expand Down Expand Up @@ -127,30 +127,30 @@ wstringconst(s) = string("Base.cconvert(Cwstring, \"", escape_string(s), "\")")
# problems in the unlikely event of read-only directories.
function writeifchanged(filename, str)
if !isfile(filename) || read(filename, String) != str
Compat.@info string(abspath(filename), " has been updated")
@info string(abspath(filename), " has been updated")
write(filename, str)
else
Compat.@info string(abspath(filename), " has not changed")
@info string(abspath(filename), " has not changed")
end
end

# return the first arg that exists in the PATH
function whichfirst(args...)
for x in args
if Compat.Sys.which(x) !== nothing
if Sys.which(x) !== nothing
return x
end
end
return ""
end

const prefsfile = VERSION < v"0.7" ? "PYTHON" : joinpath(first(DEPOT_PATH), "prefs", "PyCall")
const prefsfile = joinpath(first(DEPOT_PATH), "prefs", "PyCall")
mkpath(dirname(prefsfile))

try # make sure deps.jl file is removed on error
python = try
let py = get(ENV, "PYTHON", isfile(prefsfile) ? readchomp(prefsfile) :
(Compat.Sys.isunix() && !Compat.Sys.isapple()) || Sys.ARCH (:i686, :x86_64) ?
(Sys.isunix() && !Sys.isapple()) || Sys.ARCH (:i686, :x86_64) ?
whichfirst("python3", "python") : "Conda"),
vers = isempty(py) || py == "Conda" ? v"0.0" : vparse(pyconfigvar(py,"VERSION","0.0"))
if vers < v"2.7"
Expand All @@ -173,13 +173,13 @@ try # make sure deps.jl file is removed on error
catch e1
if Sys.ARCH in (:i686, :x86_64)
if isa(e1, UseCondaPython)
Compat.@info string("Using the Python distribution in the Conda package by default.\n",
@info string("Using the Python distribution in the Conda package by default.\n",
"To use a different Python version, set ENV[\"PYTHON\"]=\"pythoncommand\" and re-run Pkg.build(\"PyCall\").")
else
Compat.@info string( "No system-wide Python was found; got the following error:\n",
@info string( "No system-wide Python was found; got the following error:\n",
"$e1\nusing the Python distribution in the Conda package")
end
abspath(Conda.PYTHONDIR, "python" * (Compat.Sys.iswindows() ? ".exe" : ""))
abspath(Conda.PYTHONDIR, "python" * (Sys.iswindows() ? ".exe" : ""))
else
error("No system-wide Python was found; got the following error:\n",
"$e1")
Expand All @@ -205,15 +205,15 @@ try # make sure deps.jl file is removed on error
# to always be the same on Windows, where it causes
# problems if we try to include both.
exec_prefix = pysys(python, "exec_prefix")
Compat.Sys.iswindows() ? exec_prefix : pysys(python, "prefix") * ":" * exec_prefix
Sys.iswindows() ? exec_prefix : pysys(python, "prefix") * ":" * exec_prefix
else
ENV["PYTHONHOME"]
end

# cache the Python version as a Julia VersionNumber
pyversion = vparse(pyvar(python, "platform", "python_version()"))

Compat.@info "PyCall is using $python (Python $pyversion) at $programname, libpython = $libpy_name"
@info "PyCall is using $python (Python $pyversion) at $programname, libpython = $libpy_name"

if pyversion < v"2.7"
error("Python 2.7 or later is required for PyCall")
Expand Down
2 changes: 1 addition & 1 deletion deps/depsutils.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Compat.Libdl
import Libdl

hassym(lib, sym) = Libdl.dlsym_e(lib, sym) != C_NULL

Expand Down
25 changes: 8 additions & 17 deletions src/PyCall.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
VERSION < v"0.7.0-beta2.199" && __precompile__()

module PyCall

using Compat, VersionParsing
using VersionParsing

export pycall, pycall!, pyimport, pyimport_e, pybuiltin, PyObject, PyReverseDims,
PyPtr, pyincref, pydecref, pyversion,
Expand All @@ -18,8 +16,8 @@ import Base: size, ndims, similar, copy, getindex, setindex!, stride,
convert, pointer, summary, convert, show, haskey, keys, values,
eltype, get, delete!, empty!, length, isempty,
filter!, hash, splice!, pop!, ==, isequal, push!,
append!, insert!, prepend!, unsafe_convert
import Compat: pushfirst!, popfirst!, firstindex, lastindex
append!, insert!, prepend!, unsafe_convert,
pushfirst!, popfirst!, firstindex, lastindex

# Python C API is not interrupt-safe. In principle, we should
# use sigatomic for every ccall to the Python library, but this
Expand Down Expand Up @@ -70,7 +68,7 @@ mutable struct PyObject
o::PyPtr # the actual PyObject*
function PyObject(o::PyPtr)
po = new(o)
@compat finalizer(pydecref, po)
finalizer(pydecref, po)
return po
end
end
Expand Down Expand Up @@ -354,7 +352,7 @@ end

#########################################################################

@static if Compat.Sys.iswindows()
@static if Sys.iswindows()
# Many python extensions are linked against a very specific version of the
# MSVC runtime library. To load this library, libpython declares an
# appropriate manifest, but unfortunately most extensions do not.
Expand Down Expand Up @@ -527,14 +525,8 @@ macro pyimport(name, optional_varname...)
mname = modulename(name)
Name = pyimport_name(name, optional_varname)
quoteName = Expr(:quote, Name)
# VERSION 0.7
@static if isdefined(Base, Symbol("@isdefined"))
isdef_check = :(isdefined($__module__, $quoteName))
else
isdef_check = :(isdefined($quoteName))
end
quote
if !$isdef_check
if !isdefined($__module__, $quoteName)
const $(esc(Name)) = pywrap(pyimport($mname))
elseif !isa($(esc(Name)), Module)
error("@pyimport: ", $(Expr(:quote, Name)), " already defined")
Expand Down Expand Up @@ -652,7 +644,7 @@ function pyimport_conda(modulename::AbstractString, condapkg::AbstractString,
pyimport(modulename)
catch e
if conda
Compat.@info "Installing $modulename via the Conda $condapkg package..."
@info "Installing $modulename via the Conda $condapkg package..."
isempty(channel) || Conda.add_channel(channel)
Conda.add(condapkg)
pyimport(modulename)
Expand Down Expand Up @@ -836,7 +828,6 @@ for (mime, method) in ((MIME"text/html", "_repr_html_"),
(MIME"image/svg+xml", "_repr_svg_"),
(MIME"text/latex", "_repr_latex_"))
T = istextmime(mime()) ? AbstractString : Vector{UInt8}
showable = VERSION < v"0.7.0-DEV.4047" ? :mimewritable : :showable
@eval begin
function show(io::IO, mime::$mime, o::PyObject)
if !ispynull(o) && haskey(o, $method)
Expand All @@ -845,7 +836,7 @@ for (mime, method) in ((MIME"text/html", "_repr_html_"),
end
throw(MethodError(show, (io, mime, o)))
end
Base.$showable(::$mime, o::PyObject) =
Base.showable(::$mime, o::PyObject) =
!ispynull(o) && haskey(o, $method) && let meth = o[$method]
meth.o != pynothing[] &&
pycall(meth, PyObject).o != pynothing[]
Expand Down
80 changes: 27 additions & 53 deletions src/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -536,59 +536,33 @@ struct PyDict_Iterator
i::Int # current position in items list (0-based)
len::Int # length of items list
end
@static if VERSION < v"0.7.0-DEV.5126" # julia#25261
Base.start(d::PyDict{K,V,true}) where {K,V} = PyDict_Iterator(Ref{PyPtr}(), Ref{PyPtr}(), Ref(0), 0, length(d))
Base.done(d::PyDict{K,V,true}, itr::PyDict_Iterator) where {K,V} = itr.i >= itr.len
function Base.next(d::PyDict{K,V,true}, itr::PyDict_Iterator) where {K,V}
if 0 == ccall((@pysym :PyDict_Next), Cint,
(PyPtr, Ref{Int}, Ref{PyPtr}, Ref{PyPtr}),
d, itr.pa, itr.ka, itr.va)
error("unexpected end of PyDict_Next")
end
ko = pyincref(itr.ka[]) # PyDict_Next returns
vo = pyincref(itr.va[]) # borrowed ref, so incref
(Pair(convert(K,ko), convert(V,vo)),
PyDict_Iterator(itr.ka, itr.va, itr.pa, itr.i+1, itr.len))
end

# Iterator for generic mapping, using Python items iterator.
# To strictly use the Julia iteration protocol, we should pass
# d.o["items"] rather than d.o to done and next, but the PyObject
# iterator functions only look at the state s, so we are okay.
Base.start(d::PyDict{K,V,false}) where {K,V} = start(pycall(d.o["items"], PyObject))
Base.done(d::PyDict{K,V,false}, s) where {K,V} = done(d.o, s)
function Base.next(d::PyDict{K,V,false}, s) where {K,V}
nxt = PyObject(@pycheck ccall((@pysym :PyIter_Next), PyPtr, (PyPtr,), s[2]))
return (convert(Pair{K,V}, s[1]), (nxt, s[2]))
end
else
function Base.iterate(d::PyDict{K,V,true}, itr=PyDict_Iterator(Ref{PyPtr}(), Ref{PyPtr}(), Ref(0), 0, length(d))) where {K,V}
itr.i >= itr.len && return nothing
if 0 == ccall((@pysym :PyDict_Next), Cint,
(PyPtr, Ref{Int}, Ref{PyPtr}, Ref{PyPtr}),
d, itr.pa, itr.ka, itr.va)
error("unexpected end of PyDict_Next")
end
ko = pyincref(itr.ka[]) # PyDict_Next returns
vo = pyincref(itr.va[]) # borrowed ref, so incref
(Pair(convert(K,ko), convert(V,vo)),
PyDict_Iterator(itr.ka, itr.va, itr.pa, itr.i+1, itr.len))
end

# Iterator for generic mapping, using Python items iterator.
# Our approach is to wrap an iterator over d.o["items"]
# which necessitates including d.o["items"] in the state.
function _start(d::PyDict{K,V,false}) where {K,V}
d_items = pycall(d.o["items"], PyObject)
(d_items, iterate(d_items))
end
function Base.iterate(d::PyDict{K,V,false}, itr=_start(d)) where {K,V}
d_items, iter_result = itr
iter_result === nothing && return nothing
item, state = iter_result
iter_result = iterate(d_items, state)
(item[1] => item[2], (d_items, iter_result))
end

function Base.iterate(d::PyDict{K,V,true}, itr=PyDict_Iterator(Ref{PyPtr}(), Ref{PyPtr}(), Ref(0), 0, length(d))) where {K,V}
itr.i >= itr.len && return nothing
if 0 == ccall((@pysym :PyDict_Next), Cint,
(PyPtr, Ref{Int}, Ref{PyPtr}, Ref{PyPtr}),
d, itr.pa, itr.ka, itr.va)
error("unexpected end of PyDict_Next")
end
ko = pyincref(itr.ka[]) # PyDict_Next returns
vo = pyincref(itr.va[]) # borrowed ref, so incref
(Pair(convert(K,ko), convert(V,vo)),
PyDict_Iterator(itr.ka, itr.va, itr.pa, itr.i+1, itr.len))
end

# Iterator for generic mapping, using Python items iterator.
# Our approach is to wrap an iterator over d.o["items"]
# which necessitates including d.o["items"] in the state.
function _start(d::PyDict{K,V,false}) where {K,V}
d_items = pycall(d.o["items"], PyObject)
(d_items, iterate(d_items))
end
function Base.iterate(d::PyDict{K,V,false}, itr=_start(d)) where {K,V}
d_items, iter_result = itr
iter_result === nothing && return nothing
item, state = iter_result
iter_result = iterate(d_items, state)
(item[1] => item[2], (d_items, iter_result))
end

#########################################################################
Expand Down
6 changes: 1 addition & 5 deletions src/gui.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ end

# call doevent(status) every sec seconds
function install_doevent(doevent, sec::Real)
@static if VERSION < v"0.7.0-DEV.3526" # julia#25647
return Base.Timer(doevent, sec, sec)
else
return Base.Timer(doevent, sec, interval=sec)
end
return Base.Timer(doevent, sec, interval=sec)
end

# For PyPlot issue #181: recent pygobject releases emit a warning
Expand Down
4 changes: 2 additions & 2 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ macro with_ioraise(expr)
end

function jl_io_readline(io::IO, nb)
d = Compat.readline(io, keep=true)
d = readline(io, keep=true)
if sizeof(d) > nb 0
error("byte-limited readline is not yet supported by PyCall")
end
Expand All @@ -38,7 +38,7 @@ function jl_io_readlines(io::IO, nb)
ret = PyObject[]
nread = 0
while (nb < 0 || nread nb) && !eof(io)
d = Compat.readline(io, keep=true)
d = readline(io, keep=true)
nread += sizeof(d)
push!(ret, PyObject(d))
end
Expand Down
7 changes: 2 additions & 5 deletions src/pyarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,8 @@ function NoCopyArray(o::PyObject)
"Array datatype '$(get_format_str(pybuf))' not supported"))
# TODO more checks on strides etc
sz = size(pybuf)
@static if VERSION >= v"0.7.0-DEV.3526" # julia#25647
arr = unsafe_wrap(Array, convert(Ptr{T}, pybuf.buf.buf), sz, own=false)
else
arr = unsafe_wrap(Array, convert(Ptr{T}, pybuf.buf.buf), sz, false)
end
arr = unsafe_wrap(Array, convert(Ptr{T}, pybuf.buf.buf), sz, own=false)

!f_contiguous(T, sz, strides(pybuf)) &&
(arr = PermutedDimsArray(reshape(arr, reverse(sz)), (pybuf.buf.ndim:-1:1)))
return arr
Expand Down
2 changes: 1 addition & 1 deletion src/pybuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mutable struct PyBuffer
b = new(Py_buffer(C_NULL, PyPtr_NULL, 0, 0,
0, 0, C_NULL, C_NULL, C_NULL, C_NULL,
C_NULL, C_NULL, C_NULL))
@compat finalizer(pydecref, b)
finalizer(pydecref, b)
return b
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/pydates.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Conversion functions for date and time objects in the Python datetime
# module and the Julia Dates module.
import Compat.Dates
import Dates

# Unfortunately, the Python C API (in Python/Include/datetime.h) is somewhat
# painful to call from Julia because it consists mainly of macros that
Expand Down
Loading

0 comments on commit 45cbcee

Please sign in to comment.