Skip to content

Commit

Permalink
Merge pull request #119 from GNS-Science/move-resources-and-scripts
Browse files Browse the repository at this point in the history
Move resources and scripts under top level package
  • Loading branch information
chrisdicaprio authored Dec 17, 2024
2 parents 3e4251a + 26e11ed commit 39e57ee
Show file tree
Hide file tree
Showing 60 changed files with 58 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.13.4
current_version = 0.13.5
commit = True
tag = True

Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [0.13.5] 2024-17-12

### Changed
- moved scripts and resources packages to be under nzshm_model package

## [0.13.4] 2024-12-12

### Added
Expand Down
4 changes: 2 additions & 2 deletions docs/scripts.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# CLI Reference

::: mkdocs-click
:module: scripts.cli
:module: nzshm_model.scripts.cli
:command: cli
:prog_name: cli

::: mkdocs-click
:module: scripts.slt
:module: nzshm_model.scripts.slt
:command: slt
:prog_name: slt
2 changes: 1 addition & 1 deletion docs/scripts/cli.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
::: mkdocs-click
:module: scripts.cli
:module: nzshm_model.scripts.cli
:command: cli
:prog_name: cli

2 changes: 1 addition & 1 deletion docs/scripts/slt.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
::: mkdocs-click
:module: scripts.slt
:module: nzshm_model.scripts.slt
:command: slt
:prog_name: slt
1 change: 0 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ repo_name: GNS-Science/nzshm-model
watch:
- nzshm_model
- docs
- scripts
nav:
- Home: index.md
- Installation: installation.md
Expand Down
2 changes: 1 addition & 1 deletion nzshm_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
from .model_version import CURRENT_VERSION, all_model_versions, get_model_version, versions

# Python package version is different than the NSHM MODEL version !!
__version__ = '0.13.4'
__version__ = '0.13.5'
13 changes: 6 additions & 7 deletions nzshm_model/branch_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@

import csv
import hashlib

# import io
import pathlib
import importlib.resources as resources
from dataclasses import asdict, dataclass
from typing import IO, Any, Optional

HEADERS = ['hash_digest', 'identity', 'extra']
GMM_REGISTRY_CSV = pathlib.Path(__file__).parent.parent / 'resources' / 'gmm_branches.csv'
SOURCE_REGISTRY_CSV = pathlib.Path(__file__).parent.parent / 'resources' / 'source_branches.csv'
RESOURCES_DIR = resources.files('nzshm_model.resources')
GMM_REGISTRY_CSV = RESOURCES_DIR / 'gmm_branches.csv'
SOURCE_REGISTRY_CSV = RESOURCES_DIR / 'source_branches.csv'


def identity_digest(identity: str) -> str:
Expand Down Expand Up @@ -53,13 +52,13 @@ class Registry:
@property
def gmm_registry(self) -> 'BranchRegistry':
if not self._gmms:
self._gmms = BranchRegistry().load(open(GMM_REGISTRY_CSV, 'r'))
self._gmms = BranchRegistry().load(GMM_REGISTRY_CSV.open('r'))

Check warning on line 55 in nzshm_model/branch_registry.py

View check run for this annotation

Codecov / codecov/patch

nzshm_model/branch_registry.py#L55

Added line #L55 was not covered by tests
return self._gmms

@property
def source_registry(self) -> 'BranchRegistry':
if not self._sources:
self._sources = BranchRegistry().load(open(SOURCE_REGISTRY_CSV, 'r'))
self._sources = BranchRegistry().load(SOURCE_REGISTRY_CSV.open('r'))
return self._sources


Expand Down
2 changes: 1 addition & 1 deletion nzshm_model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from .psha_adapter.hazard_config import HazardConfig, HazardConfigType

RESOURCES_PATH = resources.files('resources')
RESOURCES_PATH = resources.files('nzshm_model.resources')

SLT_SOURCE_PATH = RESOURCES_PATH / "SRM_JSON"
GMM_JSON_SOURCE_PATH = RESOURCES_PATH / "GMM_JSON"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
72 changes: 20 additions & 52 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
[tool.poetry]
name = "nzshm-model"
version = "0.13.4"
version = "0.13.5"
description = "The logic tree definitions, final configurations, and versioning of the New Zealand | Aotearoa National Seismic Hazard Model"
authors = ["Chris DiCaprio <[email protected]>", "Chris Chamberlain <[email protected]>"]
license = "AGPL3"
readme = "README.md"
packages = [
{include = "nzshm_model"},
{include = "resources"},
{include = "scripts"},
{include = "tests", format = "sdist" }
]

[tool.poetry.scripts]
slt = 'scripts.slt:slt'
model = 'scripts.cli:cli'
slt = 'nzshm_model.scripts.slt:slt'
model = 'nzshm_model.scripts.cli:cli'

[tool.poetry.dependencies]
python = ">=3.9,<4.0"
Expand Down Expand Up @@ -48,12 +46,12 @@ mkdocstrings = {extras = ["python"], version = "^0.27.0"}
black = { version = "^22.3"}
bump2version = "^1.0.1"
isort = { version = "^5.8.0"}
pytest = { version = "^6.2.4"}
pytest-cov = { version = "^2.12.0"}
tox = "^4.2.8"
mypy = "^1.8.0"
flake8 = "^7.1.1"
flake8-docstrings = {version = "^1.7.0", optional = true}
pytest = "^8.3.4"
pytest-cov = "^6.0.0"

