Skip to content

Commit

Permalink
Add tox, update tests.yml GHA workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
danirus committed Nov 20, 2024
1 parent b25cbeb commit 77d23ae
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 96 deletions.
39 changes: 0 additions & 39 deletions .github/workflows/lint.yaml

This file was deleted.

62 changes: 50 additions & 12 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,59 @@ on:
- main
pull_request:

env:
FORCE_COLOR: true
NODE: 20
PYTHON: 3.13

permissions:
contents: read

jobs:
tests:
syntax-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "${{ env.NODE }}"
cache: npm
- name: Install npm dependencies
run: npm ci
- uses: actions/setup-python@v5
with:
python-version: "${{ env.PYTHON }}"
cache: pip
- name: Install pip dependencies
run: pip install .[dev]
- name: Run make lint
run: make lint

python-tests:
runs-on: ubuntu-latest
strategy:
matrix:
sphinx: ["7.3", "7.4", "8.0", "8.1"]
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v3
- uses: actions/setup-python@v5
with:
node-version: '18'
- name: Cache dependencies
uses: actions/cache@v4
python-version: "${{ env.PYTHON }}"
cache: pip
- name: Install deps
run: pip install tox
- name: Run unit tests
run: tox -e py3.13-sphinx${{ matrix.sphinx }}

javascript-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm install
- run: npm run js-test
node-version: "${{ env.NODE }}"
cache: npm
- name: Install npm dependencies
run: npm ci
- name: Run unit tests
run: npm run js-test
86 changes: 41 additions & 45 deletions sphinx_nefertiti/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,51 +26,47 @@ def initialize_theme(app):
dest_dir = Path(app.builder.outdir) / "_static"
dest_dir.mkdir(exist_ok=True)

try:
colorset_provider = colorsets.ColorsetProvider(app)
app.show_colorset_choices = colorset_provider.multiple
app.active_colorset = colorset_provider.colorset
if app.show_colorset_choices:
shutil.copyfile(
colorsets_path / "colorsets.js",
Path(app.builder.outdir) / "_static" / "colorsets.js",
)
app.add_js_file("colorsets.js")
for colorset in colorset_provider:
colorset.copy_to_static()
else:
app.active_colorset.copy_to_static()
app.add_css_file(app.active_colorset.link_stylesheet)

font_provider = fonts.FontProvider(app)
for font in font_provider:
font.copy_to_static()
app.add_css_file(font.link_stylesheet)

pygments_provider = pygments.PygmentsProvider(app)
for asset in pygments_provider:
dest_file = asset.create_pygments_style_file(app.builder.srcdir)
app.add_css_file(dest_file.name)

docsver_provider = docsver.DocsVersionProvider(app)
app.all_docs_versions = list(docsver_provider)

header_links_provider = links.HeaderLinksProvider(app)
app.header_links = list(header_links_provider)

footer_links_provider = links.FooterLinksProvider(app)
app.footer_links = list(footer_links_provider)

doc_versions_script = "doc_versions.js"
doc_versions_path = dest_dir / doc_versions_script
with doc_versions_path.open("w") as f:
f.write("const doc_versions = " + json.dumps(app.all_docs_versions))
app.add_js_file(doc_versions_script)
app.add_js_file("sphinx-nefertiti.min.js")
app.add_js_file("bootstrap.bundle.min.js")

except (fonts.FontNotSupportedException, Exception):
raise
colorset_provider = colorsets.ColorsetProvider(app)
app.show_colorset_choices = colorset_provider.multiple
app.active_colorset = colorset_provider.colorset
if app.show_colorset_choices:
shutil.copyfile(
colorsets_path / "colorsets.js",
Path(app.builder.outdir) / "_static" / "colorsets.js",
)
app.add_js_file("colorsets.js")
for colorset in colorset_provider:
colorset.copy_to_static()
else:
app.active_colorset.copy_to_static()
app.add_css_file(app.active_colorset.link_stylesheet)

font_provider = fonts.FontProvider(app)
for font in font_provider:
font.copy_to_static()
app.add_css_file(font.link_stylesheet)

pygments_provider = pygments.PygmentsProvider(app)
for asset in pygments_provider:
dest_file = asset.create_pygments_style_file(app.builder.srcdir)
app.add_css_file(dest_file.name)

docsver_provider = docsver.DocsVersionProvider(app)
app.all_docs_versions = list(docsver_provider)

header_links_provider = links.HeaderLinksProvider(app)
app.header_links = list(header_links_provider)

footer_links_provider = links.FooterLinksProvider(app)
app.footer_links = list(footer_links_provider)

doc_versions_script = "doc_versions.js"
doc_versions_path = dest_dir / doc_versions_script
with doc_versions_path.open("w") as f:
f.write("const doc_versions = " + json.dumps(app.all_docs_versions))
app.add_js_file(doc_versions_script)
app.add_js_file("sphinx-nefertiti.min.js")
app.add_js_file("bootstrap.bundle.min.js")


def update_context(app, pagename, templatename, context, doctree):
Expand Down
25 changes: 25 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[pytest]
python_files = test_*.py

[tox]
skipsdist = True
envlist = py3.13-sphinx{7.3,7.4,8.0,8.1}

[testenv]
changedir = {toxinidir}
commands =
coverage erase
coverage run --source=sphinx_nefertiti -m pytest -sra
coverage report -m
deps =
.[dev]
py3.13-sphinx7.3: sphinx>=7.3,<7.4
py3.13-sphinx7.3: sphinx[test]>=7.3,<7.4
py3.13-sphinx7.4: sphinx>=7.4,<7.5
py3.13-sphinx7.4: sphinx[test]>=7.4,<7.5
py3.13-sphinx8.0: sphinx>=8.0,<8.1
py3.13-sphinx8.0: sphinx[test]>=8.0,<8.1
py3.13-sphinx8.1: sphinx>=8.1,<8.2
py3.13-sphinx8.1: sphinx[test]>=8.1,<8.2
setenv =
PYTHONPATH = {toxinidir}:{toxinidir}

0 comments on commit 77d23ae

Please sign in to comment.