Skip to content

Commit 50b93c4

Browse files
authored
Merge pull request #1079 from onekey-sec/uv
Poetry -> uv
2 parents 1c12b45 + 2e61e4d commit 50b93c4

19 files changed

+1812
-2203
lines changed

.github/ISSUE_TEMPLATE/bug-report-🐞.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ A clear and concise description of what you expected to happen.
4646

4747
**Environment information (please complete the following information):**
4848
- OS: [e.g. Ubuntu Linux]
49-
- Software versions (Docker, Python, Nix, Poetry, if applicable)
49+
- Software versions (Docker, Python, Nix, Uv, if applicable)
5050

5151
We recommend you execute and paste the results of those commands in this issue so we can get a sense of your environment:
5252

5353
- Linux/Darwin kernel version with `uname -avr`
5454
- Linux distribution with `cat /etc/lsb-release`
5555
- MacOS distribution with `sw_vers`
56-
- Poetry version with `poetry env info`
56+
- Uv version with `uv version`
5757
- Nix install info with `nix flake info`
5858
- Pip install info `pip freeze`
5959
- Unblob dependencies info with `unblob --show-external-dependencies`

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

+7-29
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,13 @@ runs:
1313
run: sudo unblob/install-deps.sh
1414
shell: bash
1515

16-
- name: Setup Python
17-
uses: actions/setup-python@v5
16+
- name: Install uv & Python
17+
uses: astral-sh/setup-uv@v5
1818
with:
19-
python-version: ${{ inputs.python-version }}
19+
enable-cache: true
20+
cache-dependency-glob: "uv.lock"
21+
python-version: ${{ matrix.python-version }}
2022

21-
- name: Restore pip cache
22-
uses: actions/cache@v4
23-
with:
24-
path: ~/.cache/pip
25-
key: pip-${{ inputs.python-version }}
26-
27-
- name: Pip install
28-
run: python -m pip install --upgrade pip poetry
29-
shell: bash
30-
31-
- name: Restore poetry cache
32-
uses: actions/cache@v4
33-
with:
34-
path: |
35-
~/.cache/pypoetry/cache
36-
~/.cache/pypoetry/artifacts
37-
key: poetry-cache-and-artifacts-${{ inputs.python-version }}
38-
39-
- name: Restore virtualenvs
40-
uses: actions/cache@v4
41-
with:
42-
path: ~/.cache/pypoetry/virtualenvs
43-
key: venv-${{ hashFiles('poetry.lock') }}-${{ inputs.python-version }}
44-
45-
- name: Poetry install
46-
run: poetry install --with dev
23+
- name: Install the project
24+
run: uv sync
4725
shell: bash

.github/workflows/build-publish-image.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ jobs:
3434
- name: Setup 3rd party dependencies
3535
uses: ./.github/actions/setup-dependencies
3636

37-
- name: Poetry build
38-
run: poetry build --format wheel
37+
- name: uv build
38+
run: uv build --wheel
3939

4040
- name: Docker meta
4141
id: meta

.github/workflows/documentation.yml

+8-36
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,15 @@ jobs:
1313
- name: Checkout source code
1414
uses: actions/checkout@v4
1515

16-
- name: Setup Python
17-
uses: actions/setup-python@v5
16+
- name: Install uv & Python
17+
uses: astral-sh/setup-uv@v5
1818
with:
19-
python-version: 3.9
19+
enable-cache: true
20+
cache-dependency-glob: "uv.lock"
21+
python-version: "3.9"
2022

21-
- name: Setup Python
22-
uses: actions/setup-python@v5
23-
with:
24-
python-version: 3.9
25-
26-
- name: Restore pip cache
27-
uses: actions/cache@v4
28-
with:
29-
path: ~/.cache/pip
30-
key: pip-3.9
31-
32-
- name: Upgrade pip and install poetry
33-
run: python -m pip install --upgrade pip poetry
34-
shell: bash
35-
36-
- name: Restore poetry cache
37-
uses: actions/cache@v4
38-
with:
39-
path: |
40-
~/.cache/pypoetry/cache
41-
~/.cache/pypoetry/artifacts
42-
key: poetry-cache-and-artifacts-3.9
43-
44-
- name: Restore virtualenvs
45-
uses: actions/cache@v4
46-
with:
47-
path: ~/.cache/pypoetry/virtualenvs
48-
key: venv-${{ hashFiles('poetry.lock') }}-3.9
49-
50-
- name: Poetry install
51-
run: poetry install --only docs
52-
shell: bash
23+
- name: Install the project
24+
run: uv sync --only-group docs
5325

5426
- name: Generate documentation
55-
run: poetry run mkdocs gh-deploy --force
27+
run: uv run mkdocs gh-deploy --force

.github/workflows/release.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
- name: Setup dependencies
1616
uses: ./.github/actions/setup-dependencies
1717

