Skip to content

Commit

Permalink
Merge pull request #9 from Vizzuality/update-package
Browse files Browse the repository at this point in the history
Update project tooling and structure
  • Loading branch information
BielStela authored Apr 30, 2024
2 parents 4e97ff0 + bd169c7 commit 92ea36c
Show file tree
Hide file tree
Showing 16 changed files with 190 additions and 175 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ dist
__pycache__
.pytest_cache
.mypy_cache
.ruff_cache
.venv
.tox
dask-worker-space
*.egg-info
Expand All @@ -19,4 +21,4 @@ output.tif.msk
.DS_Store

*#
*~
*~
35 changes: 17 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
exclude: 'docs|test|setup.py'
repos:
- repo: https://github.com/psf/black
rev: 21.7b0
exclude: "docs"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: black
language_version: python
- id: check-yaml
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
language_version: python

- repo: https://github.com/PyCQA/pydocstyle
rev: 6.1.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.2
hooks:
- id: pydocstyle
language_version: python
- id: ruff
args: [ --fix ]
types_or: [ python, pyi, jupyter ]

- id: ruff-format
types_or: [ python, pyi, jupyter ]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.910'
rev: v1.10.0
hooks:
- id: mypy
language_version: python
File renamed without changes.
Binary file removed cog_worker/__init__.pyc
Binary file not shown.
96 changes: 96 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "cog_worker"
description = "Scalable geospatial analysis on Cloud Optimized GeoTIFFs."
readme = "README.md"
requires-python = ">=3.9"
license = { file = "LICENSE.txt" }
authors = [
{ name = "Francis Gassert", email = "[email protected]" },
]
keywords = ["cog", "geotiff", "raster", "gdal", "rasterio", "dask"]
classifiers = [
"Intended Audience :: Information Technology",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering :: GIS",
]
dynamic = ["version"]
dependencies = [
"numpy>=1,<2",
"pyproj>=3.0.0,<4",
"rasterio>=1.3,<2",
"morecantile>=4.3.0,<5",
"rio_tiler>=5.0.0,<6",
]

[project.urls]
Homepage = "https://github.com/vizzuality/cog_worker"
Issues = "https://github.com/vizzuality/cog_worker/issues"

[project.optional-dependencies]
test = ["pytest"]
dev = ["pre-commit"]
distributed = ["dask[distributed]"]
docs = ["Sphinx", "sphinxcontrib-napoleon", "furo", "nbsphinx", "nbconvert"]

[tool.ruff]
line-length = 120
extend-include = ["*.ipynb"]
src = ["src"]

[tool.ruff.lint]
select = [
"D1", # pydocstyle errors
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # flake8
"C", # flake8-comprehensions
"B", # flake8-bugbear
"N", # Naming conventions
"I", # isort
]
pydocstyle.convention = "google"
pydocstyle.ignore-decorators = ["property"]

[tool.ruff.lint.per-file-ignores]
"**/{tests}/*" = [
"D103", # Missing docstring in public function
"D100", # Missing docstring in public module
]

[tool.bumpversion]
current_version = "0.2.0"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{minor}.{patch}"]
search = "{current_version}"
replace = "{new_version}"
regex = false
ignore_missing_version = false
ignore_missing_files = false
tag = true
sign_tags = false
tag_name = "v{new_version}"
tag_message = "Bump version: {current_version} → {new_version}"
allow_dirty = false
commit = true
message = "Bump version: {current_version} → {new_version}"
commit_args = ""

[[tool.bumpversion.files]]
filename = "src/cog_worker/__init__.py"

[[tool.bumpversion.files]]
filename = "sphinx_docs/source/conf.py"

[[tool.bumpversion.files]]
filename = "pyproject.toml"
23 changes: 0 additions & 23 deletions setup.cfg

This file was deleted.

38 changes: 0 additions & 38 deletions setup.py

This file was deleted.

File renamed without changes.
24 changes: 11 additions & 13 deletions cog_worker/distributed.py → src/cog_worker/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ def my_analysis(worker):
results = manager.chunk_execute(my_analysis)
total = sum(results)
"""
from typing import Iterable, Iterator, Mapping, Union, Tuple, Any

import logging
from typing import Any, Iterable, Iterator, Mapping, Tuple, Union

import dask
import dask.distributed
from dask.delayed import Delayed
from pyproj import Proj

import cog_worker
from cog_worker.types import WorkerFunction, BoundingBox

from cog_worker.types import BoundingBox, WorkerFunction

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -79,11 +79,11 @@ def __init__(
def execute(
self,
f: WorkerFunction,
f_args: Iterable = None,
f_kwargs: Mapping = None,
f_args: Union[Iterable, None] = None,
f_kwargs: Union[Mapping, None] = None,
clip: bool = True,
compute: bool = True,
**kwargs
**kwargs,
) -> Union[Tuple[Any, BoundingBox], Delayed]:
"""Execute a cog_worker function in the DaskManager's cluster.
Expand Down Expand Up @@ -134,11 +134,11 @@ def execute(
def chunk_execute(
self,
f: WorkerFunction,
f_args: Iterable = None,
f_kwargs: Mapping = None,
f_args: Union[Iterable, None] = None,
f_kwargs: Union[Mapping, None] = None,
chunksize: int = 512,
compute: bool = True,
) -> Union[Iterator[Tuple[Any, BoundingBox]], Iterator[Delayed]]:
) -> Union[Iterator[Tuple[Any, BoundingBox]], Iterator[Delayed]]: # type: ignore
"""Compute chunks in parallel in the DaskManager's cluster.
Chunks will be yielded as they are completed. The order in which they
Expand Down Expand Up @@ -169,10 +169,8 @@ def chunk_execute(
]
if compute:
futures = self.client.compute(tasks)
for future, result in dask.distributed.as_completed(
futures, with_results=True
):
for future, result in dask.distributed.as_completed(futures, with_results=True):
future.release()
yield result
else:
return tasks
return tasks # type: ignore
Loading

0 comments on commit 92ea36c

Please sign in to comment.