From a28772c93f73aa2dcb79a6edff99b4f89cffa371 Mon Sep 17 00:00:00 2001 From: moleculekayak Date: Thu, 19 Dec 2024 10:26:31 -0800 Subject: [PATCH 1/8] Updated app-release action --- .github/workflows/app-release.yml | 2 +- pyproject.toml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/app-release.yml b/.github/workflows/app-release.yml index 40b4b369..a5a553da 100644 --- a/.github/workflows/app-release.yml +++ b/.github/workflows/app-release.yml @@ -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/') diff --git a/pyproject.toml b/pyproject.toml index 8f174104..4481dfff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,12 +8,12 @@ dependencies = [ "bencoder", "colorama", "requests", - "flask", - "pytest", - "requests-mock", - "ruff", + "flask" ] +[project.optional-dependencies] +dev = ["pytest", "ruff", "requests-mock"] + [project.scripts] fertilizer = "fertilizer.main:main" From 3f96d2ffe005743aca9625f6ec121707db12f6fa Mon Sep 17 00:00:00 2001 From: moleculekayak Date: Thu, 19 Dec 2024 10:49:09 -0800 Subject: [PATCH 2/8] Got tests working locally --- Dockerfile | 3 ++- pyproject.toml | 7 ++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 00981295..0c0bd30c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,8 @@ COPY src src RUN apt-get update \ && echo "----- Installing python requirements" \ - && pip install --trusted-host pypi.python.org . \ + && pip install uv \ + && uv pip install -r pyproject.toml --system --all-extras \ && echo "----- Preparing directories" \ && mkdir /config /data /torrents \ && echo "----- Cleanup" \ diff --git a/pyproject.toml b/pyproject.toml index 4481dfff..2009b61e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,11 +21,8 @@ fertilizer = "fertilizer.main:main" requires = ["setuptools"] build-backend = "setuptools.build_meta" -[dependency-groups] -dev = [ - "pytest", - "requests-mock", -] +[tool.pytest.ini_options] +pythonpath = "src" [tool.ruff] line-length = 120 From b2628daae35e89dfa6ab7c4b49756b82f8974b14 Mon Sep 17 00:00:00 2001 From: moleculekayak Date: Thu, 19 Dec 2024 10:50:02 -0800 Subject: [PATCH 3/8] Updated test CI --- .github/workflows/lint-and-test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index 652d2f62..cc7a1723 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -22,7 +22,8 @@ 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 - name: Lint with Ruff run: ruff check - name: Check formatting with Ruff From e4be04c24be5e83e60781df6543490da6637f316 Mon Sep 17 00:00:00 2001 From: moleculekayak Date: Thu, 19 Dec 2024 11:09:39 -0800 Subject: [PATCH 4/8] WIP - set up dev dockerfile --- Dockerfile | 6 ++---- Dockerfile.dev | 21 +++++++++++++++++++++ docker-compose.yaml | 2 +- 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 Dockerfile.dev diff --git a/Dockerfile b/Dockerfile index 0c0bd30c..7bc98df5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,13 +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 uv \ - && uv pip install -r pyproject.toml --system --all-extras \ + # TODO: install fertilizer from pip && echo "----- Preparing directories" \ && mkdir /config /data /torrents \ && echo "----- Cleanup" \ diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 00000000..75b835e3 --- /dev/null +++ b/Dockerfile.dev @@ -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"] diff --git a/docker-compose.yaml b/docker-compose.yaml index f3588eb8..cf294302 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,7 +2,7 @@ services: fertilizer: build: context: . - dockerfile: ./Dockerfile + dockerfile: ./Dockerfile.dev volumes: - '.:/app' ports: From f4ac98e5577f93ce9846f81c6732230cdbc44e60 Mon Sep 17 00:00:00 2001 From: moleculekayak Date: Thu, 19 Dec 2024 11:44:02 -0800 Subject: [PATCH 5/8] Reverted pytest shenanigans --- .github/workflows/lint-and-test.yml | 1 + pyproject.toml | 3 --- uv.lock | 18 +++++------------- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index cc7a1723..add117e2 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -24,6 +24,7 @@ jobs: python -m pip install --upgrade pip 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 diff --git a/pyproject.toml b/pyproject.toml index 2009b61e..9c2540a1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,9 +21,6 @@ fertilizer = "fertilizer.main:main" requires = ["setuptools"] build-backend = "setuptools.build_meta" -[tool.pytest.ini_options] -pythonpath = "src" - [tool.ruff] line-length = 120 indent-width = 2 diff --git a/uv.lock b/uv.lock index c77add16..f6ac68d0 100644 --- a/uv.lock +++ b/uv.lock @@ -108,16 +108,14 @@ dependencies = [ { name = "bencoder" }, { name = "colorama" }, { name = "flask" }, - { name = "pytest" }, { name = "requests" }, - { name = "requests-mock" }, - { name = "ruff" }, ] -[package.dev-dependencies] +[package.optional-dependencies] dev = [ { name = "pytest" }, { name = "requests-mock" }, + { name = "ruff" }, ] [package.metadata] @@ -125,16 +123,10 @@ requires-dist = [ { name = "bencoder" }, { name = "colorama" }, { name = "flask" }, - { name = "pytest" }, + { name = "pytest", marker = "extra == 'dev'" }, { name = "requests" }, - { name = "requests-mock" }, - { name = "ruff" }, -] - -[package.metadata.requires-dev] -dev = [ - { name = "pytest" }, - { name = "requests-mock" }, + { name = "requests-mock", marker = "extra == 'dev'" }, + { name = "ruff", marker = "extra == 'dev'" }, ] [[package]] From ee62ff6f121c186f136090ca2388ad670376d2a3 Mon Sep 17 00:00:00 2001 From: moleculekayak Date: Thu, 19 Dec 2024 12:35:40 -0800 Subject: [PATCH 6/8] Create a script to consolidate version bumping --- bump-version | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 bump-version diff --git a/bump-version b/bump-version new file mode 100755 index 00000000..6a14cf6f --- /dev/null +++ b/bump-version @@ -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 From 04d1ebb8c35418ddc3bcc3e33650b6ffbbfe2d3b Mon Sep 17 00:00:00 2001 From: moleculekayak Date: Thu, 19 Dec 2024 12:49:28 -0800 Subject: [PATCH 7/8] Added new pypi actions file --- .github/workflows/pypi-release.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/pypi-release.yml diff --git a/.github/workflows/pypi-release.yml b/.github/workflows/pypi-release.yml new file mode 100644 index 00000000..376d39fa --- /dev/null +++ b/.github/workflows/pypi-release.yml @@ -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 From 4246d21d4db1b3968b70d91c17d3d8e00bf8fa0c Mon Sep 17 00:00:00 2001 From: moleculekayak Date: Thu, 19 Dec 2024 12:50:43 -0800 Subject: [PATCH 8/8] Added pip install to 'prod' dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7bc98df5..0508be52 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ COPY docker_start ./ RUN apt-get update \ && echo "----- Installing python requirements" \ - # TODO: install fertilizer from pip + && pip install fertilizer \ && echo "----- Preparing directories" \ && mkdir /config /data /torrents \ && echo "----- Cleanup" \