Skip to content

Commit 82ca28d

Browse files
committed
Add lint front + rollback back lint
1 parent 536f9e9 commit 82ca28d

29 files changed

+2387
-4708
lines changed

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "github-actions"
9+
directory: "/"
10+
schedule:
11+
interval: "weekly"

.github/workflows/lint.yml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,37 @@ jobs:
66
backend:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v3
9+
- uses: actions/checkout@v5
1010
with:
1111
fetch-depth: 0
12-
line-length: 99
12+
13+
- name: Backend code formatting check (Black)
14+
uses: psf/black@stable
15+
with:
16+
use_pyproject: true
17+
18+
frontend:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v5
24+
25+
- name: Use setup-node
26+
uses: actions/setup-node@v5
27+
with:
28+
node-version-file: './atlas/static/.nvmrc'
29+
# cache: 'npm'
30+
# cache-dependency-path: './atlas/static/package-lock.json'
31+
32+
- name: Install dependencies
33+
run: node --version
34+
# working-directory: atlas
35+
36+
- name: Install dependencies
37+
run: npm ci
38+
working-directory: ./atlas/static
39+
40+
- name: Run check with ESLint
41+
run: npm run lint
42+
working-directory: ./atlas/static

atlas/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def inject_context():
7575
translations=get_tranlated_labels(),
7676
now=now,
7777
timedelta=timedelta,
78-
page_name=request.endpoint.split(".")[1]
78+
page_name=request.endpoint.split(".")[1],
7979
)
8080

8181
@app.template_filter("pretty")

atlas/atlasAPI.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,13 @@ def getObservationsPointAPI():
110110
)
111111
return jsonify(observations)
112112

113+
113114
@api.route("/taxonList", methods=["GET"])
114115
@api.route("/taxonList/area/<id_area>", methods=["GET"])
115116
@api.route("/taxonList/liste/<cd_ref>", methods=["GET"])
116117
@api.route("/taxonList/group/<group_name>", methods=["GET"])
117118
def get_taxon_list(id_area=None, cd_ref=None, group_name=None):
118-
"""
119+
"""
119120
return a list of taxon in html with various filters
120121
121122
Returns

atlas/atlasRoutes.py

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,7 @@ def index():
115115
listTaxons = []
116116
if current_app.config["AFFICHAGE_TERRITOIRE_OBS"]:
117117
nb_taxons = vmTaxonsRepository.get_nb_taxons()
118-
listTaxons = vmTaxonsRepository.getListTaxon(
119-
params={
120-
"page": 0
121-
}
122-
)
123-
118+
listTaxons = vmTaxonsRepository.getListTaxon(params={"page": 0})
124119

125120
# si AFFICHAGE_TERRITOIRE_OBS on charge les données en AJAX
126121
# si AFFICHAGE_DERNIERES_OBS = False, on ne charge pas les obs
@@ -131,19 +126,19 @@ def index():
131126
observations = []
132127
observations_mailles = None
133128
if current_app.config["AFFICHAGE_DERNIERES_OBS"]:
134-
# on charge les observations point meme si on est en mode maille pour afficher
129+
# on charge les observations point meme si on est en mode maille pour afficher
135130
# la liste des dernières obs
136131
observations = vmObservationsRepository.getObservationsChilds(
137132
params={
138133
"last_obs": str(current_app.config["NB_DAY_LAST_OBS"]) + " day",
139-
"fields": "taxons,medias"
134+
"fields": "taxons,medias",
140135
},
141136
)
142137
if current_app.config["AFFICHAGE_MAILLE"]:
143138
observations_mailles = vmObservationsMaillesRepository.getObservationsMaillesChilds(
144139
params={
145140
"last_obs": str(current_app.config["NB_DAY_LAST_OBS"]) + " day",
146-
"fields": "taxons,ids_obs"
141+
"fields": "taxons,ids_obs",
147142
}
148143
)
149144

@@ -179,7 +174,7 @@ def index():
179174
personal_data=personal_data,
180175
group2_inpn=group2_inpn,
181176
listTaxons=listTaxons,
182-
nb_taxons=nb_taxons
177+
nb_taxons=nb_taxons,
183178
)
184179

185180

@@ -316,20 +311,15 @@ def is_statut_in_groupe(statut, groupe):
316311
def area(id_area):
317312
area = vmAreasRepository.getAreaFromIdArea(id_area)
318313
stats_area = vmAreasRepository.getStatsByArea(id_area)
319-
listTaxons = vmTaxonsRepository.getListTaxon(
320-
id_area=id_area,
321-
params=MultiDict({
322-
"page": 0
323-
})
324-
)
314+
listTaxons = vmTaxonsRepository.getListTaxon(id_area=id_area, params=MultiDict({"page": 0}))
325315
group2_inpn = vmTaxonsRepository.get_group_inpn("group2_inpn", id_area)
326316
return render_template(
327317
"templates/areaSheet/_main.html",
328318
stats_area=stats_area,
329319
areaInfos=area,
330320
id_area=id_area,
331321
listTaxons=listTaxons,
332-
group2_inpn=group2_inpn
322+
group2_inpn=group2_inpn,
333323
)
334324

