Skip to content

Commit 2febb09

Browse files
committed
Merge branch 'develop'
2 parents ec03a75 + c14e247 commit 2febb09

33 files changed

+479
-218
lines changed

.flaskenv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FLASK_APP=pypnnomenclature:create_app
2+
FLASK_ENV=development
3+
FLASK_DEBUG=1
4+
NOMENCLATURE_SETTINGS=settings.py

.github/workflows/pytest.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: pytest
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- develop
8+
pull_request:
9+
branches:
10+
- master
11+
- develop
12+
13+
jobs:
14+
build:
15+
16+
runs-on: ubuntu-latest
17+
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
include:
22+
- name: "Debian 10"
23+
python-version: "3.7"
24+
postgres-version: "11-stretch"
25+
- name: "Debian 11"
26+
python-version: "3.9"
27+
postgres-version: "13-bullseye"
28+
29+
name: ${{ matrix.name }}
30+
31+
services:
32+
postgres:
33+
image: postgres:${{ matrix.postgres-version }}
34+
env:
35+
POSTGRES_PASSWORD: postgres
36+
ports:
37+
- 5432:5432
38+
options: >-
39+
--health-cmd pg_isready
40+
--health-interval 10s
41+
--health-timeout 5s
42+
--health-retries 5
43+
44+
steps:
45+
- name: Add database extensions
46+
run: |
47+
psql -h localhost -U postgres -d postgres -tc 'CREATE EXTENSION "uuid-ossp";'
48+
psql -h localhost -U postgres -d postgres -tc 'CREATE EXTENSION "pg_trgm";'
49+
env:
50+
PGPASSWORD: postgres
51+
- uses: actions/checkout@v2
52+
with:
53+
submodules: recursive
54+
- name: Set up Python ${{ matrix.python-version }}
55+
uses: actions/setup-python@v2
56+
with:
57+
python-version: ${{ matrix.python-version }}
58+
- name: Install dependencies
59+
run: |
60+
python -m pip install --upgrade pip
61+
python -m pip install \
62+
pytest-cov \
63+
-e .[tests] \
64+
-e file:dependencies/Utils-Flask-SQLAlchemy#egg=utils-flask-sqlalchemy \
65+
-e file:dependencies/TaxHub#egg=taxhub \
66+
-e file:dependencies/UsersHub-authentification-module#egg=pypnusershub
67+
- name: Install database
68+
run: |
69+
flask db upgrade nomenclatures@head
70+
flask db upgrade nomenclatures_inpn_data@head
71+
flask db upgrade nomenclatures_taxonomie@head
72+
flask db upgrade nomenclatures_taxonomie_inpn_data@head
73+
env:
74+
NOMENCLATURE_SETTINGS: test_settings.py
75+
- name: Test with pytest
76+
run: |
77+
pytest -v --cov --cov-report xml
78+
env:
79+
NOMENCLATURE_SETTINGS: test_settings.py
80+
- name: Upload coverage to Codecov
81+
if: ${{ matrix.name == 'Debian 11' }}
82+
uses: codecov/codecov-action@v2
83+
with:
84+
flags: pytest

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,8 @@ ENV/
103103

