Skip to content

Commit

Permalink
Switch to pipenv
Browse files Browse the repository at this point in the history
The requirements-tools project, while nice, has been abandoned by Yelp
for ages. A good approach for applications is pipenv, which can lock
dependencies in the same way requirements-tools. Let's switch to this.
By managing pre-commit in the pipenv development environment, we can
ensure that the hooks run the same locally as they do in CI as well.

Signed-off-by: Stephen Brennan <[email protected]>
  • Loading branch information
brenns10 committed Nov 13, 2024
1 parent 2bddc64 commit e4de10d
Show file tree
Hide file tree
Showing 11 changed files with 849 additions and 61 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ jobs:
with:
python-version: '3.13'
- name: Install pre-commit and mypy
run: pip install pre-commit && make dev
run: pip install pipenv && make dev
- name: Run pre-commit hooks
run: pre-commit run --all-files --show-diff-on-failure
run: .venv/bin/pre-commit run --all-files --show-diff-on-failure
7 changes: 4 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install gzip bzip2 xz-utils zstd tar rpm cpio dpkg make
pip install pipenv
make venv
- name: Checkout gh-pages and setup git
run: |
Expand All @@ -36,12 +37,12 @@ jobs:
git config --global user.email '[email protected]'
- name: Fetch updates and build page
run: |
venv/bin/python -m kconfigs.main config.ini \
.venv/bin/python -m kconfigs.main config.ini \
--state ../gh-pages/state.json \
--output-dir ../gh-pages/out
venv/bin/python -m kconfigs.cleanup config.ini \
.venv/bin/python -m kconfigs.cleanup config.ini \
--input-dir ../gh-pages/out
venv/bin/python -m kconfigs.analyzer config.ini \
.venv/bin/python -m kconfigs.analyzer config.ini \
--input-dir ../gh-pages/out \
--output-file ../gh-pages/docs/summary.json
cp index.html tux-sm.png ../gh-pages/docs/
Expand Down
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
exclude: "^.*.json|.*/config"
Expand All @@ -12,29 +12,29 @@ repos:
- id: check-added-large-files
exclude: "^.*.json|.*/config"
- repo: https://github.com/psf/black
rev: "23.7.0"
rev: "24.10.0"
hooks:
- id: black
args: [--line-length=80, --exclude=setup.py]
- repo: https://github.com/pycqa/flake8
rev: "6.1.0"
rev: "7.1.1"
hooks:
- id: flake8
- repo: local
hooks:
- id: mypy
name: mypy
entry: venv/bin/mypy
entry: .venv/bin/mypy
language: system
args: [--strict, --disallow-untyped-calls]
files: "^.*.py$"
verbose: true
- repo: https://github.com/asottile/reorder_python_imports
rev: v3.10.0
rev: v3.14.0
hooks:
- id: reorder-python-imports
- repo: https://github.com/netromdk/vermin
rev: v1.5.2
rev: v1.6.0
hooks:
- id: vermin
args: ['-t=3.11-', '--violations', '--eval-annotations']
20 changes: 9 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,21 @@ PYTHON ?= python3.13

.PHONY: venv
venv:
rm -rf venv
$(PYTHON) -m venv venv
venv/bin/pip install -r requirements.txt
@mkdir -p .venv # ensure that pipenv sees .venv
$(PYTHON) -m pipenv install

.PHONY: run
run:
venv/bin/python -m kconfigs.main config.ini
venv/bin/python -m kconfigs.cleanup config.ini
venv/bin/python -m kconfigs.analyzer config.ini
.venv/bin/python -m kconfigs.main config.ini
.venv/bin/python -m kconfigs.cleanup config.ini
.venv/bin/python -m kconfigs.analyzer config.ini

.PHONY: dev
dev:
rm -rf venv
$(PYTHON) -m venv venv
venv/bin/pip install -r requirements.txt -r requirements-dev.txt
pre-commit install --install-hooks
@mkdir -p .venv # ensure that pipenv sees .venv
$(PYTHON) -m pipenv install --dev
.venv/bin/pre-commit install --install-hooks

.PHONY: upgrade-requirements
upgrade-requirements:
venv/bin/upgrade-requirements
$(PYTHON) -m pipenv upgrade
18 changes: 18 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
aiohttp = "*"
aiofiles = "*"
aiosqlite = "*"

[dev-packages]
mypy = "*"
ptpython = "*"
types-aiofiles = "*"
pre-commit = "*"

[requires]
python_version = "3.13"
808 changes: 808 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions kconfigs/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async def download_file(
async with self.sem:
try:
print(
f"Download {url} to {file} [try {i+1}/{self.RETRIES}]"
f"Download {url} to {file} [try {i + 1}/{self.RETRIES}]"
)
async with self.session.get(url) as resp, aiofiles.open(
file, "wb"
Expand Down Expand Up @@ -106,7 +106,7 @@ async def download_file_mem(
out = io.BytesIO()
try:
async with self.sem, self.session.get(url) as resp:
print(f"Download {url} to mem [try {i+1}/{self.RETRIES}]")
print(f"Download {url} to mem [try {i + 1}/{self.RETRIES}]")
async for chunk in resp.content.iter_chunked(4096):
if checksum:
h.update(chunk)
Expand Down
4 changes: 0 additions & 4 deletions requirements-dev-minimal.txt

This file was deleted.

19 changes: 0 additions & 19 deletions requirements-dev.txt

This file was deleted.

3 changes: 0 additions & 3 deletions requirements-minimal.txt

This file was deleted.

11 changes: 0 additions & 11 deletions requirements.txt

This file was deleted.

0 comments on commit e4de10d

Please sign in to comment.