Skip to content

Commit 152755a

Browse files
authored
small patch to github plugin (#9)
- fix bug where license is not specified in REST API response payload - update cache directory name (was still using old dev name) and related docs Other changes - update pre-commit hooks' versions - relax ruff's max line length to allow 100 chars - dynamically set site_url according to build env - correct code-snippet used in config doc
1 parent 7c53eb5 commit 152755a

File tree

7 files changed

+24
-11
lines changed

7 files changed

+24
-11
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/python/black
3-
rev: 23.3.0
3+
rev: 23.7.0
44
hooks:
55
- id: black
66
exclude: ^cookiecutter/
@@ -17,7 +17,7 @@ repos:
1717
- id: mixed-line-ending
1818
args: ["--fix=lf"]
1919
- repo: https://github.com/astral-sh/ruff-pre-commit
20-
rev: v0.0.277
20+
rev: v0.0.278
2121
hooks:
2222
- id: ruff
2323
exclude: ^cookiecutter/

docs/conf.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
name, url = url_str.split(", ")
4848
urls[name] = url
4949

50+
html_baseurl = os.environ.get(
51+
"READTHEDOCS_CANONICAL_URL", "https://2bndy5.github.io/sphinx-social-cards/"
52+
)
53+
5054
# -- Project information -----------------------------------------------------
5155
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
5256

@@ -83,7 +87,7 @@
8387
# -- Options for sphinx_social_cards ------------------------------------------
8488
social_cards = {
8589
"description": pkg_meta["summary"],
86-
"site_url": urls["Documentation"],
90+
"site_url": html_baseurl,
8791
}
8892

8993
# -- Options for autodoc -----------------------------------------------------
@@ -144,6 +148,7 @@
144148
},
145149
"repo_url": urls["Source"],
146150
"repo_name": "Sphinx-Social-Cards",
151+
"site_url": html_baseurl,
147152
"edit_uri": "blob/main/docs",
148153
"features": [
149154
"navigation.expand",

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ version_scheme= "no-guess-dev"
4949
local_scheme = "no-local-version"
5050
fallback_version = "0.0.0"
5151

52+
[tool.ruff]
53+
# Decrease the maximum line length to 100 characters. (mostly for unbreakable docstrings)
54+
line-length = 100
55+
5256
[tool.mypy]
5357
show_error_codes = true
5458
show_column_numbers = true

src/sphinx_social_cards/plugins/github/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,13 @@
7474
OS used:
7575
7676
- On Windows:
77-
``%LOCALAPPDATA%\\2bndy5\\sphinx-social-cards\\Cache\\<month> <day>
78-
<year>``
79-
- On Linux: ``/home/$(whoami)/.cache/sphinx-social-cards/<month> <day>
80-
<year>``
81-
- On MacOS: ``/Users/$(id -un)/Library/Caches/sphinx-social-cards/<month>
77+
``%LOCALAPPDATA%\\2bndy5\\sphinx_social_cards.plugins.github\\Cache\\<month>
8278
<day> <year>``
79+
- On Linux:
80+
``/home/$(whoami)/.cache/sphinx_social_cards.plugins.github/<month> <day> <year>``
81+
- On MacOS:
82+
``/Users/$(id -un)/Library/Caches/sphinx_social_cards.plugins.github/<month> <day>
83+
<year>``
8384
"""
8485
from pathlib import Path
8586
from typing import Tuple

src/sphinx_social_cards/plugins/github/context.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,14 @@ def get_context_github(owner: Optional[str], repo: Optional[str]) -> Dict[str, A
196196
LOGGER.info("Fetching info for github context about repo: %s/%s", owner, repo)
197197
res_json = try_request(f"https://api.github.com/repos/{owner}/{repo}").json()
198198
res_json = cast(Dict[str, Any], res_json)
199+
license_name = ""
200+
if isinstance(res_json.get("license", None), dict):
201+
license_name = res_json.get("license", {}).get("name", "")
199202
gh_ctx.repo = Repo(
200203
stars=reduce_big_number(res_json.get("stargazers_count", 0)),
201204
watchers=reduce_big_number(res_json.get("watchers_count", 0)),
202205
forks=reduce_big_number(res_json.get("forks", 0)),
203-
license=res_json.get("license", {}).get("name", ""),
206+
license=license_name,
204207
open_issues=reduce_big_number(res_json.get("open_issues_count", 0)),
205208
topics=res_json.get("topics", []),
206209
name=res_json.get("name", ""),

src/sphinx_social_cards/plugins/github/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def get_cache_dir() -> str:
4646
today = time.strftime(time_fmt, time.localtime())
4747
cache_dir = Path(
4848
user_cache_dir(
49-
"sphinx_social_cards.plugins.vcs", "2bndy5", version=today # (1)!
49+
"sphinx_social_cards.plugins.github", "2bndy5", version=today # (1)!
5050
)
5151
)
5252
if cache_dir.parent.exists() and not cache_dir.exists():

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def sphinx_make_app(
2020
html_logo = "images/message.png"
2121
# -- Options for sphinx_social_cards
2222
social_cards = {
23-
"site_url": "https://github.com/2bndy5/sphinx-social-cards",
23+
"site_url": "https://2bndy5.github.io/sphinx-social-cards",
2424
"description": "Generate social media preview cards for your sphinx documentation.",
2525
}
2626
"""

0 commit comments

Comments
 (0)