Skip to content

Commit

Permalink
Refactor: factorize enum and geo format (#37)
Browse files Browse the repository at this point in the history
# Goal
The purpose of this PR is to refactor the `enum_format.py` and
`geo_format.py` files into a single `set_format.py` file to eliminate
redundancy and improve maintainability . Additionally, it reorganizes
the project structure by consolidating all French formats into a
dedicated `formats` folder."

---------

Co-authored-by: Pierre Camilleri <[email protected]>
  • Loading branch information
Sarrabah and pierrecamilleri authored Jan 16, 2025
1 parent 22ac607 commit dcafec8
Show file tree
Hide file tree
Showing 35 changed files with 210 additions and 184 deletions.
40 changes: 20 additions & 20 deletions src/frformat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
# flake8: noqa
from .custom_format import * # isort:skip
from .code_rna import CodeRNA as CodeRNA
from .geo.canton import Canton as Canton
from .geo.code_commune_insee import CodeCommuneInsee as CodeCommuneInsee
from .geo.code_fantoir import CodeFantoir as CodeFantoir
from .geo.code_pays import CodePaysISO2 as CodePaysISO2
from .geo.code_pays import CodePaysISO3 as CodePaysISO3
from .geo.code_postal import CodePostal as CodePostal
from .geo.code_region import CodeRegion as CodeRegion
from .geo.commune import Commune as Commune
from .geo.coordonnees_gps_francaises import (
from .formats.canton import Canton as Canton
from .formats.code_commune_insee import CodeCommuneInsee as CodeCommuneInsee
from .formats.code_fantoir import CodeFantoir as CodeFantoir
from .formats.code_pays import CodePaysISO2 as CodePaysISO2
from .formats.code_pays import CodePaysISO3 as CodePaysISO3
from .formats.code_postal import CodePostal as CodePostal
from .formats.code_region import CodeRegion as CodeRegion
from .formats.code_rna import CodeRNA as CodeRNA
from .formats.commune import Commune as Commune
from .formats.coordonnees_gps_francaises import (
CoordonneesGPSFrancaises as CoordonneesGPSFrancaises,
)
from .geo.departement import Departement as Departement
from .geo.latitude_l93 import LatitudeL93 as LatitudeL93
from .geo.longitude_l93 import LongitudeL93 as LongitudeL93
from .geo.numero_departement import NumeroDepartement as NumeroDepartement
from .geo.pays import Pays as Pays
from .geo.region import Region as Region
from .geo_format import Millesime as Millesime
from .nomenclature_acte_format import NomenclatureActe as NomenclatureActe
from .formats.departement import Departement as Departement
from .formats.latitude_l93 import LatitudeL93 as LatitudeL93
from .formats.longitude_l93 import LongitudeL93 as LongitudeL93
from .formats.nomenclature_acte_format import NomenclatureActe as NomenclatureActe
from .formats.numero_departement import NumeroDepartement as NumeroDepartement
from .formats.pays import Pays as Pays
from .formats.region import Region as Region
from .formats.siren import Siren as Siren
from .formats.siret import Siret as Siret
from .options import Options as Options
from .siren import Siren as Siren
from .siret import Siret as Siret
from .set_format import Millesime as Millesime

all_formats = [
Canton,
Expand Down
35 changes: 0 additions & 35 deletions src/frformat/enum_format.py

This file was deleted.

8 changes: 4 additions & 4 deletions src/frformat/geo/canton.py → src/frformat/formats/canton.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from frformat import geo_format
from frformat.geo.canton_frozenset import CANTON_COG_2023, CANTON_COG_2024
from frformat.geo_format import Millesime
from frformat import set_format
from frformat.formats.canton_frozenset import CANTON_COG_2023, CANTON_COG_2024
from frformat.set_format import Millesime
from frformat.versioned_set import VersionedSet

name = "Nom de canton"
Expand All @@ -10,4 +10,4 @@
canton_versioned_data.add_version(Millesime.M2023, CANTON_COG_2023)
canton_versioned_data.add_version(Millesime.M2024, CANTON_COG_2024)

Canton = geo_format.new("Canton", name, description, canton_versioned_data)
Canton = set_format.new_geo("Canton", name, description, canton_versioned_data)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from frformat import geo_format
from frformat.geo.code_commune_insee_frozenset import (
from frformat import set_format
from frformat.formats.code_commune_insee_frozenset import (
CODES_COMMUNES_INSEE_COG_2023,
CODES_COMMUNES_INSEE_COG_2024,
)
from frformat.geo_format import Millesime
from frformat.set_format import Millesime
from frformat.versioned_set import VersionedSet

name = "Code commune INSEE"
Expand All @@ -17,6 +17,6 @@
Millesime.M2024, CODES_COMMUNES_INSEE_COG_2024
)

CodeCommuneInsee = geo_format.new(
CodeCommuneInsee = set_format.new_geo(
"CodeCommuneInsee", name, description, code_commune_insee_versioned_data
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import string

from frformat import CustomStrFormat, Metadata
from frformat.formats.code_fantoir_frozenset import PARTIAL_CODE_FANTOIR
from frformat.formatter import Formatter
from frformat.geo.code_fantoir_frozenset import PARTIAL_CODE_FANTOIR

name = "Code fantoir"
description = "Vérifie les codes fantoirs valides"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from frformat import geo_format
from frformat.geo.code_pays_frozenset import (
from frformat import set_format
from frformat.formats.code_pays_frozenset import (
CODES_PAYS_ISO2_COG_2023,
CODES_PAYS_ISO2_COG_2024,
CODES_PAYS_ISO3_COG_2023,
CODES_PAYS_ISO3_COG_2024,
)
from frformat.geo_format import Millesime
from frformat.set_format import Millesime
from frformat.versioned_set import VersionedSet

name = "Codes ISO2 Pays"
Expand All @@ -15,7 +15,7 @@
code_pays_IS02_versioned_data.add_version(Millesime.M2023, CODES_PAYS_ISO2_COG_2023)
code_pays_IS02_versioned_data.add_version(Millesime.M2024, CODES_PAYS_ISO2_COG_2024)

CodePaysISO2 = geo_format.new(
CodePaysISO2 = set_format.new_geo(
"CodePaysISO2", name, description, code_pays_IS02_versioned_data
)

Expand All @@ -27,6 +27,6 @@
code_pays_IS03_versioned_data.add_version(Millesime.M2023, CODES_PAYS_ISO3_COG_2023)
code_pays_IS03_versioned_data.add_version(Millesime.M2024, CODES_PAYS_ISO3_COG_2024)

CodePaysISO3 = geo_format.new(
CodePaysISO3 = set_format.new_geo(
"CodePaysISO3", name, description, code_pays_IS03_versioned_data
)
File renamed without changes.
7 changes: 7 additions & 0 deletions src/frformat/formats/code_postal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from frformat import set_format
from frformat.formats.code_postal_frozenset import CODES_POSTAUX

name = "Code postal"
description = "Vérifie que le code postal est bien un code postal français"

CodePostal = set_format.new("CodePostal", name, description, CODES_POSTAUX)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from frformat import geo_format
from frformat import set_format
from frformat.versioned_set import VersionedSet

from ..geo_format import Millesime
from ..set_format import Millesime

CODES_REGIONS_COG_2023 = frozenset(
{
Expand Down Expand Up @@ -34,4 +34,6 @@
code_region_versioned_data.add_version(Millesime.M2023, CODES_REGIONS_COG_2023)
code_region_versioned_data.add_version(Millesime.M2024, CODES_REGIONS_COG_2024)

CodeRegion = geo_format.new("CodeRegion", name, description, code_region_versioned_data)
CodeRegion = set_format.new_geo(
"CodeRegion", name, description, code_region_versioned_data
)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from frformat import geo_format
from frformat.geo.commune_frozenset import COMMUNES_COG_2023, COMMUNES_COG_2024
from frformat.geo_format import Millesime
from frformat import set_format
from frformat.formats.commune_frozenset import COMMUNES_COG_2023, COMMUNES_COG_2024
from frformat.set_format import Millesime
from frformat.versioned_set import VersionedSet

name = "Nom de commune"
Expand All @@ -13,4 +13,4 @@
commune_versioned_data.add_version(Millesime.M2023, COMMUNES_COG_2023)
commune_versioned_data.add_version(Millesime.M2024, COMMUNES_COG_2024)

Commune = geo_format.new("Commune", name, description, commune_versioned_data)
Commune = set_format.new_geo("Commune", name, description, commune_versioned_data)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from frformat import geo_format
from frformat.geo.departement_frozenset import (
from frformat import set_format
from frformat.formats.departement_frozenset import (
DEPARTEMENTS_COG_2023,
DEPARTEMENTS_COG_2024,
)
from frformat.geo_format import Millesime
from frformat.set_format import Millesime
from frformat.versioned_set import VersionedSet

name = "Nom de département"
Expand All @@ -13,6 +13,6 @@
departement_versioned_data.add_version(Millesime.M2023, DEPARTEMENTS_COG_2023)
departement_versioned_data.add_version(Millesime.M2024, DEPARTEMENTS_COG_2024)

Departement = geo_format.new(
Departement = set_format.new_geo(
"Departement", name, description, departement_versioned_data
)
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from frformat import CustomNumericFormat, Metadata
from frformat.geo.latitude_l93 import UnitFormatter
from frformat.formats.latitude_l93 import UnitFormatter

name = "Longitude en Lambert 93"
description = "Vérifie que la longitude en France métropolitaine donnée est une longitude en lambert 93"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from frformat import geo_format
from frformat.geo_format import Millesime
from frformat import set_format
from frformat.set_format import Millesime
from frformat.versioned_set import VersionedSet

NUMEROS_DEPARTEMENTS_COG_2023 = frozenset(
Expand All @@ -24,6 +24,6 @@
Millesime.M2024, NUMEROS_DEPARTEMENTS_COG_2024
)

NumeroDepartement = geo_format.new(
NumeroDepartement = set_format.new_geo(
"NumeroDepartement", name, description, numero_departement_versioned_data
)
8 changes: 4 additions & 4 deletions src/frformat/geo/pays.py → src/frformat/formats/pays.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from frformat import geo_format
from frformat.geo.pays_frozenset import PAYS_COG_2024
from frformat.geo_format import Millesime
from frformat import set_format
from frformat.formats.pays_frozenset import PAYS_COG_2024
from frformat.set_format import Millesime
from frformat.versioned_set import VersionedSet

name = "Pays et territoires étrangers"
Expand All @@ -11,4 +11,4 @@
pays_versioned_data = VersionedSet[Millesime]()
pays_versioned_data.add_version(Millesime.M2024, PAYS_COG_2024)

Pays = geo_format.new("Pays", name, description, pays_versioned_data)
Pays = set_format.new_geo("Pays", name, description, pays_versioned_data)
File renamed without changes.
8 changes: 4 additions & 4 deletions src/frformat/geo/region.py → src/frformat/formats/region.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from frformat import geo_format
from frformat.geo.region_frozenset import REGIONS_COG_2023, REGIONS_COG_2024
from frformat.geo_format import Millesime
from frformat import set_format
from frformat.formats.region_frozenset import REGIONS_COG_2023, REGIONS_COG_2024
from frformat.set_format import Millesime
from frformat.versioned_set import VersionedSet

name = "Nom de région"
Expand All @@ -12,4 +12,4 @@
region_versioned_data.add_version(Millesime.M2023, REGIONS_COG_2023)
region_versioned_data.add_version(Millesime.M2024, REGIONS_COG_2024)

Region = geo_format.new("Region", name, description, region_versioned_data)
Region = set_format.new_geo("Region", name, description, region_versioned_data)
File renamed without changes.
2 changes: 1 addition & 1 deletion src/frformat/siren.py → src/frformat/formats/siren.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from frformat.common import NNBSP
from frformat.formatter import Formatter

from . import CustomStrFormat, Metadata
from .. import CustomStrFormat, Metadata

name = "SIREN"
description = (
Expand Down
2 changes: 1 addition & 1 deletion src/frformat/siret.py → src/frformat/formats/siret.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from frformat.common import NNBSP
from frformat.formatter import Formatter

from . import CustomStrFormat, Metadata
from .. import CustomStrFormat, Metadata

name = "SIRET"
description = (
Expand Down
7 changes: 0 additions & 7 deletions src/frformat/geo/code_postal.py

This file was deleted.

78 changes: 0 additions & 78 deletions src/frformat/geo_format.py

This file was deleted.

Loading

0 comments on commit dcafec8

Please sign in to comment.