18-
- run: poetry publish --build
18+
- run: uv build
19+
- run: uv publish
1920
env:
20-
POETRY_PYPI_TOKEN_PYPI: ${{secrets.POETRY_PYPI_TOKEN_PYPI}}
21+
UV_PUBLISH_TOKEN: ${{secrets.POETRY_PYPI_TOKEN_PYPI}}

.github/workflows/run-tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
uses: ./.github/actions/setup-dependencies
4242

4343
- name: Check - pyright
44-
run: poetry run pyright .
44+
run: uv run pyright .
4545

4646
run_tests:
4747
name: Run tests
@@ -62,4 +62,4 @@ jobs:
6262
uses: ./.github/actions/setup-git-lfs
6363

6464
- name: Run pytest
65-
run: poetry run pytest -vvv
65+
run: uv run pytest -vvv

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build/
77
*.so
88
.idea
99
.coverage*
10-
/.venv/
10+
/.venv
1111
unblob.log
1212
/.devenv
1313
/.direnv

.pre-commit-config.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ repos:
2020
language: system
2121
types_or: [python, pyi]
2222
require_serial: true
23-
entry: poetry run ruff check --force-exclude
23+
entry: uv run ruff check --force-exclude
2424
args:
2525
[--output-format=full, --fix, --show-fixes, --exit-non-zero-on-fix]
2626
- id: ruff-format
2727
name: Format python (ruff)
2828
language: system
2929
types_or: [python, pyi]
3030
require_serial: true
31-
entry: poetry run ruff format --force-exclude
31+
entry: uv run ruff format --force-exclude
3232
- id: nixfmt
3333
name: Format Nix (nixfmt)
3434
types: [nix]
@@ -44,12 +44,12 @@ repos:
4444
name: Format TOML (taplo)
4545
language: system
4646
types: [toml]
47-
entry: poetry run taplo format
47+
entry: uv run taplo format
4848
- id: taplo-lint
4949
name: Lint TOML (taplo)
5050
language: system
5151
types: [toml]
52-
entry: poetry run taplo lint
52+
entry: uv run taplo lint
5353
args:
5454
- --default-schema-catalogs
5555

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ WORKDIR /data/output
99
COPY unblob/install-deps.sh /
1010
RUN sh -xeu /install-deps.sh
1111

