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/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index 652d2f62..add117e2 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -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 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 diff --git a/Dockerfile b/Dockerfile index 00981295..0508be52 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" \ 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/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 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: diff --git a/pyproject.toml b/pyproject.toml index 8f174104..9c2540a1 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" @@ -21,12 +21,6 @@ fertilizer = "fertilizer.main:main" requires = ["setuptools"] build-backend = "setuptools.build_meta" -[dependency-groups] -dev = [ - "pytest", - "requests-mock", -] - [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]]