pelican-avatar 1.0.8__py3-none-any.whl → 1.0.10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pelican-avatar might be problematic. Click here for more details.

@@ -0,0 +1 @@
1
+ from .avatar import * # NOQA: F403
@@ -0,0 +1,92 @@
1
+ """Avatar plugin for Pelican."""
2
+
3
+ # Copyright (C) 2015, 2021-2024 Rafael Laboissière <rafael@laboissiere.net>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify it
6
+ # under the terms of the GNU General Affero Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or (at
8
+ # your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see http://www.gnu.org/licenses/.
17
+
18
+ from libgravatar import Gravatar
19
+ from libravatar import libravatar_url
20
+
21
+ from pelican import signals
22
+
23
+
24
+ def initialize(pelicanobj):
25
+ """Initialize the Avatar plugin."""
26
+ pelicanobj.settings.setdefault("AVATAR_MISSING", None)
27
+ pelicanobj.settings.setdefault("AVATAR_SIZE", None)
28
+ pelicanobj.settings.setdefault("AVATAR_USE_GRAVATAR", None)
29
+
30
+
31
+ def gen_avatar_url(settings, email):
32
+ """Generate the appropriate libravatar/gravatar URL based on the provided email."""
33
+ # Early exit if there is nothing to do
34
+ if not email:
35
+ return None
36
+
37
+ missing = settings.get("AVATAR_MISSING")
38
+ size = settings.get("AVATAR_SIZE")
39
+
40
+ email = email.lower()
41
+ # Compose URL
42
+ if settings.get("AVATAR_USE_GRAVATAR"):
43
+ params = {}
44
+ if missing:
45
+ params["default"] = missing
46
+ if size:
47
+ params["size"] = size
48
+ url = Gravatar(email).get_image(**params)
49
+ else:
50
+ url = libravatar_url(email)
51
+ if missing or size:
52
+ url = url + "?"
53
+ if missing:
54
+ url = url + "d=" + missing
55
+ if size:
56
+ url = url + "&"
57
+ if size:
58
+ url = url + "s=" + str(size)
59
+
60
+ return url
61
+
62
+
63
+ def add_avatar_context(generator):
64
+ """Add generator context connector for Avatar plugin."""
65
+ # This adds the avatar URL to the global generator context based on the
66
+ # global setting.
67
+ email = generator.settings.get("AVATAR_AUTHOR_EMAIL")
68
+ url = gen_avatar_url(generator.settings, email)
69
+ if url:
70
+ generator.context["author_avatar"] = url
71
+
72
+
73
+ def add_avatar(generator, metadata):
74
+ """Add Avatar URL to the article/page metadata."""
75
+ # Check the presence of the Email header
76
+ if "email" in metadata:
77
+ email = metadata["email"]
78
+ else:
79
+ email = generator.settings.get("AVATAR_AUTHOR_EMAIL")
80
+
81
+ url = gen_avatar_url(generator.settings, email)
82
+ if url:
83
+ # Add URL to the article/page metadata
84
+ metadata["author_avatar"] = url
85
+
86
+
87
+ def register():
88
+ """Register the Avatar plugin with Pelican."""
89
+ signals.initialized.connect(initialize)
90
+ signals.article_generator_context.connect(add_avatar)
91
+ signals.page_generator_context.connect(add_avatar)
92
+ signals.generator_init.connect(add_avatar_context)
@@ -0,0 +1,160 @@
1
+ """Unit testing suite for the Avatar Plugin."""
2
+
3
+ # Copyright (C) 2015, 2021-2023 Rafael Laboissiere <rafael@laboissiere.net>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify it
6
+ # under the terms of the GNU General Affero Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or (at
8
+ # your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see http://www.gnu.org/licenses/.
17
+
18
+ import os
19
+ from shutil import rmtree
20
+ from tempfile import mkdtemp
21
+ import unittest
22
+
23
+ from libgravatar import Gravatar
24
+ from libravatar import libravatar_url
25
+
26
+ from pelican import Pelican
27
+ from pelican.settings import read_settings
28
+
29
+ from . import avatar
30
+
31
+ GLOBAL_AUTHOR_EMAIL = "homer.simpson@example.com"
32
+ ARTICLE_AUTHOR_EMAIL = "bart.simpson@example.com"
33
+ GLOBAL_GRAVATAR_URL = Gravatar(GLOBAL_AUTHOR_EMAIL).get_image()
34
+ GLOBAL_LIBRVATAR_URL = libravatar_url(GLOBAL_AUTHOR_EMAIL)
35
+ ARTICLE_GRAVATAR_URL = Gravatar(ARTICLE_AUTHOR_EMAIL).get_image()
36
+ ARTICLE_LIBRAVATAR_URL = libravatar_url(ARTICLE_AUTHOR_EMAIL)
37
+
38
+
39
+ class TestAvatarURL(unittest.TestCase):
40
+ """Class for testing the URL output of the Avatar plugin."""
41
+
42
+ def setUp(self, override=None):
43
+ """Set up the test environment."""
44
+ self.output_path = mkdtemp(prefix="pelicantests.")
45
+ self.content_path = mkdtemp(prefix="pelicantests.")
46
+ with open(
47
+ os.path.join(self.content_path, "article_infos.html"), "w"
48
+ ) as article_infos_file:
49
+ article_infos_file.write(
50
+ """
51
+ <footer class="post-info">
52
+ <div align="center">
53
+ <img src="{{ article.author_avatar }}">
54
+ </div>
55
+ </footer>
56
+ """
57
+ )
58
+
59
+ with open(
60
+ os.path.join(self.content_path, "global_info.html"), "w"
61
+ ) as global_infos_file:
62
+ global_infos_file.write(
63
+ """
64
+ <footer class="post-info">
65
+ <div align="center">
66
+ <img src="{{ author_avatar }}">
67
+ </div>
68
+ </footer>
69
+ """
70
+ )
71
+
72
+ settings = {
73
+ "PATH": self.content_path,
74
+ "THEME_TEMPLATES_OVERRIDES": [self.content_path],
75
+ "OUTPUT_PATH": self.output_path,
76
+ "PLUGINS": [avatar],
77
+ "CACHE_CONTENT": False,
78
+ "AVATAR_AUTHOR_EMAIL": GLOBAL_AUTHOR_EMAIL,
79
+ }
80
+ if override:
81
+ settings.update(override)
82
+
83
+ with open(
84
+ os.path.join(self.content_path, "global_test.md"), "w"
85
+ ) as test_md_file:
86
+ test_md_file.write("Title: Global Test\nDate: 2019-09-05\n\n")
87
+
88
+ with open(os.path.join(self.content_path, "test.md"), "w") as test_md_file:
89
+ test_md_file.write(
90
+ "Title: Test\nDate: 2019-09-05\nEmail: " + ARTICLE_AUTHOR_EMAIL + "\n\n"
91
+ )
92
+
93
+ self.settings = read_settings(override=settings)
94
+ pelican = Pelican(settings=self.settings)
95
+ pelican.run()
96
+
97
+ def tearDown(self):
98
+ """Tidy up the test environment."""
99
+ rmtree(self.output_path)
100
+ rmtree(self.content_path)
101
+
102
+ def _assert_url_in_file(self, filename, url, options):
103
+ with open(os.path.join(self.output_path, filename)) as test_html_file:
104
+ found = False
105
+ search_url = url + options
106
+ for line in test_html_file:
107
+ if search_url in line:
108
+ found = True
109
+ break
110
+ assert found
111
+
112
+ def test_url(self, options=""):
113
+ """Test whether the Avatar URL appears in the generated HTML file."""
114
+ if self.settings["AVATAR_USE_GRAVATAR"]:
115
+ global_base_url = GLOBAL_GRAVATAR_URL
116
+ article_base_url = ARTICLE_GRAVATAR_URL
117
+ else:
118
+ global_base_url = GLOBAL_LIBRVATAR_URL
119
+ article_base_url = ARTICLE_LIBRAVATAR_URL
120
+
121
+ self._assert_url_in_file("test.html", article_base_url, options)
122
+ self._assert_url_in_file("global-test.html", global_base_url, options)
123
+
124
+
125
+ class TestAvatarMissing(TestAvatarURL):
126
+ """Class for testing the "missing picture" option."""
127
+
128
+ def setUp(self, override=None):
129
+ """Set up the test environment."""
130
+ self.library = "wavatar"
131
+ TestAvatarURL.setUp(self, override={"AVATAR_MISSING": self.library})
132
+
133
+ def test_url(self):
134
+ """Test whether the 'd' option appears in the Avatar URL."""
135
+ TestAvatarURL.test_url(self, r"?d=" + self.library)
136
+
137
+
138
+ class TestAvatarSize(TestAvatarURL):
139
+ """Class for testing the size option."""
140
+
141
+ def setUp(self, override=None):
142
+ """Set up the test environment."""
143
+ self.size = 100
144
+ TestAvatarURL.setUp(self, override={"AVATAR_SIZE": self.size})
145
+
146
+ def test_url(self):
147
+ """Test whether the 's' option appears in the Avatar URL."""
148
+ TestAvatarURL.test_url(self, r"?s=" + str(self.size))
149
+
150
+
151
+ class TestAvatarUseGravatar(TestAvatarURL):
152
+ """Class for testing the 'use Gravatar' option."""
153
+
154
+ def setUp(self, override=None):
155
+ """Set up the test environment."""
156
+ TestAvatarURL.setUp(self, override={"AVATAR_USE_GRAVATAR": True})
157
+
158
+ def test_url(self):
159
+ """Test whether Gravatar is used."""
160
+ TestAvatarURL.test_url(self)
@@ -1,16 +1,16 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pelican-avatar
3
- Version: 1.0.8
3
+ Version: 1.0.10
4
4
  Summary: Libravatar/Gravatar plugin for Pelican
