jrnl/tasks.py
Jonathan Wren 671f403602
Fix docs pipeline, make docs tests easier to run locally and on different OSes (#1554)
* update docs pipeline to use poe task runner

* move npm dependency into package.json file instead of hardcoding into pipeline

* replace nix-specific call with python version (for windows compat)

* update commands to use python for win compat

* update lock file

* change deps to take out xq and use xmltodict instead

* move script tasks from pyproject into new tasks.py

* run linting on new tasks.py file

* fix typo

* clean up pyproject to make valid toml

* update docs with correct task runner command

* use npx in case node_modules/.bin isn't in the path

* Run pa11y-ci in cross-platform manner (works on Windows)

* Add node_modules to .gitignore

* clean up poe alias

Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
2022-08-21 13:47:25 -07:00

56 lines
1.2 KiB
Python

# Copyright © 2012-2022 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html
import json
import os
import pathlib
import subprocess
import requests
import xmltodict
DOCS_URL = "http://127.0.0.1:8000"
SITEMAP_FILENAME = "sitemap.xml"
CONFIG_FILENAME = "config.json"
def delete_files(files):
for file in files:
pathlib.Path(file).unlink(missing_ok=True)
def run_shell(command):
# Required to run NPM commands in Windows and *nix
subprocess.call(command, shell=True)
def generate_sitemap():
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():
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):
if not os.getenv("CI", False):
return
print(f"::group::{file}")
with open(file) as f:
print(f.read())
print("::endgroup::")