Skip to content

Commit c556634

Browse files
ivanzatileoll2
andauthored
Switch lib-lint-and-test workflow to uv (#4932)
Co-authored-by: Leonardo Lai <[email protected]>
1 parent d9dda72 commit c556634

File tree

11 files changed

+6328
-237
lines changed

11 files changed

+6328
-237
lines changed

.github/workflows/lib-lint-and-test.yaml

Lines changed: 96 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
# Determines if workflow should execute based on event type and changed paths
2525
# If push or workflow_dispatch -> always run
2626
# If PR or merge_group -> run only if files in specified paths changed
27-
check_paths:
27+
check-paths:
2828
name: Check if workflow should run
2929
runs-on: ubuntu-latest
3030
outputs:
@@ -55,95 +55,110 @@ jobs:
5555
echo "run=false" >> "$GITHUB_OUTPUT"
5656
fi
5757
58-
Code-Quality-Checks:
58+
code-quality-checks:
5959
runs-on: ubuntu-24.04
60-
needs: check_paths
61-
if: needs.check_paths.outputs.run_workflow == 'true'
60+
needs: check-paths
61+
if: needs.check-paths.outputs.run_workflow == 'true'
6262
permissions:
6363
contents: read
6464
steps:
6565
- name: Checkout repository
6666
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
6767
with:
6868
persist-credentials: false
69+
6970
- name: Set up Python
7071
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
7172
with:
72-
python-version: "3.12"
73-
- name: Install tox
73+
python-version: "3.13"
74+
75+
- name: Install uv
76+
uses: astral-sh/setup-uv@3259c6206f993105e3a61b142c2d97bf4b9ef83d # v7.1.0
77+
with:
78+
version: "0.9.7"
79+
enable-cache: false
80+
81+
- name: Installing dependencies
7482
working-directory: library
7583
run: |
76-
pip install '.[dev]'
77-
- name: Code quality checks
84+
uv lock --check
85+
uv sync --frozen
86+
87+
- name: Check formatting with ruff
7888
working-directory: library
79-
run: tox r -vv -e pre-commit
80-
Unit-Test:
89+
run: |
90+
uv run ruff check --output-format=github .
91+
uv run ruff format --check .
92+
93+
# TODO: remove 'continue-on-error' after addressing all mypy issues
94+
# https://github.com/open-edge-platform/training_extensions/issues/5006
95+
- name: Check source code with mypy
96+
continue-on-error: true
97+
working-directory: library
98+
run: |
99+
uv run mypy src/otx
100+
101+
unit-tests:
81102
runs-on: [self-hosted, linux, x64, dev, dmount]
82103
permissions:
83104
contents: read
105+
# The id-token permission is required by Codecov to use OIDC
106+
id-token: write
84107
needs:
85-
- Code-Quality-Checks
86-
- check_paths
87-
if: needs.check_paths.outputs.run_workflow == 'true'
108+
- code-quality-checks
109+
- check-paths
110+
if: needs.check-paths.outputs.run_workflow == 'true'
88111
timeout-minutes: 120
89112
strategy:
90113
fail-fast: false
91114
matrix:
92-
include:
93-
- python-version: "3.12"
94-
tox-env: "py312"
95-
- python-version: "3.11"
96-
tox-env: "py311"
97-
name: Unit-Test-with-Python${{ matrix.python-version }}
115+
python-version: ["3.10", "3.13"]
116+
name: unit-tests-with-Python${{ matrix.python-version }}
98117
steps:
99118
- name: Checkout repository
100119
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
101120
with:
102121
persist-credentials: false
103-
- name: Install Python
122+
123+
- name: Set up Python
104124
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
105125
with:
106-
python-version: ${{ matrix.python-version }}
107-
- name: Install tox
126+
python-version: "3.13"
127+
128+
- name: Install uv
129+
uses: astral-sh/setup-uv@3259c6206f993105e3a61b142c2d97bf4b9ef83d # v7.1.0
130+
with:
131+
version: "0.9.7"
132+
enable-cache: false
133+
134+
- name: Installing dependencies
108135
working-directory: library
109136
run: |
110-
pip install '.[dev]'
111-
- name: Run unit test
137+
uv lock --check
138+
uv sync --frozen
139+
140+
- name: Unit testing
112141
working-directory: library
113-
run: tox r -vv -e unit-test-${{ matrix.tox-env }}
142+
run: uv run pytest tests/unit --cov --cov-report=xml
143+
114144
- name: Upload coverage reports to Codecov
115-
working-directory: library
116-
run: |
117-
# If the workflow is triggered from PR then it gets the commit id from the PR.
118-
# else it uses the commit id of the latest commit. This is because the commit
119-
# of the checked-out branch/commit does not exist in the tree as it is grafted.
120-
# Also note: GitHub does not pass secrets to pipelines triggered from a fork.
121-
# This means that upload will fail for PRs from forks.
122-
if [ -n "${{ github.event.pull_request.head.sha }}" ]
123-
then
124-
COMMIT_ID=${{ github.event.pull_request.head.sha }}
125-
else
126-
COMMIT_ID=${{ github.sha }}
127-
fi
128-
# current version of codecov-action does not support uploading reports through the proxy
129-
# so we use the latest version of codecov uploader binary
130-
curl -Os https://uploader.codecov.io/latest/linux/codecov
131-
chmod +x codecov
132-
./codecov -t ${{ secrets.CODECOV_TOKEN }} --sha $COMMIT_ID -U $HTTP_PROXY -f .tox/coverage_unit-test-${{ matrix.tox-env }}.xml -F ${{ matrix.tox-env }}
133-
Integration-Test:
134-
if: |
135-
github.event.pull_request.draft == false &&
136-
!(startsWith(github.event.pull_request.title, '[WIP]')) &&
137-
needs.check_paths.outputs.run_workflow == 'true'
145+
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
146+
with:
147+
directory: library
148+
flags: coverage_unit-tests_Python-${{ matrix.python-version }}
149+
use_oidc: true
150+
151+
integration-tests:
138152
runs-on: [self-hosted, linux, x64, dev, dmount]
139153
permissions:
140154
contents: read
141155
needs:
142-
- Unit-Test
143-
- check_paths
156+
- unit-tests
157+
- check-paths
144158
strategy:
145159
fail-fast: false
146160
matrix:
161+
python-version: ["3.10", "3.13"]
147162
include:
148163
- task: "multi_class_cls"
149164
- task: "multi_label_cls"
@@ -152,31 +167,50 @@ jobs:
152167
- task: "detection"
153168
- task: "instance_segmentation"
154169
- task: "semantic_segmentation"
155-
name: Integration-Test-${{ matrix.task }}-py312
170+
name: integration-tests-${{ matrix.task }}-py${{ matrix.python-version }}
156171
steps:
157172
- name: Checkout repository
158173
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
159174
with:
160175
persist-credentials: false
161-
- name: Install Python
176+
177+
- name: Set up Python
162178
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
163179
with:
164-
python-version: "3.12"
165-
- name: Install tox
180+
python-version: ${{ matrix.python-version }}
181+
182+
- name: Install uv
183+
uses: astral-sh/setup-uv@3259c6206f993105e3a61b142c2d97bf4b9ef83d # v7.1.0
184+
with:
185+
version: "0.9.7"
186+
enable-cache: false
187+
188+
- name: Installing dependencies
166189
working-directory: library
167190
run: |
168-
pip install '.[dev]'
169-
- name: Run Integration Test
191+
uv lock --check
192+
uv sync --frozen --extra cuda
193+
194+
- name: Integration testing
170195
working-directory: library
171-
run: tox r -vv -e integration-test-${{ matrix.task }} -- --task ${{ matrix.task }} --run-category-only
196+
env:
197+
CUBLAS_WORKSPACE_CONFIG: ":4096:8"
198+
run: |
199+
uv run --frozen --extra cuda pytest tests/integration \
200+
-ra \
201+
--showlocals \
202+
--csv=${{ matrix.task }}_Python-${{ matrix.python-version }}.csv \
203+
--task ${{ matrix.task }} \
204+
--open-subprocess \
205+
--run-category-only
172206
173-
required_check:
207+
required-check:
174208
name: Required Check lib-lint-and-test
175209
needs:
176-
- check_paths
177-
- Code-Quality-Checks
178-
- Unit-Test
179-
- Integration-Test
210+
- check-paths
211+
- code-quality-checks
212+
- unit-tests
213+
- integration-tests
180214
runs-on: ubuntu-latest
181215
env:
182216
CHECKS: ${{ join(needs.*.result, ' ') }}

library/docs/source/guide/get_started/installation.rst

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,34 +141,32 @@ Example output:
141141
Run tests
142142
*********
143143

144-
To run tests locally, install development dependencies:
144+
To run tests locally, just call `pytest`. `uv` will automatically sync all necessary dependencies.
145145

146146
.. code-block:: shell
147147
148-
uv pip install -e '.[dev]'
149-
pytest tests/
148+
uv run pytest tests
150149
151-
To run integration tests using `tox`:
150+
To run integration tests:
152151

153152
.. code-block:: shell
154153
155-
uv tool install tox --with tox-uv
156-
tox -e integration-test-all
154+
uv run pytest tests/integration
157155
158156
.. note::
159157

160-
The first time `tox` is run, it will create virtual environments and install all required dependencies.
161-
This may take several minutes before the actual tests begin.
158+
Integration tests may be slow because they involve downloading datasets and simulating training rounds.
159+
It is recommended to run them on a platform with GPU/XPU support.
162160

163161
***************
164162
Troubleshooting
165163
***************
166164

167-
1. If you encounter issues with `uv pip`, update uv:
165+
1. If you encounter issues with `uv`, update it:
168166

169167
.. code-block:: shell
170168
171-
pip install --upgrade uv
169+
uv self update
172170
173171
2. If you're having issues installing `torch` or `mmcv`, check CUDA compatibility with your PyTorch version.
174172
Update your CUDA toolkit and drivers if needed. See `CUDA 11.8 Installer <https://developer.nvidia.com/cuda-11-8-0-download-archive?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=runfile_local>`_.
@@ -178,7 +176,6 @@ Update your CUDA toolkit and drivers if needed. See `CUDA 11.8 Installer <https:
178176
.. code-block:: shell
179177
180178
export HTTP_PROXY=http://<user>:<password>@<proxy>:<port>
181-
uv pip install <package>
182179
183180
4. For CLI-related issues, check the help message:
184181

library/docs/source/guide/tutorials/base/explain.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ To be specific, this tutorial uses as an example of the ATSS model trained throu
1212

1313
For visualization we use images from WGISD dataset from the :doc:`object detection tutorial <how_to_train/detection>` together with trained model.
1414

15-
1. Activate the virtual environment
16-
created in the previous step.
15+
1. Activate the virtual environment created in the previous step.
1716

1817
.. code-block:: shell
1918
20-
.otx/bin/activate
21-
# or by this line, if you created an environment, using tox
22-
. venv/otx/bin/activate
19+
source .venv/bin/activate
2320
2421
2. ``otx predict`` with the ``--explain True`` parameter returns saliency maps,
2522
which are heatmaps with red-colored areas indicating focus. Here's an example how to generate saliency maps from trained checkpoint:

library/docs/source/guide/tutorials/base/export.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ Export
1212

1313
"export" method should be implemented within a framework engine like OTXEngine to be able to export the model. Optimization and validation steps are required to use OVEngine.
1414

15-
1. Activate the virtual environment
16-
created in the previous step.
15+
1. Activate the virtual environment created in the previous step.
1716

1817
.. code-block:: shell
1918
20-
source .otx/bin/activate
21-
# or by this line, if you created an environment, using tox
22-
. venv/otx/bin/activate
19+
source .venv/bin/activate
2320
2421
2. ``otx export`` returns an ``.onnx``, ``openvino.xml(.bin)`` and ``.zip``
2522
exportable code with demo depending on the export type passed to CLI or API.

library/docs/source/guide/tutorials/base/how_to_train/detection.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,11 @@ Setup virtual environment
2626
1. You can follow the installation process from a :doc:`quick start guide <../../../get_started/installation>`
2727
to create a universal virtual environment for OpenVINO™ Training Extensions.
2828

29-
2. Activate your virtual
30-
environment:
29+
2. Activate your virtual environment:
3130

3231
.. code-block:: shell
3332
34-
.otx/bin/activate
35-
# or by this line, if you created an environment, using tox
36-
. venv/otx/bin/activate
33+
source .venv/bin/activate
3734
3835
3936
.. _wgisd_dataset_descpiption:

library/docs/source/guide/tutorials/base/how_to_train/instance_segmentation.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@ Setup virtual environment
2424
1. You can follow the installation process from a :doc:`quick start guide <../../../get_started/installation>`
2525
to create a universal virtual environment for OpenVINO™ Training Extensions.
2626

27-
2. Activate your virtual
28-
environment:
27+
2. Activate your virtual environment:
2928

3029
.. code-block:: shell
3130
32-
.otx/bin/activate
33-
# or by this line, if you created an environment, using tox
34-
. venv/otx/bin/activate
31+
source .venv/bin/activate
3532
3633
3734
***************************

library/docs/source/guide/tutorials/base/how_to_train/semantic_segmentation.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@ Setup virtual environment
2323
1. You can follow the installation process from a :doc:`quick start guide <../../../get_started/installation>`
2424
to create a universal virtual environment for OpenVINO™ Training Extensions.
2525

26-
2. Activate your virtual
27-
environment:
26+
2. Activate your virtual environment:
2827

2928
.. code-block:: shell
3029
31-
.otx/bin/activate
32-
# or by this line, if you created an environment, using tox
33-
. venv/otx/bin/activate
30+
source .venv/bin/activate
3431
3532
***************************
3633
Dataset preparation

0 commit comments

Comments
 (0)