-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from Guts/packaging/improve-metadata
Packaging: complete metadata and test it
- Loading branch information
Showing
7 changed files
with
351 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,12 +26,20 @@ | |
__copyright__ = f"2014 - {date.today().year}, {__author__}" | ||
__email__ = "[email protected]" | ||
__executable_name__ = "DicoGIS.exe" | ||
__package_name__ = "dicogis" | ||
__keywords__ = ["GIS", "metadata", "INSPIRE", "GDAL", "OGR", "data management"] | ||
__license__ = "GNU General Public License v3.0" | ||
__summary__ = "Create Excel spreadsheet describing geographical data." | ||
__summary__ = ( | ||
"Create Excel spreadsheet describing geographical data from a PostGIS " | ||
"Database or a file tree structure." | ||
) | ||
__title__ = "DicoGIS" | ||
__title_clean__ = "".join(e for e in __title__ if e.isalnum()) | ||
__uri__ = "https://github.com/Guts/DicoGIS/" | ||
__uri_doc__ = "https://guts.github.io/DicoGIS/" | ||
__uri_homepage__ = "https://guts.github.io/DicoGIS/" | ||
__uri_repository__ = "https://github.com/Guts/DicoGIS/" | ||
__uri_tracker__ = f"{__uri_repository__}/issues/" | ||
__uri__ = __uri_repository__ | ||
|
||
|
||
__version__ = "3.0.0" | ||
__version_info__ = tuple( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
#! python3 # noqa: E265 | ||
|
||
"""Helpers to retrieve information from execution environment like software versions.""" | ||
|
||
# ############################################################################ | ||
# ########## Libraries ############# | ||
# ################################## | ||
|
||
# standard library | ||
import logging | ||
import re | ||
import subprocess | ||
from os import getenv | ||
|
||
try: | ||
from osgeo import gdal, osr | ||
|
||
GDAL_IS_AVAILABLE: bool = True | ||
except ImportError: | ||
logging.info("GDAL (ou ses bindings Python) n'est pas installé.") | ||
gdal = osr = None | ||
GDAL_IS_AVAILABLE: bool = False | ||
|
||
try: | ||
import pyproj | ||
|
||
PYPROJ_IS_AVAILABLE: bool = True | ||
except ImportError: | ||
logging.info("PyProj n'est pas installé.") | ||
pyproj = None | ||
PYPROJ_IS_AVAILABLE: bool = False | ||
|
||
# ############################################################################ | ||
# ########### Globals ############## | ||
# ################################## | ||
|
||
# logs | ||
logger = logging.getLogger(__name__) | ||
|
||
# ############################################################################ | ||
# ########### Functions ############ | ||
# ################################## | ||
|
||
|
||
def get_gdal_version() -> str: | ||
"""Return GDAL version from gdal-config cmd or from environment variable GDAL_VERSION. | ||
Returns: | ||
str: version of GDAL | ||
""" | ||
gdal_fallback_version = "3.*" | ||
|
||
# if available use, | ||
if GDAL_IS_AVAILABLE: | ||
logger.debug( | ||
f"Version de GDAL obtenue depuis les bindings Python : {gdal.__version__}" | ||
) | ||
return gdal.__version__ | ||
|
||
# try to get it from gdalinfo (installed with gdal) | ||
try: | ||
returned_output: bytes = subprocess.check_output( | ||
"gdalinfo --version", shell=True | ||
) | ||
logger.debug( | ||
f"GDAL version retrieved from gdalinfo: {returned_output.decode('utf-8')}" | ||
) | ||
return returned_output[5:10].decode("utf-8") | ||
except Exception: | ||
pass | ||
|
||
# try to get it from gdal-config (installed with gdaldev) | ||
try: | ||
returned_output: bytes = subprocess.check_output( | ||
"gdal-config --version", shell=True | ||
) | ||
logger.debug( | ||
f"GDAL version retrieved from gdal-config: {returned_output.decode('utf-8')}" | ||
) | ||
return returned_output.decode("utf-8") | ||
except Exception: | ||
pass | ||
|
||
# first check environment variable | ||
gdal_version = getenv("GDAL_VERSION") | ||
if gdal_version: | ||
return gdal_version | ||
|
||
logging.warning( | ||
"Unable to retrieve GDAL version from command-line or environment var. " | ||
f"Using default version: {gdal_fallback_version}" | ||
) | ||
return gdal_fallback_version | ||
|
||
|
||
def get_proj_version() -> str | None: | ||
"""Get PROJ version, using GDAL, PyProj, installed proj binaries or environment | ||
variable. | ||
Returns: | ||
str | None: PROJ's version as Major.Minor.Micro or None if not found | ||
""" | ||
proj_version = None | ||
|
||
# from GDAL bindings | ||
if osr is not None and GDAL_IS_AVAILABLE: | ||
try: | ||
proj_version = ( | ||
f"{osr.GetPROJVersionMajor()}." | ||
f"{osr.GetPROJVersionMinor()}." | ||
f"{osr.GetPROJVersionMicro()}" | ||
) | ||
logger.debug( | ||
f"Version de PROJ obtenue depuis les bindings Python de GDAL : {proj_version}" | ||
) | ||
return proj_version | ||
except Exception: | ||
pass | ||
|
||
# from PyProj | ||
if pyproj is not None and PYPROJ_IS_AVAILABLE: | ||
try: | ||
proj_version = pyproj.__proj_version__ | ||
logger.debug(f"Version de PROJ obtenue depuis PyProj : {proj_version}") | ||
return proj_version | ||
except Exception: | ||
pass | ||
|
||
# from PROJ command-line | ||
try: | ||
# Exécute la commande "proj" en utilisant subprocess | ||
result = subprocess.check_output(["proj"], stderr=subprocess.STDOUT, text=True) | ||
|
||
# Recherche de la version dans la sortie à l'aide d'une expression régulière | ||
if version_match := re.search(r"Rel\. ([0-9.]+)", result): | ||
proj_version = version_match.group(1) | ||
logger.debug( | ||
f"Version de PROJ obtenue depuis le binaire proj : {proj_version}" | ||
) | ||
return proj_version | ||
else: | ||
logger.error( | ||
"PROJ est bien installé mais impossible de trouver la version en regex." | ||
) | ||
except FileNotFoundError as err: | ||
logger.info(f"Proj n'est pas installé. Trace : {err}") | ||
except subprocess.CalledProcessError as e: | ||
logger.info(f"Erreur lors de l'exécution de la commande : {e}") | ||
|
||
# from environment variable | ||
if proj_version := getenv("PROJ_VERSION"): | ||
return proj_version | ||
|
||
logging.warning( | ||
"Impossible de déterminer la version de PROJ depuis les bindings GDAL, PyProj, " | ||
"les binaires proj ou la variable d'environnement PROJ_VERSION. " | ||
) | ||
return proj_version | ||
|
||
|
||
# ############################################################################ | ||
# ##### Stand alone program ######## | ||
# ################################## | ||
|
||
if __name__ == "__main__": | ||
"""Standalone execution.""" | ||
print(get_gdal_version()) | ||
print(get_proj_version()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pytest-cov>=3,<4.1 | ||
semver>=2.13,<2.14 | ||
pytest-cov>=4,<5 | ||
packaging>=20,<24 | ||
validators>=0.19,<0.21 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.