From e448ddb1328662790acc0d27a8c1a4155273d9e5 Mon Sep 17 00:00:00 2001 From: Alex Drlica-Wagner Date: Tue, 25 Jun 2024 18:52:26 -0500 Subject: [PATCH] update github actions for python3 --- .github/workflows/python-package.yml | 10 +++++----- notebooks/kernel_example.ipynb | 16 ++++++++-------- tests/test_notebook.py | 10 ++++++---- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 90d992b..43affee 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -17,11 +17,11 @@ jobs: strategy: max-parallel: 3 matrix: - python-version: [2.7, 3.8] + python-version: ["3.7", "3.8", "3.9"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Setup conda @@ -32,7 +32,7 @@ jobs: conda info - name: Create conda environment run: | - conda create -y -q -n env python=${{ matrix.python-version }} numpy scipy matplotlib astropy healpy pyyaml emcee fitsio corner -c conda-forge -c kadrlica + conda create -y -q -n env python=${{ matrix.python-version }} numpy scipy matplotlib astropy healpy pyyaml emcee fitsio corner -c conda-forge # Add UGALIDIR to environment conda env config vars set UGALIDIR=$HOME/.ugali -n env - name: Install package @@ -55,7 +55,7 @@ jobs: # Exclude notebook tests nosetests -v -I test_notebook.py; - name: Test notebooks - if: ${{ matrix.python-version == '2.7' }} + if: ${{ true }} run: | source activate env conda install -q jupyter nbconvert -c conda-forge diff --git a/notebooks/kernel_example.ipynb b/notebooks/kernel_example.ipynb index e1f25e8..7cc5c39 100644 --- a/notebooks/kernel_example.ipynb +++ b/notebooks/kernel_example.ipynb @@ -82,7 +82,7 @@ ], "source": [ "plummer = kernel.factory(name='EllipticalPlummer',lon=0,lat=0,r_h=0.1,ellipticity=0.5, position_angle=45)\n", - "print plummer" + "print(plummer)" ] }, { @@ -227,9 +227,9 @@ "# `extension` member, though the meaning of `extension` is \n", "# different for each kernel type\n", "\n", - "print plummer\n", - "print king\n", - "print exponential" + "print(plummer)\n", + "print(king)\n", + "print(exponential)" ] }, { @@ -317,7 +317,7 @@ "ker.extension = 0.2\n", "ker.r_h = 0.2 \n", "\n", - "print ker" + "print(ker)" ] }, { @@ -340,7 +340,7 @@ "try:\n", " ker.r_h = 40\n", "except ValueError as e:\n", - " print \"Error:\",e\n" + " print(\"Error:\",e)\n" ] }, { @@ -396,8 +396,8 @@ "plt.sca(ax[1])\n", "bins = np.linspace(0,1,100)\n", "centers = (bins[:-1]+bins[1:])/2.\n", - "plt.hist(angsep(ker.lon,ker.lat,lon,lat),bins=bins,histtype='step',normed=True,label='Polar Radius')\n", - "plt.hist(ker.radius(lon,lat),bins=bins,histtype='step',normed=True,label='Elliptical Radius')\n", + "plt.hist(angsep(ker.lon,ker.lat,lon,lat),bins=bins,histtype='step',density=True,label='Polar Radius')\n", + "plt.hist(ker.radius(lon,lat),bins=bins,histtype='step',density=True,label='Elliptical Radius')\n", "plt.plot(centers,[len(bins)*ker.integrate(b1,b2) for b1,b2 in zip(bins[:-1],bins[1:])],label='Elliptical Radius')\n", "plt.xlim(0,0.7)\n", "plt.xlabel('Radius (deg)')\n", diff --git a/tests/test_notebook.py b/tests/test_notebook.py index a18341a..2e18a91 100644 --- a/tests/test_notebook.py +++ b/tests/test_notebook.py @@ -5,7 +5,7 @@ Adapted from: https://blog.thedataincubator.com/2016/06/testing-jupyter-notebooks/ """ -import os +import os,sys import unittest import glob @@ -18,11 +18,13 @@ def _notebook_run(path): """Execute a notebook via nbconvert and collect output. :returns (parsed nb object, execution errors) """ + kernel_name = "python"+str(sys.version_info.major) with tempfile.NamedTemporaryFile(suffix=".ipynb") as fout: args = ["jupyter", "nbconvert", "--to", "notebook", "--execute", - "--ExecutePreprocessor.timeout=60", - "--log-level=WARN", - "--output", fout.name, path] + "--ExecutePreprocessor.timeout=60", + "--ExecutePreprocessor.kernel_name=%s"%(kernel_name), + "--log-level=WARN", + "--output", fout.name, path] subprocess.check_call(args) fout.seek(0)