mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-17 03:28:31 +02:00
move script tasks from pyproject into new tasks.py
This commit is contained in:
parent
9d37040890
commit
21edd49905
3 changed files with 64 additions and 41 deletions
2
.github/workflows/docs.yaml
vendored
2
.github/workflows/docs.yaml
vendored
|
@ -69,4 +69,4 @@ jobs:
|
|||
run: poetry run poe docs-run &
|
||||
|
||||
- name: Accessibility testing (Pa11y)
|
||||
run: poetry run poe docs-check-ci
|
||||
run: poetry run poe docs-check
|
||||
|
|
|
@ -62,26 +62,6 @@ xmltodict = "*"
|
|||
jrnl = 'jrnl.cli:cli'
|
||||
|
||||
[tool.poe.tasks]
|
||||
script-clean-docs.interpreter = "python"
|
||||
script-clean-docs.shell = """
|
||||
import pathlib
|
||||
files = ["sitemap.xml", "list.json"]
|
||||
for f in files:
|
||||
pathlib.Path(f).unlink(missing_ok=True)
|
||||
"""
|
||||
script-generate-sitemap.interpreter = "python"
|
||||
script-generate-sitemap.shell = '''
|
||||
import requests
|
||||
sitemap = requests.get("http://127.0.0.1:8000/sitemap.xml")
|
||||
with open('sitemap.xml', 'wb+') as f:
|
||||
f.write(sitemap.content)
|
||||
'''
|
||||
script-generate-page-list-from-sitemap.shell = '''
|
||||
select='{urls: ["http://127.0.0.1:8000/", "http://127.0.0.1:8000/search.html?q=jrnl", .urlset.url[].loc]}'
|
||||
poetry run xq "$select" sitemap.xml > list.json
|
||||
'''
|
||||
script-run-pa11y.cmd = "pa11y-ci -c list.json"
|
||||
|
||||
format-run = [
|
||||
{cmd = "black ."},
|
||||
]
|
||||
|
@ -100,31 +80,22 @@ sort-check = [
|
|||
{cmd = "isort --version"},
|
||||
{cmd = "isort --check ."},
|
||||
]
|
||||
|
||||
docs-clean = {script = "tasks:delete_files(['sitemap.xml', 'config.json'])"}
|
||||
|
||||
docs-check = [
|
||||
"script-clean-docs",
|
||||
"script-generate-sitemap",
|
||||
"script-generate-page-list-from-sitemap",
|
||||
"script-run-pa11y",
|
||||
"script-clean-docs",
|
||||
]
|
||||
docs-check-ci = [
|
||||
"script-generate-sitemap",
|
||||
{shell = '''
|
||||
echo "::group::sitemap.xml"
|
||||
cat sitemap.xml
|
||||
echo '::endgroup::'
|
||||
'''},
|
||||
"script-generate-page-list-from-sitemap",
|
||||
{shell = '''
|
||||
echo "::group::list.json"
|
||||
cat list.json
|
||||
echo '::endgroup::'
|
||||
'''},
|
||||
"script-run-pa11y",
|
||||
"docs-clean",
|
||||
{script = "tasks:generate_sitemap"},
|
||||
{script = "tasks:output_file('sitemap.xml')"},
|
||||
{script = "tasks:generate_pa11y_config_from_sitemap"},
|
||||
{script = "tasks:output_file('config.json')"},
|
||||
{cmd = "pa11y-ci -c config.json"},
|
||||
"docs-clean",
|
||||
]
|
||||
docs-run = [
|
||||
{cmd = "mkdocs serve"},
|
||||
]
|
||||
|
||||
test-run =[
|
||||
{cmd = "tox -q -e py --"},
|
||||
]
|
||||
|
|
52
tasks.py
Normal file
52
tasks.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
# Copyright © 2012-2022 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
DOCS_URL = "http://127.0.0.1:8000"
|
||||
SITEMAP_FILENAME = "sitemap.xml"
|
||||
CONFIG_FILENAME = "config.json"
|
||||
|
||||
def delete_files(files):
|
||||
import pathlib
|
||||
|
||||
for file in files:
|
||||
pathlib.Path(file).unlink(missing_ok=True)
|
||||
|
||||
|
||||
def generate_sitemap():
|
||||
import requests
|
||||
|
||||
sitemap = requests.get(f"{DOCS_URL}/{SITEMAP_FILENAME}")
|
||||
with open(SITEMAP_FILENAME, 'wb') as f:
|
||||
f.write(sitemap.content)
|
||||
|
||||
|
||||
def generate_pa11y_config_from_sitemap():
|
||||
import xmltodict
|
||||
import json
|
||||
|
||||
with open(SITEMAP_FILENAME) as f:
|
||||
xml_sitemap = xmltodict.parse(f.read())
|
||||
|
||||
urls = [
|
||||
f"{DOCS_URL}/",
|
||||
f"{DOCS_URL}/search.html?q=jrnl",
|
||||
]
|
||||
urls += [url["loc"] for url in xml_sitemap["urlset"]["url"]]
|
||||
|
||||
with open(CONFIG_FILENAME, 'w') as f:
|
||||
f.write(json.dumps({"urls": urls}))
|
||||
|
||||
|
||||
def output_file(file):
|
||||
import os
|
||||
|
||||
if not os.getenv("CI", False):
|
||||
return
|
||||
|
||||
print(f"::group::{file}")
|
||||
|
||||
with open(file) as f:
|
||||
print(f.read())
|
||||
|
||||
print('::endgroup::')
|
||||
|
Loading…
Add table
Reference in a new issue