Skip to content

Commit e1ada49

Browse files
authored
Reemplaza pip+pip-tools por uv (#42)
1 parent 170a082 commit e1ada49

File tree

13 files changed

+104
-219
lines changed

13 files changed

+104
-219
lines changed

.github/workflows/mypy.yml

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

.github/workflows/pytest.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@ jobs:
1919
default-shell:
2020
name: Default shell
2121
runs-on: "ubuntu-latest"
22-
defaults:
23-
run:
24-
shell: bash -l {0}
22+
strategy:
23+
matrix:
24+
python-version: ["3.9", "3.10", "3.11"]
2525
steps:
2626
- uses: actions/checkout@v4
2727
- uses: actions/setup-python@v5
2828
with:
29-
python-version: "3.11"
30-
cache: "pip"
29+
python-version: ${{ matrix.python-version }}
3130
- name: Test with pytest
3231
run: |
33-
pip install -r requirements.txt
34-
pip install pytest-cov
35-
pip install -e .
36-
pytest --cov=./ --cov-report=xml --optional
32+
pip install uv
33+
uv pip install --system -r requirements-dev.txt
34+
uv pip install --system pytest-cov
35+
uv pip install --system -e .
36+
pytest --cov=./ --cov-report=xml
3737
- name: Upload coverage to Codecov
3838
uses: codecov/codecov-action@v4
3939
with:
4040
token: ${{ secrets.CODECOV_TOKEN }}
4141
name: codecov-umbrella
42-
fail_ci_if_error: true
42+
fail_ci_if_error: false
4343
verbose: true

.pre-commit-config.yaml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ repos:
4343
rev: v1.6.1
4444
hooks:
4545
- id: mypy
46+
args: ["--install-types", "--non-interactive"]
47+
additional_dependencies: [numpy]
4648
# Esto tiene la desventaja de que siempre se va a ejecutar mypy
4749
# sobre todos los ficheros del repo (incluidos en la conf de mypy)
4850
# Se puede sustituir por `files:`
@@ -59,20 +61,21 @@ repos:
5961
hooks:
6062
- id: prettier
6163
types_or: [markdown, yaml]
62-
- repo: https://github.com/jazzband/pip-tools
63-
rev: 7.3.0
64+
- repo: https://github.com/astral-sh/uv-pre-commit
65+
rev: 0.1.28
6466
hooks:
6567
- id: pip-compile
66-
name: pip-compile requirements
67-
args: [pyproject.toml]
68-
files: ^(pyproject\.toml|requirements\.txt)$
68+
name: pip-compile requirements.in
69+
args: [-o, requirements.txt, requirements.in]
6970
- id: pip-compile
70-
name: pip-compile requirements-dev
71+
name: pip-compile requirements-dev.in
7172
args:
7273
[
73-
--constraint=requirements.txt,
74-
--extra=dev,
75-
--output-file=requirements-dev.txt,
76-
pyproject.toml,
74+
-o,
75+
requirements-dev.txt,
76+
-c,
77+
requirements.txt,
78+
requirements.in,
79+
requirements-dev.in,
7780
]
78-
files: ^(pyproject\.toml|requirements-dev\.txt)$
81+
files: ^(requirements\.(in|txt)|requirements-dev\.(in|txt))$

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ ENV PIP_ROOT_USER_ACTION=ignore \
1010
PIP_DISABLE_PIP_VERSION_CHECK=1 \
1111
PIP_NO_CACHE_DIR=1
1212

13-
RUN pip install -r /code/requirements.txt
13+
RUN pip install uv
14+
RUN uv pip install --system --no-cache -r /code/requirements.txt
1415

1516
COPY ./template /code/template
1617
COPY ./pyproject.toml /code/pyproject.toml

Makefile

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
11
.ONESHELL:
2-
.PHONY: env install compile sync hooks docker build run debug push
2+
.PHONY: env install compile sync hooks ruff test mypy docker build run debug push
33

44
SHELL=/bin/bash
55
DOCKER_IMG_NAME=ghcr.io/komorebi-ai/python-template
66
DOCKER_CONTAINER=template
7-
GH_USER=albertotb
8-
GH_TOKEN_FILE=/home/atorres/GITHUB_TOKEN.txt
7+
GH_USER=GITHUB_USERNAME
8+
GH_TOKEN_FILE=GITHUB_TOKEN_PATH
99

1010
env:
1111
conda create -n python-template python=3.11
1212

1313
install:
14-
pip install -r requirements-dev.txt
15-
pip install -e .[dev]
14+
pip install uv
15+
uv pip install -r requirements-dev.txt
16+
uv pip install -e .[dev]
1617

1718
compile:
18-
pip install pip-tools
19-
pip-compile pyproject.toml
20-
pip-compile --extra dev -o requirements-dev.txt -c requirements.txt pyproject.toml
19+
pip install uv
20+
uv pip compile -o requirements.txt requirements.in
21+
uv pip compile -o requirements-dev.txt -c requirements.txt requirements.in requirements-dev.in
2122

2223
sync:
23-
pip install pip-tools
24-
pip-sync requirements-dev.txt
25-
pip install -e .[dev]
24+
pip install uv
25+
uv pip sync requirements-dev.txt
26+
uv pip install -e .[dev]
2627

2728
hooks:
2829
pre-commit install
2930
pre-commit run --all-files
3031

32+
ruff:
33+
ruff check .
34+
ruff format .
35+
36+
test:
37+
python -m pytest
38+
39+
mypy:
40+
mypy --install-types --non-interactive
41+
3142
docker: build run
3243

3344
build:
@@ -36,7 +47,7 @@ build:
3647
# https://stackoverflow.com/questions/26564825/what-is-the-meaning-of-a-double-dollar-sign-in-bash-makefile
3748
run:
3849
[ "$$(docker ps -a | grep $(DOCKER_CONTAINER))" ] && docker stop $(DOCKER_CONTAINER) && docker rm $(DOCKER_CONTAINER)
39-
docker run -d --restart=unless-stopped --name $(DOCKER_CONTAINER) -p 7654:80 $(DOCKER_IMG_NAME)
50+
docker run -d --restart=unless-stopped --name $(DOCKER_CONTAINER) -p 80:80 $(DOCKER_IMG_NAME)
4051

4152
debug:
4253
docker run -it $(DOCKER_IMG_NAME) /bin/bash

README.md

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Tools:
2525
- [ruff](https://docs.astral.sh/ruff/)
2626
- [mypy](https://mypy.readthedocs.io/)
2727
- [pytest](https://docs.pytest.org/en/)
28-
- [pip-tools](https://github.com/jazzband/pip-tools)
28+
- [uv](https://github.com/astral-sh/uv)
2929
- [pre-commit](https://pre-commit.com/)
3030
- [prettier](https://prettier.io/)
3131
- [codespell](https://github.com/codespell-project/codespell)
@@ -38,12 +38,12 @@ Install a specific version of the package with `pip`
3838
pip install git+ssh://[email protected]/Komorebi-AI/[email protected]
3939
```
4040

41-
## Install dependencies
41+
## Setup development environment
4242

43-
Create isolated environment with required Python version. This can be done with tools like venv or conda:
43+
Create isolated environment with required Python version. This assumes that you have `conda` installed ([see instructions](https://docs.anaconda.com/free/miniconda/)):
4444

4545
```{bash}
46-
conda create -n python-template python=3.9
46+
make env
4747
```
4848

4949
Then, activate the environment:
@@ -55,34 +55,12 @@ conda activate python-template
5555
Install dependencies:
5656

5757
```{bash}
58-
pip install -r requirements.txt
59-
```
60-
61-
Install package in editable mode:
62-
63-
```{bash}
64-
pip install -e .[dev]
58+
make install
6559
```
6660

6761
Install and run pre-commit hooks:
6862

6963
```{bash}
70-
pre-commit install
71-
pre-commit run --all-files
72-
```
73-
74-
Alternatively, you can use the included `env.yml` file that performs all the previous steps (except the pre-commit hooks):
75-
76-
```{bash}
77-
conda env create -f env.yml
78-
```
79-
80-
or `make`
81-
82-
```{bash}
83-
make env
84-
conda activate python-template
85-
make install
8664
make hooks
8765
```
8866

@@ -91,33 +69,29 @@ make hooks
9169
The `requirements.txt` is generated automatically with `pip-tools` and it should not be edited manually. Add abstract dependencies to `requirements.in` and `requirements-dev.in`. If necessary, add version requirements but try to be as flexible as possible. Then, update the `requirements.txt` file with:
9270

9371
```{bash}
94-
pip-compile --extra dev pyproject.toml
72+
make compile
9573
```
9674

97-
If you want to pin separately production and dev dependencies you can use instead:
75+
Sync the local environment with the `requirements-dev.txt` file:
9876

9977
```{bash}
100-
pip-compile pyproject.toml
78+
make sync
10179
```
10280

103-
And:
81+
## Run linter and formatter
10482

10583
```{bash}
106-
pip-compile --extra dev -o requirements-dev.txt -c requirements.txt pyproject.toml
84+
make ruff
10785
```
10886

109-
Or simply:
87+
## Run tests
11088

11189
```{bash}
112-
make compile
90+
make test
11391
```
11492

115-
Flag `-c` constrains the `dev` dependencies to be the same exact versions as the production dependencies. `pip-tools` also has a `pip-sync` command to make sure that the local environment is in sync with the `requirements.txt` or `requirements-dev.txt` file:
93+
## Run type checker
11694

11795
```{bash}
118-
make sync
96+
make mypy
11997
```
120-
121-
## Run tests
122-
123-
- Run tests: `python -m pytest`

env.yml

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

pyproject.toml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
6-
requires-python = ">=3.11,<3.12"
6+
requires-python = ">=3.9,<3.12"
77
name = "template"
88
# La versión se obtiene automáticamente de git con `setuptools_scm`
99
#version = "0.1.0"
@@ -30,8 +30,8 @@ optional-dependencies.dev = { file = ["requirements-dev.in"] }
3030

3131
[tool.ruff]
3232
line-length = 88
33-
target-version = "py311"
34-
lint.select = [
33+
[tool.ruff.lint]
34+
select = [
3535
"E", # pycodestyle
3636
"F", # Pyflakes
3737
"UP", # pyupgrade
@@ -49,22 +49,14 @@ lint.select = [
4949

5050
# Ignore D100 Missing docstring in public module
5151
ignore = ["D100"]
52-
[tool.ruff.per-file-ignores]
52+
[tool.ruff.lint.per-file-ignores]
5353
# Also ignore `D104` in all `__init__.py` files.
5454
"__init__.py" = ["D104"]
5555
"tests/*.py" = ["D"]
5656

5757
[tool.ruff.lint.pydocstyle]
5858
convention = "numpy"
5959

60-
[tool.pytest.ini_options]
61-
minversion = "7"
62-
testpaths = ["tests"]
63-
log_cli_level = "INFO"
64-
xfail_strict = true
65-
addopts = ["-ra", "--strict-config", "--strict-markers"]
66-
filterwarnings = ["error", "ignore::DeprecationWarning"]
67-
6860
[tool.mypy]
6961
files = "./template"
7062
strict = true
@@ -73,5 +65,14 @@ ignore_missing_imports = true
7365
python_version = "3.11"
7466
warn_return_any = true
7567
warn_unused_configs = true
76-
allow_untyped_decorators = true
7768
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
69+
70+
[tool.pytest.ini_options]
71+
minversion = "7"
72+
testpaths = ["tests"]
73+
log_cli_level = "INFO"
74+
xfail_strict = true
75+
addopts = ["-ra", "--strict-config", "--strict-markers"]
76+
filterwarnings = ["error", "ignore::DeprecationWarning"]
77+
78+

requirements-dev.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pip-tools
1+
uv
22
pytest
33
ruff
44
mypy

0 commit comments

Comments
 (0)