Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyPi Setup #37

Merged
merged 8 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +25 to +26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if you use uv sync ., you can avoid the pythonpath shenanigans for pytest.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That didn't work immediately, but it looks like uv pip install -e . --system did! Good enough for me

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, I think because you want a system-wide installation. uv sync creates a virtual environment at $PWD/.venv.

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
Comment on lines +1 to +20
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't be bothered to set up a gh action to bump versions so instead I'll run this locally and it'll handle all the bumping required

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.

Loading