Skip to content

Commit

Permalink
Replace Poetry with PDM, various linters with Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmayer committed May 27, 2024
1 parent f901db4 commit 72bb7f3
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 166 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
custom: https://donate.getpelican.com
github: justinmayer
liberapay: pelican
98 changes: 41 additions & 57 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,52 @@ on: [push, pull_request]
env:
PYTEST_ADDOPTS: "--color=yes"

jobs:
permissions:
contents: read

jobs:
test:
name: Test - ${{ matrix.python-version }}
name: Test - Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }} & PDM
uses: pdm-project/setup-pdm@v4
with:
python-version: ${{ matrix.python-version }}
- name: Set up Pip cache
uses: actions/cache@v2
id: pip-cache
with:
path: ~/.cache/pip
key: pip-${{ hashFiles('**/pyproject.toml') }}
- name: Upgrade Pip
run: python -m pip install --upgrade pip
- name: Install Poetry
run: python -m pip install poetry
- name: Set up Poetry cache
uses: actions/cache@v2
id: poetry-cache
with:
path: ~/.cache/pypoetry/virtualenvs
key: poetry-${{ hashFiles('**/poetry.lock') }}
cache: true
cache-dependency-path: ./pyproject.toml

- name: Install dependencies
run: |
poetry run pip install --upgrade pip
poetry install
- name: Run tests
run: poetry run invoke tests
run: pdm install

- name: Run tests
run: pdm run invoke tests

lint:
name: Lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"

- name: Set Poetry cache
uses: actions/cache@v2
id: poetry-cache
- name: Set up Python & PDM
uses: pdm-project/setup-pdm@v4
with:
path: ~/.cache/pypoetry/virtualenvs
key: poetry-${{ hashFiles('**/poetry.lock') }}

- name: Install Poetry
run: python -m pip install poetry
python-version: "3.10"
cache: true
cache-dependency-path: ./pyproject.toml

- name: Install dependencies
run: |
poetry install --no-interaction
run: pdm install

- name: Run linters
run: poetry run invoke lint --diff
run: pdm run invoke lint --diff

deploy:
name: Deploy
Expand All @@ -80,29 +59,34 @@ jobs:
runs-on: ubuntu-latest
if: github.ref=='refs/heads/main' && github.event_name!='pull_request'

permissions:
contents: write
id-token: write

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.9"
python-version: "3.10"

- name: Check release
id: check_release
run: |
python -m pip install --upgrade pip
python -m pip install poetry githubrelease httpx==0.18.2 autopub
echo "release=$(autopub check)" >> $GITHUB_OUTPUT
python -m pip install autopub[github]
autopub check
- name: Publish
if: ${{ steps.check_release.outputs.release=='' }}
if: ${{ steps.check_release.outputs.autopub_release=='true' }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git remote set-url origin https://[email protected]/${{ github.repository }}
autopub prepare
poetry build
autopub commit
autopub build
autopub githubrelease
poetry publish -u __token__ -p $PYPI_PASSWORD
- name: Upload package to PyPI
if: ${{ steps.check_release.outputs.autopub_release=='true' }}
uses: pypa/gh-action-pypi-publish@release/v1
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
poetry.lock
.pdm-python
pdm.lock
33 changes: 6 additions & 27 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ci:
# See https://pre-commit.com/hooks.html for info on hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-ast
Expand All @@ -20,30 +20,9 @@ repos:
- id: forbid-new-submodules
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 23.3.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.5
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
args: [--max-line-length=88]

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py38-plus]

- repo: https://github.com/hakancelikdev/unimport
rev: 0.12.3
hooks:
- id: unimport
args: [--remove, --include-star-import]
- id: ruff
- id: ruff-format
args: ["--check"]
123 changes: 81 additions & 42 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,73 +1,112 @@
[tool.poetry]
[project]
name = "pelican-pdf"
version = "1.0.3"
description = "PDF Generator is a Pelican plugin that exports articles and pages as PDF files during site generation"
authors = ["Pelican Dev Team <authors@getpelican.com>"]
license = "AGPL-3.0"
authors = [{name = "Justin Mayer", email = "entroP@gmail.com"}, {name = "Dominik Wombacher", email = "[email protected]"}]
license = {text = "AGPL-3.0"}
readme = "README.md"
keywords = ["pelican", "plugin", "pdf", "generator"]
repository = "https://github.com/pelican-plugins/pdf"
documentation = "https://docs.getpelican.com"
packages = [
{ include = "pelican" },
]

classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Framework :: Pelican",
"Framework :: Pelican :: Plugins",
"Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Software Development :: Libraries :: Python Modules",
]

[tool.poetry.urls]
"Funding" = "https://donate.getpelican.com/"
requires-python = ">=3.8.1,<4.0"
dependencies = [
"pelican>=4.5",
"rst2pdf>=0.99",
"xhtml2pdf>=0.2.5",
]

[project.urls]
Homepage = "https://github.com/pelican-plugins/pdf"
"Issue Tracker" = "https://github.com/pelican-plugins/pdf/issues"
Funding = "https://donate.getpelican.com/"

[tool.poetry.dependencies]
python = ">=3.8.1,<4.0"
pelican = ">=4.5"
markdown = {version = ">=3.2.2", optional = true}
rst2pdf = ">=0.99"
xhtml2pdf = ">=0.2.5"
[tool.pdm]

[tool.poetry.dev-dependencies]
black = "^23"
flake8 = "^3.9"
flake8-black = "^0.3"
invoke = "^2.0"
isort = "^5.12.0"
markdown = "^3.4"
pytest = "^6.0"
pytest-cov = "^2.8"
pytest-pythonpath = "^0.7.3"
pytest-sugar = "^0.9.6"
[tool.pdm.dev-dependencies]
lint = [
"invoke>=2.2.0",
"ruff>=0.4.5,<0.5.0"
]
test = [
"markdown>=3.4",
"pytest>=7.0",
"pytest-cov>=4.0",
"pytest-sugar>=1.0.0",
]

[tool.poetry.extras]
markdown = ["markdown"]
[tool.pdm.build]
source-includes = [
"CHANGELOG.md",
"CONTRIBUTING.md",
]
includes = ["pelican/"]
excludes = ["**/.DS_Store", "tasks.py"]

[tool.autopub]
project-name = "PDF Generator"
git-username = "botpub"
git-email = "[email protected]"
append-github-contributor = true

[tool.isort]
# Maintain compatibility with Black
profile = "black"
multi_line_output = 3
[tool.ruff.lint]
select = [
"B", # flake8-bugbear
"BLE", # flake8-blind-except
"C4", # flake8-comprehensions
"D", # pydocstyle
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"ICN", # flake8-import-conventions
"ISC", # flake8-implicit-str-concat
"PGH", # pygrep-hooks
"PL", # pylint
"RET", # flake8-return
"RUF", # ruff-specific rules
"SIM", # flake8-simplify
"T10", # flake8-debugger
"T20", # flake8-print
"TID", # flake8-tidy-imports
"TRY", # tryceratops
"UP", # pyupgrade
"W", # pycodestyle
"YTT", # flake8-2020
]

# Sort imports within their section independent of the import type
force_sort_within_sections = true
ignore = [
"D100", # missing docstring in public module
"D102", # missing docstring in public method
"D103", # missing docstring in public function
"D104", # missing docstring in public package
"D107", # missing docstring in __init__
"D203", # blank line before class docstring
"D213", # multi-line docstring summary should start at the second line
"ISC001", # disabled so that format works without warning
"PGH004", # use specific rule codes when using `NOQA`
"RUF100", # unused blanket `NOQA` directive
]

# Designate "pelican" and "pdf" as separate import sections
known_pelican = "pelican"
known_pdf = "pdf"
sections = "FUTURE,STDLIB,THIRDPARTY,PELICAN,PDF,FIRSTPARTY,LOCALFOLDER"
[tool.ruff.lint.isort]
combine-as-imports = true
force-sort-within-sections = true
known-first-party = ["pelican"]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
requires = ["pdm-backend"]
build-backend = "pdm.backend"
Loading

0 comments on commit 72bb7f3

Please sign in to comment.