From 831bed306da99d04e0c5fe8f11e25defcab3254a Mon Sep 17 00:00:00 2001 From: Greg Lucas Date: Sat, 24 Jun 2023 22:03:25 -0600 Subject: [PATCH] BLD: cleanup setup.py and pyproject.toml Simplify some of the setup.py build work now that we have removed more extension libraries. Move the static content over to pyproject.toml and migrate more content to the modern build utilities. --- .appveyor.yml | 46 ------- .circleci/config.yml | 46 +------ .github/workflows/ci-testing.yml | 62 ++++----- .github/workflows/release.yml | 135 ++++++++++++------- INSTALL | 53 +------- MANIFEST.in | 3 +- docs/source/reference/matplotlib.rst | 3 +- environment.yml | 1 - lib/cartopy/trace.pyx | 4 +- pyproject.toml | 66 ++++++++++ requirements/default.txt | 5 - requirements/ows.txt | 2 - requirements/plotting.txt | 2 - requirements/tests.txt | 3 - setup.py | 186 +++------------------------ 15 files changed, 212 insertions(+), 405 deletions(-) delete mode 100644 .appveyor.yml delete mode 100644 requirements/default.txt delete mode 100644 requirements/ows.txt delete mode 100644 requirements/plotting.txt delete mode 100644 requirements/tests.txt diff --git a/.appveyor.yml b/.appveyor.yml deleted file mode 100644 index 6778b52ea..000000000 --- a/.appveyor.yml +++ /dev/null @@ -1,46 +0,0 @@ -environment: - matrix: - - PYTHON_VERSION: "3.9" - CONDA_INSTALL_LOCN: "C:\\Miniconda3-x64" - PACKAGES: "cython numpy matplotlib-base pyproj pykdtree scipy" - -install: - # Install miniconda - # ----------------- - - set PATH=%CONDA_INSTALL_LOCN%;%CONDA_INSTALL_LOCN%\scripts;%PATH%; - - # Create the testing environment - # ------------------------------ - - conda config --set always_yes yes --set changeps1 no --set show_channel_urls yes - - conda config --add channels conda-forge - - conda config --add channels conda-forge/label/testing - - set ENV_NAME=test-environment - - set PACKAGES=%PACKAGES% owslib pep8 pillow pyshp pytest pytest-mpl!=0.16.0 - - set PACKAGES=%PACKAGES% setuptools_scm shapely - - conda create -n %ENV_NAME% python=%PYTHON_VERSION% %PACKAGES% - - activate %ENV_NAME% - - set INCLUDE=%CONDA_PREFIX%\Library\include;%INCLUDE% - - set LIB=%CONDA_PREFIX%\Library\lib;%LIB% - - # Conda debug - # ----------- - - conda list -n %ENV_NAME% - - conda list -n %ENV_NAME% --explicit - - conda info -a - -build_script: - # Install cartopy - # --------------- - - pip install --no-deps . - - python -c "import cartopy; print('Version ', cartopy.__version__)" - -test_script: - - set MPLBACKEND=Agg - - set PYPROJ_GLOBAL_CONTEXT=ON - - pytest -ra --pyargs cartopy - --mpl --mpl-generate-summary=html --mpl-results-path=cartopy_test_output - -artifacts: - - path: cartopy_test_output - name: cartopy_test_output - type: zip diff --git a/.circleci/config.yml b/.circleci/config.yml index 389e640c8..e25eecbf8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,50 +18,15 @@ apt-run: &apt-install g++ \ make -env-run: &env-setup - # Create the basic testing environment - # Mixing conda-forge and defaults in root is a recipe for trouble, so create - # a separate environment. - name: Setup conda environment - command: | - conda config \ - --set always_yes yes \ - --set changeps1 no \ - --set show_channel_urls yes \ - --set auto_activate_base false - conda config --add channels conda-forge - conda create -n test-environment python=$PYTHON_VERSION - -deps-run: &deps-install - name: Install Python dependencies - command: | - conda install -n test-environment --quiet \ - cython \ - 'matplotlib>3.3' \ - numpy \ - owslib \ - pillow \ - pyproj \ - pykdtree \ - pyshp \ - scipy \ - setuptools_scm \ - shapely \ - $EXTRA_PACKAGES \ - --file docs/doc-requirements.txt - conda list -n test-environment - cp-run: &cp-install name: Install Cartopy command: | - source activate test-environment - pip install -ve . + python -m pip install --upgrade --user pip + python -m pip install -ve .[doc] doc-run: &doc-build name: Build documentation command: | - source activate test-environment - PYPROJ_GLOBAL_CONTEXT=ON make -C docs html @@ -72,16 +37,11 @@ doc-run: &doc-build jobs: docs-python3: docker: - - image: continuumio/miniconda3:latest + - image: cimg/python:3.11 steps: - checkout - run: *apt-install - - run: - <<: *env-setup - environment: - PYTHON_VERSION: 3.11 - - run: *deps-install - run: *cp-install - run: *doc-build diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index 815f83d3e..fd9877272 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -10,81 +10,71 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] python-version: [3.9, '3.10', '3.11'] shapely-dev: [false] include: - os: ubuntu-latest python-version: '3.11' shapely-dev: true - defaults: - run: - shell: bash -l {0} steps: - uses: actions/checkout@v3 - - uses: conda-incubator/setup-miniconda@v2 with: - activate-environment: test-environment + fetch-depth: 0 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: python-version: ${{ matrix.python-version }} - channels: conda-forge/label/testing,conda-forge + cache: 'pip' - name: Minimum packages - # Only run on Linux for now - # Conda's linux packages don't grab the testing label of matplotlib causing failures due to freetype differences if: matrix.python-version == '3.9' && matrix.os == 'ubuntu-latest' id: minimum-packages run: | - echo "PACKAGES=cython=0.29.24 matplotlib-base=3.4 numpy=1.21 owslib=0.24.1 pyproj=3.1 proj=8.0 scipy=1.6.3 shapely=1.7.1" >> $GITHUB_ENV - - - name: Latest packages - if: steps.minimum-packages.conclusion == 'skipped' && !matrix.shapely-dev - run: | - echo "PACKAGES=cython fiona matplotlib-base numpy pyproj pykdtree scipy shapely" >> $GITHUB_ENV - - - name: Latest packages with Shapely dev - if: steps.minimum-packages.conclusion == 'skipped' && matrix.shapely-dev - run: | - echo "PACKAGES=cython fiona matplotlib-base numpy pyproj pykdtree scipy geos" >> $GITHUB_ENV + pip install cython==0.29.24 matplotlib==3.4.3 numpy==1.21 owslib==0.24.1 pyproj==3.1 scipy==1.6.3 shapely==1.7.1 - name: Coverage packages id: coverage # only want the coverage to be run on the latest ubuntu if: matrix.python-version == '3.11' && matrix.os == 'ubuntu-latest' run: | - echo "PACKAGES=$PACKAGES pytest-cov coveralls" >> $GITHUB_ENV echo "CYTHON_COVERAGE=1" >> $GITHUB_ENV - echo "EXTRA_TEST_ARGS=--cov=cartopy -ra" >> $GITHUB_ENV - - - name: Install dependencies - run: | - PACKAGES="$PACKAGES owslib pep8 pillow pyshp pytest pytest-mpl!=0.16.0" - PACKAGES="$PACKAGES pytest-xdist setuptools_scm" - conda install $PACKAGES - conda info -a - conda list + # Also add doctest here to avoid windows runners which expect a different path separator + echo "EXTRA_TEST_ARGS=--cov=cartopy -ra --doctest-modules" >> $GITHUB_ENV + pip install cython - name: Install Shapely dev if: matrix.shapely-dev run: | - python -m pip install git+https://github.com/shapely/shapely.git@main + # Install Shapely from source on ubuntu + sudo apt-get update + sudo apt-get install -yy libgeos-dev + pip install git+https://github.com/shapely/shapely.git@main - name: Install Cartopy id: install run: | - MPL_CONFIG_DIR=~/.config/matplotlib - mkdir -p $MPL_CONFIG_DIR - echo "backend : agg" > $MPL_CONFIG_DIR/matplotlibrc - pip install --no-deps -e . + pip install -e .[test] python -c "import cartopy; print('Version ', cartopy.__version__)" + - name: Install extras + # Default is to install just the minimum testing requirements, + # but we want to get as much coverage as possible. + if: steps.minimum-packages.conclusion == 'skipped' + run: | + pip install .[extras,ows,plotting] + - name: Testing id: test + # we need to force bash to use line continuations + shell: bash run: | # Check that the downloader tool at least knows where to get the data from (but don't actually download it) python tools/cartopy_feature_download.py gshhs physical --dry-run CARTOPY_GIT_DIR=$PWD - PYPROJ_GLOBAL_CONTEXT=ON pytest -ra -n 4 --doctest-modules \ + pytest -ra -n 4 \ --color=yes \ --mpl --mpl-generate-summary=html \ --mpl-results-path="cartopy_test_output-${{ matrix.os }}-${{ matrix.python-version }}" \ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4d299075e..a66dc0ef5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,63 +1,108 @@ name: Build and upload to PyPI +concurrency: + group: ${{ github.workflow }}-${{ github.event.number }}-${{ github.event.ref }} + cancel-in-progress: true + # Only build on published releases -on: - release: - types: - - published +on: [push, pull_request] +# on: +# release: +# types: +# - published jobs: - build: - name: Build sdist - runs-on: ubuntu-18.04 + generate-wheels-matrix: + name: Generate wheels matrix + runs-on: ubuntu-latest + outputs: + include: ${{ steps.set-matrix.outputs.include }} + steps: + - uses: actions/checkout@v3 + - name: Install cibuildwheel + run: pipx install cibuildwheel==2.12.0 + - id: set-matrix + run: | + MATRIX=$( + { + cibuildwheel --print-build-identifiers --platform linux \ + | jq -nRc '{"only": inputs, "os": "ubuntu-latest"}' \ + && cibuildwheel --print-build-identifiers --platform macos \ + | jq -nRc '{"only": inputs, "os": "macos-latest"}' \ + && cibuildwheel --print-build-identifiers --platform windows \ + | jq -nRc '{"only": inputs, "os": "windows-2019"}' + } | jq -sc + ) + echo "include=$MATRIX" >> $GITHUB_OUTPUT + env: + CIBW_BUILD: "cp39-* cp310-* cp311-*" + # Skip 32 bit windows builds due to compiler + # Skip musllinux because there aren't musllinux wheels yet + CIBW_SKIP: "*-win32 *-musllinux*" + CIBW_ARCHS_MACOS: x86_64 arm64 + build_wheels: + name: Build ${{ matrix.os }} ${{ matrix.only }} + needs: generate-wheels-matrix + strategy: + matrix: + include: ${{ fromJson(needs.generate-wheels-matrix.outputs.include) }} + runs-on: ${{ matrix.os }} defaults: run: - shell: bash -l {0} - + shell: bash steps: - uses: actions/checkout@v3 - - uses: conda-incubator/setup-miniconda@v2 - with: - activate-environment: test-environment - python-version: ${{ matrix.python-version }} - channels: conda-forge/label/testing,conda-forge - - name: Install dependencies - run: | - PACKAGES="cython fiona matplotlib-base numpy pyproj pykdtree scipy" - PACKAGES="$PACKAGES owslib pep8 pillow pyshp pytest" - PACKAGES="$PACKAGES pytest-xdist setuptools_scm shapely" - conda install $PACKAGES + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' - - name: Create sdist - run: python setup.py build_ext sdist + - uses: pypa/cibuildwheel@v2.12.0 + with: + only: ${{ matrix.only }} - - name: Save built packages as artifact - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v3 with: - name: packages-${{ runner.os }}-${{ matrix.python-version }} - path: dist/ - if-no-files-found: error - retention-days: 5 - - publish: - name: Publish to PyPI - needs: build - environment: - name: PyPI - url: https://pypi.org/project/cartopy - permissions: - id-token: write # IMPORTANT: this permission is mandatory for trusted publishing - runs-on: ubuntu-18.04 + path: ./wheelhouse/*.whl + build_sdist: + name: Build source distribution + runs-on: ubuntu-latest steps: - - name: Download packages - uses: actions/download-artifact@v3 + - uses: actions/checkout@v3 + + - uses: actions/setup-python@v4 + name: Install Python + with: + python-version: '3.11' - - name: Consolidate packages for upload + - name: Build sdist run: | - mkdir dist - cp packages-*/* dist/ + python -m pip install build + python -m build --sdist + - uses: actions/upload-artifact@v3 + with: + path: dist/*.tar.gz + + # publish: + # name: Publish to PyPI + # needs: [build_wheels, build_sdist] + # environment: + # name: PyPI + # url: https://pypi.org/project/cartopy + # permissions: + # id-token: write # IMPORTANT: this permission is mandatory for trusted publishing + # runs-on: ubuntu-18.04 + + # steps: + # - name: Download packages + # uses: actions/download-artifact@v3 + + # - name: Consolidate packages for upload + # run: | + # mkdir dist + # cp packages-*/* dist/ - - name: Publish Package - uses: pypa/gh-action-pypi-publish@v1.8.6 + # - name: Publish Package + # uses: pypa/gh-action-pypi-publish@v1.8.6 diff --git a/INSTALL b/INSTALL index 23351841f..7af341eab 100644 --- a/INSTALL +++ b/INSTALL @@ -46,11 +46,8 @@ Required dependencies ~~~~~~~~~~~~~~~~~~~~~ In order to install Cartopy, or to access its basic functionality, it will be -necessary to first install **GEOS**, **Shapely**, and -**pyshp**. Many of these packages can be installed using pip or -other package managers such as apt-get (Linux) and brew (macOS). Many of these -dependencies are built as part of Cartopy's conda distribution, and the recipes -for these packages can be found at https://github.com/conda-forge/feedstocks. +necessary to first install **Shapely**, and +**pyshp**. Many of these packages can be installed using pip We include a conda environment file that contains a list of all the dependencies required to build and install cartopy, which can be used to @@ -63,47 +60,6 @@ To use it:: conda activate cartopy-dev pip install -e . -You can also use your system's package manager to install the dependencies. - -Ubuntu / Debian -_______________ - -On Debian, you can install the required system libraries using the system package manager:: - - sudo apt -y install libgeos-dev - -Then you can proceed to install cartopy using a python package manager:: - - pip3 install cartopy - -MacOS -_____ - -For macOS, the required dependencies can be installed in the following way:: - - brew install geos - pip3 install --upgrade pyshp - # shapely needs to be built from source to link to geos. If it is already - # installed, uninstall it by: pip3 uninstall shapely - pip3 install shapely --no-binary shapely - -Still on macOS, make sure you have installed pkg-config and set the -`PKG_CONFIG_PATH` environment variable as follows:: - - brew install pkg-config - export PKG_CONFIG_PATH=/usr/local/bin/pkgconfig - -Then you can install cartopy using:: - - pip3 install cartopy - -Other -_____ - -If you are installing dependencies with a package manager on Linux, you may -need to install the development packages (look for a "-dev" or "-devel" suffix) in addition -to the core packages. - Further information about the required dependencies can be found here: **Python** 3.9 or later (https://www.python.org/) @@ -113,9 +69,8 @@ Further information about the required dependencies can be found here: Python package for 2D plotting. Python package required for any graphical capabilities. -**Shapely** 1.7.1 or later (https://github.com/Toblerity/Shapely) - Python package for the manipulation and analysis of planar geometric - objects. +**Shapely** 1.7.1 or later (https://github.com/shapely/shapely) + Python package for the manipulation and analysis of planar geometric objects. **pyshp** 2.1 or later (https://pypi.python.org/pypi/pyshp) Pure Python read/write support for ESRI Shapefile format. diff --git a/MANIFEST.in b/MANIFEST.in index 15f79d452..8fa5acf5c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,7 +3,6 @@ prune .circleci prune benchmarks prune docs prune examples -include requirements/*.txt graft tools exclude .appveyor.yml exclude .coveragerc @@ -16,3 +15,5 @@ include COPYING* include environment.yml include INSTALL recursive-include lib/cartopy *.cpp *.h *.py *.pyx +recursive-include lib/cartopy *.TXT *.dbf *.jpg *.json *.nc *.png *.shp *.shx *.txt +include lib/cartopy/data/LICENSE diff --git a/docs/source/reference/matplotlib.rst b/docs/source/reference/matplotlib.rst index b113914ab..19cb8fa93 100644 --- a/docs/source/reference/matplotlib.rst +++ b/docs/source/reference/matplotlib.rst @@ -64,8 +64,7 @@ Additional extensions ~~~~~~~~~~~~~~~~~~~~~ Extra functionality that is primarily intended for developers. They describe -some of the capabilities for transforming -between GEOS, Shapely, and Matplotlib paths. +some of the capabilities for transforming between Shapely, and Matplotlib paths. .. autosummary:: :toctree: generated/ diff --git a/environment.yml b/environment.yml index 375ac525a..a7b40258e 100644 --- a/environment.yml +++ b/environment.yml @@ -11,7 +11,6 @@ dependencies: - cython>=0.28.5 - numpy>=1.18 - shapely>=1.6.4 - - geos>=3.7.2 - pyshp>=2.1 - pyproj>=3.0.0 # The testing label has the proper version of freetype included diff --git a/lib/cartopy/trace.pyx b/lib/cartopy/trace.pyx index 3cac0cad3..b7f5b99d1 100644 --- a/lib/cartopy/trace.pyx +++ b/lib/cartopy/trace.pyx @@ -305,9 +305,7 @@ cdef bool straightAndDomain(double t_start, const Point &p_start, p_mid = interpolator.interpolate(t_mid) # Determine the closest point on the segment to the midpoint, in - # normalized coordinates. We could use GEOSProjectNormalized_r - # here, but since it's a single line segment, it's much easier to - # just do the math ourselves: + # normalized coordinates. We can just do the math ourselves: # ○̩ (x1, y1) (assume that this is not necessarily vertical) # │ # │ D diff --git a/pyproject.toml b/pyproject.toml index 3784b8aa5..bff484950 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,6 +8,72 @@ requires = [ ] build-backend = "setuptools.build_meta" +[project] +name = "Cartopy" +authors = [ + {name = "UK Met Office"}, +] +description = "A Python library for cartographic visualizations with Matplotlib" +readme = "README.md" +requires-python = ">=3.9" +keywords = ["cartography", "map", "transform", "projection", "pyproj", "shapely", "shapefile"] +license = {file = "COPYING.LESSER"} +classifiers = [ + 'Development Status :: 4 - Beta', + 'Framework :: Matplotlib', + 'License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)', + 'Operating System :: MacOS :: MacOS X', + 'Operating System :: Microsoft :: Windows', + 'Operating System :: POSIX', + 'Operating System :: POSIX :: AIX', + 'Operating System :: POSIX :: Linux', + 'Programming Language :: C++', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3 :: Only', + 'Topic :: Scientific/Engineering', + 'Topic :: Scientific/Engineering :: GIS', + 'Topic :: Scientific/Engineering :: Visualization', +] +dependencies = [ + "numpy>=1.21", + "matplotlib>=3.4", + "shapely>=1.7", + "pyshp>=2.1", + "pyproj>=3.1.0", +] +dynamic = ["version"] + +[project.optional-dependencies] +doc = ["beautifulsoup4", "pydata-sphinx-theme", "sphinx", "sphinx-gallery"] +extras = ["pykdtree", "fiona"] +ows = ["OWSLib>=0.20.0", "pillow>=6.1.0"] +plotting = ["pillow>=6.1.0", "scipy>=1.3.1"] +test = ["packaging>=20", "pytest>=5.1.2", "pytest-mpl>=0.11", "pytest-xdist", "pytest-cov", "coveralls"] + +[project.scripts] +feature_download = "tools.cartopy_feature_download.py:__main__" + +[project.urls] +documentation='https://scitools.org.uk/cartopy/docs/latest/' +homepage='https://github.com/SciTools/cartopy' + +[tool.setuptools.packages.find] +where = ["lib"] +exclude = ["cartopy.tests*"] + +[tool.setuptools.package-data] +cartopy = ["lib/cartopy/tests/mpl/baseline_images/**", + "lib/cartopy/data/**", + "lib/cartopy/tests/lakes_shapefile/**", + "io/srtm.npz"] + +[tool.setuptools_scm] +write_to = "lib/cartopy/_version.py" + [tool.codespell] ignore-words-list = "damon,koordinates,linz,slippy,subtiles,tring" skip = "./.git,./docs/build,./docs/source/gallery,./docs/source/reference,*.cpp,*.css,*.examples,*.js,*.html,*.ipynb,*.pdf,*.rst.txt" diff --git a/requirements/default.txt b/requirements/default.txt deleted file mode 100644 index 861450c3c..000000000 --- a/requirements/default.txt +++ /dev/null @@ -1,5 +0,0 @@ -numpy>=1.18 -matplotlib>=3.1 -shapely>=1.6.4 -pyshp>=2.1 -pyproj>=3.0.0 diff --git a/requirements/ows.txt b/requirements/ows.txt deleted file mode 100644 index 05caa5d0b..000000000 --- a/requirements/ows.txt +++ /dev/null @@ -1,2 +0,0 @@ -OWSLib>=0.20.0 -pillow>=6.1.0 diff --git a/requirements/plotting.txt b/requirements/plotting.txt deleted file mode 100644 index 89bfb59b9..000000000 --- a/requirements/plotting.txt +++ /dev/null @@ -1,2 +0,0 @@ -pillow>=6.1.0 -scipy>=1.3.1 diff --git a/requirements/tests.txt b/requirements/tests.txt deleted file mode 100644 index 02688a323..000000000 --- a/requirements/tests.txt +++ /dev/null @@ -1,3 +0,0 @@ -packaging>=20 -pytest>=5.1.2 -pytest-mpl>=0.11 diff --git a/setup.py b/setup.py index 4ddda131c..8370decc1 100644 --- a/setup.py +++ b/setup.py @@ -4,35 +4,11 @@ # See COPYING and COPYING.LESSER in the root of the repository for full # licensing details. -# NOTE: This file must remain Python 2 compatible for the foreseeable future, -# to ensure that we error out properly for people with outdated setuptools -# and/or pip. -import sys - - -PYTHON_MIN_VERSION = (3, 9) - -if sys.version_info < PYTHON_MIN_VERSION: - error = """ -Beginning with Cartopy 0.22, Python {} or above is required. -You are using Python {}. - -This may be due to an out of date pip. - -Make sure you have pip >= 9.0.1. -""".format('.'.join(str(n) for n in PYTHON_MIN_VERSION), - '.'.join(str(n) for n in sys.version_info[:3])) - sys.exit(error) - - -from collections import defaultdict import os from pathlib import Path -import subprocess -from sysconfig import get_config_var -import warnings -from setuptools import Extension, find_packages, setup +import numpy as np +from setuptools import Extension, setup # The existence of a PKG-INFO directory is enough to tell us whether this is a @@ -48,74 +24,31 @@ "Cython 0.29+ is required to install cartopy from source.") from Cython.Distutils import build_ext as cy_build_ext + ext = '.pyx' + cmdclass = {'build_ext': cy_build_ext} +else: + ext = '.cpp' + cmdclass = {} +# General extension paths +compiler_directives = {} +define_macros = [] -try: - import numpy as np -except ImportError: - raise ImportError('NumPy 1.21+ is required to install cartopy.') - - -def file_walk_relative(root): - """ - Return a list of files from the top of the tree, removing - the lib/cartopy prefix from the resulting paths. - - """ - return [str(p.relative_to(Path('lib') / 'cartopy')) - for p in root.glob("**/*")] - - -# Dependency checks -# ================= +compiler_directives['profile'] = True +compiler_directives['linetrace'] = True -# Python dependencies -extras_require = {} -for name in (HERE / 'requirements').iterdir(): - with open(name) as fh: - section, ext = name.stem, name.suffix - extras_require[section] = [] - for line in fh: - if line.startswith('#'): - pass - elif line.startswith('-'): - pass - else: - extras_require[section].append(line.strip()) -install_requires = extras_require.pop('default') -tests_require = extras_require.get('tests', []) -# General extension paths -if sys.platform.startswith('win'): - def get_config_var(name): - return '.' -include_dir = get_config_var('INCLUDEDIR') -library_dir = get_config_var('LIBDIR') -extra_extension_args = defaultdict(list) -if not sys.platform.startswith('win'): - extra_extension_args["runtime_library_dirs"].append( - get_config_var('LIBDIR') - ) - -# Description -# =========== -with open(HERE / 'README.md') as fh: - description = ''.join(fh.readlines()) - - -cython_coverage_enabled = os.environ.get('CYTHON_COVERAGE', None) +cython_coverage_enabled = os.environ.get('CYTHON_COVERAGE', False) if cython_coverage_enabled: - extra_extension_args["define_macros"].append( - ('CYTHON_TRACE_NOGIL', '1') - ) + define_macros.append(('CYTHON_TRACE_NOGIL', '1')) extensions = [ Extension( 'cartopy.trace', - ['lib/cartopy/trace.pyx'], - include_dirs=[include_dir, './lib/cartopy', np.get_include()], + [f'lib/cartopy/trace{ext}'], + include_dirs=[np.get_include()], language='c++', - **extra_extension_args), + define_macros=define_macros), ] @@ -123,94 +56,13 @@ def get_config_var(name): # We need to explicitly cythonize the extension in order # to control the Cython compiler_directives. from Cython.Build import cythonize + extensions = cythonize(extensions, compiler_directives=compiler_directives) - directives = {'linetrace': True, - 'binding': True} - extensions = cythonize(extensions, compiler_directives=directives) - - -def decythonize(extensions, **_ignore): - # Remove pyx sources from extensions. - # Note: even if there are changes to the pyx files, they will be ignored. - for extension in extensions: - sources = [] - for sfile in extension.sources: - spath = Path(sfile) - ext = spath.suffix - if ext in ('.pyx',): - if extension.language == 'c++': - ext = '.cpp' - else: - ext = '.c' - sfile = str(spath.with_suffix(ext)) - sources.append(sfile) - extension.sources[:] = sources - return extensions - - -if IS_SDIST and not FORCE_CYTHON: - extensions = decythonize(extensions) - cmdclass = {} -else: - cmdclass = {'build_ext': cy_build_ext} - -base_path = Path('lib') / 'cartopy' -package_data = ( - file_walk_relative(base_path / 'tests' / 'mpl' / 'baseline_images') - + file_walk_relative(base_path / 'data') - + file_walk_relative(base_path / 'tests' / 'lakes_shapefile') - + ['io/srtm.npz']) # Main setup # ========== setup( - name='Cartopy', - url='https://scitools.org.uk/cartopy/docs/latest/', - download_url='https://github.com/SciTools/cartopy', - author='UK Met Office', - description='A cartographic python library with Matplotlib support for ' - 'visualisation', - long_description=description, - long_description_content_type='text/markdown', - license="LGPLv3", - keywords="cartography map transform projection proj proj.4 geos shapely " - "shapefile", - - install_requires=install_requires, - extras_require=extras_require, - tests_require=tests_require, - - use_scm_version={ - 'write_to': 'lib/cartopy/_version.py', - }, - - packages=find_packages("lib"), - package_dir={'': 'lib'}, - package_data={'cartopy': package_data}, - - scripts=['tools/cartopy_feature_download.py'], ext_modules=extensions, cmdclass=cmdclass, - python_requires='>=' + '.'.join(str(n) for n in PYTHON_MIN_VERSION), - classifiers=[ - 'Development Status :: 4 - Beta', - 'Framework :: Matplotlib', - 'License :: OSI Approved :: GNU Lesser General Public License v3 ' - 'or later (LGPLv3+)', - 'Operating System :: MacOS :: MacOS X', - 'Operating System :: Microsoft :: Windows', - 'Operating System :: POSIX', - 'Operating System :: POSIX :: AIX', - 'Operating System :: POSIX :: Linux', - 'Programming Language :: C++', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'Programming Language :: Python :: 3 :: Only', - 'Topic :: Scientific/Engineering', - 'Topic :: Scientific/Engineering :: GIS', - 'Topic :: Scientific/Engineering :: Visualization', - ], + )