104104
# mypy
105105
.mypy_cache/
106+
107+
*.swp
108+
*.swo
109+
110+
/*settings.py

.gitmodules

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[submodule "dependencies/Utils-Flask-SQLAlchemy"]
2+
path = dependencies/Utils-Flask-SQLAlchemy
3+
url = https://github.com/PnX-SI/Utils-Flask-SQLAlchemy.git
4+
[submodule "dependencies/TaxHub"]
5+
path = dependencies/TaxHub
6+
url = https://github.com/PnX-SI/TaxHub.git
7+
[submodule "dependencies/UsersHub-authentification-module"]
8+
path = dependencies/UsersHub-authentification-module
9+
url = https://github.com/PnX-SI/UsersHub-authentification-module.git

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Nomenclature-api-module
22

3+
[![pytest](https://github.com/PnX-SI/Nomenclature-api-module/actions/workflows/pytest.yml/badge.svg)](https://github.com/PnX-SI/Nomenclature-api-module/actions/workflows/pytest.yml)
4+
[![codecov](https://codecov.io/gh/PnX-SI/Nomenclature-api-module/branch/master/graph/badge.svg?token=KGZRGXFWCK)](https://codecov.io/gh/PnX-SI/Nomenclature-api-module)
5+
36
Flask (Python) module for Nomenclature API.
47

58
It is used in [GeoNature](https://github.com/PnX-SI/GeoNature) but can also be used as a standalone API service to manage and returns various nomenclatures with their hierarchy.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.5
1+
1.5.0

admin.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

dependencies/TaxHub

Submodule TaxHub added at 11fbe53

dependencies/Utils-Flask-SQLAlchemy

Submodule Utils-Flask-SQLAlchemy added at df44a22

docs/changelog.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22
CHANGELOG
33
=========
44

5+
1.5.0 (2022-01-04)
6+
------------------
7+
8+
**🚀 Nouveautés**
9+
10+
* Possibilité de lancer l’API Nomenclature de manière autonome
11+
* Possibilité de créer son schéma de base de données de manière autonome
12+
* Mise en place des tests unitaires
13+
* Mise en place de l’intégration continue
14+
* Intégration des dépendances en tant que sous-module Git
15+
16+
* Utils-Flask-SQLAlchemy
17+
* TaxHub (pour la taxonomie)
18+
* UsersHub-authentification-module (car requis par TaxHub)
19+
20+
**🐛 Corrections**
21+
22+
* Suppression d’anciens fichiers devenus inutiles suite au paquetage
23+
524
1.4.5 (2021-01-03)
625
------------------
726

install_app.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

models.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

pyproject.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[tool.pytest.ini_options]
2+
minversion = "6.0"
3+
testpaths = [
4+
"src",
5+
]
6+
7+
[tool.coverage.run]
8+
source = [
9+
"pypnnomenclature",
10+
]
11+
omit = [
12+
"*/tests/*",
13+
"*/migrations/*",
14+
]

repository.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

requirements.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
python-dotenv
12
flask
23
Flask-Admin
34
flask-sqlalchemy
5+
flask-migrate
46
psycopg2
5-
utils-flask-sqlalchemy
7+
utils-flask-sqlalchemy>=0.2.6
68
flask-marshmallow
9+
marshmallow-sqlalchemy
710

routes.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

server.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

config.py.sample renamed to settings.py.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ COOKIE_EXPIRATION = 3600
1313
COOKIE_AUTORENEW = True
1414

1515
# Ajouter les filtres taxonomiques à l'API
16-
# Nécessite d'avoir exécuté le script 'data/nomenclature_taxonomie.sql' qui installe les tables nécessaires
16+
# Nécessite d'avoir monté la branche alembic nomenclature_taxonomie
1717
ENABLE_NOMENCLATURE_TAXONOMIC_FILTERS = True
1818

1919
# URL de l'interface d'administration

setup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
with (root_dir / 'requirements.in').open() as f:
1111
requirements = f.read().splitlines()
1212

13+
1314
setuptools.setup(
1415
name='pypnnomenclature',
1516
version=version,
@@ -23,6 +24,9 @@
2324
package_dir={'': 'src'},
2425
package_data={'pypnnomenclature.migrations': ['data/*.sql']},
2526
install_requires=requirements,
27+
extras_require={
28+
'tests': [ 'pytest', 'pytest-flask', ],
29+
},
2630
entry_points={
2731
'alembic': [
2832
'migrations = pypnnomenclature.migrations:versions',

src/pypnnomenclature/__init__.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1-
__version__ = "1.1.1"
1+
from pathlib import Path
2+
from itertools import chain
3+
from pkg_resources import iter_entry_points
4+
5+
from flask import Flask
6+
from flask_migrate import Migrate
7+
8+
from pypnnomenclature.env import db, ma
9+
from pypnnomenclature.routes import routes
10+
11+
12+
migrate = Migrate()
13+
14+
15+
@migrate.configure
16+
def configure_alembic(alembic_config):
17+
version_locations = alembic_config.get_main_option('version_locations', default='').split()
18+
for entry_point in chain(iter_entry_points('alembic', 'migrations')):
19+
_, migrations = str(entry_point).split('=', 1)
20+
version_locations += [ migrations.strip() ]
21+
alembic_config.set_main_option('version_locations', ' '.join(version_locations))
22+
return alembic_config
23+
24+
25+
def create_app():
26+
app = Flask('Habref')
27+
app.config.from_envvar('NOMENCLATURE_SETTINGS')
28+
ma.init_app(app)
29+
db.init_app(app)
30+
migrate.init_app(app, db, directory=Path(__file__).parent / 'migrations')
31+
app.register_blueprint(routes, url_prefix='/nomenclatures')
32+
# TODO admin
33+
return app

0 commit comments

Comments
 (0)