mirror of
https://github.com/nlohmann/json.git
synced 2026-10-05 14:10:31 +00:00
Cache the release headers with functools.lru_cache
Codacy (Pylint) flagged the mutable default argument that header() used as its cache. functools.lru_cache keeps the same memoization without it. The script's output is unchanged. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -10,6 +10,7 @@ they were documented for users. The check is heuristic and meant to be run by ha
|
|||||||
usage: python3 check_version_history.py (from docs/mkdocs/docs, needs the git tags)
|
usage: python3 check_version_history.py (from docs/mkdocs/docs, needs the git tags)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import functools
|
||||||
import glob
|
import glob
|
||||||
import re
|
import re
|
||||||
# the script only runs git with fixed arguments and without a shell
|
# the script only runs git with fixed arguments and without a shell
|
||||||
@@ -32,16 +33,14 @@ def release_tags():
|
|||||||
return sorted(versions)
|
return sorted(versions)
|
||||||
|
|
||||||
|
|
||||||
def header(tag, cache={}):
|
@functools.lru_cache(maxsize=None)
|
||||||
if tag not in cache:
|
def header(tag):
|
||||||
cache[tag] = ""
|
for path in HEADER_PATHS:
|
||||||
for path in HEADER_PATHS:
|
# fixed git command without a shell; the tag names come from "git tag"
|
||||||
# fixed git command without a shell; the tag names come from "git tag"
|
result = subprocess.run(["git", "show", f"{tag}:{path}"], capture_output=True, text=True) # nosec B603, B607
|
||||||
result = subprocess.run(["git", "show", f"{tag}:{path}"], capture_output=True, text=True) # nosec B603, B607
|
if result.returncode == 0:
|
||||||
if result.returncode == 0:
|
return result.stdout
|
||||||
cache[tag] = result.stdout
|
return ""
|
||||||
break
|
|
||||||
return cache[tag]
|
|
||||||
|
|
||||||
|
|
||||||
def macros_and_versions(page):
|
def macros_and_versions(page):
|
||||||
|
|||||||
Reference in New Issue
Block a user