Skip to content

Commit 1b0b39b

Browse files
dolfim-ibmceberamvagenas
authored
refactor: use uv as dependencies management and packaging (#307)
* use new pyproject.toml format with uv Signed-off-by: Michele Dolfi <[email protected]> * update ci/cd scripts Signed-off-by: Michele Dolfi <[email protected]> * update MD files Signed-off-by: Michele Dolfi <[email protected]> * build without pre-commit cache Signed-off-by: Michele Dolfi <[email protected]> * run pre-commit from uv Signed-off-by: Michele Dolfi <[email protected]> * small changes Signed-off-by: Michele Dolfi <[email protected]> * add uv package install Signed-off-by: Michele Dolfi <[email protected]> * Apply suggestions from code review Co-authored-by: Cesar Berrospi Ramis <[email protected]> Signed-off-by: Michele Dolfi <[email protected]> * docs: update README Signed-off-by: Panos Vagenas <[email protected]> --------- Signed-off-by: Michele Dolfi <[email protected]> Signed-off-by: Michele Dolfi <[email protected]> Signed-off-by: Panos Vagenas <[email protected]> Co-authored-by: Cesar Berrospi Ramis <[email protected]> Co-authored-by: Panos Vagenas <[email protected]>
1 parent a523107 commit 1b0b39b

File tree

12 files changed

+3065
-3749
lines changed

12 files changed

+3065
-3749
lines changed

.github/actions/setup-poetry/action.yml

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

.github/scripts/release.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ fi
1010
CHGLOG_FILE="${CHGLOG_FILE:-CHANGELOG.md}"
1111

1212
# update package version
13-
poetry version "${TARGET_VERSION}"
13+
uvx --from=toml-cli toml set --toml-path=pyproject.toml project.version "${TARGET_VERSION}"
14+
uv lock --upgrade-package docling-core
1415

1516
# collect release notes
1617
REL_NOTES=$(mktemp)
17-
poetry run semantic-release changelog --unreleased >> "${REL_NOTES}"
18+
uv run --no-sync semantic-release changelog --unreleased >> "${REL_NOTES}"
1819

1920
# update changelog
2021
TMP_CHGLOG=$(mktemp)
@@ -30,7 +31,7 @@ mv "${TMP_CHGLOG}" "${CHGLOG_FILE}"
3031
# push changes
3132
git config --global user.name 'github-actions[bot]'
3233
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
33-
git add pyproject.toml "${CHGLOG_FILE}"
34+
git add pyproject.toml uv.lock "${CHGLOG_FILE}"
3435
COMMIT_MSG="chore: bump version to ${TARGET_VERSION} [skip ci]"
3536
git commit -m "${COMMIT_MSG}"
3637
git push origin main

.github/workflows/cd.yml

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,6 @@ env:
88
PYTHON_KEYRING_BACKEND: keyring.backends.null.Keyring
99

1010
jobs:
11-
# To be enabled when we add docs
12-
# docs:
13-
# permissions:
14-
# contents: write
15-
# runs-on: ubuntu-latest
16-
# steps:
17-
# - uses: actions/checkout@v3
18-
# - uses: ./.github/actions/setup-poetry
19-
# - name: Build and push docs
20-
# run: poetry run mkdocs gh-deploy --force
21-
2211
code-checks:
2312
uses: ./.github/workflows/checks.yml
2413
with:
@@ -28,18 +17,23 @@ jobs:
2817
outputs:
2918
TARGET_TAG_V: ${{ steps.version_check.outputs.TRGT_VERSION }}
3019
steps:
31-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
3221
with:
3322
fetch-depth: 0 # for fetching tags, required for semantic-release
34-
- uses: ./.github/actions/setup-poetry
23+
- name: Install uv and set the python version
24+
uses: astral-sh/setup-uv@v5
25+
with:
26+
enable-cache: true
27+
- name: Install dependencies
28+
run: uv sync --only-dev
3529
- name: Check version of potential release
3630
id: version_check
3731
run: |
38-
TRGT_VERSION=$(poetry run semantic-release print-version)
39-
echo "TRGT_VERSION=${TRGT_VERSION}" >> $GITHUB_OUTPUT
40-
echo "${TRGT_VERSION}"
32+
TRGT_VERSION=$(uv run --no-sync semantic-release print-version)
33+
echo "TRGT_VERSION=${TRGT_VERSION}" >> "$GITHUB_OUTPUT"
34+
echo "${TRGT_VERSION}"
4135
- name: Check notes of potential release
42-
run: poetry run semantic-release changelog --unreleased
36+
run: uv run --no-sync semantic-release changelog --unreleased
4337
release:
4438
needs: [code-checks, pre-release-check]
4539
if: needs.pre-release-check.outputs.TARGET_TAG_V != ''
@@ -56,7 +50,12 @@ jobs:
5650
with:
5751
token: ${{ steps.app-token.outputs.token }}
5852
fetch-depth: 0 # for fetching tags, required for semantic-release
59-
- uses: ./.github/actions/setup-poetry
53+
- name: Install uv and set the python version
54+
uses: astral-sh/setup-uv@v5
55+
with:
56+
enable-cache: true
57+
- name: Install dependencies
58+
run: uv sync --only-dev
6059
- name: Run release script
6160
env:
6261
GH_TOKEN: ${{ steps.app-token.outputs.token }}

.github/workflows/checks.yml

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,73 @@ jobs:
2626
with:
2727
path: ~/.cache/huggingface
2828
key: huggingface-cache-py${{ matrix.python-version }}
29-
- uses: ./.github/actions/setup-poetry
29+
- name: Install uv and set the python version
30+
uses: astral-sh/setup-uv@v5
3031
with:
3132
python-version: ${{ matrix.python-version }}
32-
- name: Run styling check
33-
run: poetry run pre-commit run --all-files
33+
enable-cache: true
34+
- name: pre-commit cache key
35+
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> "$GITHUB_ENV"
36+
- uses: actions/cache@v4
37+
with:
38+
path: ~/.cache/pre-commit
39+
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
40+
- name: Install dependencies
41+
run: uv sync --frozen --all-extras
42+
- name: Check style and run tests
43+
run: pre-commit run --all-files
3444
- name: Upload coverage to Codecov
3545
if: inputs.push_coverage
3646
uses: codecov/codecov-action@v5
3747
with:
3848
token: ${{ secrets.CODECOV_TOKEN }}
3949
files: ./coverage.xml
50+
51+
build-package:
52+
runs-on: ubuntu-latest
53+
strategy:
54+
matrix:
55+
python-version: ['3.12']
56+
steps:
57+
- uses: actions/checkout@v4
58+
- name: Install uv and set the python version
59+
uses: astral-sh/setup-uv@v5
60+
with:
61+
python-version: ${{ matrix.python-version }}
62+
enable-cache: true
63+
- name: Install dependencies
64+
run: uv sync --all-extras
65+
- name: Build package
66+
run: uv build
67+
- name: Check content of wheel
68+
run: unzip -l dist/*.whl
69+
- name: Store the distribution packages
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: python-package-distributions
73+
path: dist/
74+
75+
test-package:
76+
needs:
77+
- build-package
78+
runs-on: ubuntu-latest
79+
strategy:
80+
matrix:
81+
python-version: ['3.12']
82+
steps:
83+
- name: Download all the dists
84+
uses: actions/download-artifact@v4
85+
with:
86+
name: python-package-distributions
87+
path: dist/
88+
- name: Install uv and set the python version
89+
uses: astral-sh/setup-uv@v5
90+
with:
91+
python-version: ${{ matrix.python-version }}
92+
enable-cache: true
93+
- name: Install package
94+
run: uv pip install dist/*.whl
95+
- name: Load the DoclingDocument package
96+
run: python -c 'from docling_core.types.doc import DoclingDocument'
97+
- name: Check if package data is present
98+
run: python -c 'from importlib import resources; from pathlib import Path; p=Path(resources.files("docling_core").joinpath("resources/schemas/doc/DOC.json")); assert p.exists()'

.github/workflows/ci.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,10 @@ on:
88
- "**"
99
- "!gh-pages"
1010

11-
env:
12-
# disable keyring (https://github.com/actions/runner-images/issues/6185):
13-
PYTHON_KEYRING_BACKEND: keyring.backends.null.Keyring
14-
1511
jobs:
1612
code-checks:
1713
if: ${{ github.event_name == 'push' || (github.event.pull_request.head.repo.full_name != 'docling-project/docling-core' && github.event.pull_request.head.repo.full_name != 'docling-project/docling-core') }}
1814
uses: ./.github/workflows/checks.yml
1915
secrets:
2016
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2117

22-
# To enable when we add the ./docs
23-
# build-docs:
24-
# runs-on: ubuntu-latest
25-
# steps:
26-
# - uses: actions/checkout@v3
27-
# - uses: ./.github/actions/setup-poetry
28-
# - name: Build docs
29-
# run: poetry run mkdocs build --verbose --clean
30-

.github/workflows/pypi.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,28 @@ on:
77
permissions:
88
contents: read
99

10-
env:
11-
# disable keyring (https://github.com/actions/runner-images/issues/6185):
12-
PYTHON_KEYRING_BACKEND: keyring.backends.null.Keyring
13-
1410
jobs:
1511
build-and-publish:
1612
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: ['3.12']
1716
environment:
1817
name: pypi
1918
url: https://pypi.org/p/docling-core
2019
permissions:
2120
id-token: write # IMPORTANT: mandatory for trusted publishing
2221
steps:
2322
- uses: actions/checkout@v4
24-
- uses: ./.github/actions/setup-poetry
25-
- name: Build and publish
26-
run: poetry build
23+
- name: Install uv and set the python version
24+
uses: astral-sh/setup-uv@v5
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
enable-cache: true
28+
- name: Install dependencies
29+
run: uv sync --all-extras
30+
- name: Build package
31+
run: uv build
2732
- name: Publish distribution 📦 to PyPI
2833
uses: pypa/gh-action-pypi-publish@release/v1
2934
with:

.pre-commit-config.yaml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,59 @@ repos:
44
hooks:
55
- id: black
66
name: Black
7-
entry: poetry run black docling_core test
7+
entry: uv run --no-sync black docling_core test
88
pass_filenames: false
99
language: system
1010
files: '\.py$'
1111
- repo: local
1212
hooks:
1313
- id: isort
1414
name: isort
15-
entry: poetry run isort docling_core test
15+
entry: uv run --no-sync isort docling_core test
1616
pass_filenames: false
1717
language: system
1818
files: '\.py$'
1919
- repo: local
2020
hooks:
2121
- id: autoflake
2222
name: autoflake
23-
entry: poetry run autoflake docling_core test
23+
entry: uv run --no-sync autoflake docling_core test
2424
pass_filenames: false
2525
language: system
2626
files: '\.py$'
2727
- repo: local
2828
hooks:
2929
- id: mypy
3030
name: MyPy
31-
entry: poetry run mypy docling_core test
31+
entry: uv run --no-sync mypy docling_core test
3232
pass_filenames: false
3333
language: system
3434
files: '\.py$'
3535
- repo: local
3636
hooks:
3737
- id: flake8
3838
name: Flake8
39-
entry: poetry run flake8 docling_core
39+
entry: uv run --no-sync flake8 docling_core
4040
pass_filenames: false
4141
language: system
4242
files: '\.py$'
4343
- repo: local
4444
hooks:
4545
- id: pytest
4646
name: Pytest
47-
entry: poetry run pytest --cov=docling_core --cov-report=xml test/
47+
entry: uv run --no-sync pytest --cov=docling_core --cov-report=xml test
4848
pass_filenames: false
4949
language: system
5050
files: '\.py$'
5151
- repo: local
5252
hooks:
5353
- id: docs
5454
name: Docs
55-
entry: poetry run generate_docs docs
55+
entry: uv run --no-sync python -m docling_core.utils.generate_docs docs
5656
pass_filenames: false
5757
language: system
5858
files: '\.py$'
59-
- repo: local
59+
- repo: https://github.com/astral-sh/uv-pre-commit
60+
rev: 0.7.8
6061
hooks:
61-
- id: poetry
62-
name: Poetry
63-
entry: poetry check --lock
64-
pass_filenames: false
65-
language: system
62+
- id: uv-lock

0 commit comments

Comments
 (0)