Skip to content

Commit

Permalink
PyPi Setup (#37)
Browse files Browse the repository at this point in the history
* Updated app-release action

* Got tests working locally

* Updated test CI

* WIP - set up dev dockerfile

* Reverted pytest shenanigans

* Create a script to consolidate version bumping

* Added new pypi actions file

* Added pip install to 'prod' dockerfile
  • Loading branch information
moleculekayak authored Dec 20, 2024
1 parent 56c4a18 commit 46e5555
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/app-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Build Artifacts
run: zip -r fertilizer.zip src main.py requirements.txt
run: zip -r fertilizer.zip src pyproject.toml
- name: Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --trusted-host pypi.python.org -r requirements.txt
pip install uv
uv pip install -r pyproject.toml --system --all-extras
uv pip install -e . --system
- name: Lint with Ruff
run: ruff check
- name: Check formatting with Ruff
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/pypi-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Publish Python distribution to PyPI and TestPyPI

on:
release:
types:
- published
workflow_dispatch:

jobs:
build:
name: Build distribution
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/fertilizer
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install pypa/build
run: python3 -m pip install build twine --user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ FROM python:3.11-slim-buster

WORKDIR /app

COPY pyproject.toml docker_start ./
COPY src src
COPY docker_start ./

RUN apt-get update \
&& echo "----- Installing python requirements" \
&& pip install --trusted-host pypi.python.org . \
&& pip install fertilizer \
&& echo "----- Preparing directories" \
&& mkdir /config /data /torrents \
&& echo "----- Cleanup" \
Expand Down
21 changes: 21 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.11-slim-buster

WORKDIR /app

COPY pyproject.toml docker_start ./
COPY src src

RUN apt-get update \
&& echo "----- Installing python requirements" \
&& pip install uv \
&& uv pip install -r pyproject.toml --system --all-extras \
&& uv pip install -e . --system \
&& echo "----- Preparing directories" \
&& mkdir /config /data /torrents \
&& echo "----- Cleanup" \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

EXPOSE 9713

ENTRYPOINT ["./docker_start"]
20 changes: 20 additions & 0 deletions bump-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# Get current version from pyproject.toml
CURRENT_VERSION=$(grep "^version = " pyproject.toml | sed "s/^version = \"\(.*\)\"/\1/g")
# Get the new version from stdin
NEW_VERSION=$1

echo "Bumping from $CURRENT_VERSION to $NEW_VERSION"

# Check that the user wants to continue. exit if not
read -p "Continue? (y/n) " -n 1 -r
echo # move to a new line

if [[ $REPLY =~ ^[Yy]$ ]]; then
# Update the version in the pyproject.toml file
sed -i "" "s/^version = \".*\"/version = \"$NEW_VERSION\"/g" "pyproject.toml"

# Set the git tag
git tag "v$NEW_VERSION"
fi
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ services:
fertilizer:
build:
context: .
dockerfile: ./Dockerfile
dockerfile: ./Dockerfile.dev
volumes:
- '.:/app'
ports:
Expand Down
14 changes: 4 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,19 @@ dependencies = [
"bencoder",
"colorama",
"requests",
"flask",
"pytest",
"requests-mock",
"ruff",
"flask"
]

[project.optional-dependencies]
dev = ["pytest", "ruff", "requests-mock"]

[project.scripts]
fertilizer = "fertilizer.main:main"

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[dependency-groups]
dev = [
"pytest",
"requests-mock",
]

[tool.ruff]
line-length = 120
indent-width = 2
Expand Down
18 changes: 5 additions & 13 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 46e5555

Please sign in to comment.