12-
# You MUST do a poetry build before to have the wheel to copy & install here (CI action will do this when building)
12+
# You MUST do an uv build before to have the wheel to copy & install here (CI action will do this when building)
1313
COPY dist/*.whl /tmp/
1414
RUN pip --disable-pip-version-check install --upgrade pip
1515
RUN pip install /tmp/unblob*.whl --prefix /usr/local

devenv.nix

+32-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
{ lib, pkgs, ... }:
1+
{
2+
config,
3+
lib,
4+
pkgs,
5+
...
6+
}:
27

38
# https://devenv.sh/reference/options/
49
{
@@ -7,33 +12,49 @@
712
libraries = with pkgs; [
813
file # python-magic
914
];
10-
poetry = {
15+
venv.enable = true; # put venv in PATH
16+
uv = {
1117
enable = true;
12-
activate.enable = true;
13-
install.enable = true;
14-
install = {
15-
groups = [ "dev" ];
16-
installRootPackage = true;
17-
};
18+
sync.enable = true;
19+
sync.arguments = [
20+
# by default it contains `--no-install-workspace`
21+
"--frozen"
22+
"--group"
23+
"dev"
24+
];
1825
};
1926
};
2027

28+
env.UV_LINK_MODE = "copy";
29+
2130
packages =
2231
with pkgs;
2332
[
24-
nvfetcher
2533
nodejs # for pyright and renovate
2634
]
2735
++ unblob.runtimeDeps;
2836

2937
tasks = {
38+
"venv:link" = {
39+
exec = ''
40+
VENV_DIR="${config.devenv.root}/.venv"
41+
42+
if [[ -d "$VENV_DIR" && ! -L "$VENV_DIR" ]]; then
43+
echo "Found an existing ${config.devenv.root}/.venv directory. Please remove it."
44+
exit 1
45+
fi
46+
ln -snf "${config.devenv.state}/venv" "${config.devenv.root}/.venv"
47+
'';
48+
after = [ "devenv:python:uv" ];
49+
before = [ "devenv:enterShell" ];
50+
};
3051
"venv:patchelf" = {
3152
exec = ''
3253
for exe in taplo ruff; do
33-
${lib.getExe pkgs.patchelf} --set-interpreter ${pkgs.stdenv.cc.bintools.dynamicLinker} $VIRTUAL_ENV/bin/$exe
54+
${lib.getExe pkgs.patchelf} --set-interpreter ${pkgs.stdenv.cc.bintools.dynamicLinker} "${config.devenv.state}/venv/bin/$exe"
3455
done
3556
'';
36-
after = [ "devenv:python:poetry" ];
57+
after = [ "devenv:python:uv" ];
3758
before = [ "devenv:enterShell" ];
3859
};
3960
};

docs/development.md

+10-16
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ where the exciting stuff is.
3232
- **git**: You need it for cloning the repository.
3333
Install it [from the git-scm website](https://git-scm.com/download).
3434

35-
- **Poetry**: it is a package manager for Python dependencies. Follow the instructions on the
36-
[Poetry website](https://python-poetry.org/docs/master/#installation) to install the latest version.
35+
- **uv**: it is a package manager for Python dependencies. Follow the instructions on the
36+
[uv website](https://docs.astral.sh/uv/getting-started/installation/) to install the latest version.
3737

3838
- **pre-commit**: We are using [pre-commit](https://pre-commit.com/) to run
3939
checks like linters, type checks and formatting issues.
@@ -72,16 +72,10 @@ You need to setup Git LFS once, before you will be able to run the whole test su
7272

7373
The recommended way to develop Python projects in a semi-isolated way is to use `virtualenv`.
7474

75-
If you don't want to manage it separately, you can rely on `Poetry` to automatically
75+
If you don't want to manage it separately, you can rely on `uv` to automatically
7676
create a virtualenv for you on install.
7777

78-
If you don't want Poetry to automatically create a virtualenv, you can turn it off with this command:
79-
80-
```shell
81-
poetry config virtualenvs.create false
82-
```
83-
84-
Or instead of Poetry you can use `pyenv`. You can set the Python interpreter
78+
Or instead of uv you can use `pyenv`. You can set the Python interpreter
8579
version for the local folder only with:
8680

8781
```
@@ -90,29 +84,29 @@ pyenv local 3.12.7
9084

9185
### Installing Python dependencies
9286

93-
We are using [poetry](https://python-poetry.org/) to manage our Python
87+
We are using [uv](https://docs.astral.sh/uv/) to manage our Python
9488
dependencies. To install all required dependencies for development, you can run
9589
the following command:
9690

9791
```
98-
poetry install --with dev
92+
uv install
9993
```
10094

10195
Please note that it installs dependencies within the dedicated virtual
10296
environment. So if you want to run `unblob` or `pytest`, you need to do it from
10397
within the virtual environment:
10498

105-
Using poetry run:
99+
Using uv run:
106100

107101
```
108-
poetry run unblob
109-
poetry run pytest tests -v
102+
uv run unblob
103+
uv run pytest tests -v
110104
```
111105

112106
By dropping into the virtual environment:
113107

114108
```
115-
poetry shell
109+
uv run $SHELL
116110
unblob
117111
pytest tests -v
118112
```

docs/extractors.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ The following executables found installed, which are needed by unblob:
4949

5050
✅: These extractors come with unblob, check
5151
[pyproject.toml](https://github.com/onekey-sec/unblob/blob/main/pyproject.toml)
52-
and [poetry.lock](https://github.com/onekey-sec/unblob/blob/main/poetry.lock)
52+
and [uv.lock](https://github.com/onekey-sec/unblob/blob/main/uv.lock)
5353
for current versions.
5454

5555
| Extractor | Provided commands | Minimum version | Pre-Installed | More information |

docs/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ unblob has been developed with the following objectives in mind:
6060
tested](https://github.com/onekey-sec/unblob/issues?q=label%3Afuzzing+)
6161
against a large corpus of files and firmware images. We rely on up-to-date
6262
third party dependencies that are
63-
[locked](https://github.com/onekey-sec/unblob/blob/main/poetry.lock) to limit
63+
[locked](https://github.com/onekey-sec/unblob/blob/main/uv.lock) to limit
6464
potential supply chain issues. We use safe extractors that we audited and
6565
fixed where required (see [path traversal in
6666
ubi_reader](https://github.com/onekey-sec/ubi_reader/commit/4a81f3f0a714bb83d6ee71db09b7748619fa9fb7),

docs/installation.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -192,23 +192,23 @@ For imperative package installation, follow these steps:
192192
## From source
193193

194194
1. Install [Git](https://git-scm.com/download/) if you don't have it yet.
195-
2. Install the [Poetry](https://python-poetry.org/docs/#installation) Python package manager.
195+
2. Install [uv](https://docs.astral.sh/uv/getting-started/installation/) Python package manager.
196196
3. **Clone** the unblob **repository from GitHub**:
197197

198198
git clone https://github.com/onekey-sec/unblob.git
199199

200-
4. Install **Python dependencies** with Poetry:
200+
4. Install **Python dependencies** with uv:
201201

202202
1. Python packages:
203203

204204
cd unblob
205-
poetry install --no-dev
205+
uv sync --no-dev
206206

207207
2. Make sure you [installed all extractors](#install-extractors).
208208

209209
3. Check that everything works correctly:
210210

211-
poetry run unblob --show-external-dependencies
211+
uv run unblob --show-external-dependencies
212212

213213
## Install extractors
214214

0 commit comments

Comments
 (0)