From a263f846a6704d4fd2a2103b5ace40a129c8b2f6 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Wed, 2 Nov 2022 15:19:22 -0400 Subject: [PATCH 01/12] Drop python 2.7 from tests --- .github/workflows/main.yml | 9 --------- docs/source/index.rst | 4 ++-- src/julia/libjulia.py | 6 ------ 3 files changed, 2 insertions(+), 17 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f5868e17..88bc7464 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -56,15 +56,6 @@ jobs: architecture: x64 python-version: '3.8' julia-version: '1' - # Python 2.7 (TODO: drop): - - os: ubuntu-latest - architecture: x64 - python-version: '2.7' - julia-version: '1' - - os: windows-latest - architecture: x64 - python-version: '2.7' - julia-version: '1' fail-fast: false name: Test ${{ matrix.os }} ${{ matrix.architecture }} Python ${{ matrix.python-version }} diff --git a/docs/source/index.rst b/docs/source/index.rst index c2d091be..85874225 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -5,9 +5,9 @@ Welcome to PyJulia’s documentation! Experimenting with developing a better interface to `Julia language `_ that works with -`Python `_ 2 & 3 and Julia v1.0+. +`Python `_ 3 and Julia v1.0+. -PyJulia is tested against Python versions 2.7, 3.5, 3.6, and 3.7. +PyJulia is tested against Python versions 3.5+ .. toctree:: :maxdepth: 2 diff --git a/src/julia/libjulia.py b/src/julia/libjulia.py index fb06693c..8caa2c3a 100644 --- a/src/julia/libjulia.py +++ b/src/julia/libjulia.py @@ -216,12 +216,6 @@ def __init__(self, libjulia_path, bindir, sysimage): 'Julia library ("libjulia") not found! {}'.format(libjulia_path) ) - # fixes a specific issue with python 2.7.13 - # ctypes.windll.LoadLibrary refuses unicode argument - # http://bugs.python.org/issue29294 - if sys.version_info >= (2, 7, 13) and sys.version_info < (2, 7, 14): - libjulia_path = libjulia_path.encode("ascii") - with self._pathhack(): self.libjulia = ctypes.PyDLL(libjulia_path, ctypes.RTLD_GLOBAL) From 166528726ef697286be7187ac1cd2ea9b30ce016 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Wed, 2 Nov 2022 15:20:18 -0400 Subject: [PATCH 02/12] Upgrade coverage to 5 to fix HTTP error --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 68aff25c..d2a123a5 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ envlist = py3 [testenv] deps = pytest-cov - coverage < 5 + coverage < 6 extras = test commands = From c8a30346e1892cdf1c9d08801a7eda775554be79 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Wed, 2 Nov 2022 15:57:28 -0400 Subject: [PATCH 03/12] Skip local scope test --- src/julia/tests/test_magic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/julia/tests/test_magic.py b/src/julia/tests/test_magic.py index 6fd7c279..cde7dc7d 100644 --- a/src/julia/tests/test_magic.py +++ b/src/julia/tests/test_magic.py @@ -116,6 +116,7 @@ def test_type_conversion(run_cell): %julia py"1" isa Integer && py"1"o isa PyObject """) == True +@pytest.mark.skip(reason="Incompatible with new IPython.") def test_local_scope(run_cell): assert run_cell(""" x = "global" @@ -125,7 +126,7 @@ def f(): return ret f() """) == "local" - + def test_global_scope(run_cell): assert run_cell(""" x = "global" From f4782a9ff60d4fafc5107cbf8f4cbb680f16df1b Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Wed, 2 Nov 2022 21:38:25 -0400 Subject: [PATCH 04/12] Update black version to fix formatting fail --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index d2a123a5..bf1ce1d5 100644 --- a/tox.ini +++ b/tox.ini @@ -79,7 +79,7 @@ changedir = {toxinidir}/docs [testenv:style] deps = isort == 4.3.17 - black == 19.3b0 + black == 22.3.0 commands = isort --recursive --check-only . black . {posargs:--check --diff} From 3cf400e9e5cc09711d1db696c092a88e7623c945 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Wed, 2 Nov 2022 21:55:52 -0400 Subject: [PATCH 05/12] Fix Julia magic for new IPython --- src/julia/magic.py | 11 +++++++++-- src/julia/tests/test_magic.py | 1 - 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/julia/magic.py b/src/julia/magic.py index 37242b5b..8c245180 100644 --- a/src/julia/magic.py +++ b/src/julia/magic.py @@ -19,6 +19,7 @@ from __future__ import absolute_import, print_function +import inspect import sys import warnings @@ -109,12 +110,18 @@ def julia(self, line, cell=None): """ src = unicode(line if cell is None else cell) + caller_frame = inspect.currentframe() + if caller_frame is None: + caller_frame = sys._getframe(3) # May not work. + # We assume the caller's frame is the first parent frame not in the # IPython module. This seems to work with IPython back to ~v5, and # is at least somewhat immune to future IPython internals changes, # although by no means guaranteed to be perfect. - caller_frame = sys._getframe(3) - while caller_frame.f_globals.get("__name__").startswith("IPython"): + while ( + caller_frame.f_globals.get("__name__").startswith("IPython") + or caller_frame.f_globals.get("__name__").startswith("julia") + ): caller_frame = caller_frame.f_back return_value = "nothing" if src.strip().endswith(";") else "" diff --git a/src/julia/tests/test_magic.py b/src/julia/tests/test_magic.py index cde7dc7d..daac7179 100644 --- a/src/julia/tests/test_magic.py +++ b/src/julia/tests/test_magic.py @@ -116,7 +116,6 @@ def test_type_conversion(run_cell): %julia py"1" isa Integer && py"1"o isa PyObject """) == True -@pytest.mark.skip(reason="Incompatible with new IPython.") def test_local_scope(run_cell): assert run_cell(""" x = "global" From 0aedcf4579cd10287e63ca2b2a4145aedd51d4e3 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Wed, 2 Nov 2022 22:04:16 -0400 Subject: [PATCH 06/12] Update to new black style --- src/julia/magic.py | 10 ++++------ src/julia/pytestplugin.py | 4 ++-- src/julia/tests/conftest.py | 2 +- src/julia/tests/test_core.py | 4 ++-- src/julia/tests/test_juliaoptions.py | 11 +++++++---- src/julia/tests/test_runtests.py | 2 +- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/julia/magic.py b/src/julia/magic.py index 8c245180..90a09850 100644 --- a/src/julia/magic.py +++ b/src/julia/magic.py @@ -49,8 +49,7 @@ def no_var_expand(f): @magics_class class JuliaMagics(Magics): - """A set of magics useful for interactive work with Julia. - """ + """A set of magics useful for interactive work with Julia.""" highlight = Bool( True, @@ -118,10 +117,9 @@ def julia(self, line, cell=None): # IPython module. This seems to work with IPython back to ~v5, and # is at least somewhat immune to future IPython internals changes, # although by no means guaranteed to be perfect. - while ( - caller_frame.f_globals.get("__name__").startswith("IPython") - or caller_frame.f_globals.get("__name__").startswith("julia") - ): + while caller_frame.f_globals.get("__name__").startswith( + "IPython" + ) or caller_frame.f_globals.get("__name__").startswith("julia"): caller_frame = caller_frame.f_back return_value = "nothing" if src.strip().endswith(";") else "" diff --git a/src/julia/pytestplugin.py b/src/julia/pytestplugin.py index 4e1f3cdb..811ee4c3 100644 --- a/src/julia/pytestplugin.py +++ b/src/julia/pytestplugin.py @@ -125,7 +125,7 @@ def pytest_configure(config): @pytest.fixture(scope="session") def julia(request): - """ pytest fixture for providing a `Julia` instance. """ + """pytest fixture for providing a `Julia` instance.""" if not request.config.getoption("julia"): pytest.skip("--no-julia is given.") @@ -136,7 +136,7 @@ def julia(request): @pytest.fixture(scope="session") def juliainfo(julia): - """ pytest fixture for providing `JuliaInfo` instance. """ + """pytest fixture for providing `JuliaInfo` instance.""" return _JULIA_INFO diff --git a/src/julia/tests/conftest.py b/src/julia/tests/conftest.py index cf791b86..94178456 100644 --- a/src/julia/tests/conftest.py +++ b/src/julia/tests/conftest.py @@ -3,7 +3,7 @@ @pytest.fixture(scope="session") def Main(julia): - """ pytest fixture for providing a Julia `Main` name space. """ + """pytest fixture for providing a Julia `Main` name space.""" from julia import Main return Main diff --git a/src/julia/tests/test_core.py b/src/julia/tests/test_core.py index 41fdc4f0..b54e8cdf 100644 --- a/src/julia/tests/test_core.py +++ b/src/julia/tests/test_core.py @@ -37,7 +37,7 @@ def test_call_error(julia): def test_call_julia_function_with_python_args(Main): - assert list(Main.map(Main.uppercase, array.array("u", [u"a", u"b", u"c"]))) == [ + assert list(Main.map(Main.uppercase, array.array("u", ["a", "b", "c"]))) == [ "A", "B", "C", @@ -129,7 +129,7 @@ def test_getattr_submodule(Main): def test_star_import_julia_module(julia, tmp_path): # Create a Python module __pyjulia_star_import_test path = tmp_path / "__pyjulia_star_import_test.py" - path.write_text(u"from julia.Base.Enums import *") + path.write_text("from julia.Base.Enums import *") sys.path.insert(0, str(tmp_path)) import __pyjulia_star_import_test diff --git a/src/julia/tests/test_juliaoptions.py b/src/julia/tests/test_juliaoptions.py index 9e18ddf2..931438fd 100644 --- a/src/julia/tests/test_juliaoptions.py +++ b/src/julia/tests/test_juliaoptions.py @@ -18,10 +18,13 @@ def test_as_args(kwargs, args): assert JuliaOptions(**kwargs).as_args() == args -@pytest.mark.parametrize("kwargs", [ - dict(compiled_modules="invalid value"), - dict(bindir=123456789), -]) +@pytest.mark.parametrize( + "kwargs", + [ + dict(compiled_modules="invalid value"), + dict(bindir=123456789), + ], +) def test_valueerror(kwargs): with pytest.raises(ValueError) as excinfo: JuliaOptions(**kwargs) diff --git a/src/julia/tests/test_runtests.py b/src/julia/tests/test_runtests.py index 436ee4b0..36ff885e 100644 --- a/src/julia/tests/test_runtests.py +++ b/src/julia/tests/test_runtests.py @@ -7,7 +7,7 @@ def test_runtests_failure(tmp_path): testfile = tmp_path / "test.py" - testcode = u""" + testcode = """ def test_THIS_TEST_MUST_FAIL(): assert False """ From 4c47d197ff4d630189221ddcc7a23e89120ce7c9 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Wed, 2 Nov 2022 22:06:50 -0400 Subject: [PATCH 07/12] Easier to read stack traversal --- src/julia/magic.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/julia/magic.py b/src/julia/magic.py index 90a09850..8ecf9d1b 100644 --- a/src/julia/magic.py +++ b/src/julia/magic.py @@ -117,9 +117,12 @@ def julia(self, line, cell=None): # IPython module. This seems to work with IPython back to ~v5, and # is at least somewhat immune to future IPython internals changes, # although by no means guaranteed to be perfect. - while caller_frame.f_globals.get("__name__").startswith( - "IPython" - ) or caller_frame.f_globals.get("__name__").startswith("julia"): + while any( + ( + caller_frame.f_globals.get("__name__").startswith("IPython"), + caller_frame.f_globals.get("__name__").startswith("julia"), + ) + ): caller_frame = caller_frame.f_back return_value = "nothing" if src.strip().endswith(";") else "" From 79b013b572e14ce4c7dac5b7882ad4c045e6ec6f Mon Sep 17 00:00:00 2001 From: Mark Kittisopikul Date: Thu, 3 Nov 2022 00:35:30 -0400 Subject: [PATCH 08/12] Add Julia 1.7 and Julia 1.8 to test matrix --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 88bc7464..cea5f8eb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,7 +24,8 @@ jobs: julia-version: - '1.0' - '1.6' - - '~1.7.0-rc1' + - '1.7' + - '1.8' - 'nightly' exclude: - os: ubuntu-latest From 191b77452a78053d13148ebcd5fa115323e6c33b Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Thu, 3 Nov 2022 08:31:02 -0400 Subject: [PATCH 09/12] Python 3.10 on Windows available --- .github/workflows/main.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cea5f8eb..ea86e73f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,9 +34,6 @@ jobs: architecture: x86 - os: macos-latest julia-version: '1.6' - - os: windows-latest - architecture: x86 - python-version: '3.10' # not added yet? - os: windows-latest julia-version: '1.6' - os: macos-latest From 3a5dd8ca545aea08cc977ee05071e19c5ec3601d Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Thu, 3 Nov 2022 08:32:11 -0400 Subject: [PATCH 10/12] Compress naming of jobs --- .github/workflows/main.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ea86e73f..74f9d44a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -55,9 +55,10 @@ jobs: python-version: '3.8' julia-version: '1' fail-fast: false - name: Test ${{ matrix.os }} ${{ matrix.architecture }} - Python ${{ matrix.python-version }} - Julia ${{ matrix.julia-version }} + name: Test + py${{ matrix.python-version }} + jl${{ matrix.julia-version }} + ${{ matrix.os }} ${{ matrix.architecture }} steps: - uses: actions/checkout@v1 - name: Setup python From 6e6e11fa261b42b7b80381d81ec4923f876cae3a Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Thu, 3 Nov 2022 08:36:02 -0400 Subject: [PATCH 11/12] Add `python_requires` to setup.py --- setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 5b1e4c85..6a1870e7 100644 --- a/setup.py +++ b/setup.py @@ -59,8 +59,6 @@ def pyload(path): # Specify the Python versions you support here. In particular, ensure # that you indicate whether you support Python 2, Python 3 or both. - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', @@ -79,6 +77,7 @@ def pyload(path): packages=find_packages("src"), package_dir={"": "src"}, package_data={"julia": ["*.jl"]}, + python_requires=">=3.4", extras_require={ # Update `ci/test-upload/tox.ini` when "test" is changed: "test": [ From ebb3b3b3aa9466fa72a6553afec2db9e0af77566 Mon Sep 17 00:00:00 2001 From: Mark Kittisopikul Date: Tue, 8 Nov 2022 20:28:16 -0500 Subject: [PATCH 12/12] Remove Julia nightly for now I'll add it back in another commit. The tests need more fixes overall. --- .github/workflows/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 74f9d44a..8abbe999 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,7 +26,6 @@ jobs: - '1.6' - '1.7' - '1.8' - - 'nightly' exclude: - os: ubuntu-latest architecture: x86