From abc6574590502f478919657b1dd11e76f654b485 Mon Sep 17 00:00:00 2001 From: Etienne Delclaux Date: Tue, 23 Apr 2024 14:09:27 +0200 Subject: [PATCH 1/2] feat: update lint configuration to match geontautre 2.14 --- frontend/.nvmrc | 1 + frontend/.prettierignore | 0 frontend/.prettierrc | 6 +++++- frontend/package-lock.json | 14 +++++++------- frontend/package.json | 2 +- lint.sh | 11 +++++++++++ pyproject.toml | 21 ++++++++++++++++++++- 7 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 frontend/.nvmrc create mode 100644 frontend/.prettierignore create mode 100755 lint.sh diff --git a/frontend/.nvmrc b/frontend/.nvmrc new file mode 100644 index 00000000..112a2eae --- /dev/null +++ b/frontend/.nvmrc @@ -0,0 +1 @@ +lts/gallium \ No newline at end of file diff --git a/frontend/.prettierignore b/frontend/.prettierignore new file mode 100644 index 00000000..e69de29b diff --git a/frontend/.prettierrc b/frontend/.prettierrc index 86e01b23..11da2cd8 100644 --- a/frontend/.prettierrc +++ b/frontend/.prettierrc @@ -4,5 +4,9 @@ "useTabs": false, "tabWidth": 2, "semi": true, - "bracketSpacing": true + "bracketSpacing": true, + "trailingComma": "es5", + "singleAttributePerLine": true, + "bracketSameLine": false, + "htmlWhitespaceSensitivity": "ignore" } \ No newline at end of file diff --git a/frontend/package-lock.json b/frontend/package-lock.json index db58fdc3..5f93d4e9 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -17,7 +17,7 @@ "pbf": "^3.2.1" }, "devDependencies": { - "prettier": "^3.0.3" + "prettier": "~3.1.0" } }, "node_modules/@angular/common": { @@ -219,9 +219,9 @@ "deprecated": "This module has moved: please install @mapbox/point-geometry instead" }, "node_modules/prettier": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", - "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.1.1.tgz", + "integrity": "sha512-22UbSzg8luF4UuZtzgiUOfcGM8s4tjBv6dJRT7j275NXsy2jb4aJa4NNveul5x4eqlF1wuhuR2RElK71RvmVaw==", "dev": true, "bin": { "prettier": "bin/prettier.cjs" @@ -549,9 +549,9 @@ "integrity": "sha512-tXK8bY2l3/CPkyO7+UbOWbVjCpKoYY4t6uY3AYYy4Bagd4Z942gLeQOgtHICwBwgPf8dI6fw4VqKwzSNgvlw4A==" }, "prettier": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", - "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.1.1.tgz", + "integrity": "sha512-22UbSzg8luF4UuZtzgiUOfcGM8s4tjBv6dJRT7j275NXsy2jb4aJa4NNveul5x4eqlF1wuhuR2RElK71RvmVaw==", "dev": true }, "protocol-buffers-schema": { diff --git a/frontend/package.json b/frontend/package.json index 97bef457..5c3944ab 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -19,6 +19,6 @@ "pbf": "^3.2.1" }, "devDependencies": { - "prettier": "^3.0.3" + "prettier": "~3.1.0" } } diff --git a/lint.sh b/lint.sh new file mode 100755 index 00000000..f9399ad1 --- /dev/null +++ b/lint.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +# backend +black . + +# frontend +cd frontend +source ~/.nvm/nvm.sh +nvm use +npm run format +cd .. diff --git a/pyproject.toml b/pyproject.toml index 71429910..b4a29d0c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,4 +14,23 @@ omit = [ ] [tool.black] -line-length = 99 \ No newline at end of file +line-length = 100 +exclude =''' +( + /( + \.eggs # exclude a few common directories in the + | \.git # root of the project + | \.hg + | \.mypy_cache + | \.tox + | \.venv + | _build + | buck-out + | build + | dist + | node_modules + | venv + | dependencies + )/ +) +''' \ No newline at end of file From 019860f5d3375ad0e9127e696a2eea3f6ddcdcd5 Mon Sep 17 00:00:00 2001 From: Etienne Delclaux Date: Tue, 23 Apr 2024 14:11:37 +0200 Subject: [PATCH 2/2] lint: run linter --- backend/gn_module_zh/blueprint.py | 4 +-- backend/gn_module_zh/forms.py | 10 +++---- backend/gn_module_zh/geometry.py | 6 ++-- backend/gn_module_zh/hierarchy.py | 20 +++++++------ .../migrations/01cb1aaa2062_init_zh.py | 1 + .../migrations/22b14fc3abe0_set_srid.py | 1 + .../migrations/26d6515219fe_add_indexes.py | 5 ++-- .../510677623a13_declare_permisision.py | 1 + .../migrations/643743e807f6_add_atlas_view.py | 1 + .../migrations/b4e1775f1e7c_sample_data.py | 1 + backend/gn_module_zh/model/cards.py | 29 +++++-------------- backend/gn_module_zh/model/zh.py | 8 +++-- backend/gn_module_zh/model/zh_schema.py | 4 +-- frontend/app/services/zh-data.service.ts | 14 ++++----- .../tabs/tab1/zh-form-tab1.component.ts | 12 ++++---- .../tabs/tab3/zh-form-tab3.component.ts | 8 ++--- .../tabs/tab5/zh-form-tab5.component.ts | 4 +-- .../tabs/tab6/zh-form-tab6.component.ts | 4 +-- 18 files changed, 61 insertions(+), 72 deletions(-) diff --git a/backend/gn_module_zh/blueprint.py b/backend/gn_module_zh/blueprint.py index 7d109ad3..8641583b 100644 --- a/backend/gn_module_zh/blueprint.py +++ b/backend/gn_module_zh/blueprint.py @@ -595,9 +595,7 @@ def get_tab_data(id_tab): ) # select active geo refs in config - active_geo_refs = [ - ref for ref in blueprint.config["ref_geo_referentiels"] if ref["active"] - ] + active_geo_refs = [ref for ref in blueprint.config["ref_geo_referentiels"] if ref["active"]] intersection = None # Check on geometry that should always exist (PATCH or POST) if len(form_data["geom"]["geometry"]["coordinates"]) == 0: diff --git a/backend/gn_module_zh/forms.py b/backend/gn_module_zh/forms.py index 52f97f29..560081a8 100644 --- a/backend/gn_module_zh/forms.py +++ b/backend/gn_module_zh/forms.py @@ -281,9 +281,7 @@ def update_zh_tab0(form_data, polygon, area, info_role, zh_date, geo_refs): # update pr_zh.cor_lim_list id_lim_list, ef_area = ( - DB.session.query(TZH.id_lim_list, TZH.ef_area) - .filter(TZH.id_zh == form_data["id_zh"]) - .one() + DB.session.query(TZH.id_lim_list, TZH.ef_area).filter(TZH.id_zh == form_data["id_zh"]).one() ) DB.session.query(CorLimList).filter(CorLimList.id_lim_list == id_lim_list).delete() @@ -844,9 +842,9 @@ def update_zh_tab6(data): TZH.update_author: data["update_author"], TZH.update_date: data["update_date"], TZH.is_other_inventory: is_other_inventory, - TZH.remark_is_other_inventory: data["remark_is_other_inventory"] - if is_other_inventory - else None, + TZH.remark_is_other_inventory: ( + data["remark_is_other_inventory"] if is_other_inventory else None + ), } ) DB.session.flush() diff --git a/backend/gn_module_zh/geometry.py b/backend/gn_module_zh/geometry.py index 652e9310..76851ad2 100644 --- a/backend/gn_module_zh/geometry.py +++ b/backend/gn_module_zh/geometry.py @@ -13,9 +13,9 @@ def set_geom(geometry, id_zh=None): if not id_zh: id_zh = 0 # SetSRID for POSTGIS < 3.0 compat - polygon = DB.session.query( - func.ST_SetSRID(func.ST_GeomFromGeoJSON(str(geometry)), 4326) - ).one()[0] + polygon = DB.session.query(func.ST_SetSRID(func.ST_GeomFromGeoJSON(str(geometry)), 4326)).one()[ + 0 + ] q_zh = ( DB.session.query(TZH) .filter( diff --git a/backend/gn_module_zh/hierarchy.py b/backend/gn_module_zh/hierarchy.py index 0cfa91c7..4cd861dd 100644 --- a/backend/gn_module_zh/hierarchy.py +++ b/backend/gn_module_zh/hierarchy.py @@ -934,9 +934,11 @@ def __str__(self): "qualification": self.__get_qualif_mnemo(), "knowledge": self.__get_knowledge_mnemo(), "name": self.__get_rule_name(), - "note": Hierarchy.get_str_note(self.note, self.denominator) - if self.active - else "Non paramétrée", + "note": ( + Hierarchy.get_str_note(self.note, self.denominator) + if self.active + else "Non paramétrée" + ), } @@ -973,9 +975,11 @@ def get_note(value): filter( None, [ - (float(item["note"].split("/")[0])) - if item["note"] is not None - else None + ( + (float(item["note"].split("/")[0])) + if item["note"] is not None + else None + ) for item in value if item["active"] ], @@ -1213,9 +1217,7 @@ def __check_if_rules(self): def get_denom(rb_id, col_name): rb_name = DB.session.query(TRiverBasin).filter(TRiverBasin.id_rb == rb_id).one().name return getattr( - DB.session.query(RbNotesSummary) - .filter(RbNotesSummary.bassin_versant == rb_name) - .one(), + DB.session.query(RbNotesSummary).filter(RbNotesSummary.bassin_versant == rb_name).one(), col_name, ) diff --git a/backend/gn_module_zh/migrations/01cb1aaa2062_init_zh.py b/backend/gn_module_zh/migrations/01cb1aaa2062_init_zh.py index 93e26c91..dc88a0b6 100644 --- a/backend/gn_module_zh/migrations/01cb1aaa2062_init_zh.py +++ b/backend/gn_module_zh/migrations/01cb1aaa2062_init_zh.py @@ -5,6 +5,7 @@ Create Date: 2023-03-27 11:54:34.602380 """ + import importlib from alembic import op diff --git a/backend/gn_module_zh/migrations/22b14fc3abe0_set_srid.py b/backend/gn_module_zh/migrations/22b14fc3abe0_set_srid.py index 2f71367e..1ca7dcdf 100644 --- a/backend/gn_module_zh/migrations/22b14fc3abe0_set_srid.py +++ b/backend/gn_module_zh/migrations/22b14fc3abe0_set_srid.py @@ -5,6 +5,7 @@ Create Date: 2023-04-19 14:58:14.295664 """ + from alembic import op import sqlalchemy as sa diff --git a/backend/gn_module_zh/migrations/26d6515219fe_add_indexes.py b/backend/gn_module_zh/migrations/26d6515219fe_add_indexes.py index a3728a02..a27ad87a 100644 --- a/backend/gn_module_zh/migrations/26d6515219fe_add_indexes.py +++ b/backend/gn_module_zh/migrations/26d6515219fe_add_indexes.py @@ -5,6 +5,7 @@ Create Date: 2023-06-05 12:07:39.416188 """ + from alembic import op import sqlalchemy as sa @@ -20,9 +21,7 @@ def upgrade(): op.create_index("index_t_zh_id_sdage", table_name="t_zh", columns=["id_sdage"], schema=SCHEMA) - op.create_index( - "index_t_zh_id_thread", table_name="t_zh", columns=["id_thread"], schema=SCHEMA - ) + op.create_index("index_t_zh_id_thread", table_name="t_zh", columns=["id_thread"], schema=SCHEMA) op.create_index( "index_t_zh_id_diag_bio", table_name="t_zh", columns=["id_diag_bio"], schema=SCHEMA ) diff --git a/backend/gn_module_zh/migrations/510677623a13_declare_permisision.py b/backend/gn_module_zh/migrations/510677623a13_declare_permisision.py index e4deb880..c9cf52e0 100644 --- a/backend/gn_module_zh/migrations/510677623a13_declare_permisision.py +++ b/backend/gn_module_zh/migrations/510677623a13_declare_permisision.py @@ -5,6 +5,7 @@ Create Date: 2023-05-25 15:33:36.262722 """ + from alembic import op import sqlalchemy as sa diff --git a/backend/gn_module_zh/migrations/643743e807f6_add_atlas_view.py b/backend/gn_module_zh/migrations/643743e807f6_add_atlas_view.py index e5f3555c..572acc99 100644 --- a/backend/gn_module_zh/migrations/643743e807f6_add_atlas_view.py +++ b/backend/gn_module_zh/migrations/643743e807f6_add_atlas_view.py @@ -5,6 +5,7 @@ Create Date: 2023-06-05 12:20:36.897280 """ + from alembic import op import sqlalchemy as sa diff --git a/backend/gn_module_zh/migrations/b4e1775f1e7c_sample_data.py b/backend/gn_module_zh/migrations/b4e1775f1e7c_sample_data.py index 4a64c82e..fa35508d 100644 --- a/backend/gn_module_zh/migrations/b4e1775f1e7c_sample_data.py +++ b/backend/gn_module_zh/migrations/b4e1775f1e7c_sample_data.py @@ -5,6 +5,7 @@ Create Date: 2023-03-27 13:32:22.741263 """ + import importlib from alembic import op diff --git a/backend/gn_module_zh/model/cards.py b/backend/gn_module_zh/model/cards.py index 6b2e1347..ea67101e 100644 --- a/backend/gn_module_zh/model/cards.py +++ b/backend/gn_module_zh/model/cards.py @@ -207,9 +207,7 @@ def __get_author(self, type="authors"): if getattr(self.zh, type).prenom_role is not None else "" ) - nom = ( - getattr(self.zh, type).nom_role if getattr(self.zh, type).nom_role is not None else "" - ) + nom = getattr(self.zh, type).nom_role if getattr(self.zh, type).nom_role is not None else "" return prenom + " " + nom.upper() def __get_organism(self, type="authors"): @@ -485,8 +483,7 @@ def __str__(self): return { "presentation": self.presentation.__str__(), "espace": [ - f"{cd} - {label}" - for cd, label in Utils.get_cd_and_mnemo(self.id_corine_landcovers) + f"{cd} - {label}" for cd, label in Utils.get_cd_and_mnemo(self.id_corine_landcovers) ], "usage": self.use.__str__(), "basin": self.basin.__str__(), @@ -868,9 +865,7 @@ def hydro(self): @hydro.setter def hydro(self, val): self.__hydro = [ - Function( - v["id_function"], v["id_qualification"], v["id_knowledge"], v["justification"] - ) + Function(v["id_function"], v["id_qualification"], v["id_knowledge"], v["justification"]) for v in val ] @@ -881,9 +876,7 @@ def bio(self): @bio.setter def bio(self, value): self.__bio = [ - Function( - v["id_function"], v["id_qualification"], v["id_knowledge"], v["justification"] - ) + Function(v["id_function"], v["id_qualification"], v["id_knowledge"], v["justification"]) for v in value ] @@ -911,9 +904,7 @@ def interet_patrim(self): @interet_patrim.setter def interet_patrim(self, val): self.__interet_patrim = [ - Function( - i["id_function"], i["id_qualification"], i["id_knowledge"], i["justification"] - ) + Function(i["id_function"], i["id_qualification"], i["id_knowledge"], i["justification"]) for i in val ] @@ -924,18 +915,14 @@ def val_soc_eco(self): @val_soc_eco.setter def val_soc_eco(self, val): self.__val_soc_eco = [ - Function( - i["id_function"], i["id_qualification"], i["id_knowledge"], i["justification"] - ) + Function(i["id_function"], i["id_qualification"], i["id_knowledge"], i["justification"]) for i in val ] @interet_patrim.setter def interet_patrim(self, val): self.__interet_patrim = [ - Function( - i["id_function"], i["id_qualification"], i["id_knowledge"], i["justification"] - ) + Function(i["id_function"], i["id_qualification"], i["id_knowledge"], i["justification"]) for i in val ] @@ -1092,7 +1079,7 @@ def __set_localisation(self): self.info.localisation = Localisation( self.id_zh, self.properties["geo_info"]["regions"], - self.properties["geo_info"]["departments"] + self.properties["geo_info"]["departments"], # self.ref_geo_config ) diff --git a/backend/gn_module_zh/model/zh.py b/backend/gn_module_zh/model/zh.py index 6efaba8e..404759a3 100644 --- a/backend/gn_module_zh/model/zh.py +++ b/backend/gn_module_zh/model/zh.py @@ -165,9 +165,11 @@ def get_instruments(self): "instruments": [ { "id_instrument": instrument.id_instrument, - "instrument_date": instrument.instrument_date.date().strftime("%d/%m/%Y") - if instrument.instrument_date - else None, + "instrument_date": ( + instrument.instrument_date.date().strftime("%d/%m/%Y") + if instrument.instrument_date + else None + ), } for instrument in ZH.get_data_by_id(TInstruments, self.zh.id_zh) ] diff --git a/backend/gn_module_zh/model/zh_schema.py b/backend/gn_module_zh/model/zh_schema.py index 1defeb29..e8e2ba19 100644 --- a/backend/gn_module_zh/model/zh_schema.py +++ b/backend/gn_module_zh/model/zh_schema.py @@ -680,9 +680,7 @@ class TActivity(DB.Model): class TOutflow(DB.Model): __tablename__ = "t_outflow" __table_args__ = {"schema": "pr_zh"} - id_outflow = DB.Column( - DB.Integer, ForeignKey(TNomenclatures.id_nomenclature), primary_key=True - ) + id_outflow = DB.Column(DB.Integer, ForeignKey(TNomenclatures.id_nomenclature), primary_key=True) id_zh = DB.Column(DB.Integer, ForeignKey(TZH.id_zh), primary_key=True) id_permanance = DB.Column( DB.Integer, diff --git a/frontend/app/services/zh-data.service.ts b/frontend/app/services/zh-data.service.ts index d08fd57d..bcca0ad7 100644 --- a/frontend/app/services/zh-data.service.ts +++ b/frontend/app/services/zh-data.service.ts @@ -16,7 +16,7 @@ export class ZhDataService { constructor( private _api: HttpClient, - public config: ConfigService, + public config: ConfigService ) {} setCurrentZh(zh: any) { @@ -47,7 +47,7 @@ export class ZhDataService { autocompletBib(search_title: string) { return this._api.get( - `${this.config.API_ENDPOINT}/zones_humides/references/autocomplete?search_title=${search_title}`, + `${this.config.API_ENDPOINT}/zones_humides/references/autocomplete?search_title=${search_title}` ); } @@ -57,7 +57,7 @@ export class ZhDataService { getHabitatByCorine(corineId: string) { return this._api.get( - `${this.config.API_ENDPOINT}/zones_humides/forms/cahierhab/${corineId}`, + `${this.config.API_ENDPOINT}/zones_humides/forms/cahierhab/${corineId}` ); } @@ -72,7 +72,7 @@ export class ZhDataService { map((municipalities: any) => { municipalities.map((item) => (item.disabled = false)); return municipalities; - }), + }) ); } @@ -82,7 +82,7 @@ export class ZhDataService { getZhDetails(zhId: number) { return this._api.get( - `${this.config.API_ENDPOINT}/zones_humides/${zhId}/complete_card`, + `${this.config.API_ENDPOINT}/zones_humides/${zhId}/complete_card` ); } @@ -107,7 +107,7 @@ export class ZhDataService { postMainPicture(zhId: number, mediaId: number) { return this._api.patch( `${this.config.API_ENDPOINT}/zones_humides/${zhId}/main_pict/${mediaId}`, - {}, + {} ); } @@ -117,7 +117,7 @@ export class ZhDataService { getHierZh(zhId: string) { return this._api.get( - `${this.config.API_ENDPOINT}/zones_humides/${zhId}/hierarchy`, + `${this.config.API_ENDPOINT}/zones_humides/${zhId}/hierarchy` ); } diff --git a/frontend/app/zh-forms/tabs/tab1/zh-form-tab1.component.ts b/frontend/app/zh-forms/tabs/tab1/zh-form-tab1.component.ts index 26aa3f16..841d3624 100755 --- a/frontend/app/zh-forms/tabs/tab1/zh-form-tab1.component.ts +++ b/frontend/app/zh-forms/tabs/tab1/zh-form-tab1.component.ts @@ -47,7 +47,7 @@ export class ZhFormTab1Component implements OnInit { private _tabService: TabsService, private _error: ErrorTranslatorService, public ngbModal: NgbModal, - private _config: ConfigService, + private _config: ConfigService ) {} ngOnInit() { @@ -168,7 +168,7 @@ export class ZhFormTab1Component implements OnInit { this._toastr.error(frontMsg, '', { positionClass: 'toast-top-right', }); - }, + } ); } } @@ -182,13 +182,13 @@ export class ZhFormTab1Component implements OnInit { map((res: any) => res.filter((r) => { return !this.listBib.map((bib) => bib.id_reference).includes(r.id_reference); - }), + }) ), catchError(() => { return of([]); - }), - ), - ), + }) + ) + ) ); formatter = (result: any) => `${result.title}`; diff --git a/frontend/app/zh-forms/tabs/tab3/zh-form-tab3.component.ts b/frontend/app/zh-forms/tabs/tab3/zh-form-tab3.component.ts index 18f16c40..2abd4bc8 100755 --- a/frontend/app/zh-forms/tabs/tab3/zh-form-tab3.component.ts +++ b/frontend/app/zh-forms/tabs/tab3/zh-form-tab3.component.ts @@ -469,8 +469,8 @@ export class ZhFormTab3Component implements OnInit { a.human_activity.mnemonique.slice(0, 2) > b.human_activity.mnemonique.slice(0, 2) ? 1 : b.human_activity.mnemonique.slice(0, 2) > a.human_activity.mnemonique.slice(0, 2) - ? -1 - : 0 + ? -1 + : 0 ); } @@ -480,8 +480,8 @@ export class ZhFormTab3Component implements OnInit { a.mnemonique.slice(0, 2) > b.mnemonique.slice(0, 2) ? 1 : b.mnemonique.slice(0, 2) > a.mnemonique.slice(0, 2) - ? -1 - : 0 + ? -1 + : 0 ); } return impacts; diff --git a/frontend/app/zh-forms/tabs/tab5/zh-form-tab5.component.ts b/frontend/app/zh-forms/tabs/tab5/zh-form-tab5.component.ts index 72a3294a..b4efaa9e 100755 --- a/frontend/app/zh-forms/tabs/tab5/zh-form-tab5.component.ts +++ b/frontend/app/zh-forms/tabs/tab5/zh-form-tab5.component.ts @@ -1162,8 +1162,8 @@ export class ZhFormTab5Component implements OnInit { a.function.mnemonique.slice(0, 2) > b.function.mnemonique.slice(0, 2) ? 1 : b.function.mnemonique.slice(0, 2) > a.function.mnemonique.slice(0, 2) - ? -1 - : 0 + ? -1 + : 0 ); } diff --git a/frontend/app/zh-forms/tabs/tab6/zh-form-tab6.component.ts b/frontend/app/zh-forms/tabs/tab6/zh-form-tab6.component.ts index 2310ffe4..3df38a8c 100755 --- a/frontend/app/zh-forms/tabs/tab6/zh-form-tab6.component.ts +++ b/frontend/app/zh-forms/tabs/tab6/zh-form-tab6.component.ts @@ -1041,8 +1041,8 @@ export class ZhFormTab6Component implements OnInit { a.area.municipality_name > b.area.municipality_name ? 1 : b.area.municipality_name > a.area.municipality_name - ? -1 - : 0 + ? -1 + : 0 ); }