5
- Keywords: pelican plugin libravatar gravatar
6
- Author-Email: Rafael Laboissière <rafael@laboissiere.net>
5
+ Keywords: pelican,plugin,libravatar,gravatar
6
+ Author-Email: =?utf-8?q?Rafael_Laboissi=C3=A8re?= <rafael@laboissiere.net>
7
7
  License: AGPL-3.0
8
8
  Classifier: Development Status :: 5 - Production/Stable
9
9
  Classifier: Environment :: Console
10
10
  Classifier: Framework :: Pelican
11
11
  Classifier: Framework :: Pelican :: Plugins
12
12
  Classifier: Intended Audience :: End Users/Desktop
13
- Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
13
+ Classifier: License :: OSI Approved :: GNU Affero General Public License v3
14
14
  Classifier: Operating System :: OS Independent
15
15
  Classifier: Programming Language :: Python :: 3
16
16
  Classifier: Programming Language :: Python :: 3.8
@@ -28,8 +28,8 @@ Requires-Dist: pelican>=4.5
28
28
  Requires-Dist: libgravatar>=0.2.5
29
29
  Requires-Dist: py3dns>=3.2
30
30
  Requires-Dist: pylibravatar>=1.7
31
- Requires-Dist: markdown>=3.4; extra == "markdown"
32
31
  Provides-Extra: markdown
