Skip to content

Commit

Permalink
Merge pull request #12 from DHI/maintenance/use_pyproject_toml
Browse files Browse the repository at this point in the history
Maintenance/use pyproject toml
  • Loading branch information
ryan-kipawa authored Oct 31, 2024
2 parents aced90d + 8af6f9e commit 7573420
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 78 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/notebooks_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install watobs
Expand Down
13 changes: 4 additions & 9 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,16 @@ jobs:
python-version: [3.8, 3.9, "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1 # Fail fast if there are any linting errors
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install wheel flake8 pytest pytest-cov
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
pip install wheel pytest pytest-cov
- name: Install watobs
run: |
pip install .[test]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/scheduled_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
python-version: [3.9, "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install watobs
Expand Down
10 changes: 6 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
},
"python.testing.pytestArgs": [
"tests"
],
"python.formatting.provider": "black",
"editor.formatOnSave": true,
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true,
}
"notebook.formatOnSave.enabled": true,
}
71 changes: 71 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["watobs"]

[tool.hatch.build.targets.sdist]
exclude = ["notebooks", "tests", "images"]

[project]
name = "watobs"
version = "0.1.1"
dependencies = [
"numpy",
"pandas",
"requests",
"matplotlib",
]

authors = [
{ name="Jesper Sandvig Mariegaard", email="jem@dhigroup.com" },
]
description = "Access water observation data"
readme = "README.md"
requires-python = ">=3.8"
license = "MIT"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Development Status :: 2 - Pre-Alpha",
"Operating System :: OS Independent",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering",
]

[project.optional-dependencies]
dev = [
"pytest",
"ruff",
"sphinx",
"myst-parser",
"sphinx-book-theme",
]

test = [
"pytest",
"pytest-cov",
"mikeio",
]

notebooks = [
"nbformat",
"nbconvert",
"jupyter",
"folium",
"rtree",
"mapclassify",
"geopandas",
"xarray",
"netcdf4",
"NDBC",
]

[tool.ruff]
include = ["pyproject.toml", "watobs/**/*.py"]
# ignore long lines
lint.ignore = ["E501"]

[project.urls]
"Homepage" = "https://github.com/DHI/watobs"
51 changes: 0 additions & 51 deletions setup.py

This file was deleted.

2 changes: 2 additions & 0 deletions watobs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
from .altimetry import DHIAltimetryRepository

__version__ = "0.1.1"

__all__ = ["DMIOceanObsRepository", "DHIAltimetryRepository"]
8 changes: 5 additions & 3 deletions watobs/altimetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def get_altimetry_data(
satellites : str, list of str, optional
Satellites to be downloaded, e.g. '', '3a', 'j3, by default ''
qual_filters : int, list[int], optional
Accepted qualities 0=god, 1=acceptable, 2=bad, e.g. [0, 1],
Accepted qualities 0=god, 1=acceptable, 2=bad, e.g. [0, 1],
by default None meaning no filter (=all data)
Examples
Expand Down Expand Up @@ -565,7 +565,7 @@ def _area_time_sat_payload(
# nan_value : str, optional
# Value to use to indicate bad or missing data, or an empty string to use the default (-9999). Default: ''.
# qual_filters : int, list[int], optional
# Accepted qualities 0=god, 1=acceptable, 2=bad, e.g. [0, 1],
# Accepted qualities 0=god, 1=acceptable, 2=bad, e.g. [0, 1],
# by default None meaning no filter (=all data)
# # numeric : bool, optional
# If True, return columns as numeric and return fewer columns in order to comply with the Met-Ocean on Demand
Expand All @@ -586,7 +586,9 @@ def _create_query_payload(
if nan_value:
d["nodata"] = nan_value
if qual_filters is not None:
qual_filters = qual_filters if hasattr(qual_filters, "__len__") else [qual_filters]
qual_filters = (
qual_filters if hasattr(qual_filters, "__len__") else [qual_filters]
)
if len(qual_filters) > 0:
d["qual_filters"] = str(qual_filters).strip("[] ").replace(" ", "")
if numeric:
Expand Down
10 changes: 3 additions & 7 deletions watobs/dmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class DMIOceanObsRepository:
"""

def __init__(self, api_key: str) -> None:

self.__api__key = api_key
self._stations = None

Expand Down Expand Up @@ -105,15 +104,14 @@ def get_observed_data(
end_time = pd.to_datetime(end_time)

if start_time or end_time:

if start_time and end_time is None:
params["datetime"] = f"{start_time.isoformat()}Z/.."
elif end_time and start_time is None:
params["datetime"] = f"../{end_time.isoformat()}Z"
else:
params[
"datetime"
] = f"{start_time.isoformat()}Z/{end_time.isoformat()}Z"
params["datetime"] = (
f"{start_time.isoformat()}Z/{end_time.isoformat()}Z"
)

resp = requests.get(
"https://dmigw.govcloud.dk/v2/oceanObs/collections/observation/items",
Expand All @@ -136,7 +134,6 @@ def get_observed_data(
next_link = data["links"][1]["href"]

while next_link and (len(ts) < limit):

resp = requests.get(next_link)
data = resp.json()
if data["numberReturned"] == 0:
Expand All @@ -157,7 +154,6 @@ def get_observed_data(
return df

def _data_to_ts(self, data, parameter_id):

ts = [
{
"time": p["properties"]["observed"].replace("Z", ""),
Expand Down

0 comments on commit 7573420

Please sign in to comment.