Skip to content

Commit

Permalink
Merge pull request #8 from bensteinberg/switch-to-poetry
Browse files Browse the repository at this point in the history
Switch to Poetry, update OS
  • Loading branch information
bensteinberg authored Apr 19, 2024
2 parents da63874 + 4a28794 commit 99dc597
Show file tree
Hide file tree
Showing 11 changed files with 1,767 additions and 387 deletions.
6 changes: 1 addition & 5 deletions setup.cfg → .flake8
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
## http://pytest.org/latest/customize.html#adding-default-options
[tool:pytest]
addopts = --cov-report term-missing --cov --cov-fail-under=100 --flake8

## http://flake8.pycqa.org/en/latest/user/configuration.html
[flake8]
ignore = E266,
E501,
# default ignore list via `flake8 --help`
E121,E123,E126,E226,E24,E704,W503,W504
exclude = .git,test_assets
exclude = .git,test_assets
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
shell: 'script -q -e -c "bash --noprofile --norc -eo pipefail {0}"' # avoid docker-compose "the input device is not a TTY" -- see https://github.com/actions/runner/issues/241#issuecomment-842566950
run: |
docker compose up -d
docker compose exec web flake8
docker compose exec -d web bash -c "service clamav-daemon start && service clamav-freshclam start && uvicorn main:app --reload --host 0.0.0.0"
sleep 25
docker compose exec web pytest
674 changes: 674 additions & 0 deletions COPYING

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.lil.tools/library/python:3.9-bullseye
FROM registry.lil.tools/library/python:3.11-bookworm
ENV PYTHONUNBUFFERED 1
ENV UVICORN_PORT 8000

Expand All @@ -14,7 +14,7 @@ RUN freshclam
RUN mkdir /app
WORKDIR /app
COPY requirements.txt /app
RUN pip install pip==23.1.2 \
RUN pip install pip==24.0 \
&& pip install -r requirements.txt --src /usr/local/src \
&& rm requirements.txt

Expand Down
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,32 @@ Microservice to check files for expected file type, extension, and antivirus.

## Local install

$ docker-compose up
$ docker-compose exec web bash
docker compose up
docker compose exec web bash

Commands starting with `#` are run inside `docker-compose exec web bash`.
Commands starting with `#` are run inside `docker compose exec web bash`.

## Local development

Start the web server:

# uvicorn main:app --reload --host 0.0.0.0

Check a file:

$ curl -F 'file=@test_assets/test.gif' http://127.0.0.1:8000/scan/
curl -F 'file=@test_assets/test.gif' http://127.0.0.1:8000/scan/
{"safe":true}

Add a dependency:

* edit requirements.in
* run `pip-compile --allow-unsafe --generate-hashes`
Add a dependency; it's essential to update `requirements.txt`, as that's what's used to build the Docker image:

poetry add <packagename>
poetry export -o requirements.txt
docker compose up -d --build # to reinstall requirements in the container

Run tests:
Run lints and tests:

pytest
docker compose exec web flake8
docker compose exec web pytest

Tests will fail if test coverage goes below 100%.

Expand Down
Empty file removed conftest.py
Empty file.
5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
version: '2'
services:
web:
build:
context: .
args:
clamav-cache-buster: 44FFAF5C-F799-4F20-854D-54E521D503A7
image: registry.lil.tools/harvardlil/perma-filecheck:0.100
clamav-cache-buster: 1138a94d-acad-4372-ac08-7e767e8d929b
image: registry.lil.tools/harvardlil/perma-filecheck:0.101
volumes:
- .:/app
command: ["/bin/bash"]
Expand Down
735 changes: 735 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[tool.poetry]
name = "perma-filecheck"
license = "GPL-3.0-or-later"
package-mode = false

[tool.poetry.dependencies]
python = "^3.9"
fastapi = "^0.110.1"
uvicorn = "^0.29.0"
python-multipart = "^0.0.9"
filetype = "^1.2.0"
python-dateutil = "^2.9.0.post0"
pytest = "^8.1.1"
pytest-cov = "^5.0.0"
requests = "^2.31.0"
httpx = "^0.27.0"
flake8 = "^7.0.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
addopts = "--cov-report term-missing --cov --cov-fail-under=100"
18 changes: 0 additions & 18 deletions requirements.in

This file was deleted.

663 changes: 315 additions & 348 deletions requirements.txt

Large diffs are not rendered by default.

0 comments on commit 99dc597

Please sign in to comment.