32
+ Requires-Dist: markdown>=3.4; extra == "markdown"
33
33
  Description-Content-Type: text/markdown
34
34
 
35
35
  Avatar: A Plugin for Pelican
@@ -37,7 +37,8 @@ Avatar: A Plugin for Pelican
37
37
 
38
38
  [![Build Status](https://img.shields.io/github/actions/workflow/status/pelican-plugins/avatar/main.yml?branch=main)](https://github.com/pelican-plugins/avatar/actions)
39
39
  [![PyPI Version](https://img.shields.io/pypi/v/pelican-avatar)](https://pypi.org/project/pelican-avatar/)
40
- ![License](https://img.shields.io/pypi/l/pelican-avatar?color=blue)
40
+ [![Downloads](https://img.shields.io/pypi/dm/pelican-avatar)](https://pypi.org/project/pelican-avatar/)
41
+ [![License](https://img.shields.io/pypi/l/pelican-avatar?color=blue)](https://www.gnu.org/licenses/agpl-3.0.en.html)
41
42
 
42
43
  This plugin allows the inclusion of [Libravatar][] or [Gravatar][] user profile pictures, corresponding to the email address of the article's author.
43
44
 
@@ -51,6 +52,8 @@ This plugin can be installed via:
51
52
 
52
53
  python -m pip install pelican-avatar
53
54
 
55
+ 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 `avatar` 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.
56
+
54
57
  Usage
55
58
  -----
56
59
 
@@ -0,0 +1,8 @@
1
+ pelican/plugins/avatar/__init__.py,sha256=tt8WB0hhhW_jgsRgQNEn-r3TKl1RJRglrXKeudL8zO0,36
2
+ pelican/plugins/avatar/avatar.py,sha256=zjaTE3Hp2Q5Fm7cseenMXzOgeCgdYxLFK6kzLUQNavI,3065
3
+ pelican/plugins/avatar/test_avatar.py,sha256=e9xkj-0G1rZ23LedjvxsFh9ERSVbt2JFr78DeItb5wk,5511
4
+ pelican_avatar-1.0.10.dist-info/METADATA,sha256=EoGYJt4bwWvJC6F2CPOOXoaU73J37A59VTHsPb4n4oo,7345
5
+ pelican_avatar-1.0.10.dist-info/WHEEL,sha256=Vza3XR51HW1KmFP0iIMUVYIvz0uQuKJpIXKYOBGQyFQ,90
6
+ pelican_avatar-1.0.10.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
7
+ pelican_avatar-1.0.10.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
8
+ pelican_avatar-1.0.10.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: pdm-backend (2.1.8)
2
+ Generator: pdm-backend (2.4.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -0,0 +1,4 @@
1
+ [console_scripts]
2
+
3
+ [gui_scripts]
4
+
@@ -1,5 +0,0 @@
1
- pelican_avatar-1.0.8.dist-info/METADATA,sha256=moAqqvUJzexH52upKopx_BTWAZpC9lftSHhkGohMR70,6813
2
- pelican_avatar-1.0.8.dist-info/WHEEL,sha256=N2J68yzZqJh3mI_Wg92rwhw0rtJDFpZj9bwQIMJgaVg,90
3
- pelican_avatar-1.0.8.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
4
- tasks.py,sha256=vSB2IaG--1O3QmrCUYQt_ZXF2r3b7t3uRheSmhQ5MPA,3164
5
- pelican_avatar-1.0.8.dist-info/RECORD,,
tasks.py DELETED
@@ -1,99 +0,0 @@
1
- from inspect import cleandoc
2
- import logging
3
- import os
4
- from pathlib import Path
5
- from shutil import which
6
-
7
- from invoke import task
8
-
9
- logger = logging.getLogger(__name__)
10
-
11
- PKG_NAME = "avatar"
12
- PKG_PATH = Path(f"pelican/plugins/{PKG_NAME}")
13
-
14
- ACTIVE_VENV = os.environ.get("VIRTUAL_ENV", None)
15
- VENV_HOME = Path(os.environ.get("WORKON_HOME", "~/.local/share/virtualenvs"))
16
- VENV_PATH = Path(ACTIVE_VENV) if ACTIVE_VENV else (VENV_HOME.expanduser() / PKG_NAME)
17
- VENV = str(VENV_PATH.expanduser())
18
- BIN_DIR = "bin" if os.name != "nt" else "Scripts"
19
- VENV_BIN = Path(VENV) / Path(BIN_DIR)
20
-
21
- TOOLS = ("pdm", "pre-commit")
22
- PDM = which("pdm") if which("pdm") else (VENV_BIN / "pdm")
23
- CMD_PREFIX = f"{VENV_BIN}/" if ACTIVE_VENV else f"{PDM} run "
24
- PRECOMMIT = which("pre-commit") if which("pre-commit") else f"{CMD_PREFIX}pre-commit"
25
- PTY = os.name != "nt"
26
-
27
-
28
- @task
29
- def tests(c, deprecations=False):
30
- """Run the test suite, optionally with `--deprecations`."""
31
- deprecations_flag = "" if deprecations else "-W ignore::DeprecationWarning"
32
- c.run(f"{CMD_PREFIX}pytest {deprecations_flag}", pty=PTY)
33
-
34
-
35
- @task
36
- def black(c, check=False, diff=False):
37
- """Run Black auto-formatter, optionally with `--check` or `--diff`."""
38
- check_flag, diff_flag = "", ""
39
- if check:
40
- check_flag = "--check"
41
- if diff:
42
- diff_flag = "--diff"
43
- c.run(f"{CMD_PREFIX}black {check_flag} {diff_flag} {PKG_PATH} tasks.py", pty=PTY)
44
-
45
-
46
- @task
47
- def ruff(c, fix=False, diff=False):
48
- """Run Ruff to ensure code meets project standards."""
49
- diff_flag, fix_flag = "", ""
50
- if fix:
51
- fix_flag = "--fix"
52
- if diff:
53
- diff_flag = "--diff"
54
- c.run(f"{CMD_PREFIX}ruff check {diff_flag} {fix_flag} .", pty=PTY)
55
-
56
-
57
- @task
58
- def lint(c, fix=False, diff=False):
59
- """Check code style via linting tools."""
60
- ruff(c, fix=fix, diff=diff)
61
- black(c, check=(not fix), diff=diff)
62
-
63
-
64
- @task
65
- def tools(c):
66
- """Install development tools in the virtual environment if not already on PATH."""
67
- for tool in TOOLS:
68
- if not which(tool):
69
- logger.info(f"** Installing {tool} **")
70
- c.run(f"{CMD_PREFIX}pip install {tool}")
71
-
72
-
73
- @task
74
- def precommit(c):
75
- """Install pre-commit hooks to .git/hooks/pre-commit."""
76
- logger.info("** Installing pre-commit hooks **")
77
- c.run(f"{PRECOMMIT} install")
78
-
79
-
80
- @task
81
- def setup(c):
82
- """Set up the development environment."""
83
- if which("pdm") or ACTIVE_VENV:
84
- tools(c)
85
- c.run(f"{CMD_PREFIX}python -m pip install --upgrade pip", pty=PTY)
86
- c.run(f"{PDM} update --dev", pty=PTY)
87
- precommit(c)
88
- logger.info("\nDevelopment environment should now be set up and ready!\n")
89
- else:
90
- error_message = """
91
- PDM is not installed, and there is no active virtual environment available.
92
- You can either manually create and activate a virtual environment, or you can
93
- install PDM via:
94
-
95
- curl -sSL https://raw.githubusercontent.com/pdm-project/pdm/main/install-pdm.py | python3 -
96
-
97
- Once you have taken one of the above two steps, run `invoke setup` again.
98
- """ # noqa: E501
99
- raise SystemExit(cleandoc(error_message))