Skip to content

Commit d963b2d

Browse files
Move configuration objects to virtualship.models (#189)
* Move location.py and spacetime.py to models * Move ship_config to models * Move schedule to models * Move space_time_region to models * Move errors to separate file * Run hooks * Update reference to ConfigError * Add tidy-imports ruff rule * Add models.__init__ * Update imports to models subpackage * Update imports of errors * cleanup virtualship/expedition/__init__.py * cleanup virtualship/__init__.py
1 parent a77f348 commit d963b2d

38 files changed

+140
-118
lines changed

docs/user-guide/tutorials/Drifter_data_tutorial.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"metadata": {},
1818
"outputs": [],
1919
"source": [
20-
"from virtualship import Location, Spacetime\n",
20+
"from virtualship.models import Location, Spacetime\n",
2121
"from virtualship.instruments.drifter import Drifter, simulate_drifters\n",
2222
"from virtualship.expedition.input_data import InputData\n",
2323
"from pathlib import Path\n",

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ select = [
9595
"ICN", # import conventions
9696
"RUF", # ruff
9797
"ISC001", # single-line-implicit-string-concatenation
98+
"TID", # flake8-tidy-imports
9899
]
99100
ignore = [
100101
# line too long (82 > 79 characters)

src/virtualship/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@
22

33
from importlib.metadata import version as _version
44

5-
from .location import Location
6-
from .spacetime import Spacetime
7-
85
try:
96
__version__ = _version("virtualship")
107
except Exception:
118
# Local copy or not installed with setuptools
129
__version__ = "unknown"
1310

1411
__all__ = [
15-
"Location",
16-
"Spacetime",
1712
"__version__",
1813
]

src/virtualship/cli/_creds.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@
66
import pydantic
77
import yaml
88

9-
CREDENTIALS_FILE = "credentials.yaml"
10-
9+
from virtualship.errors import CredentialFileError
1110

12-
class CredentialFileError(Exception):
13-
"""Exception raised for errors in the input file format."""
14-
15-
pass
11+
CREDENTIALS_FILE = "credentials.yaml"
1612

1713

1814
class Credentials(pydantic.BaseModel):

src/virtualship/cli/_fetch.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from pydantic import BaseModel
1010

11+
from virtualship.errors import IncompleteDownloadError
1112
from virtualship.utils import (
1213
_dump_yaml,
1314
_generic_load_yaml,
@@ -16,7 +17,7 @@
1617
)
1718

1819
if TYPE_CHECKING:
19-
from virtualship.expedition.space_time_region import SpaceTimeRegion
20+
from virtualship.models import SpaceTimeRegion
2021

2122
import click
2223
import copernicusmarine
@@ -38,7 +39,7 @@ def _fetch(path: str | Path, username: str | None, password: str | None) -> None
3839
be provided on prompt, via command line arguments, or via a YAML config file. Run
3940
`virtualship fetch` on an expedition for more info.
4041
"""
41-
from virtualship.expedition.ship_config import InstrumentType
42+
from virtualship.models import InstrumentType
4243

4344
if sum([username is None, password is None]) == 1:
4445
raise ValueError("Both username and password must be provided when using CLI.")
@@ -329,12 +330,6 @@ def hash_to_filename(hash: str) -> str:
329330
return f"{datetime.now().strftime('%Y%m%d_%H%M%S')}_{hash}"
330331

331332

332-
class IncompleteDownloadError(Exception):
333-
"""Exception raised for incomplete downloads."""
334-
335-
pass
336-
337-
338333
class DownloadMetadata(BaseModel):
339334
"""Metadata for a data download."""
340335

src/virtualship/errors.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class CredentialFileError(Exception):
2+
"""Exception raised for errors in the input file format."""
3+
4+
pass
5+
6+
7+
class IncompleteDownloadError(Exception):
8+
"""Exception raised for incomplete downloads."""
9+
10+
pass
11+
12+
13+
class CheckpointError(RuntimeError):
14+
"""An error in the checkpoint."""
15+
16+
pass
17+
18+
19+
class ScheduleError(RuntimeError):
20+
"""An error in the schedule."""
21+
22+
pass
23+
24+
25+
class ConfigError(RuntimeError):
26+
"""An error in the config."""
27+
28+
pass

src/virtualship/expedition/__init__.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,8 @@
22

33
from .do_expedition import do_expedition
44
from .input_data import InputData
5-
from .schedule import Schedule, Waypoint
6-
from .ship_config import (
7-
ADCPConfig,
8-
ArgoFloatConfig,
9-
CTD_BGCConfig,
10-
CTDConfig,
11-
DrifterConfig,
12-
ShipConfig,
13-
ShipUnderwaterSTConfig,
14-
)
15-
from .space_time_region import SpaceTimeRegion
165

176
__all__ = [
18-
"ADCPConfig",
19-
"ArgoFloatConfig",
20-
"CTDConfig",
21-
"CTD_BGCConfig",
22-
"DrifterConfig",
237
"InputData",
24-
"InstrumentType",
25-
"Schedule",
26-
"ShipConfig",
27-
"ShipUnderwaterSTConfig",
28-
"SpaceTimeRegion",
29-
"Waypoint",
308
"do_expedition",
31-
"instruments",
329
]

src/virtualship/expedition/checkpoint.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import pydantic
88
import yaml
99

10-
from .schedule import Schedule
11-
from .ship_config import InstrumentType
10+
from virtualship.errors import CheckpointError
11+
from virtualship.models import InstrumentType, Schedule
1212

1313

1414
class _YamlDumper(yaml.SafeDumper):
@@ -71,9 +71,3 @@ def verify(self, schedule: Schedule) -> None:
7171
raise CheckpointError(
7272
"Past waypoints in schedule have been changed! Restore past schedule and only change future waypoints."
7373
)
74-
75-
76-
class CheckpointError(RuntimeError):
77-
"""An error in the checkpoint."""
78-
79-
pass

src/virtualship/expedition/do_expedition.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pyproj
88

99
from virtualship.cli._fetch import get_existing_download, get_space_time_region_hash
10+
from virtualship.models import Schedule, ShipConfig
1011
from virtualship.utils import (
1112
CHECKPOINT,
1213
_get_schedule,
@@ -16,8 +17,6 @@
1617
from .checkpoint import Checkpoint
1718
from .expedition_cost import expedition_cost
1819
from .input_data import InputData
19-
from .schedule import Schedule
20-
from .ship_config import ShipConfig
2120
from .simulate_measurements import simulate_measurements
2221
from .simulate_schedule import ScheduleProblem, simulate_schedule
2322

src/virtualship/expedition/simulate_measurements.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
from pathlib import Path
77
from typing import TYPE_CHECKING
88

9-
from ..instruments.adcp import simulate_adcp
10-
from ..instruments.argo_float import simulate_argo_floats
11-
from ..instruments.ctd import simulate_ctd
12-
from ..instruments.ctd_bgc import simulate_ctd_bgc
13-
from ..instruments.drifter import simulate_drifters
14-
from ..instruments.ship_underwater_st import simulate_ship_underwater_st
15-
from ..instruments.xbt import simulate_xbt
16-
from .ship_config import ShipConfig
9+
from virtualship.instruments.adcp import simulate_adcp
10+
from virtualship.instruments.argo_float import simulate_argo_floats
11+
from virtualship.instruments.ctd import simulate_ctd
12+
from virtualship.instruments.ctd_bgc import simulate_ctd_bgc
13+
from virtualship.instruments.drifter import simulate_drifters
14+
from virtualship.instruments.ship_underwater_st import simulate_ship_underwater_st
15+
from virtualship.instruments.xbt import simulate_xbt
16+
from virtualship.models import ShipConfig
17+
1718
from .simulate_schedule import MeasurementsToSimulate
1819

1920
if TYPE_CHECKING:

0 commit comments

Comments
 (0)