Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.[0-9]+.dev[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+.dev[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+.*'
pull_request: { }
workflow_dispatch:

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,5 @@ example/minimal_usage/farm_data/*
!example/minimal_usage/farm_data/farm.json
!example/minimal_usage/main.py
src/pyholos/resources/soil_landscapes_of_canada_v3r2
src/pyholos/resources/holos4_cli
**/UserFarmsPath.txt
5 changes: 0 additions & 5 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@ Move inside the project folder:

cd pyholos

Unzip the pre-installed Holos4 CLI located under `src/pyholos/resources/holos4_cli.zip`
into `src/pyholos/resources/holos4_cli`. This ensures that pyholos works with a specific version of Holos4 CLI.
Working with other CLI versions should be performed by manually replacing this unzipped folder with new version files.
However, breaking-change problems may occur.


Now you can create a **conda** (or **mamba**) environment inside which you will install ``pyholos`` and all its
dependencies. Let's create and activate an environment called 'MyEnv':
Expand Down
41 changes: 37 additions & 4 deletions src/pyholos/config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
import zipfile
from os import environ
from pathlib import Path

DATE_FMT = "%Y-%m-%d"

_PATH_HOLOS_SERVICE_RESOURCES = Path(__file__).parent / 'resources'
PATH_HOLOS_CLI = _PATH_HOLOS_SERVICE_RESOURCES / 'holos4_cli/H.CLI.exe'
_PATH_RESOURCES = Path(__file__).parent / 'resources'

_PATH_RESOURCES_UNZIP: Path = _PATH_RESOURCES if (pth := environ.get('PATH_RESOURCES_UNZIP')) is None else Path(pth)


def _ensure_resources_extracted():
"""Extract resource zip files if not already extracted."""
# Extract HOLOS CLI if needed
holos_cli_zip = _PATH_RESOURCES_UNZIP / 'holos4_cli.zip'
holos_cli_dir = _PATH_RESOURCES_UNZIP / 'holos4_cli'
holos_cli_exe = holos_cli_dir / 'H.CLI.exe'

if holos_cli_zip.exists() and not holos_cli_exe.exists():
with zipfile.ZipFile(holos_cli_zip, 'r') as zip_ref:
zip_ref.extractall(_PATH_RESOURCES_UNZIP)

# Extract SLC data if needed
slc_zip = _PATH_RESOURCES_UNZIP / 'soil_landscapes_of_canada_v3r2.zip'
slc_dir = _PATH_RESOURCES_UNZIP / 'soil_landscapes_of_canada_v3r2'
slc_geojson = slc_dir / 'soil_landscapes_of_canada_v3r2.geojson'

if slc_zip.exists() and not slc_geojson.exists():
with zipfile.ZipFile(slc_zip, 'r') as zip_ref:
zip_ref.extractall(_PATH_RESOURCES_UNZIP)


# Auto-extract resources on import
_ensure_resources_extracted()

PATH_HOLOS_CLI = _PATH_RESOURCES_UNZIP / 'holos4_cli/H.CLI.exe'


class PathsHolosResources:
_path_root = _PATH_HOLOS_SERVICE_RESOURCES / 'holos'
_path_root = _PATH_RESOURCES / 'holos'
Table_Tillage_Factor = _path_root / (
'Table_Tillage_Factor.csv')
Table_6_Manure_Types_And_Default_Composition = _path_root / (
Expand Down Expand Up @@ -40,9 +70,12 @@ class PathsHolosResources:


class PathsSlcData:
_path_root = _PATH_HOLOS_SERVICE_RESOURCES / 'soil_landscapes_of_canada_v3r2'
_path_root = _PATH_RESOURCES_UNZIP / 'soil_landscapes_of_canada_v3r2'
geojson_file = _path_root / 'soil_landscapes_of_canada_v3r2.geojson'
csv_dir = _path_root / 'soil_landscapes_of_canada_v3r2_csv'
cmp_file = csv_dir / 'ca_all_slc_v3r2_cmp.csv'
slt_file = csv_dir / 'ca_all_slc_v3r2_slt.csv'
snt_file = csv_dir / 'ca_all_slc_v3r2_snt.csv'


pass
5 changes: 3 additions & 2 deletions src/pyholos/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
major = 0
minor = 2
minor = 3
post = 0
patch = ""

__version__ = ".".join([str(s) for s in (major, minor, post)])
__version__ = f'{major}.{minor}.{post}' + (f'.{patch}' if patch != "" else '')
Loading