Skip to content

Commit 054e331

Browse files
author
Gonzalo Diaz
committed
first try
1 parent a1ac5e1 commit 054e331

9 files changed

Lines changed: 911 additions & 23 deletions

File tree

.github/workflows/python-coverage.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ env:
1515
jobs:
1616
coverage:
1717
name: "Python CI Coverage"
18-
strategy:
19-
fail-fast: false
20-
matrix:
21-
os: ["ubuntu-24.04"]
22-
python: ["3.14"]
23-
runs-on: ${{ matrix.os }}
18+
runs-on: ubuntu-24.04
2419
steps:
2520
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
2621
with:
@@ -30,11 +25,22 @@ jobs:
3025
- name: Setup Python
3126
uses: actions/setup-python@master
3227
with:
33-
python-version: ${{ matrix.python }}
28+
python-version: 3.14
29+
30+
- name: Install tooling
31+
run: >
32+
sudo apt install pipenv
33+
34+
- name: Tooling check
35+
run: |
36+
python3 --version
37+
pipenv --version
38+
make --version
3439
3540
- name: Install
3641
run: |
37-
pip3 install -r requirements.txt
42+
# Use the lockfile to install deterministic, audited dependencies
43+
pipenv sync --dev
3844
3945
- name: Test an coverage collect
4046
run: >

.github/workflows/python-lint.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,35 @@ jobs:
2626
with:
2727
python-version: ${{ matrix.python }}
2828

29+
- name: Install tooling on Ubuntu
30+
if: runner.os == 'Linux'
31+
run: |
32+
sudo apt-get update
33+
sudo apt-get install -y pipenv
34+
shell: bash
35+
36+
- name: Install tooling on macOS
37+
if: runner.os == 'macOS'
38+
run: |
39+
brew install pipenv
40+
shell: bash
41+
42+
- name: Install tooling on Windows
43+
if: runner.os == 'Windows'
44+
run: |
45+
choco install pipenv -y
46+
shell: pwsh
47+
48+
- name: Tooling check
49+
run: |
50+
python3 --version
51+
pipenv --version
52+
make --version
53+
2954
- name: Install
3055
run: |
31-
pip3 install -r requirements.txt
56+
# Use the lockfile to install deterministic, audited dependencies
57+
pipenv sync --dev
3258
3359
- name: Lint (pylint)
3460
run: |

.github/workflows/python-test.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,35 @@ jobs:
2929
with:
3030
python-version: ${{ matrix.python }}
3131

32+
- name: Install tooling on Ubuntu
33+
if: runner.os == 'Linux'
34+
run: |
35+
sudo apt-get update
36+
sudo apt-get install -y pipenv
37+
shell: bash
38+
39+
- name: Install tooling on macOS
40+
if: runner.os == 'macOS'
41+
run: |
42+
brew install pipenv
43+
shell: bash
44+
45+
- name: Install tooling on Windows
46+
if: runner.os == 'Windows'
47+
run: |
48+
choco install pipenv -y
49+
shell: pwsh
50+
51+
- name: Tooling check
52+
run: |
53+
python3 --version
54+
pipenv --version
55+
make --version
56+
3257
- name: Install
3358
run: |
34-
pip3 install -r requirements.txt
59+
# Use the lockfile to install deterministic, audited dependencies
60+
pipenv sync --dev
3561
3662
- name: Test
3763
run: >

.github/workflows/yamllint.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,17 @@ jobs:
1717
- name: Checkout repository
1818
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
1919

20+
- name: Set up Python
21+
uses: actions/setup-python@v6
22+
with:
23+
python-version: 3.14
24+
25+
- name: Install pipenv
26+
run: >
27+
sudo apt install pipenv
2028
- name: Install yamllint
21-
run: pip install yamllint
29+
run: >
30+
pipenv sync --dev
2231
2332
- name: Lint YAML files
2433
run: >

