Skip to content

Commit

Permalink
Merge pull request #5 from eodash/generate-single-item-fallback
Browse files Browse the repository at this point in the history
Generate single item fallback
  • Loading branch information
lubojr authored Jun 27, 2024
2 parents d7b8de1 + 592d2e8 commit 39a1685
Show file tree
Hide file tree
Showing 16 changed files with 1,465 additions and 1,338 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Python package

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.12"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
# You can test your matrix by printing the current Python version
- name: Install dependencies
run: python -m pip install -r requirements.txt
- name: Lint
run: python -m ruff check --no-cache .
- name: Test
run: python -m pytest -p no:cacheprovider
170 changes: 162 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,167 @@
.eggs
*.egg-info
*.pyc
.cache
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
.pytest*
*.gfs
__pycache__
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
catalogs/
collections/
layers/

.venv
.pytest
6 changes: 0 additions & 6 deletions .pre-commit-config.yaml

This file was deleted.

8 changes: 6 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"editor.formatOnSave": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
"editor.formatOnSave": true,
},
"editor.defaultFormatter": "charliermarsh.ruff",
}
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@
pip install eodash_catalog
```

## Testing

Project uses pytest and runs it as part of CI:

```bash
python -m pytest
```

## Testing

Project uses ruff to perform checks on code style and formatting
```bash
ruff check .
```


## Building and publishing

To build and publish we use hatch, first bump the version in `src/eodash_catalog/__about__.py` then run
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,6 @@ tests = ["tests", "*/eodash_catalog/tests"]

[tool.coverage.report]
exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"]

[tool.mypy]
disable_error_code = ["import-untyped"]
7 changes: 6 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ python-dateutil<3
swiftspec==0.0.2
mergedeep
structlog<22.0
OWSLib
OWSLib<1.0
spdx-lookup<=0.3.3
pystac[validation]<=1.8.3

# dev tooling
pytest==8.1.1
pytest-watch==4.2.0
ruff==0.4.2
8 changes: 8 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
exclude = ["venv"]

line-length = 100
target-version = "py312"

[lint]
select = ["E", "F", "UP", "B", "SIM", "I", "W", "C90", "ASYNC", "A", "C4", "PERF", "RUF"]
ignore = ["B019", "C901"]
25 changes: 7 additions & 18 deletions src/eodash_catalog/duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
The class Duration allows to define durations in years and months and can be
used as limited replacement for timedelta objects.
"""

from datetime import timedelta
from decimal import Decimal, ROUND_FLOOR
from decimal import ROUND_FLOOR, Decimal


def fquotmod(val, low, high):
Expand Down Expand Up @@ -82,9 +83,7 @@ def __init__(
years = Decimal(str(years))
self.months = months
self.years = years
self.tdelta = timedelta(
days, seconds, microseconds, milliseconds, minutes, hours, weeks
)
self.tdelta = timedelta(days, seconds, microseconds, milliseconds, minutes, hours, weeks)

def __getstate__(self):
return self.__dict__
Expand Down Expand Up @@ -167,13 +166,8 @@ def __add__(self, other):
carry, newmonth = fquotmod(newmonth, 1, 13)
newyear = other.year + self.years + carry
maxdays = max_days_in_month(newyear, newmonth)
if other.day > maxdays:
newday = maxdays
else:
newday = other.day
newdt = other.replace(
year=int(newyear), month=int(newmonth), day=int(newday)
)
newday = maxdays if other.day > maxdays else other.day
newdt = other.replace(year=int(newyear), month=int(newmonth), day=int(newday))
# does a timedelta + date/datetime
return self.tdelta + newdt
except AttributeError:
Expand Down Expand Up @@ -252,13 +246,8 @@ def __rsub__(self, other):
carry, newmonth = fquotmod(newmonth, 1, 13)
newyear = other.year - self.years + carry
maxdays = max_days_in_month(newyear, newmonth)
if other.day > maxdays:
newday = maxdays
else:
newday = other.day
newdt = other.replace(
year=int(newyear), month=int(newmonth), day=int(newday)
)
newday = maxdays if other.day > maxdays else other.day
newdt = other.replace(year=int(newyear), month=int(newmonth), day=int(newday))
return newdt - self.tdelta
except AttributeError:
# other probably was not compatible with data/datetime
Expand Down
Loading

0 comments on commit 39a1685

Please sign in to comment.