Skip to content

Commit

Permalink
Merge pull request #90 from lpoaura/fix_89
Browse files Browse the repository at this point in the history
Fix 89
  • Loading branch information
lpofredc authored Oct 7, 2024
2 parents 67c82d3 + c89fb1d commit 4f3c509
Show file tree
Hide file tree
Showing 6 changed files with 266 additions and 222 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/), and this

<!-- ## Unreleased [{version_tag}](https://github.com/opengisch/qgis-plugin-ci/releases/tag/{version_tag}) - YYYY-MM-DD -->

## 1.6.7 - 2024-10-xx

### Fixes

- Populate `additional_data` (if column exists) on `gn_meta.t_datasets`, `gn_meta.t_acquisition_frameworks` and `gn_synthese.t_sources`,fix #87
- Replace module `pkg_resouces` by native `importlib`, fix #88

## 1.6.6 - 2024-08-20

### Fixes
Expand Down
9 changes: 5 additions & 4 deletions gn2pg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
from pathlib import Path

import coloredlogs
from pkg_resources import DistributionNotFound, get_distribution

from importlib.metadata import version

from gn2pg import metadata

try:
DIST_NAME = "gn2pg_client"
__version__ = get_distribution(DIST_NAME).version
except DistributionNotFound: # pragma: no cover
__version__ = version(DIST_NAME)
except : # pragma: no cover
__version__ = metadata.VERSION
finally:
del get_distribution, DistributionNotFound
del version

__author__ = metadata.AUTHORS_STRING
__license__ = metadata.LICENSE
Expand Down
Empty file added gn2pg/data/__init__.py
Empty file.
18 changes: 12 additions & 6 deletions gn2pg/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pathlib import Path
from subprocess import call

import pkg_resources
import importlib.resources

from gn2pg import _
from gn2pg.download import Data
Expand All @@ -22,20 +22,24 @@

sh_col = BColors()


def init(file: str) -> None:
"""Init config file from template
Args:
file (str): [description]
file (str): The name of the configuration file to create.
"""

toml_src = pkg_resources.resource_filename(__name__, "data/gn2pgconfig.toml")

# Get the path to the template file
toml_src = importlib.resources.files(__name__).joinpath("data", "gn2pgconfig.toml")

toml_dst = str(ENVDIR / file)

# Check if the destination file already exists
if Path(toml_dst).is_file():
ENVDIR.mkdir(exist_ok=True)
logger.info(_("Conf directory %s created"), str(ENVDIR))
logger.warning(_("%s file already exists"), toml_dst)

overwrite = input(
_(
f"{sh_col.color('header')}Would you like to overwrite file "
Expand All @@ -44,16 +48,18 @@ def init(file: str) -> None:
f"/[{sh_col.color('bold')}n{sh_col.color('endc')}]o) ? "
)
)

if overwrite.lower() == "n":
logger.warning(_("File %s will be preserved"), toml_dst)
sys.exit(0)
else:
logger.warning(_("file %s will be overwritten"), toml_dst)

logger.info(_("Creating TOML configuration file %s, from %s"), toml_dst, toml_src)
shutil.copyfile(toml_src, toml_dst)
logger.info(_("Please edit %s before running the script"), toml_dst)
sys.exit(0)


def edit(file: str) -> None:
"""Open editor to edit config file
Expand Down
4 changes: 2 additions & 2 deletions gn2pg/store_postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from datetime import datetime
from pathlib import Path
from typing import Any, Optional
import importlib.resources

import pkg_resources
from sqlalchemy import (
Column,
DateTime,
Expand Down Expand Up @@ -287,7 +287,7 @@ def custom_script(self, script: str = "to_gnsynthese") -> None:
logger.info(_("Start to execute %s script"), script)
conn = self._db.connect()
if script == "to_gnsynthese":
file = pkg_resources.resource_filename(__name__, "data/to_gnsynthese.sql")
file = importlib.resources.files(__name__).joinpath("data", "to_gnsynthese.sql")
logger.info(
_("You choosed to use internal to_gnsynthese.sql script in schema %s"),
self._db_schema,
Expand Down
Loading

0 comments on commit 4f3c509

Please sign in to comment.