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

Replace Poetry with PDM, Flake8/isort with Ruff #12

Merged
merged 5 commits into from
Jun 14, 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
95 changes: 72 additions & 23 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,90 @@ on:
pull_request:
branches:

env:
PYTEST_ADDOPTS: "--color=yes"

permissions:
contents: read

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

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }} & PDM
uses: pdm-project/setup-pdm@v4
with:
python-version: "3.9"
- name: Install Poetry
run: python -m pip install poetry
python-version: ${{ matrix.python-version }}
cache: true
cache-dependency-path: ./pyproject.toml

- name: Install dependencies
run: poetry install
run: pdm install

- name: Run tests
run: poetry run invoke tests
run: pdm run invoke tests

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

steps:
- uses: actions/checkout@v4

- name: Set up Python & PDM
uses: pdm-project/setup-pdm@v4
with:
python-version: "3.10"

- name: Install dependencies
run: pdm install

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

deploy:
name: Deploy
environment: Deployment
needs: [test, lint]
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@v4

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

- name: Check release
if: github.ref == 'refs/heads/main'
run: |
python -m pip install githubrelease
python -m pip install autopub
echo "##[set-output name=release;]$(autopub check)"
id: check_release
- name: Deploy
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && steps.check_release.outputs.release == ''
run: |
git checkout ${GITHUB_REF##*/}
git remote set-url origin https://[email protected]/${GITHUB_REPOSITORY}
python -m pip install autopub httpx
python -m pip install https://github.com/scikit-build/github-release/archive/master.zip
autopub check

- name: Publish
if: ${{ steps.check_release.outputs.autopub_release=='true' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
autopub prepare
poetry build
autopub commit
autopub build
autopub githubrelease
poetry publish -u __token__ -p $PYPI_PASSWORD
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
PYPI_PASSWORD: ${{ secrets.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.8
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.16.0
hooks:
- id: unimport
args: [--remove, --include-star-import]
- id: ruff
- id: ruff-format
args: ["--check"]
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ Simple Footnotes
================

[![Build Status](https://img.shields.io/github/actions/workflow/status/pelican-plugins/simple-footnotes/main.yml?branch=main)](https://github.com/pelican-plugins/simple-footnotes/actions)

[![PyPI Version](https://img.shields.io/pypi/v/pelican-simple-footnotes)](https://pypi.org/project/pelican-simple-footnotes/)
[![Downloads](https://img.shields.io/pypi/dm/pelican-simple-footnotes)](https://pypi.org/project/pelican-simple-footnotes/)
![License](https://img.shields.io/pypi/l/pelican-simple-footnotes?color=blue)

Simple Footnotes is a Pelican plugin for adding footnotes to articles and pages.

Expand All @@ -14,6 +15,8 @@ This plugin, and its dependent package `html5lib`, can be installed via:

python -m pip install pelican-simple-footnotes

As long as you have not explicitly added a `PLUGINS` setting to your Pelican settings file, then the newly-installed plugin should be automatically detected and enabled. Otherwise, you must add `simple_footnotes` to your existing `PLUGINS` list. For more information, please see the [How to Use Plugins](https://docs.getpelican.com/en/latest/plugins.html#how-to-use-plugins) documentation.

Usage
-----

Expand All @@ -23,12 +26,11 @@ When writing an article or page, add a footnote like this:

This will appear as, roughly:

Here’s my written text<sup>1</sup>
Here is my written text<sup>1</sup>

1. and here is a footnote ↩&#xFE0E;

This should work with any content format (reST, Markdown, et cetera), because
it looks for `[ref]` and `[/ref]` once the conversion to HTML has happened.
This should work with any content format (Markdown, reStructuredText, et cetera), because the plugin looks for `[ref]` and `[/ref]` once the conversion to HTML has happened.

Contributing
------------
Expand All @@ -40,10 +42,7 @@ To start contributing to this plugin, review the [Contributing to Pelican][] doc
Credits
-------

Originally authored by [Stuart Langridge](https://kryogenix.org/), February 2014,
and subsequently enhanced by members of the Pelican community, including
[Justin Mayer](https://justinmayer.com/), who re-packaged it for publication to
PyPI.
Originally authored by [Stuart Langridge](https://kryogenix.org/), February 2014, and subsequently enhanced by members of the Pelican community, including [Justin Mayer](https://justinmayer.com/), who re-packaged it for publication to PyPI.

Inspired by Andrew Nacin’s [Simple Footnotes WordPress plugin](https://wordpress.org/plugins/simple-footnotes/).

Expand Down
6 changes: 6 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Release type: patch

- Enable footnote generation on hidden pages and other page types
- Render arrow Unicode character as text instead of emoji on iOS
- Replace Poetry with PDM, Flake8/isort with Ruff
- Drop official support for Python 3.6 & 3.7
13 changes: 7 additions & 6 deletions pelican/plugins/simple_footnotes/simple_footnotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@

def getText(node, recursive=False):
"""Get all the text associated with this node.
With recursive == True, all text from child nodes is retrieved."""

With recursive == True, all text from child nodes is retrieved.
"""
L = [""]
for n in node.childNodes:
if n.nodeType in (node.TEXT_NODE, node.CDATA_SECTION_NODE):
L.append(n.data)
else:
if not recursive:
return None
elif not recursive:
return None
L.append(getText(n))
return "".join(L)

Expand Down Expand Up @@ -68,7 +69,7 @@ def parse_for_footnotes(article_or_page_generator):
number = dom.createElement("sup")
number.setAttribute("id", fnbackid)
numbera = dom.createElement("a")
numbera.setAttribute("href", "#%s" % fnid)
numbera.setAttribute("href", f"#{fnid}")
numbera.setAttribute("class", "simple-footnote")
numbera.appendChild(dom.createTextNode(str(count)))
txt = getText(footnote, recursive=True).replace("\n", " ")
Expand All @@ -84,7 +85,7 @@ def parse_for_footnotes(article_or_page_generator):
while e.firstChild:
li.appendChild(e.firstChild)
backlink = dom.createElement("a")
backlink.setAttribute("href", "#%s" % fnbackid)
backlink.setAttribute("href", f"#{fnbackid}")
backlink.setAttribute("class", "simple-footnote-back")
backlink.appendChild(dom.createTextNode("\u21a9\ufe0e"))
li.appendChild(dom.createTextNode(" "))
Expand Down
2 changes: 1 addition & 1 deletion pelican/plugins/simple_footnotes/test_simple_footnotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_simple(self):
(
'words<sup id="sf-article-1-back"><a href="#sf-article-1" class="simple-footnote" title="footnote">1</a></sup>end'
'<ol class="simple-footnotes">'
'<li id="sf-article-1">footnote <a href="#sf-article-1-back" class="simple-footnote-back">\u21a9</a></li>'
'<li id="sf-article-1">footnote <a href="#sf-article-1-back" class="simple-footnote-back">\u21a9\ufe0e</a></li>'
"</ol>"
),
)
Expand Down
Loading