Skip to content

Commit

Permalink
Install Python and Pypy using Micromamba (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-berchet authored Feb 6, 2023
1 parent 103e0cb commit fd3fce0
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 26 deletions.
56 changes: 33 additions & 23 deletions .github/workflows/test_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -63,45 +80,38 @@ 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
- name: Coveralls
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
Expand Down
8 changes: 8 additions & 0 deletions GeoAlchemy2_dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: GeoAlchemy2_dev
channels:
- conda-forge
dependencies:
- libspatialite
- python=3.7.*
- pyproj
- psycopg2
2 changes: 2 additions & 0 deletions TEST.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
===========================

Expand Down
14 changes: 14 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import re
import shutil
import sys

import pytest
from packaging import version
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ python =
[testenv]
passenv=
PYTEST_DB_URL
PROJ_LIB
SPATIALITE_LIBRARY_PATH
SPATIALITE_DB_PATH
setenv=
Expand Down

0 comments on commit fd3fce0

Please sign in to comment.