335325

@@ -340,12 +330,7 @@ def ficheRangTaxonomie(cd_ref=None):
340330
referenciel = vmTaxrefRepository.getInfoFromCd_ref(cd_ref)
341331
taxonomyHierarchy = vmTaxrefRepository.getAllTaxonomy(cd_ref)
342332
observers = vmObservationsRepository.getObservers(cd_ref)
343-
listTaxons = vmTaxonsRepository.getListTaxon(
344-
cd_ref=cd_ref,
345-
params=MultiDict({
346-
"page": 0
347-
})
348-
)
333+
listTaxons = vmTaxonsRepository.getListTaxon(cd_ref=cd_ref, params=MultiDict({"page": 0}))
349334

350335
return render_template(
351336
"templates/taxoRankSheet/_main.html",
@@ -354,7 +339,7 @@ def ficheRangTaxonomie(cd_ref=None):
354339
referenciel=referenciel,
355340
taxonomyHierarchy=taxonomyHierarchy,
356341
observers=observers,
357-
cd_ref=cd_ref
342+
cd_ref=cd_ref,
358343
)
359344

360345

@@ -364,12 +349,7 @@ def ficheGroupe(groupe):
364349
groups = vmTaxonsRepository.getAllINPNgroup()
365350
nb_taxons = vmTaxonsRepository.get_nb_taxons(group_name=groupe)
366351
observers = vmObservationsRepository.getGroupeObservers(groupe)
367-
listTaxons = vmTaxonsRepository.getListTaxon(
368-
group_name=groupe,
369-
params=MultiDict({
370-
"page": 0
371-
})
372-
)
352+
listTaxons = vmTaxonsRepository.getListTaxon(group_name=groupe, params=MultiDict({"page": 0}))
373353

374354
return render_template(
375355
"templates/groupSheet/_main.html",

atlas/configuration/config_schema.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class MapConfig(Schema):
127127
load_default={"fill": False, "fillColor": "#020202", "fillOpacity": 0.7}
128128
)
129129

130+
130131
class CouchesSigConfig(Schema):
131132
name = fields.Str(required=True)
132133
type = fields.Str(required=True, validate=validate.OneOf(["wms", "geojson"]))
@@ -139,7 +140,9 @@ class CouchesSigConfig(Schema):
139140

140141
@validates_schema
141142
def layer_required_for_wms_type(self, data, **kwargs):
142-
if data["type"] == "wms" and (not data.get("options").get("layers") or not data.get("options").get("wms_version")):
143+
if data["type"] == "wms" and (
144+
not data.get("options").get("layers") or not data.get("options").get("wms_version")
145+
):
143146
raise ValidationError("'layers' and 'wms_version' are required for type 'wms'")
144147

145148

@@ -302,7 +305,7 @@ class Meta:
302305
)
303306
MAP = fields.Nested(MapConfig, load_default=dict())
304307
DEFAULT_LEGEND_DISPLAY = fields.Boolean(load_default=True)
305-
COUCHES_SIG = fields.List(fields.Nested(CouchesSigConfig), load_default=list())
308+
COUCHES_SIG = fields.List(fields.Nested(CouchesSigConfig), load_default=list())
306309
# coupe le nom_vernaculaire à la 1ere virgule sur les fiches espèces
307310
SPLIT_NOM_VERN = fields.Boolean(load_default=True)
308311
INTERACTIVE_MAP_LIST = fields.Boolean(load_default=True)

atlas/modeles/entities/vmMedias.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@ class VmMedias(db.Model):
2121
id_type: Mapped[int] = mapped_column()
2222
licence: Mapped[str] = mapped_column(String(100))
2323
source: Mapped[str] = mapped_column(String(25))
24-

atlas/modeles/entities/vmTaxons.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ class VmTaxons(db.Model):
4646
main_media: Mapped[VmMedias] = relationship(
4747
VmMedias,
4848
primaryjoin=and_(
49-
VmMedias.cd_ref == cd_ref,
50-
VmMedias.id_type == current_app.config["ATTR_MAIN_PHOTO"]
49+
VmMedias.cd_ref == cd_ref, VmMedias.id_type == current_app.config["ATTR_MAIN_PHOTO"]
5150
),
5251
)
52+
5353
def as_dict(self, with_main_media=False):
5454
d = {
5555
"cd_ref": self.cd_ref,
@@ -63,13 +63,13 @@ def as_dict(self, with_main_media=False):
6363
"yearmax": self.yearmax,
6464
"nb_obs": self.nb_obs,
6565
"group2_inpn": utils.deleteAccent(self.group2_inpn),
66-
"group3_inpn": utils.deleteAccent(self.group3_inpn)
66+
"group3_inpn": utils.deleteAccent(self.group3_inpn),
6767
}
6868
if with_main_media:
6969
d["media"] = self.get_main_media()
7070
return d
7171

