Skip to content

Commit e7dd8e3

Browse files
authored
Upgrade packaging process for V2 beta release (#215)
Packaging with pyproject.toml and Hatch - Add pyproject.toml. Set Python ≥3.10. - Introduce Hatch for packaging and dependency management. - Update cloudbuild.yaml and run_test.sh to align with Hatch.
1 parent 56173fc commit e7dd8e3

File tree

12 files changed

+253
-34
lines changed

12 files changed

+253
-34
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 2.0.0 [forthcoming]
4+
5+
36
## 1.4.3
47

58
**Date** - 11/10/2020

cloudbuild.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
steps:
22
- id: api_python
33
name: python:3.10-slim
4-
entrypoint: /bin/sh
4+
entrypoint: /bin/bash
55
args:
66
- -c
7-
- "./run_test.sh -s -a"
7+
- "./run_test.sh -s && hatch run test:all"

datacommons_client/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Data Commons Python API
2+
3+
This is a Python library for accessing data in the Data Commons Graph.
4+
5+
To get started, install this package from pip.
6+
7+
```bash
8+
pip install datacommons-client
9+
```
10+
11+
To get additional functionality to work with Pandas DataFrames, install the package
12+
with the optional Pandas dependency.
13+
14+
```bash
15+
pip install "datacommons-client[Pandas]"
16+
```
17+
18+
Once the package is installed, import `datacommons_client`.
19+
20+
```python
21+
import datacommons_client as dc
22+
```
23+
24+
For more detail on getting started with the API, please visit our
25+
[API Overview](https://docs.datacommons.org/api/).
26+
27+
When you are ready to use the API, you can refer to `examples` for
28+
examples on how to use this package to perform various tasks. More tutorials and
29+
documentation can be found on our [tutorials page](https://docs.datacommons.org/tutorials/)!
30+
31+
## About Data Commons
32+
33+
[Data Commons](https://datacommons.org/) is an open knowledge repository that
34+
provides a unified view across multiple public data sets and statistics. You can
35+
view what [datasets](https://datacommons.org/datasets) are currently ingested
36+
and browse the graph using our [browser](https://datacommons.org/browser).
37+
38+
## License
39+
40+
Apache 2.0
41+
42+
## Support
43+
44+
For general questions or issues about the API, please open an issue on our
45+
[issues](https://github.com/google/datacommons/issues) page. For all other
46+
questions, please send an email to `[email protected]`.

datacommons_client/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
__version__ = "2.0.0b1"
2+
"""
3+
Data Commons Client Package
4+
5+
This package provides a Python client for interacting with the Data Commons API.
6+
"""
7+
8+
from datacommons_client.client import DataCommonsClient
9+
from datacommons_client.endpoints.base import API
10+
from datacommons_client.endpoints.node import NodeEndpoint
11+
from datacommons_client.endpoints.observation import ObservationEndpoint
12+
from datacommons_client.endpoints.resolve import ResolveEndpoint
13+
14+
__all__ = [
15+
"DataCommonsClient",
16+
"API",
17+
"NodeEndpoint",
18+
"ObservationEndpoint",
19+
"ResolveEndpoint",
20+
]

datacommons_client/endpoints/node.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from datacommons_client.endpoints.base import API
44
from datacommons_client.endpoints.base import Endpoint
55
from datacommons_client.endpoints.payloads import NodeRequestPayload
6-
from datacommons_client.endpoints.payloads import \
7-
normalize_properties_to_string
6+
from datacommons_client.endpoints.payloads import normalize_properties_to_string
87
from datacommons_client.endpoints.response import NodeResponse
98

109

datacommons_client/endpoints/payloads.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
from enum import Enum
66
from typing import Optional
77

8-
from datacommons_client.utils.error_handling import \
9-
InvalidObservationSelectError
8+
from datacommons_client.utils.error_handling import InvalidObservationSelectError
109

1110

1211
def normalize_properties_to_string(properties: str | list[str]) -> str:

datacommons_client/tests/endpoints/test_payloads.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
from datacommons_client.endpoints.payloads import ObservationRequestPayload
66
from datacommons_client.endpoints.payloads import ObservationSelect
77
from datacommons_client.endpoints.payloads import ResolveRequestPayload
8-
from datacommons_client.utils.error_handling import \
9-
InvalidObservationSelectError
8+
from datacommons_client.utils.error_handling import InvalidObservationSelectError
109

1110

1211
def test_node_payload_normalize():

datacommons_client/tests/endpoints/test_resolve_endpoint.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from unittest.mock import MagicMock
22

33
from datacommons_client.endpoints.base import API
4-
from datacommons_client.endpoints.resolve import \
5-
_resolve_correspondence_expression
4+
from datacommons_client.endpoints.resolve import _resolve_correspondence_expression
65
from datacommons_client.endpoints.resolve import flatten_resolve_response
76
from datacommons_client.endpoints.resolve import ResolveEndpoint
87
from datacommons_client.endpoints.response import ResolveResponse

docs/development.md

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,55 @@
11
# Python API Development
22

3-
The Python API currently supports `python>=3.7`.
3+
This client library supports `python>=3.10`.
44

5-
To set up the Python environment for tests, run:
5+
## Set up
6+
If you haven't already, clone this repository.
7+
8+
```bash
9+
git clone https://github.com/datacommonsorg/api-python.git
10+
cd api-python
11+
```
12+
13+
To set up the Python environment for development, run:
614

715
```bash
816
./run_test.sh -s
917
```
1018

11-
To test, run:
19+
This will install `hatch`, which is the main tool used to manage the
20+
environment, dependencies, and development tools. You can also manually install
21+
`hatch` and create a virtual environment.
1222

1323
```bash
14-
./run_test.sh -a
24+
pip install hatch
25+
hatch env create
1526
```
1627

17-
To format, run:
28+
## Code style and linting
29+
We use `isort` and `yapf` for code formatting. Check formatting with:
1830

1931
```bash
20-
./run_test.sh -f
32+
hatch run lint:check
2133
```
2234

23-
To debug the continuous integration tests, run:
35+
To automatically fix formatting run:
2436

2537
```bash
26-
gcloud builds submit . --project=datcom-ci --config=cloudbuild.yaml
38+
hatch run lint:format
2739
```
2840

29-
Both commands will run the same set of tests.
41+
## Running tests
3042

31-
To run the examples:
43+
To test, run:
3244

3345
```bash
34-
python -m datacommons.examples.XXX
46+
hatch run test:all
47+
```
48+
49+
To debug the continuous integration tests, run:
50+
51+
```bash
52+
gcloud builds submit . --project=datcom-ci --config=cloudbuild.yaml
3553
```
3654

37-
where XXX is the module you want to run.
55+
Both commands will run the same set of tests.

docs/release.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
11
# Python API Release
22

3+
## Releasing the `datacommons_client` package
4+
Support for V2 of the Data Commons API is being released as a new client library
5+
called `datacommons_client`.
6+
7+
To release:
8+
1. Update [CHANGELOG.md](../CHANGELOG.md) with relevant changes.
9+
2. Bump the version by running `hatch version` followed by `patch`, `minor`, `major`, a
10+
specific version number, or `--pre beta` for a beta version, for example.
11+
3. Build the package
12+
```bash
13+
hatch build
14+
```
15+
4. (optionally) Test the deployment process locally
16+
```bash
17+
hatch run release:localtest
18+
```
19+
5. Test the deployment process on Test PyPi
20+
```bash
21+
hatch run release:testpypi
22+
```
23+
24+
6. Once verified, upload to PyPI:
25+
```bash
26+
hatch run release:pypi
27+
```
28+
29+
7. Create a version tag on Git:
30+
```bash
31+
hatch run release:tag
32+
```
33+
34+
---
35+
36+
## Releasing the legacy packages
37+
38+
339
Note: Always release `datacommons_pandas` when `datacommons` is released.
440

541
**If this is your first time releasing to PyPI**, please review the PyPI guide

0 commit comments

Comments
 (0)