From cdd120c629c0d7d4ebba7f281c6b6fc9bd0500a8 Mon Sep 17 00:00:00 2001 From: MARCHAND MANON Date: Wed, 8 Nov 2023 11:29:36 +0100 Subject: [PATCH 1/2] ci: add tests for python 3.12 This commit also refactors all the requirement files into optional dependencies bundles in the pyproject file --- .github/workflows/cov-and-doc.yml | 8 +++--- .github/workflows/deploy-docs.yml | 10 ++++---- .github/workflows/deploy.yml | 22 ++++++++-------- .github/workflows/notebooks.yml | 15 ++++++----- .github/workflows/test.yml | 16 ++++++------ README.rst | 19 ++++++++++---- docs/contribute.rst | 42 +++++++++++++++---------------- pyproject.toml | 30 ++++++++++++++++++---- python/mocpy/moc/moc.py | 14 +++++------ requirements/contributing.txt | 27 -------------------- requirements/docs.txt | 16 ------------ requirements/environment.yml | 17 ------------- requirements/notebooks.txt | 14 ----------- requirements/tests.txt | 17 ------------- 14 files changed, 102 insertions(+), 165 deletions(-) delete mode 100644 requirements/contributing.txt delete mode 100644 requirements/docs.txt delete mode 100644 requirements/environment.yml delete mode 100644 requirements/notebooks.txt delete mode 100644 requirements/tests.txt diff --git a/.github/workflows/cov-and-doc.yml b/.github/workflows/cov-and-doc.yml index 8def7625..69c4f7c0 100644 --- a/.github/workflows/cov-and-doc.yml +++ b/.github/workflows/cov-and-doc.yml @@ -15,13 +15,13 @@ jobs: runs-on: ubuntu-latest steps: - name: "Checkout branch ${{ github.head_ref }}" - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} - name: "Set up Python on Ubuntu" uses: actions/setup-python@v4 with: - python-version: 3.11 + python-version: 3.12 # Test Rust code - name: "Test with coverage, build and test doc" run: | @@ -37,12 +37,12 @@ jobs: # Build and install mocpy maturin develop --release # Install pytest-cov, needed to test with coverage - pip install -r requirements/tests.txt + pip install .[dev] pip install pytest-cov # Run test with coverage and doctests python -m pytest -v -s --doctest-modules python/mocpy --cov-report=term --cov=python/mocpy # Install dependencies needed to build the docs - pip install -r requirements/docs.txt + pip install .[docs] sudo apt-get install pandoc # Compile the docs and run the test examples cd ./docs diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index 547254aa..80990958 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -11,13 +11,13 @@ jobs: runs-on: ubuntu-latest steps: - name: "Checkout branch ${{ github.head_ref }}" - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} - name: "Set up Python on Ubuntu" uses: actions/setup-python@v4 with: - python-version: 3.11 + python-version: 3.12 - name: "Build doc" run: | # Build the doc @@ -31,7 +31,7 @@ jobs: # - Build and install mocpy maturin develop --release # - Install dependencies needed to build the docs - pip install -r requirements/docs.txt + pip install .[docs] sudo apt-get install pandoc # - Build the doc: once done, it is in docs/_build/html/ cd ./docs @@ -40,8 +40,8 @@ jobs: # Switch off the virtualenv deactivate - name: "Publish doc on github pages (commit on branch gh-pages)" - uses: JamesIves/github-pages-deploy-action@4.4.3 + uses: JamesIves/github-pages-deploy-action@v4 with: branch: gh-pages folder: docs/_build/html/ - + diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c8cb270e..281114f7 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -28,7 +28,7 @@ jobs: run: | source $HOME/.cargo/env rustup target add wasm32-unknown-emscripten - for PYBIN in /opt/python/cp3[78910]*/bin; do + for PYBIN in /opt/python/cp3{8,9,10,11,12}-*/bin; do "${PYBIN}/pip" install --upgrade pip "${PYBIN}/pip" install maturin "${PYBIN}/maturin" publish -i "${PYBIN}/python" --skip-existing --compatibility manylinux2014 --username "$MATURIN_USERNAME" @@ -47,10 +47,10 @@ jobs: img: quay.io/pypa/manylinux2014_i686 steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: "Set up QEMU" id: qemu - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@v3 - name: Install dependencies run: | docker run --rm -v ${{ github.workspace }}:/ws:rw --workdir=/ws \ @@ -59,7 +59,7 @@ jobs: ${{ env.img }} \ bash -exc 'curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \ source $HOME/.cargo/env && \ - for PYBIN in /opt/python/cp3[8910]*/bin; do + for PYBIN in /opt/python/cp3{8,9,10,11,12}-*/bin; do echo "Loop on PYBIN: $PYBIN" "${PYBIN}/pip" install --upgrade pip "${PYBIN}/pip" install maturin @@ -76,10 +76,10 @@ jobs: img: quay.io/pypa/manylinux2014_aarch64 steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: "Set up QEMU" id: qemu - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@v3 - name: Install dependencies run: | docker run --rm -v ${{ github.workspace }}:/ws:rw --workdir=/ws \ @@ -88,7 +88,7 @@ jobs: ${{ env.img }} \ bash -exc 'curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-host aarch64-unknown-linux-gnu -y && \ source $HOME/.cargo/env && \ - for PYBIN in /opt/python/cp3[78910]*/bin; do + for PYBIN in /opt/python/cp3{8,9,10,11,12}-*/bin; do echo "Loop on PYBIN: $PYBIN" "${PYBIN}/pip" install maturin "${PYBIN}/maturin" -V @@ -104,10 +104,10 @@ jobs: fail-fast: false matrix: os: [windows-latest] - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] + python-version: ['3.8', '3.9', '3.10', '3.11','3.12'] steps: # Checkout the project - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 # Set up python, see https://docs.github.com/en/actions/guides/building-and-testing-python - name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }} uses: actions/setup-python@v4 @@ -139,10 +139,10 @@ jobs: fail-fast: false matrix: os: [macOS-latest] - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] steps: # Checkout the project - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 # Set up python, see https://docs.github.com/en/actions/guides/building-and-testing-python - name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }} uses: actions/setup-python@v4 diff --git a/.github/workflows/notebooks.yml b/.github/workflows/notebooks.yml index fbe61dee..2b1d05f2 100644 --- a/.github/workflows/notebooks.yml +++ b/.github/workflows/notebooks.yml @@ -1,23 +1,22 @@ name: notebooks-mocpy on: workflow_dispatch -jobs: +jobs: # Run the notebooks. This add more examples to test the code with. - # This workflow should not block the deployment pipeline. + # This workflow should not block the deployment pipeline. run-notebooks: runs-on: ubuntu-latest steps: - name: "Checkout branch ${{ github.head_ref }}" - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} - - name: "Set up Python 3.8 on Ubuntu" + - name: "Set up Python 3.12 on Ubuntu" uses: actions/setup-python@v4 with: - python-version: 3.8 - # Test Rust code + python-version: 3.12 - name: "Run notebooks" run: | - # Install virtualenv + # Install virtualenv pip install virtualenv # Create and activate a new virtualenv virtualenv mocpy-env @@ -29,7 +28,7 @@ jobs: # Build and install mocpy maturin develop --release # Install pytest-cov, needed to test with coverage - pip install -r requirements/notebooks.txt + pip install .[notebooks] # Add the mocpy-env environnement as a jupyter kernel python -m ipykernel install --user --name mocpy-env # Run the notebooks under that kernel diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3df8c1af..e8c4568e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,7 +29,7 @@ jobs: - name: "Build and test wheels" run: | source $HOME/.cargo/env - for PYBIN in /opt/python/cp{37,38,39,310,311}-*/bin; do + for PYBIN in /opt/python/cp3{8,9,10,11,12}-*/bin; do echo "Loop on PYBIN: $PYBIN" # With maturin develop, we have to use virtualenv "${PYBIN}/pip" install virtualenv @@ -39,7 +39,7 @@ jobs: pip install maturin maturin build --release --compatibility manylinux2014 maturin develop --release - pip install -r requirements/tests.txt + pip install .[dev] python -m pytest -v -s python/mocpy pip freeze > requirements-uninstall.txt pip uninstall -r requirements-uninstall.txt -y @@ -51,11 +51,11 @@ jobs: runs-on: macOS-latest strategy: matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] steps: # Checkout the project - name: "Checkout branch ${{ github.head_ref }}" - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} # Set up python, see https://docs.github.com/en/actions/guides/building-and-testing-python @@ -77,7 +77,7 @@ jobs: maturin build --release --target universal2-apple-darwin maturin develop --release # Install dependencies - pip install -r requirements/tests.txt + pip install .[dev] # Run tests python -m pytest -v -s python/mocpy # Clean @@ -90,11 +90,11 @@ jobs: runs-on: windows-latest strategy: matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] steps: # Checkout the project - name: "Checkout branch ${{ github.head_ref }}" - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} # Set up python, see https://docs.github.com/en/actions/guides/building-and-testing-python @@ -114,7 +114,7 @@ jobs: pip install maturin maturin develop --release # Install dependencies - pip install -r requirements\tests.txt + pip install .[dev] # Run tests python -m pytest -v -s python\mocpy deactivate diff --git a/README.rst b/README.rst index 0c55b79d..55ecd688 100644 --- a/README.rst +++ b/README.rst @@ -77,17 +77,26 @@ Latest stable version - from conda ``conda install -c conda-forge mocpy`` - from this repository -Developpement version -********************* +Unreleased latest version +************************* .. code:: git clone https://github.com/cds-astro/mocpy.git cd mocpy pip install . - + Note that the point is important. - + +To run the notebooks +******************** + +The example notebooks require additional dependencies. They can be installed with + +.. code:: + + pip install mocpy[notebooks] + For use in pyodide ****************** -Wheels that run in pyodide can be downloaded from `this repository assets `__. This is not fully tested. +Wheels that run in pyodide can be downloaded from `this repository assets `__. This is not fully tested. diff --git a/docs/contribute.rst b/docs/contribute.rst index d56b94f9..12fe483a 100644 --- a/docs/contribute.rst +++ b/docs/contribute.rst @@ -10,24 +10,24 @@ interpreter and package manager. Setting up the environment -------------------------- -There is two ways to set up an environment. +Here we highlight two ways to set up an environment. Using conda (installed from miniconda or anaconda) or -using the pip package called +using the pip package `virtualenv `__ . -Choose the one you prefer. +Choose the one you prefer, or your own one. Using conda ~~~~~~~~~~~ - Set up the conda environment and activate it:: - conda env create -q python=3.8 -f /requirements/environment.yml -n mocpy-env - source activate mocpy-env + conda create -n mocpy-dev python==3.12.* + source activate mocpy-dev - Once you are done with your developments you can deactivate your conda environment:: - source deactivate + conda deactivate Using virtualenv ~~~~~~~~~~~~~~~~ @@ -53,9 +53,9 @@ along with a new empty pip package manager. opens a session with the ``mocpy-env`` interpreter. - You can now install all the necessary pip packages - for developping and testing MOCpy:: + for developing and testing MOCpy:: - pip install -r /requirements/contributing.txt + pip install .[dev] - Once you are done with your developments you can deactivate the virtual env:: @@ -68,7 +68,7 @@ Pre-commits setup pre-commit install -It will run linting and formating tests at each of your commits. +It will run linting and formatting tests at each of your commits. Now build package ----------------- @@ -83,7 +83,8 @@ Now build package This step will inform you of any issue in the rust part. -- After a new version of mocpy goes out, if a ``maturin develop --release`` does not actualise your ``Cargo.toml`` file, you might need to before executing the ``maturin`` command again:: +- After a new version of mocpy goes out, if a ``maturin develop --release`` does not actualize your +``Cargo.toml`` file, you might need to before executing the ``maturin`` command again:: rm Cargo.lock && cargo clean @@ -102,29 +103,28 @@ Once your environment is set up and activated you can run the tests - When contributing to the notebooks:: - python -m pip install -r requirements/notebooks.txt + python -m pip install .[notebooks] python -m pytest --nbmake -n=auto "./notebooks" -You also can have a html output of the coverage. For that set ``--cov-report=html``, -this will generate an ``htmlcov`` folder where all the static html files can be found. +You also can have a html output of the coverage with the flag ``--cov-report=html``. +This will generate an ``htmlcov`` folder where all the static html files can be found. Building the documentation -------------------------- -To see the documentation locally, you'll need to install the python packages in -:file:`requirements/docs.txt` and the pandoc software. +To see the documentation locally, you'll need to install the additional python dependencies with -- To build the docs from the repo directory:: + pip install .[docs] - cd docs - make html - cd .. +and the pandoc software (``sudo apt-get install pandoc`` on ubuntu, +``choco install pandoc`` on windows, ``brew install pandoc`` on mac, +``pacman -S haskell-pandoc`` on arch). -- Other API examples found in the documentation can be run with:: +- To build the docs from the repo directory:: cd docs - make doctest + make html cd .. You will find the html index file in the :file:`docs/_build/html` folder. diff --git a/pyproject.toml b/pyproject.toml index 79be6e22..800e9a67 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,11 +2,12 @@ [project] name = "mocpy" # 3.6 is no longer maintained and no more supported by maturin -requires-python = ">=3.7" +requires-python = ">=3.8" # https://numpy.org/neps/nep-0029-deprecation_policy.html # https://docs.astropy.org/en/stable/changelog.html dependencies = [ - "astropy", + "astropy<5.3; python_version == '3.8'", + "astropy; python_version > '3.8'", "matplotlib", # Used in fill and border "cdshealpix>=0.6.4", # Used in fill and border "networkx>=2.5", # Used in get_boundaries @@ -20,17 +21,36 @@ classifiers = [ ] [project.optional-dependencies] -query_fits = ["requests"] # Used to load FITS from URLs +# optional to load FITS from URLs +query_fits = ["requests"] +# for the documentation docs = [ - "sphinx", - "numpydoc", + "astropy-sphinx-theme", + "astropy_healpix", + "healpy", "nbsphinx", + "numpydoc", "sphinx-astropy", "sphinx-collections", "sphinx-copybutton", "sphinx-gallery", "sphinxcontrib-bibtex" ] +# for developpement +dev = [ + "astropy_healpix", + "pre-commit >= 2.20", + "pytest > 6.0", + "pytest-cov", + "requests" +] +# to run the notebooks +notebooks = [ + "astroquery", + "ipyaladin", + "maser-data", + "regions" +] [project.urls] repository = "https://github.com/cds-astro/mocpy" diff --git a/python/mocpy/moc/moc.py b/python/mocpy/moc/moc.py index f2125f49..c21c34d6 100644 --- a/python/mocpy/moc/moc.py +++ b/python/mocpy/moc/moc.py @@ -41,7 +41,7 @@ def validate_lonlat(function): Parameters ---------- function : - must have the sighature function(self, lon, lat, **kwargs) + must have the signature function(self, lon, lat, **kwargs) Returns ------- @@ -88,7 +88,7 @@ class MOC(AbstractMOC): - From a FITS file that stores HEALPix cells (see `load(path, 'fits')`). - Directly from a list of HEALPix cells expressed either as a numpy structural array (see `from_healpix_cells`) or a simple - python dictionnary (see `from_json`). + python dictionary (see `from_json`). - From a list of sky coordinates (see `from_skycoords`, `from_lonlat`). - From a convex/concave polygon (see `from_polygon`). - From a cone (will be implemented in a next version). @@ -385,12 +385,12 @@ def get_boundaries(self, order=None): The border(s) are expressed as a list of SkyCoord. Each SkyCoord refers to the coordinates of one border of the MOC (i.e. - either a border of a connexe MOC part or a border of a hole - located in a connexe MOC part). - This function is currently not stable: encoding a vertice of a + either a border of a connected MOC part or a border of a hole + located in a connected MOC part). + This function is currently not stable: encoding a vertex of a HEALPix cell (N, E, S, W) should not depend on the position of the - vertice but rather on the uniq value (+ 2 bits to encode the direction - of the vertice). + vertex but rather on the uniq value (+ 2 bits to encode the direction + of the vertex). Parameters ---------- diff --git a/requirements/contributing.txt b/requirements/contributing.txt deleted file mode 100644 index df7a84a0..00000000 --- a/requirements/contributing.txt +++ /dev/null @@ -1,27 +0,0 @@ -# This file is used for setting up an virtualenv environment -# for people wishing to contribute to MOCPy. -# See https://cds-astro.github.io/mocpy/contribute.html for more details. - -# Mandatory packages for MOCPy to work -astropy -astropy-sphinx-theme - -# Optional packages -astropy_healpix -cdshealpix>=0.6.1 -matplotlib -networkx>=2.5 -numpydoc - -# For pre-commits -pre-commit==2.20.* # to set hooks - -# Pytest extension package enabling test coverage -pytest-cov - -# Optional dependency -requests - -# Packages for updating the docs -sphinx -sphinxcontrib-bibtex diff --git a/requirements/docs.txt b/requirements/docs.txt deleted file mode 100644 index 1bcb9b20..00000000 --- a/requirements/docs.txt +++ /dev/null @@ -1,16 +0,0 @@ -astropy -astropy-sphinx-theme -astropy_healpix -cdshealpix>=0.6.1 -healpy -matplotlib -nbsphinx -networkx>=2.5 -numpydoc -requests -sphinx>7.0.0 # autoclass does not show properties in older versions -sphinx-astropy -sphinx-collections -sphinx-copybutton -sphinx-gallery -sphinxcontrib-bibtex diff --git a/requirements/environment.yml b/requirements/environment.yml deleted file mode 100644 index 0b6b95c9..00000000 --- a/requirements/environment.yml +++ /dev/null @@ -1,17 +0,0 @@ -channels: -- defaults -- conda-forge - -dependencies: -- astropy -- matplotlib -- pytest -- pytest-cov -- sphinx -- pip: - - numpydoc - - astropy-sphinx-theme - - networkx>=2.5 - - requests - - cdshealpix>=0.6.1 - - astropy_healpix diff --git a/requirements/notebooks.txt b/requirements/notebooks.txt deleted file mode 100644 index 2c546c21..00000000 --- a/requirements/notebooks.txt +++ /dev/null @@ -1,14 +0,0 @@ -astropy -astropy_healpix -astroquery -cdshealpix>=0.6.1 -ipyaladin -ipykernel -ipywidgets -maser-data -matplotlib -nbconvert -nbformat -networkx>=2.5 -regions -requests diff --git a/requirements/tests.txt b/requirements/tests.txt deleted file mode 100644 index 2e90bd6a..00000000 --- a/requirements/tests.txt +++ /dev/null @@ -1,17 +0,0 @@ -astropy - -astropy_healpix -cdshealpix>=0.6.1 -matplotlib -networkx>=2.5 - -pytest>6.0 -# Need to pin urllib3 to avoid error: -# ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' -# module is compiled with 'OpenSSL 1.0.2k-fips 26 -# See: -# * https://github.com/psf/requests/issues/6432 -# * https://urllib3.readthedocs.io/en/stable/v2-migration-guide.html#ssl-module-is-compiled-with-openssl-1-0-2-k-fips -# urllib3 is a dependency of requests -urllib3<2 -requests From 936b7cdce0ba79f7fce96a77e15f277a94c41e68 Mon Sep 17 00:00:00 2001 From: MARCHAND MANON Date: Wed, 8 Nov 2023 11:44:47 +0100 Subject: [PATCH 2/2] :memo: add changelog for support of python 3.12 [skip ci] --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cb4a9ad..c8e9466d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +### Changed + +* currently supported versions of python now range from 3.8 to 3.12. There is a catch for python 3.8: the corresponding astropy version is pinned to astropy<5.3 + ### Fixed * all methods of `MOC` with signatures like `function(self, lon, lat, **kwargs)` now accept both lists of coordinates and single coordinates