72-
def get_main_media(self, size=(80,80)):
72+
def get_main_media(self, size=(80, 80)):
7373
"""Get main image of default logo
7474
7575
Parameters
@@ -83,14 +83,14 @@ def get_main_media(self, size=(80,80)):
8383
The path or url of the main image if exist, the logo of the group INPN if not
8484
"""
8585
default_media = url_for(
86-
'static',
87-
filename=f"images/picto_{utils.deleteAccent(self.group2_inpn).replace(' ', '_') }.png"
86+
"static",
87+
filename=f"images/picto_{utils.deleteAccent(self.group2_inpn).replace(' ', '_') }.png",
8888
)
8989
if self.main_media:
9090
if current_app.config["REDIMENSIONNEMENT_IMAGE"]:
9191
height, width = size
9292
return urljoin(
93-
current_app.config['TAXHUB_URL'],
93+
current_app.config["TAXHUB_URL"],
9494
f"api/tmedias/thumbnail/{self.main_media.id_media}?h={height}&width={width}",
9595
)
9696
else:
@@ -103,7 +103,6 @@ def get_main_media(self, size=(80,80)):
103103
else:
104104
return default_media
105105

106-
107106
def shorten_name(self):
108107
shorten_nom_vern = self.nom_vern.split(",")[0] if self.nom_vern else ""
109108
return shorten_nom_vern + " | <i>" + self.lb_nom + " </i>"

atlas/modeles/repositories/vmAreasRepository.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,22 @@ def getAreaFromIdArea(id_area):
6565
area_dict = {
6666
"areaName": area.area_name,
6767
"areaID": str(area.id_area),
68-
"areaCode" : str(area.area_code),
68+
"areaCode": str(area.area_code),
6969
"areaGeoJson": ast.literal_eval(area.area_geojson),
7070
"typeName": area.type_name,
7171
"description": area.description,
7272
"areasParent": [],
7373
}
7474

7575
subquery = (
76-
db.session.query(VmCorAreas.id_area_parent).filter(VmCorAreas.id_area == id_area).subquery()
76+
db.session.query(VmCorAreas.id_area_parent)
77+
.filter(VmCorAreas.id_area == id_area)
78+
.subquery()
7779
)
7880

7981
areas_parent = (
8082
db.session.query(
81-
VmAreas.area_name,
82-
VmAreas.id_area,
83-
VmAreas.area_code,
84-
VmBibAreasTypes.type_name
83+
VmAreas.area_name, VmAreas.id_area, VmAreas.area_code, VmBibAreasTypes.type_name
8584
)
8685
.join(subquery, subquery.c.id_area_parent == VmAreas.id_area)
8786
.join(VmBibAreasTypes, VmBibAreasTypes.id_type == VmAreas.id_type)

atlas/modeles/repositories/vmObservationsMaillesRepository.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def getObservationsMaillesChilds(params={}):
3737
- last_obs_year : l'année à laquel la dernière observation a été faite dans la maille
3838
- obs_nbr : le nombre d'observation dans la maille
3939
- taxons (optionnel: si fields=taxons) : une liste des taxons dans la maille
40-
- ids_obs (optionnel si fields=ids_obs): la liste des id_observations de la maille
40+
- ids_obs (optionnel si fields=ids_obs): la liste des id_observations de la maille
4141
Parameters
4242
----------
4343
filters : dict, optional
@@ -70,7 +70,7 @@ def getObservationsMaillesChilds(params={}):
7070
VmAreas.area_geojson,
7171
VMCorMailleObservation.type_code,
7272
func.max(func.date_part("year", VmObservations.dateobs)).label("last_obs_year"),
73-
func.count(VmObservations.id_observation).label("obs_nbr")
73+
func.count(VmObservations.id_observation).label("obs_nbr"),
7474
]
7575
if "taxons" in fields:
7676
query_select.append(
@@ -90,9 +90,7 @@ def getObservationsMaillesChilds(params={}):
9090
).label("taxons"),
9191
)
9292
if "ids_obs" in fields:
93-
query_select.append(
94-
func.array_agg(VmObservations.id_observation).label("ids_obs")
95-
)
93+
query_select.append(func.array_agg(VmObservations.id_observation).label("ids_obs"))
9694
query = (
9795
select(*query_select)
9896
.select_from(VmObservations)
@@ -144,10 +142,9 @@ def getObservationsMaillesChilds(params={}):
144142
"nb_observations": int(o.obs_nbr),
145143
"last_observation": o.last_obs_year,
146144
"taxons": o.taxons if "taxons" in fields else None,
147-
"ids_obs": o.ids_obs if "ids_obs" in fields else None
145+
"ids_obs": o.ids_obs if "ids_obs" in fields else None,
148146
},
149147
)
150148
for o in db.session.execute(query).all()
151149
]
152150
)
153-

0 commit comments

Comments
 (0)