[tool.black]
line-length = 120
Expand Down
9 changes: 4 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ python =
allowlist_externals = pytest
extras =
test
scripts
passenv = *
setenv =
PYTHONPATH = {toxinidir}
PYTHONWARNINGS = ignore
commands =
pytest --cov=nzshm_model --cov=scripts --cov-branch --cov-report=xml --cov-report=term-missing tests
pytest --cov=nzshm_model --cov-branch --cov-report=xml --cov-report=term-missing tests

[testenv:format]
allowlist_externals =
Expand All @@ -69,8 +68,8 @@ allowlist_externals =
extras =
test
commands =
isort nzshm_model scripts tests
black nzshm_model scripts tests
isort nzshm_model tests
black nzshm_model tests

[testenv:lint]
allowlist_externals =
Expand All @@ -80,7 +79,7 @@ extras =
test
commands =
flake8
mypy nzshm_model scripts tests resources
mypy nzshm_model tests

[testenv:build]
allowlist_externals =
Expand Down
4 changes: 2 additions & 2 deletions tests/test_correlations_new.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import importlib.resources as resources
import json
from pathlib import Path

from nzshm_model.logic_tree import SourceLogicTree
from nzshm_model.logic_tree.source_logic_tree import SourceLogicTreeV1
Expand All @@ -8,7 +8,7 @@

def test_v2_correlations():

slt_filepath = Path(__file__).parent.parent / "resources" / "SRM_JSON" / "nshm_v1.0.4.json"
slt_filepath = resources.files('nzshm_model.resources') / "SRM_JSON" / "nshm_v1.0.4.json"
with slt_filepath.open() as slt_file:
slt_v1 = SourceLogicTreeV1.from_dict(json.load(slt_file))
slt_v2 = SourceLogicTree.from_source_logic_tree(slt_v1)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_logic_tree.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#! python test_logic_tree.py

import dataclasses
import importlib.resources as resources
import itertools
from pathlib import Path

Expand Down Expand Up @@ -120,7 +121,7 @@ def test_serialise_slt():

class TestSourceLogicTreeSpecification:
def test_slt_v8(self):
config = Path(__file__).parent.parent / 'resources' / 'SRM_LTs' / 'python' / 'SLT_v8_gmm_v2_final.py'
config = resources.files('nzshm_model.resources') / 'SRM_LTs' / 'python' / 'SLT_v8_gmm_v2_final.py'
slt = from_config(config)

slt_spec = slt.derive_spec()
Expand Down Expand Up @@ -154,7 +155,7 @@ def test_large_SLT_example_A_crustal(self):


class TestFlattenedSourceLogicTree:
def setup(self):
def setup_method(self):
ba0 = BranchAttributeSpec(name='C', long_name='area-magnitude scaling', value_options=[4.0, 4.1, 4.2])
ba1 = BranchAttributeSpec(name='C', long_name='area-magnitude scaling', value_options=[4.1, 4.2, 4.3])

Expand Down
7 changes: 4 additions & 3 deletions tests/test_slt_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#! test_module_import
import dataclasses
import importlib.resources as resources
import json
from pathlib import Path

Expand Down Expand Up @@ -87,7 +88,7 @@ def test_assemble_puy(self):
class TestConfigSerialisation:
@pytest.mark.parametrize("python_module", ['SLT_v9p0p0.py', 'SLT_v8_gmm_v2_final.py'])
def test_slt_dict_to_json(self, python_module):
config = Path(__file__).parent.parent / 'resources' / 'SRM_LTs' / 'python' / python_module
config = resources.files('nzshm_model.resources') / 'SRM_LTs' / 'python' / python_module
slt = from_config(config)
obj = dataclasses.asdict(slt)
jsonish = json.dumps(obj, indent=2)
Expand All @@ -97,7 +98,7 @@ def test_slt_dict_to_json(self, python_module):
@pytest.mark.parametrize("python_module", ['SLT_v9p0p0.py', 'SLT_v8_gmm_v2_final.py'])
def test_slt_v8_round_trip(self, python_module):

config = Path(__file__).parent.parent / 'resources' / 'SRM_LTs' / 'python' / python_module
config = resources.files('nzshm_model.resources') / 'SRM_LTs' / 'python' / python_module
slt = from_config(config)
obj = dataclasses.asdict(slt)
jsonish = json.dumps(obj, indent=2)
Expand All @@ -119,7 +120,7 @@ def test_slt_v8_round_trip(self, python_module):

class TestFromConfig:
def test_slt_v8(self):
config = Path(__file__).parent.parent / 'resources' / 'SRM_LTs' / 'python' / 'SLT_v8_gmm_v2_final.py'
config = resources.files('nzshm_model.resources') / 'SRM_LTs' / 'python' / 'SLT_v8_gmm_v2_final.py'
slt = from_config(config)
print(slt)
assert slt.fault_system_lts[0].branches[-1].values[0].name == 'dm'
Expand Down
Loading

0 comments on commit 39e57ee

Please sign in to comment.