Makefile

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ BRUTEFORCE :=$(shell echo '${BRUTEFORCE}'| tr '[:lower:]' '[:upper:]'| tr -d '[:
2727
.EXPORT_ALL_VARIABLES: # (2)
2828

2929
RUNTIME_TOOL=python3
30-
PACKAGE_TOOL=pip3
30+
PACKAGE_TOOL=pipenv
3131

3232
# DOCKER
3333
BUILDKIT_PROGRESS=plain
@@ -36,11 +36,10 @@ DOCKER_COMPOSE=docker compose
3636
help: list
3737
@echo ""
3838
@echo "Note: create and activate the environment in your local shell type (example):"
39-
@echo " python3 -m venv ./.venv"
40-
@echo " source .venv/bin/activate"
39+
@echo " pipenv install --dev"
40+
@echo " pipenv shell"
4141
@echo "See: "
42-
@echo " https://docs.python.org/3/library/venv.html#creating-virtual-environments"
43-
@echo " https://docs.python.org/3/library/venv.html#how-venvs-work"
42+
@echo " https://pipenv.pypa.io/en/latest/"
4443

4544
list:
4645
@LC_ALL=C $(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$'
@@ -65,20 +64,20 @@ dependencies:
6564
@echo "################################################################################"
6665
@echo "## Dependencies: ###############################################################"
6766
@echo "################################################################################"
68-
${PACKAGE_TOOL} install -r requirements.txt
67+
${PACKAGE_TOOL} install --dev
6968
@echo "################################################################################"
7069

7170
outdated:
72-
${PACKAGE_TOOL} list --outdated
71+
${PACKAGE_TOOL} update --outdated
7372

7473
update:
75-
${PACKAGE_TOOL} freeze > requirements.txt
74+
${PACKAGE_TOOL} lock --requirements > requirements.txt
7675

7776
upgrade:
78-
${PACKAGE_TOOL} list --outdated | cut -f1 -d' ' | tr " " "\n" | awk '{if(NR>=3)print}' | cut -d' ' -f1 | xargs -n1 pip3 install -U
77+
${PACKAGE_TOOL} update --dev
7978

8079
clean:
81-
${PACKAGE_TOOL} freeze > unins ; ${PACKAGE_TOOL} uninstall -y -r unins ; rm unins
80+
${PACKAGE_TOOL} --rm || true
8281
rm -f .coverage
8382
rm -fr .pytest_cache
8483
rm -fr htmlcov

PIPENV_MIGRATION.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Migración a Pipenv
2+
3+
## Resumen
4+
5+
El proyecto ha sido migrado de usar `requirements.txt` con `pip` a usar `pipenv` para la gestión de dependencias. Esto proporciona:
6+
7+
-**Lock-file reproducible**: `Pipfile.lock` asegura versiones exactas y reproducibles
8+
-**Separación clara**: Dependencias de producción vs desarrollo
9+
-**Mejor seguridad**: Detección automática de vulnerabilidades
10+
-**Gestión simplificada**: Un archivo de configuración único
11+
12+
## Archivos Modificados
13+
14+
### Nuevos archivos:
15+
- **`Pipfile`** - Definición de dependencias y configuración del proyecto
16+
- **`Pipfile.lock`** - Lock-file con versiones exactas resueltas (DEBE estar en control de versiones)
17+
18+
### Archivos actualizados:
19+
- **`Makefile`** - Todos los comandos de pip3 han sido reemplazados por pipenv
20+
- **`Dockerfile`** - Instalación de pipenv y uso de Pipfile/Pipfile.lock
21+
- **`.gitignore`** - Sin cambios (ya tenía configuración adecuada para pipenv)
22+
23+
### Archivo deprecado (pero mantenido para compatibilidad):
24+
- **`requirements.txt`** - Ya no es necesario, pero se mantiene como referencia
25+
26+
## Instalación
27+
28+
### Primera vez (local):
29+
30+
```bash
31+
# Instalar pipenv si no lo tienes
32+
pip3 install pipenv
33+
34+
# Desde el directorio del proyecto
35+
pipenv install --dev
36+
```
37+
38+
### Activar el ambiente virtual:
39+
40+
```bash
41+
pipenv shell
42+
```
43+
44+
O ejecutar comandos dentro del ambiente sin activarlo:
45+
46+
```bash
47+
pipenv run python3 script.py
48+
```
49+
50+
## Comandos Principales
51+
52+
```bash
53+
# Instalar dependencias (después de cambios en Pipfile)
54+
make install
55+
# o
56+
pipenv install --dev
57+
58+
# Actualizar todas las dependencias
59+
make upgrade
60+
61+
# Verificar dependencias obsoletas
62+
make update
63+
64+
# Limpiar el ambiente
65+
make clean
66+
67+
# Ejecutar tests
68+
make test
69+
70+
# Ejecutar linting
71+
make lint
72+
73+
# Cobertura
74+
make coverage
75+
```
76+
77+
## Cambios en el Makefile
78+
79+
| Comando antiguo | Comando nuevo |
80+
|---|---|
81+
| `pip3 install -r requirements.txt` | `pipenv install --dev` |
82+
| `pip3 list --outdated` | `pipenv check` |
83+
| `pip3 freeze > requirements.txt` | `pipenv update` |
84+
| `python3 -m pytest` | `pipenv run python3 -m pytest` |
85+
86+
## Docker
87+
88+
El Dockerfile ha sido actualizado para:
89+
1. Instalar pipenv en la imagen base
90+
2. Usar `Pipfile` y `Pipfile.lock` en lugar de `requirements.txt`
91+
3. Ejecutar `make dependencies` que ahora usa pipenv
92+
93+
```bash
94+
# Construir imagen
95+
docker compose build
96+
97+
# Ejecutar tests en contenedor
98+
docker compose run --rm algorithm-exercises-py-test make test
99+
```
100+
101+
## Beneficios
102+
103+
### Reproducibilidad
104+
- El `Pipfile.lock` contiene exactamente las versiones que fueron instaladas
105+
- Cualquiera que clone el proyecto obtendrá exactamente las mismas versiones
106+
107+
### Seguridad
108+
```bash
109+
pipenv check # Detecta vulnerabilidades conocidas
110+
```
111+
112+
### Gestión de dependencias
113+
```bash
114+
pipenv update package_name # Actualizar paquete específico
115+
pipenv graph # Ver árbol de dependencias
116+
pipenv requirements # Generar requirements.txt si es necesario
117+
```
118+
119+
### Desarrollo
120+
- Dependencias de desarrollo separadas en `[dev-packages]`
121+
- Fácil colaboración sin instalar herramientas innecesarias
122+
123+
## Migración desde requirements.txt
124+
125+
Si necesitas volver a generar `Pipfile` desde un `requirements.txt`:
126+
127+
```bash
128+
# Borrar Pipfile y Pipfile.lock actuales
129+
rm Pipfile Pipfile.lock
130+
131+
# Generar nuevos desde requirements.txt
132+
pipenv install --requirements requirements.txt
133+
134+
# Luego regenerar lock
135+
pipenv lock
136+
```
137+
138+
## Referencias
139+
140+
- [Documentación de Pipenv](https://pipenv.pypa.io/)
141+
- [Guía de instalación](https://pipenv.pypa.io/en/latest/install.html)
142+
- [Workflows comunes](https://pipenv.pypa.io/en/latest/workflows.html)

Pipfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
8+
[dev-packages]
9+
yamllint = "==1.32.0"
10+
astroid = "==4.0.3"
11+
attrs = "==26.1.0"
12+
autopep8 = "==2.3.2"
13+
coverage = "==7.13.5"
14+
dill = "==0.4.1"
15+
exceptiongroup = "==1.3.1"
16+
flake8 = "==7.3.0"
17+
iniconfig = "==2.3.0"
18+
isort = "==8.0.1"
19+
lazy-object-proxy = "==1.12.0"
20+
mccabe = "==0.7.0"
21+
nodeenv = "==1.10.0"
22+
packaging = "==26.2"
23+
platformdirs = "==4.9.6"
24+
pluggy = "==1.6.0"
25+
pycodestyle = "==2.14.0"
26+
pyflakes = "==3.4.0"
27+
pylint = "==4.0.5"
28+
pyright = "==1.1.409"
29+
pytest = "==9.0.3"
30+
pytest-cov = "==7.1.0"
31+
tomli = "==2.4.1"
32+
tomlkit = "==0.14.0"
33+
typing-extensions = "==4.15.0"
34+
wrapt = "==2.1.2"
35+
zipp = ">=3.23.1"
36+
37+
[requires]
38+
python_version = "3.12"

0 commit comments

Comments
 (0)