Skip to content

Commit

Permalink
SQLAlchemy 1.4 (#54)
Browse files Browse the repository at this point in the history
* change models for SQLA 1.4
* ci: add Debian 12, remove Debian 10

---------

Co-authored-by: Jacques Fize <[email protected]>
  • Loading branch information
bouttier and jacquesfize authored Dec 6, 2023
1 parent f9102ca commit 4125f81
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 38 deletions.
40 changes: 11 additions & 29 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,17 @@ jobs:
strategy:
fail-fast: false
matrix:
debian-version: [ "10", "11" ]
sqlalchemy-version: [ "1.3", "1.4" ]
debian-version: [ "11", "12" ]
sqlalchemy-version: [ "1.4" ]
include:
- debian-version: "10"
python-version: "3.7"
postgres-version: 11
postgis-version: 2.5
- debian-version: "11"
python-version: "3.9"
postgres-version: 13
postgis-version: 3.2
- sqlalchemy-version: '1.3'
sqlalchemy-lt-version: '1.4'
flask-sqlalchemy-version: '2'
flask-sqlalchemy-lt-version: '3'
- sqlalchemy-version: '1.4'
sqlalchemy-lt-version: '2'
flask-sqlalchemy-version: '3'
flask-sqlalchemy-lt-version: '4'
exclude:
- debian-version: "10"
sqlalchemy-version: "1.4"
postgres-version: "13"
postgis-version: "3.2"
- debian-version: "12"
python-version: "3.11"
postgres-version: "15"
postgis-version: "3.3"

name: Debian ${{ matrix.debian-version }} - SQLAlchemy ${{ matrix.sqlalchemy-version }}

Expand All @@ -59,14 +48,9 @@ jobs:
--health-retries 5
steps:
- name: Add postgis_raster database extension
if: ${{ matrix.postgis-version >= 3 }}
run: |
psql -h localhost -U postgres -d postgres -tc 'CREATE EXTENSION "postgis_raster";'
env:
PGPASSWORD: postgres
- name: Add database extensions
run: |
psql -h localhost -U postgres -d postgres -tc 'CREATE EXTENSION "postgis_raster";'
psql -h localhost -U postgres -d postgres -tc 'CREATE EXTENSION "uuid-ossp";'
psql -h localhost -U postgres -d postgres -tc 'CREATE EXTENSION "pg_trgm";'
env:
Expand All @@ -86,9 +70,7 @@ jobs:
-e .[tests] \
-e file:dependencies/Utils-Flask-SQLAlchemy#egg=utils-flask-sqlalchemy \
-e file:dependencies/TaxHub#egg=taxhub \
-e file:dependencies/UsersHub-authentification-module#egg=pypnusershub \
"sqlalchemy>=${{ matrix.sqlalchemy-version }},<${{ matrix.sqlalchemy-lt-version }}" \
"flask-sqlalchemy>=${{ matrix.flask-sqlalchemy-version }},<${{ matrix.flask-sqlalchemy-lt-version }}"
-e file:dependencies/UsersHub-authentification-module#egg=pypnusershub
- name: Install database
run: |
flask db upgrade ref_geo@head -x local-srid=2154
Expand All @@ -104,7 +86,7 @@ jobs:
env:
NOMENCLATURE_SETTINGS: test_settings.py
- name: Upload coverage to Codecov
if: ${{ matrix.debian-version == '11' && matrix.sqlalchemy-version == '1.4' }}
if: ${{ matrix.debian-version == '12' && matrix.sqlalchemy-version == '1.4' }}
uses: codecov/codecov-action@v3
with:
flags: pytest
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ psycopg2
flask-marshmallow
marshmallow-sqlalchemy
shapely<2
sqlalchemy>=1.3,<2
sqlalchemy>=1.4,<2

utils-flask-sqlalchemy>=0.3.0
taxhub>=1.10.0
Expand Down
18 changes: 10 additions & 8 deletions src/pypnnomenclature/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class TNomenclatures(db.Model):
id_type = db.Column(
db.Integer, ForeignKey("ref_nomenclatures.bib_nomenclatures_types.id_type")
)
nomenclature_type = relationship("BibNomenclaturesTypes", backref="nomenclatures")
nomenclature_type = relationship(
"BibNomenclaturesTypes",
backref="nomenclatures",
)
cd_nomenclature = db.Column(db.Unicode)
mnemonique = db.Column(db.Unicode)
label_default = db.Column(db.Unicode)
Expand All @@ -73,14 +76,12 @@ class TNomenclatures(db.Model):
@staticmethod
def get_default_nomenclature(mnemonique, id_organism=0):
q = select(
[
func.ref_nomenclatures.get_default_nomenclature_value(
mnemonique, id_organism
).label("default")
]
func.ref_nomenclatures.get_default_nomenclature_value(mnemonique, id_organism).label(
"default"
)
)
result = db.session.execute(q)
return result.fetchone()["default"]
return result.fetchone().default


class TNomenclatureTaxonomy(TNomenclatures):
Expand Down Expand Up @@ -127,7 +128,7 @@ def get_default_nomenclature(mnemonique, id_organism=0):
]
)
result = db.session.execute(q)
return result.fetchone()["default"]
return result.fetchone().default


class BibNomenclaturesTypeTaxo(BibNomenclaturesTypes):
Expand All @@ -140,6 +141,7 @@ class BibNomenclaturesTypeTaxo(BibNomenclaturesTypes):
primaryjoin="and_(TNomenclatureTaxonomy.id_type == BibNomenclaturesTypes.id_type, TNomenclatureTaxonomy.active == True)",
lazy="joined",
order_by="TNomenclatureTaxonomy.hierarchy",
viewonly=True,
)


Expand Down

0 comments on commit 4125f81

Please sign in to comment.