Skip to content

Commit fcd19d2

Browse files
authored
HDXDSYS-2684 Reimplement munge_url from libhxl in HDX Python API (#106)
* Add munge_url from libhxl as follow_url and remove libhxl dependency * Upgrade to uv
1 parent 238c651 commit fcd19d2

29 files changed

+2793
-458
lines changed

.coveragerc

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

.github/workflows/publish.yaml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,22 @@ jobs:
1313
url: https://pypi.org/p/hdx-python-api
1414

1515
permissions:
16-
id-token: write # IMPORTANT: mandatory for trusted publishing
16+
id-token: write
17+
contents: read
1718

1819
steps:
1920
- uses: actions/checkout@v6
21+
2022
- name: Get history and tags for versioning to work
2123
run: |
2224
git fetch --prune --unshallow
2325
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
24-
- name: Set up Python
25-
uses: actions/setup-python@v6
26-
with:
27-
python-version: '3.x'
28-
- name: Install dependencies
29-
run: |
30-
python -m pip install --upgrade pip
31-
- name: Install Hatch
32-
uses: pypa/hatch@install
33-
- name: Build with hatch
34-
run: |
35-
hatch build
26+
27+
- name: Install uv
28+
uses: astral-sh/setup-uv@v7
29+
30+
- name: Build with uv
31+
run: uv build
32+
3633
- name: Publish distribution 📦 to PyPI
37-
uses: pypa/gh-action-pypi-publish@release/v1
34+
run: uv publish
Lines changed: 38 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,52 @@
1-
# This workflow will install Python dependencies, lint and run tests
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3-
41
name: Run tests
52

63
on:
7-
workflow_dispatch: # add run button in github
4+
workflow_dispatch:
85
push:
9-
branches-ignore:
10-
- gh-pages
11-
- 'dependabot/**'
6+
branches-ignore: [gh-pages, "dependabot/**"]
127
pull_request:
13-
branches-ignore:
14-
- gh-pages
15-
16-
concurrency:
17-
group: ${{ github.head_ref || github.ref_name }}
18-
8+
branches-ignore: [gh-pages]
199

2010
jobs:
2111
build:
2212
runs-on: ubuntu-latest
23-
2413
permissions:
14+
contents: read
2515
checks: write
2616
pull-requests: write
2717

2818
steps:
29-
- uses: actions/checkout@v6
30-
- name: Set up Python
31-
uses: actions/setup-python@v6
32-
with:
33-
python-version: '3.x'
34-
- name: Install dependencies
35-
run: |
36-
python -m pip install --upgrade pip
37-
- name: Install Hatch
38-
uses: pypa/hatch@install
39-
- name: Test with hatch/pytest
40-
env:
41-
HDX_KEY_TEST: ${{ secrets.HDX_BOT_SCRAPERS_API_TOKEN }}
42-
GSHEET_AUTH: ${{ secrets.HDX_PIPELINE_GSHEET_AUTH }}
43-
run: |
44-
hatch test
45-
- name: Check styling
46-
if: always()
47-
run: |
48-
hatch fmt --check
49-
- name: Publish Unit Test Results
50-
uses: EnricoMi/publish-unit-test-result-action@v2
51-
if: always()
52-
with:
53-
github_token: ${{ secrets.GITHUB_TOKEN }}
54-
junit_files: test-results.xml
55-
- name: Publish in Coveralls
56-
uses: coverallsapp/github-action@v2
57-
with:
58-
github-token: ${{ secrets.GITHUB_TOKEN }}
59-
flag-name: tests
60-
format: lcov
19+
- uses: actions/checkout@v6
20+
21+
- name: Install uv
22+
uses: astral-sh/setup-uv@v7
23+
with:
24+
enable-cache: true
25+
python-version: "3.13"
26+
27+
- name: Install dependencies
28+
run: uv sync --frozen
29+
30+
- name: Check styling
31+
run: |
32+
uv run ruff format --check
33+
uv run ruff check
34+
35+
- name: Test with pytest
36+
env:
37+
HDX_KEY_TEST: ${{ secrets.HDX_BOT_SCRAPERS_API_TOKEN }}
38+
GSHEET_AUTH: ${{ secrets.HDX_PIPELINE_GSHEET_AUTH }}
39+
run: uv run pytest
40+
41+
- name: Publish Unit Test Results
42+
uses: EnricoMi/publish-unit-test-result-action@v2
43+
if: always()
44+
with:
45+
files: test-results.xml
46+
47+
- name: Publish in Coveralls
48+
uses: coverallsapp/github-action@v2
49+
if: always()
50+
with:
51+
flag-name: tests
52+
format: lcov

.pre-commit-config.yaml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
default_language_version:
2-
python: python3.13
2+
python: python3.13
3+
34
repos:
45
- repo: https://github.com/pre-commit/pre-commit-hooks
56
rev: v6.0.0
67
hooks:
78
- id: trailing-whitespace
9+
exclude: (test_loader.py|pretty-false_sortkeys-false.yaml|pretty-false_sortkeys-true.yaml)
810
- id: end-of-file-fixer
11+
exclude: (test_csv_processing_blanks.csv|test.txt)
912
- id: check-ast
13+
1014
- repo: https://github.com/astral-sh/ruff-pre-commit
11-
rev: v0.14.10
15+
rev: v0.14.13
1216
hooks:
1317
# Run the linter.
1418
- id: ruff-check
1519
args: [ --fix ]
1620
# Run the formatter.
1721
- id: ruff-format
22+
1823
- repo: https://github.com/astral-sh/uv-pre-commit
19-
rev: 0.9.22
24+
rev: 0.9.25
2025
hooks:
21-
# Run the pip compile
22-
- id: pip-compile
23-
name: pip-compile requirements.txt
24-
files: pyproject.toml
25-
args: [ pyproject.toml, --resolver=backtracking, --upgrade, -q,
26-
-o, requirements.txt ]
26+
# Ensure the lockfile is up-to-date with pyproject.toml
27+
- id: uv-lock

CONTRIBUTING.md

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,73 @@
22

33
## Environment
44

5-
Development is currently done using Python 3.11. We recommend using a virtual
6-
environment such as ``venv``:
5+
Development is currently done using Python 3.13. The environment can be created with:
76

8-
python3.11 -m venv venv
9-
source venv/bin/activate
7+
```shell
8+
uv sync
9+
```
1010

11-
In your virtual environment, please install all packages for
12-
development by running:
11+
This creates a .venv folder with the versions specified in the project's uv.lock file.
1312

14-
pip install -r requirements.txt
13+
### Pre-commit
1514

16-
## Pre-Commit
17-
18-
Also be sure to install `pre-commit`, which is run every time
19-
you make a git commit:
15+
pre-commit will be installed when syncing uv. It is run every time you make a git
16+
commit if you call it like this:
2017

18+
```shell
2119
pre-commit install
22-
23-
The configuration file for this project is in a
24-
non-standard location. Thus, you will need to edit your
25-
`.git/hooks/pre-commit` file to reflect this. Change
26-
the line that begins with `ARGS` to:
27-
28-
ARGS=(hook-impl --config=.config/pre-commit-config.yaml --hook-type=pre-commit)
20+
```
2921

3022
With pre-commit, all code is formatted according to
31-
[ruff](https://github.com/astral-sh/ruff) guidelines.
23+
[ruff](https://docs.astral.sh/ruff/) guidelines.
3224

3325
To check if your changes pass pre-commit without committing, run:
3426

35-
pre-commit run --all-files --config=.config/pre-commit-config.yaml
27+
```shell
28+
pre-commit run --all-files
29+
```
3630

37-
## Environment Variables
31+
## Packages
3832

39-
For the `test_ckan.py` tests to run successfully some configuration is required:
33+
[uv](https://github.com/astral-sh/uv) is used for package management. If
34+
you’ve introduced a new package to the source code (i.e. anywhere in `src/`),
35+
please add it to the `project.dependencies` section of `pyproject.toml` with
36+
any known version constraints.
4037

41-
1. The environment variable `HDX_KEY_TEST` needs to contain a valid key from the HDX demo server at
42-
https://demo.data-humdata-org.ahconu.org/
43-
2. Authentication details for Google Sheets need to be obtained from Mike Rans and either saved in a file named `.gsheet_auth.json` in the home directory (~) or placed in an environment variable `GSHEET_AUTH`. The file is preferred for Windows systems since adding such a long text string to an environment variable in Windows is challenging.
38+
To add packages required only for testing, add them to the
39+
`[dependency-groups]`.
4440

45-
## Testing
41+
Any changes to the dependencies will be automatically reflected in
42+
`uv.lock` with `pre-commit`, but you can re-generate the files without committing by
43+
executing:
4644

47-
To run the tests and view coverage, execute:
45+
```shell
46+
uv lock --upgrade
47+
```
4848

49-
pytest -c .config/pytest.ini --cov hdx --cov-config .config/coveragerc
49+
## Project
5050

51-
Follow the example set out already in ``documentation/main.md`` as you write the documentation.
51+
[uv](https://github.com/astral-sh/uv) is used for project management. The project can be
52+
built using:
5253

53-
## Packages
54+
```shell
55+
uv build
56+
```
5457

55-
[pip-tools](https://github.com/jazzband/pip-tools) is used for
56-
package management. If you’ve introduced a new package to the
57-
source code (i.e.anywhere in `src/`), please add it to the
58-
`project.dependencies` section of
59-
`pyproject.toml` with any known version constraints.
58+
Linting and syntax checking can be run with:
6059

61-
For adding packages for testing or development, add them to
62-
the `test` or `dev` sections under `[project.optional-dependencies]`.
60+
```shell
61+
uv run ruff check
62+
```
6363

64-
Any changes to the dependencies will be automatically reflected in
65-
`requirements.txt` with `pre-commit`, but you can re-generate
66-
the file without committing by executing:
64+
To run the tests and view coverage, execute:
65+
66+
```shell
67+
uv run pytest
68+
```
69+
70+
## Documentation
6771

68-
pre-commit run pip-compile --all-files --config=.config/pre-commit-config.yaml
72+
The documentation, including API documentation, is generated using ReadtheDocs and
73+
MkDocs with Material. As you change the source code, remember to update the
74+
documentation at `documentation/index.md`.

hatch.toml

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

0 commit comments

Comments
 (0)