Skip to content

Commit

Permalink
Merge pull request #9 from pelican-plugins/replace-poetry-with-pdm
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmayer authored Jul 7, 2024
2 parents ded166d + d6f1527 commit d2ea8af
Show file tree
Hide file tree
Showing 13 changed files with 202 additions and 140 deletions.
27 changes: 27 additions & 0 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"template": "https://github.com/getpelican/cookiecutter-pelican-plugin",
"commit": "f9a088515d09675d433595982ae643c3fe323c50",
"checkout": null,
"context": {
"cookiecutter": {
"plugin_name": "Similar Posts",
"repo_name": "similar-posts",
"package_name": "similar_posts",
"distribution_name": "pelican-similar-posts",
"version": "1.0.0",
"description": "Pelican plugin to add similar posts to articles, based on a vector space model",
"authors": "{name = \"David Lesieur\", email = \"[email protected]\"}",
"keywords": "\"pelican\", \"plugin\", \"similarity\", \"tf-idf\", \"tags\", \"gensim\", \"vector-space-model\", \"algebraic-model\", \"numpy\", \"scipy\"",
"readme": "README.md",
"contributing": "CONTRIBUTING.md",
"license": "GNU General Public License v3|GPL-3.0-only",
"repo_url": "https://github.com/pelican-plugins/similar-posts",
"dev_status": "5 - Production/Stable",
"tests_exist": true,
"python_version": ">=3.8.1,<4.0",
"pelican_version": ">=4.5",
"_template": "https://github.com/getpelican/cookiecutter-pelican-plugin"
}
},
"directory": null
}
1 change: 0 additions & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

github: justinmayer
custom: https://donate.getpelican.com
liberapay: pelican
52 changes: 19 additions & 33 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,45 @@ env:

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"]

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

- name: Install Poetry
run: pipx install poetry

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
- name: Set up Python ${{ matrix.python-version }} & PDM
uses: pdm-project/setup-pdm@v4
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"
cache-dependency-path: "pyproject.toml"
cache: true
cache-dependency-path: ./pyproject.toml

- name: Install dependencies
run: |
poetry env use "${{ matrix.python-version }}"
poetry install --no-interaction
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@v3

- name: Install Poetry
run: pipx install poetry
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
- name: Set up Python & PDM
uses: pdm-project/setup-pdm@v4
with:
python-version: "3.9"
cache: "poetry"
cache-dependency-path: "pyproject.toml"
python-version: "3.10"

- name: Install dependencies
run: |
poetry env use "3.9"
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 @@ -73,20 +59,20 @@ jobs:
id-token: write

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
token: ${{ secrets.GH_TOKEN }}

- name: Set up Python
uses: actions/setup-python@v4
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 autopub[github]
python -m pip install autopub httpx
python -m pip install https://github.com/scikit-build/github-release/archive/master.zip
autopub check
- name: Publish
Expand Down
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
21 changes: 6 additions & 15 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,18 +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.5.0
hooks:
- id: black

- repo: https://gitlab.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
- id: ruff
- id: ruff-format
args: ["--check"]
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ CHANGELOG
------------------

Initial release as namespace plugin

14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Similar Posts: A Plugin for Pelican

[![Build Status](https://img.shields.io/github/actions/workflow/status/pelican-plugins/similar-posts/main.yml?branch=main)](https://github.com/pelican-plugins/similar-posts/actions)
[![PyPI Version](https://img.shields.io/pypi/v/pelican-similar-posts)](https://pypi.org/project/pelican-similar-posts/)
![License](https://img.shields.io/pypi/l/pelican-markdown-include?color=blue)
[![Downloads](https://img.shields.io/pypi/dm/pelican-similar-posts)](https://pypi.org/project/pelican-similar-posts/)
![License](https://img.shields.io/pypi/l/pelican-similar-posts?color=blue)

**Similar Posts** is a [Pelican](https://getpelican.com/) plugin that adds the `similar_posts` variable to every published article's context.

Expand All @@ -14,7 +15,7 @@ The `similar_posts` variable is a list of `Article` objects, or an empty list if
Requirements
------------

This plugin requires Python 3.6 or later.
This plugin is compatible with Python 3.8 through 3.11. Python 3.12+ is not currently supported due to incompatibilities with one or more of the dependencies listed below.

It depends on [Gensim](https://radimrehurek.com/gensim/index.html), which has its own dependencies such as [NumPy](http://www.numpy.org/), [SciPy](https://www.scipy.org/), and [`smart_open`](https://pypi.org/project/smart_open/).

Expand All @@ -23,8 +24,8 @@ Installation

This plugin can be installed via:

```shell
python -m pip install pelican-similar-posts
python -m pip install pelican-similar-posts

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 `similar_posts` 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.

Configuration
Expand Down Expand Up @@ -81,3 +82,8 @@ To start contributing to this plugin, review the [Contributing to Pelican][] doc

[existing issues]: https://github.com/pelican-plugins/similar-posts/issues
[Contributing to Pelican]: https://docs.getpelican.com/en/latest/contribute.html

License
-------

This project is licensed under the General Public License (GPL) 3.0.
2 changes: 1 addition & 1 deletion pelican/plugins/similar_posts/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .similar_posts import * # NOQA
from .similar_posts import * # noqa: F403,PGH004,RUF100
5 changes: 3 additions & 2 deletions pelican/plugins/similar_posts/similar_posts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
Similar Posts plugin for Pelican.
"""Similar Posts plugin for Pelican.
Adds a `similar_posts` list to every article's context.
"""
Expand All @@ -16,6 +15,7 @@


def add_similar_posts(generator):
"""Add similar posts to a Pelican article."""
max_count = generator.settings.get("SIMILAR_POSTS_MAX_COUNT", 5)
min_score = generator.settings.get("SIMILAR_POSTS_MIN_SCORE", 0.0001)

Expand Down Expand Up @@ -79,4 +79,5 @@ def add_similar_posts(generator):


def register():
"""Register the plugin."""
signals.article_generator_finalized.connect(add_similar_posts)
9 changes: 4 additions & 5 deletions pelican/plugins/similar_posts/test_similar_posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ def test_no_tags(self):


class IdenticalTagsTestCase(unittest.TestCase):
"""
Test a generator whose articles all have the same tags.
"""Test a generator whose articles all have the same tags.
Some TF*IDF formulas would cause this test to fail.
"""
Expand Down Expand Up @@ -98,8 +97,7 @@ def test_identical(self):


class CommonTagTestCase(unittest.TestCase):
"""
Test a generator whose articles all have one of the tags in common.
"""Test a generator whose articles all have one of the tags in common.
Some TF*IDF formulas would cause this test to fail.
"""
Expand Down Expand Up @@ -232,8 +230,9 @@ def setUp(self):
add_similar_posts(self.generator)

def test_max_count(self):
EXPECTED_SIMILAR_POSTS_COUNT = 2
for article in self.generator.articles:
self.assertTrue(len(article.similar_posts) == 2)
self.assertTrue(len(article.similar_posts) == EXPECTED_SIMILAR_POSTS_COUNT)


class MinScoreSettingTestCase(unittest.TestCase):
Expand Down
Loading

0 comments on commit d2ea8af

Please sign in to comment.