diff --git a/.github/workflows/test_and_publish.yml b/.github/workflows/test_and_publish.yml index 1b7680ab..d1448ca9 100644 --- a/.github/workflows/test_and_publish.yml +++ b/.github/workflows/test_and_publish.yml @@ -17,11 +17,22 @@ jobs: # This workflow runs the tests tests: + # Set shell to work properly with Mamba + defaults: + run: + shell: bash -l {0} + # Setup test matrix strategy: fail-fast: false matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "pypy-3.8"] + python-version: [ + {"pkg_name": "python==3.7.*", "flag": "3.7"}, + {"pkg_name": "python==3.8.*", "flag": "3.8"}, + {"pkg_name": "python==3.9.*", "flag": "3.9"}, + {"pkg_name": "python==3.10.*", "flag": "3.10"}, + {"pkg_name": "pypy3.8", "flag": "pypy3.8"}, + ] # The type of runner that the job will run on runs-on: ubuntu-22.04 @@ -47,12 +58,18 @@ jobs: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 - # Setup Python - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + # Setup Conda for Python and Pypy + - name: Install Conda environment with Micromamba + uses: mamba-org/provision-with-micromamba@main with: - python-version: ${{ matrix.python-version }} - architecture: x64 + environment-file: false + environment-name: test_${{ matrix.python-version.flag }} + channels: conda-forge,defaults + cache-downloads: true + extra-specs: | + ${{ matrix.python-version.pkg_name }} + libspatialite + pyproj # Config PostgreSQL - name: Configure PostgreSQL @@ -63,37 +80,30 @@ jobs: # Add PostGIS extension to "gis" database psql -h localhost -p 5432 -U gis -d gis -c 'CREATE EXTENSION IF NOT EXISTS postgis;' + # Drop PostGIS Tiger Geocoder extension to "gis" database psql -h localhost -p 5432 -U gis -d gis -c 'DROP EXTENSION IF EXISTS postgis_tiger_geocoder CASCADE;' # Check python version - name: Display Python version - run: python -c "import sys; print(sys.version)" + run: | + /home/runner/micromamba-bin/micromamba info + /home/runner/micromamba-bin/micromamba list + python -c "import sys; print(sys.version)" # Install dependencies - name: Install dependencies run: | - sudo apt-get update - sudo apt-get install -y autotools-dev \ - git \ - libexpat1-dev \ - libfreexl-dev \ - libgeos-dev \ - libproj-dev \ - libreadline-dev \ - libsqlite3-dev \ - libsqlite3-mod-spatialite \ - libxml2-dev \ - zlib1g-dev - pip install --upgrade pip setuptools + python -m pip install --upgrade pip setuptools pip install tox-gh-actions # Run the test suite - name: Run the tests env: - SPATIALITE_LIBRARY_PATH: /usr/lib/x86_64-linux-gnu/mod_spatialite.so + SPATIALITE_LIBRARY_PATH: /home/runner/micromamba-root/envs/test_${{ matrix.python-version.flag }}/lib/mod_spatialite.so + PROJ_LIB: /home/runner/micromamba-root/envs/test_${{ matrix.python-version.flag }}/share/proj COVERAGE_FILE: .coverage run: | - # Run the unit test suite with SQLAlchemy=1.1.2 and then with the latest version of SQLAlchemy + # Run the unit test suite with SQLAlchemy=1.4.* and then with the latest version of SQLAlchemy tox -vv # Export coverage to Coveralls @@ -101,7 +111,7 @@ jobs: uses: AndreMiras/coveralls-python-action@v20201129 with: parallel: true - flag-name: run-${{ matrix.python-version }} + flag-name: run-${{ matrix.python-version.flag }} # This workflow aggregates coverages from all jobs and export it to Coveralls diff --git a/GeoAlchemy2_dev.yml b/GeoAlchemy2_dev.yml new file mode 100644 index 00000000..f71f71fa --- /dev/null +++ b/GeoAlchemy2_dev.yml @@ -0,0 +1,8 @@ +name: GeoAlchemy2_dev +channels: + - conda-forge +dependencies: + - libspatialite + - python=3.7.* + - pyproj + - psycopg2 diff --git a/TEST.rst b/TEST.rst index 77dda9fd..47c58da6 100644 --- a/TEST.rst +++ b/TEST.rst @@ -22,6 +22,8 @@ Install the Python dependencies:: $ pip install -r requirements.txt $ pip install psycopg2 +Or you can use the Conda environment provided in the `GeoAlchemy2_dev.yml` file. + Set up the PostGIS database =========================== diff --git a/tests/__init__.py b/tests/__init__.py index 2498594e..1e2a6688 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,6 +1,7 @@ import os import re import shutil +import sys import pytest from packaging import version @@ -99,6 +100,19 @@ def copy_and_connect_sqlite_db(input_db, tmp_db, engine_echo): "SPATIALITE VERSION:", connection.execute(text("SELECT spatialite_version();")).fetchone()[0], ) + print( + "GEOS VERSION:", + connection.execute(text("SELECT geos_version();")).fetchone()[0], + ) + if sys.version_info.minor > 7: + print( + "PROJ VERSION:", + connection.execute(text("SELECT proj_version();")).fetchone()[0], + ) + print( + "PROJ DB PATH:", + connection.execute(text("SELECT PROJ_GetDatabasePath();")).fetchone()[0], + ) if input_db.endswith("spatialite_lt_4.sqlite"): engine._spatialite_version = 3 diff --git a/tests/conftest.py b/tests/conftest.py index b86e7323..7ed25a89 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,7 +4,6 @@ import pytest from sqlalchemy import MetaData from sqlalchemy import create_engine -from sqlalchemy import text from sqlalchemy.dialects.sqlite.base import SQLiteDialect from sqlalchemy.orm import declarative_base from sqlalchemy.orm import sessionmaker @@ -137,8 +136,6 @@ def engine(tmpdir, db_url, _engine_echo): @pytest.fixture def session(engine): session = sessionmaker(bind=engine)() - if engine.dialect.name == "sqlite": - session.execute(text("SELECT InitSpatialMetaData()")) yield session session.rollback() diff --git a/tox.ini b/tox.ini index bad27c05..752f1b5f 100644 --- a/tox.ini +++ b/tox.ini @@ -14,6 +14,7 @@ python = [testenv] passenv= PYTEST_DB_URL + PROJ_LIB SPATIALITE_LIBRARY_PATH SPATIALITE_DB_PATH setenv=