From 77d23aea87ec60b4aaadf3f934efb45ea8ab5d31 Mon Sep 17 00:00:00 2001 From: Daniela Rus Morales Date: Wed, 20 Nov 2024 11:24:24 +0100 Subject: [PATCH] Add tox, update tests.yml GHA workflow --- .github/workflows/lint.yaml | 39 ---------------- .github/workflows/tests.yaml | 62 +++++++++++++++++++++----- sphinx_nefertiti/__init__.py | 86 +++++++++++++++++------------------- tox.ini | 25 +++++++++++ 4 files changed, 116 insertions(+), 96 deletions(-) delete mode 100644 .github/workflows/lint.yaml create mode 100644 tox.ini diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml deleted file mode 100644 index 443669c..0000000 --- a/.github/workflows/lint.yaml +++ /dev/null @@ -1,39 +0,0 @@ -name: lint -on: - push: - branches: - - main - pull_request: - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: '18' - - - name: Cache dependencies - uses: actions/cache@v2 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} - restore-keys: | - ${{ runner.os }}-node- - - run: npm install - - run: npm run lint - - - uses: actions/setup-python@v3 - with: - python-version: "3.11" - - - name: Install Python dependencies - run: | - python -m pip install -U pip - python -m pip install black - - - name: Lint python code - run: black --check sphinx_nefertiti diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 24f3be0..b42cd24 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -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 diff --git a/sphinx_nefertiti/__init__.py b/sphinx_nefertiti/__init__.py index 9df39a8..359cd2a 100644 --- a/sphinx_nefertiti/__init__.py +++ b/sphinx_nefertiti/__init__.py @@ -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): diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..6dc0b46 --- /dev/null +++ b/tox.ini @@ -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}