Skip to content

Commit

Permalink
Poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
mwiencek committed Nov 30, 2024
1 parent 7a54ffc commit 14d0108
Show file tree
Hide file tree
Showing 11 changed files with 510 additions and 43 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,18 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Add ~/.local/bin to PATH
run: echo "PATH=$HOME/.local/bin:$PATH" >> $GITHUB_ENV
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
python -m pip install --user 'pipx==1.7.1'
pipx install 'poetry==1.8.3'
poetry install
- name: Run flake8
run: |
. .venv/bin/activate
flake8 *.py tests/*.py --count --show-source --statistics
poetry run flake8 *.py tests/*.py --count --show-source --statistics
- name: Run tests
run: |
. .venv/bin/activate
cp config.tests.example.ini config.tests.ini
export PGHOST=localhost
export PGPORT=5432
Expand Down
14 changes: 9 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ RUN useradd --create-home --shell /bin/bash art

WORKDIR /home/art/artwork-indexer

COPY --chown=art:art requirements.txt ./
COPY --chown=art:art pyproject.toml poetry.lock ./

RUN chown art:art /home/art/artwork-indexer && \
apt-get update && \
apt-get install \
--no-install-recommends \
--no-install-suggests \
-y \
build-essential \
# build-essential \
sudo && \
pip install --upgrade pip && \
sudo -E -H -u art pip install --user -r requirements.txt && \
apt-get purge --auto-remove -y build-essential && \
# Explicit references to /usr/local/bin/python are used in case the
# Ubuntu-packaged Python 3.10 is temporarily installed via
# build-essential.
sudo -E -H -u art /usr/local/bin/python -m pip install --user --no-warn-script-location 'pipx==1.7.1' && \
sudo -E -H -u art env PATH="/home/art/.local/bin:$PATH" pipx install --python /usr/local/bin/python 'poetry==1.8.3' && \
sudo -E -H -u art env PATH="/home/art/.local/bin:$PATH" poetry install && \
# apt-get purge --auto-remove -y build-essential && \
rm -rf /var/lib/apt/lists/*

COPY --chown=art:art \
Expand Down
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Succesor to the old, Perl-and-RabbitMQ-based
## Requirements

* Python >= 3.12
* [Poetry](https://python-poetry.org/) >= 1.8.0
* PostgreSQL >= 12

You will need a MusicBrainz database. See the `INSTALL.md` document of the
Expand All @@ -24,31 +25,24 @@ project for more details.

## Installation

1. Create a [virtual environment](https://docs.python.org/3/library/venv.html)
and activate it. For example:
1. Install project dependencies with `poetry`:

```sh
python3 -m venv .venv
. .venv/bin/activate.fish # I use fish shell
poetry install
```

2. Install dependencies:
```sh
pip install -r requirements.txt
```

3. Copy `config.default.ini` to `config.ini` and edit appropriately.

4. Install the `artwork_indexer` schema, plus associated functions and
triggers. (This will use the database configured in `config.ini`.)

```sh
python indexer.py --setup-schema
poetry run python indexer.py --setup-schema
```

5. Run `indexer.py`:
```sh
python indexer.py
poetry run python indexer.py
```

## Testing
Expand Down
2 changes: 1 addition & 1 deletion create_test_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ fi
$DROPDB_COMMAND --if-exists musicbrainz_test_artwork_indexer
createdb -O musicbrainz -T musicbrainz_test -U "$POSTGRES_SUPERUSER" musicbrainz_test_artwork_indexer

python indexer.py --config=config.tests.ini --setup-schema
poetry run python indexer.py --config=config.tests.ini --setup-schema
4 changes: 3 additions & 1 deletion docker/artwork-indexer
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

cd /home/art/artwork-indexer

exec sudo -E -H -u art python indexer.py
export PATH="/home/art/.local/bin:$PATH"

exec sudo -E -H -u art poetry run python indexer.py
461 changes: 461 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[tool.poetry]
name = "artwork-indexer"
version = "2024.11.30"
description = "A daemon that updates index.json and other metadata files at the CAA and EAA"
license = "GPL-2.0-or-later"
readme = "README.md"
classifiers = ["Private :: Do Not Upload"]
package-mode = false

[tool.poetry.dependencies]
python = "^3.12"
requests = "2.31.0"
sentry-sdk = "1.39.2"
psycopg = {version = "3.1.18", extras = ["binary"]}

[tool.poetry.group.dev.dependencies]
flake8 = "7.0.0"
coverage = "7.4.1"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
15 changes: 0 additions & 15 deletions requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ cd "$(dirname "${BASH_SOURCE[0]}")"
./tests/test_concurrency.sh
./tests/test_signals.sh

exec coverage run -m unittest discover . "test_*.py"
exec poetry run coverage run -m unittest discover . "test_*.py"
2 changes: 1 addition & 1 deletion tests/test_concurrency.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ EOF
psql -U musicbrainz -d musicbrainz_test_artwork_indexer -c "$SQL" -q > /dev/null

run_indexer() {
python indexer.py \
poetry run python indexer.py \
--max-wait=1 \
--max-idle-loops=1 \
--config=config.tests.ini 2>&1
Expand Down
2 changes: 1 addition & 1 deletion tests/test_signals.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ EOF
psql -U musicbrainz -d musicbrainz_test_artwork_indexer -c "$SQL" -q > /dev/null

run_indexer() {
exec python indexer.py \
exec poetry run python indexer.py \
--max-wait=1 \
--config=config.tests.ini
}
Expand Down

0 comments on commit 14d0108

Please sign in to comment.