Skip to content

Commit 61b6724

Browse files
committed
Use hatch to build package
* use `pyproject.toml` for project metadata * version is now defined in `pyproject.toml` * use importlib to get version (py3.8+)
1 parent 6ae1812 commit 61b6724

7 files changed

Lines changed: 122 additions & 104 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
4343
- name: Patch Package Versions
4444
run: |
45-
find . -name _version.py | xargs python ./scripts/patch_version.py ${GITHUB_RUN_NUMBER:-0}
45+
python ./scripts/patch_version.py ${GITHUB_RUN_NUMBER:-0} pyproject.toml
4646
4747
- name: Build Dev Packages
4848
run: |

odc/stac/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""STAC Item -> ODC Dataset[eo3]."""
22

3-
from ._version import __version__ # isort:skip this has to be 1st import
43
from odc.loader._rio import configure_rio, configure_s3_access
54
from odc.loader.types import RasterBandMetadata, RasterLoadParams, RasterSource
65

@@ -33,14 +32,13 @@
3332
"parse_items",
3433
"extract_collection_metadata",
3534
"output_geobox",
36-
"__version__",
3735
)
3836

3937
_eo3_methods = ["stac2ds", "infer_dc_product"]
4038

4139

4240
def __dir__():
43-
return [*__all__, *_eo3_methods]
41+
return [*__all__, *_eo3_methods, "__version__"]
4442

4543

4644
def __getattr__(name):
@@ -49,4 +47,9 @@ def __getattr__(name):
4947
from . import eo3
5048

5149
return getattr(eo3, name)
50+
51+
if name == "__version__":
52+
from importlib.metadata import version
53+
54+
return version(__name__)
5255
raise AttributeError(f"module {__name__} has no attribute {name}")

odc/stac/_version.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

pyproject.toml

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,98 @@
11
[build-system]
2-
requires = ["setuptools>=51.0.0", "wheel"]
3-
build-backend = "setuptools.build_meta"
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "odc-stac"
7+
description = "Tooling for converting STAC metadata to ODC data model"
8+
version = "0.4.0a1"
9+
authors = [
10+
{name = "Open Data Cube"}
11+
]
12+
maintainers = [
13+
{name = "Open Data Cube"}
14+
]
15+
readme = "README.rst"
16+
license = {text = "Apache License 2.0"}
17+
requires-python = ">=3.8"
18+
classifiers = [
19+
"License :: OSI Approved :: Apache Software License",
20+
"Intended Audience :: Developers",
21+
"Operating System :: OS Independent",
22+
"Programming Language :: Python :: 3.8",
23+
"Programming Language :: Python :: 3.9",
24+
"Programming Language :: Python :: 3.10",
25+
"Programming Language :: Python :: 3.11",
26+
"Programming Language :: Python :: 3.12",
27+
"Topic :: Software Development :: Libraries :: Python Modules",
28+
"Topic :: Scientific/Engineering :: GIS",
29+
"Typing :: Typed"
30+
]
31+
dependencies = [
32+
"affine",
33+
"odc-geo>=0.4.7",
34+
"odc-loader>=0.5.0",
35+
"rasterio>=1.0.0,!=1.3.0,!=1.3.1",
36+
"dask[array]",
37+
"numpy>=1.20.0",
38+
"pandas",
39+
"pystac>=1.0.0,<2",
40+
"toolz",
41+
"xarray>=0.19"
42+
]
43+
44+
[project.optional-dependencies]
45+
botocore = ["botocore"]
46+
docs = [
47+
"sphinx",
48+
"sphinx_rtd_theme",
49+
"nbsphinx",
50+
"sphinx-autodoc-typehints",
51+
"matplotlib-inline",
52+
"pandas",
53+
"distributed",
54+
"datacube>=1.8.8",
55+
"ipython",
56+
"ipykernel"
57+
]
58+
test = [
59+
"pytest",
60+
"pytest-cov",
61+
"pytest-timeout",
62+
"pystac_client",
63+
"distributed",
64+
"geopandas"
65+
]
66+
test-all = [
67+
"pytest",
68+
"pytest-cov",
69+
"pytest-timeout",
70+
"pystac_client",
71+
"distributed",
72+
"geopandas",
73+
"datacube",
74+
"stackstac"
75+
]
76+
77+
[project.urls]
78+
Documentation = "https://odc-stac.readthedocs.io/en/latest/"
79+
"Bug Reporting" = "https://github.com/opendatacube/odc-stac/issues"
80+
Homepage = "https://github.com/opendatacube/odc-stac/"
81+
82+
83+
[tool.hatch.build.targets.wheel]
84+
packages = ["odc"]
85+
86+
[tool.hatch.build.targets.sdist]
87+
include = [
88+
"/odc",
89+
"/README.rst",
90+
"/tests",
91+
"/scripts",
92+
"/docs",
93+
"/notebooks",
94+
"/binder"
95+
]
496

597
[tool.mypy]
698
python_version = "3.10"
@@ -18,10 +110,8 @@ omit = [
18110
profile = "black"
19111

20112
[tool.pylint.messages_control]
21-
22113
max-line-length = 120
23114
max-args = 15
24-
25115
disable = [
26116
"missing-function-docstring",
27117
"invalid-name",

scripts/patch_version.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
"""
2+
Patch version in pyproject.toml
3+
"""
4+
15
import re
26
import sys
37

48
from packaging import version
59

6-
version_rgx = re.compile("^\\s*__version__\\s*=\\s*['\"]([^'\"]*)['\"]")
10+
version_rgx = re.compile("^\\s*version\\s*=\\s*['\"]([^'\"]*)['\"]")
711

812

913
def match_version(line):
@@ -30,18 +34,21 @@ def patch_version_lines(lines, build_number):
3034

3135

3236
def patch_file(fname, build_number):
33-
with open(fname) as src:
37+
with open(fname, encoding="utf-8") as src:
3438
lines = list(patch_version_lines(src, build_number))
35-
with open(fname, "wt") as dst:
39+
with open(fname, "wt", encoding="utf-8") as dst:
3640
dst.writelines(lines)
3741

3842

39-
if __name__ == "__main__":
40-
args = sys.argv[1:]
43+
def main(args):
4144
if len(args) < 2:
4245
print(f"Usage: {sys.argv[0]} build-number [FILE]...")
4346

4447
build_number, *files = args
4548
build_number = int(build_number)
4649
for f in files:
4750
patch_file(f, build_number)
51+
52+
53+
if __name__ == "__main__":
54+
main(sys.argv[1:])

setup.cfg

Lines changed: 0 additions & 87 deletions
This file was deleted.

tests/test_model.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# pylint: disable=redefined-outer-name,missing-module-docstring,missing-function-docstring
2+
# pylint: disable=import-outside-toplevel
23
import datetime as dt
34

45
import pytest
56
from dask.base import tokenize
67
from odc.geo.geobox import GeoBox
7-
88
from odc.loader.types import (
99
RasterBandMetadata,
1010
RasterGroupMetadata,
1111
RasterLoadParams,
1212
RasterSource,
1313
norm_key,
1414
)
15+
1516
from odc.stac import ParsedItem, RasterCollectionMetadata
1617
from odc.stac.testing.stac import b_, mk_parsed_item
1718

@@ -221,3 +222,10 @@ def test_tokenize(parsed_item_ab: ParsedItem):
221222
)
222223
def test_normkey(name, expected):
223224
assert norm_key(name) == expected
225+
226+
227+
def test_version():
228+
from odc.stac import __version__
229+
230+
assert __version__ is not None
231+
assert len(__version__.split(".")) == 3

0 commit comments

Comments
 (0)