diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 00f465f2e..ce7bc6c0a 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -51,7 +51,7 @@ jobs: run: ./ci/build.sh - name: Postprocess site shell: bash - run: make multidocs + run: nox -s deploy - name: Deploy to GitHub Pages if: env.IS_DEPLOY == '1' uses: JamesIves/github-pages-deploy-action@v4 diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 882bbbb2c..d520e034c 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -42,4 +42,4 @@ jobs: shell: bash run: pip list - name: Run Linkcheck - run: make linkcheck + run: nox -s linkcheck diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 068d90b87..fd314c157 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,11 +20,12 @@ Let us know if you have any further questions, and we look forward to your contr - [Reporting Issues](#reporting-issues) -- [Setting Up a Development Environment](#setting-up-a-development-environment) - - [Fork and clone the repo](#fork-and-clone-the-repo) +- [Cloning the repository](#cloning-the-repository) +- [Setting Up a Development Environment with Nox (Recommended)](#setting-up-a-development-environment-with-nox-recommended) +- [Setting Up a Development Environment Manually](#setting-up-a-development-environment-manually) - [Create and activate a fresh environment](#create-and-activate-a-fresh-environment) - [Install dependencies](#install-dependencies) - - [Install the required Pre-Commit hooks](#install-the-required-pre-commit-hooks) +- [Installing the Pre-Commit Hooks](#installing-the-pre-commit-hooks) - [Building the docs](#building-the-docs) - [Deciding Which Branch to Use](#deciding-which-branch-to-use) - [Making Your Changes](#making-your-changes) @@ -48,14 +49,7 @@ If referring to a particular word, line or section, please be sure to provide a -## Setting Up a Development Environment - -For non-trivial changes, its easy to work with Spyder-Docs locally by following a few simple steps. - -**Note**: You may need to substitute ``python3`` for ``python`` in the commands below on some Linux distros where ``python`` isn't mapped to ``python3`` (yet). - - -### Fork and clone the repo +## Cloning the repository First, navigate to the [project repository](https://github.com/spyder-ide/spyder-docs) in your web browser and press the ``Fork`` button to make a personal copy of the repository on your own Github account. Then, click the ``Clone or Download`` button on your repository, copy the link and run the following on the command line to clone the repo: @@ -77,6 +71,45 @@ git remote add upstream https://github.com/spyder-ide/spyder-docs.git ``` + +## Setting Up a Development Environment with Nox (Recommended) + +Our [Nox](https://nox.thea.codes/) configuration makes it easy to get set up and building Spyder-Docs in just one or two steps! + +If you already have Nox installed, you're already done! +Otherwise, you can easily install it as a standalone tool with [pipx](https://pipx.pypa.io/) (if you don't have that either, you'll need to install it first if you go that route): + +```shell +pipx install nox +``` + +Alternatively, install it into your global (or preferred) Python environment with the usual: + +```shell +conda install nox +``` + +or, if not using Conda, + +```shell +python -m pip install nox +``` + +To check that Nox is installed and browse a list of commands (called "sessions") we provide through Nox and what they do, you can run + +```shell +nox --list +``` + + + +## Setting Up a Development Environment Manually + +For advanced users, if you'd prefer to also have your own local environment with the docs dependencies that doesn't go through Nox, you can also set one up yourself. + +**Note**: You may need to substitute ``python3`` for ``python`` in the commands below on some Linux distros where ``python`` isn't mapped to ``python3`` (yet). + + ### Create and activate a fresh environment We highly recommend you create and activate a virtual environment to avoid any conflicts with other packages on your system or causing any other issues. @@ -89,7 +122,7 @@ Regardless of the tool you use, make sure to remember to always activate your en To create an environment with Conda (recommended), simply execute the following: ```shell -conda create -c conda-forge -n spyder-docs-env python=3.9 +conda create -c conda-forge -n spyder-docs-env python ``` Then, activate it with @@ -120,10 +153,9 @@ or on Windows (``cmd.exe``), ``` - ### Install dependencies -Then, you need to install the appropriate dependencies in your active Python environment to develop and build the documentation. +Then, since you're not using Nox, you need to install the appropriate dependencies in your active Python environment to develop and build the documentation. You can install them into your current Conda environment with: ```shell @@ -137,12 +169,21 @@ python -m pip install -r requirements.txt ``` -### Install the required Pre-Commit hooks + +## Installing the Pre-Commit Hooks This repository uses [Pre-Commit](https://pre-commit.com/) to install, configure and update a suite of pre-commit hooks that check for common problems and issues, and fix many of them automatically. You'll need to install the pre-commit hooks before committing any changes, as they both auto-generate/update specific files and run a comprehensive series of checks to help you find likely errors and enforce the project's code quality guidelines and style guide. They are also run on all pull requests, and will need to pass before your changes can be merged. -Pre-commit itself is installed with the [above commands](#install-dependencies), and its hooks should be enabled by running the following from the root of this repo: + +If you've [using Nox](#setting-up-a-development-environment-with-nox-recommended), it installs Pre-Commit in its own environment, and we provide our own simplified command to install the hooks: + +```shell +nox -s install-hooks +``` + +If instead you've followed the [manual install approach](#install-dependencies), pre-commit will be installed directly in your local environment. +To install the hooks, run the following from the root of this repo: ```shell pre-commit install --hook-type pre-commit --hook-type commit-msg @@ -150,7 +191,13 @@ pre-commit install --hook-type pre-commit --hook-type commit-msg The hooks will be automatically run against any new/changed files every time you commit. It may take a few minutes to install the needed packages the first time you commit, but subsequent runs should only take a few seconds. -If you made one or more commits before installing the hooks (not recommended), you can run them manually on all the files in the repo with: +If you made one or more commits before installing the hooks, or would like to run them manually on everything in the repo, you can do so with: + +```shell +nox -s lint +``` + +or ```shell pre-commit run --all-files @@ -163,29 +210,31 @@ Once you're satisfied, ``git add .`` and commit again. ## Building the docs -To build the docs locally with Sphinx, you can easily do so with our makefile from the Terminal/command line, or via running the appropriate Sphinx command. +To build the docs locally with Sphinx, if you've installed Nox you can just run + +```shell +nox -s build +``` -To build just the docs for the current version, run the following on a system terminal with ``make`` (macOS/Linux): +For manual installations, you can invoke Sphinx yourself with the appropriate options: -```bash -make docs -make serve +```shell +python -m sphinx -n -W --keep-going doc doc/_build/html ``` -To build the full site with the documentation for all Spyder versions, run: +If using Nox, you can open the rendered documentation in your default web browser with -```bash -make multidocs +```shell +nox -s serve ``` -On a system without ``make`` (like Windows, by default), or to build the docs manually, run: +and to additionally automatically keep rebuilding the docs when changes occur, you can invoke ```shell -python -m sphinx -n -W --keep-going -b html doc doc/_build/html +nox -s autobuild ``` -If you've run ``make serve``, the rendered documentation should open automatically in your default web browser. -Otherwise, navigate to the ``_build/html`` directory inside the ``spyder-docs`` repository and open ``index.html`` (the main page of the docs) in your browser. +Otherwise, navigate to the ``_build/html`` directory inside the ``spyder-docs`` repository and open ``index.html`` (the main page of the docs) in your preferred browser. @@ -193,12 +242,12 @@ Otherwise, navigate to the ``_build/html`` directory inside the ``spyder-docs`` When you start to work on a new pull request (PR), you need to be sure that your work is done on top of the correct branch, and that you base your PR on Github against it. -To guide you, issues on Github are marked with a milestone that indicates the correct branch to use. +To guide you, issues on GitHub are marked with a milestone that indicates the correct branch to use. If not, follow these guidelines: -* The ``master`` branch contains the in-development documentation for Spyder 5; most general changes and those specific to that version should be made against this branch. -* The ``4.x`` branch contains the docs for Spyder 4 and is in bugfix-only mode; no substantial new content should be added here at this point. -* The ``3.x`` branch is frozen, containing the docs for the legacy Spyder 3 version; no further PRs will be accepted +* The ``master`` branch contains the in-development documentation for Spyder 6; changes specific to that version should be made against this branch. +* The ``5.x`` branch contains the docs for Spyder 4 and is still maintained; general changes and those applicable to only this version should be made to this branch. +* The ``4.x`` and ``3.x`` branch is frozen, containing the docs for the legacy Spyder 4 and Spyder 3 versions; no further PRs will be accepted Of course, if an issue is only present in a specific branch, please base your PR on that branch. If you are at all unsure which branch to use, we'll be happy to guide you. @@ -247,7 +296,7 @@ Where ```` is the name of your feature branch, e.g. ``fix-docs-t ## Submitting a Pull Request -Finally, create a pull request to the [spyder-ide/spyder-docs repository](https://github.com/spyder-ide/spyder-docs/) on Github. +Finally, create a pull request to the [spyder-ide/spyder-docs repository](https://github.com/spyder-ide/spyder-docs/) on GitHub. Make sure to set the target branch to the one you based your PR off of (``master`` or ``X.x``). We'll then review your changes, and after they're ready to go, your work will become an official part of Spyder-Docs. diff --git a/Makefile b/Makefile deleted file mode 100644 index 9cd62a8a5..000000000 --- a/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -.PHONY: clean clean-test clean-pyc clean-build docs multidocs help -.DEFAULT_GOAL := help - -define BROWSER_PYSCRIPT -import os, webbrowser, sys - -from urllib.request import pathname2url - -webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1]))) -endef -export BROWSER_PYSCRIPT - -define PRINT_HELP_PYSCRIPT -import re, sys - -for line in sys.stdin: - match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) - if match: - target, help = match.groups() - print("%-20s %s" % (target, help)) -endef -export PRINT_HELP_PYSCRIPT - -BROWSER := python -c "$$BROWSER_PYSCRIPT" - -help: - @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) - -clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts - -autodocs: ## generate Sphinx HTML documentation, including API docs - rm -f doc/spyder.* - rm -f doc/modules.rst - sphinx-apidoc -o doc/ spyder-repo/spyder/ *tests* - -docs: ## generate Sphinx HTML documentation for the current branch - $(MAKE) -C doc clean - $(MAKE) -C doc html - -multidocs: ## prepare Sphinx HTML documentation for multiversion deployment - mkdir doc/_build/html/5 - mv doc/_build/html/* doc/_build/html/5 || true - @python scripts/safecopy.py "5" "current" -v --base-path "doc/_build/html" - @python scripts/generateredirects.py "current" -v --base-path "doc/_build/html" --base-url "https://docs.spyder-ide.org" - -linkcheck: ## check that links are still valid - $(MAKE) -C doc linkcheck - -servedocs: doc ## compile the docs watching for changes - watchmedo shell-command -p '*.rst' -c '$(MAKE) -C doc html' -R -D . - -serve: clean ## Launch the docs in a web browser - $(BROWSER) doc/_build/html/index.html diff --git a/README.md b/README.md index b6f768eb1..ce3a9b066 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ [![Lint](https://github.com/spyder-ide/spyder-docs/actions/workflows/lint.yaml/badge.svg)](https://github.com/spyder-ide/spyder-docs/actions/workflows/lint.yaml) [![Netlify Status](https://api.netlify.com/api/v1/badges/06f113a8-c699-4171-afc6-db3a3c77d93b/deploy-status)](https://app.netlify.com/sites/spyder-docs-preview/deploys) [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit) +[![Nox](https://img.shields.io/badge/%F0%9F%A6%8A-Nox-D85E00.svg)](https://github.com/wntrblm/nox) [![OpenCollective Backers](https://opencollective.com/spyder/backers/badge.svg?color=blue)](https://opencollective.com/spyder) @@ -41,13 +42,15 @@ For more information about Spyder itself, please see our [website](https://www.s ## Building and Deploying The docs are built with [Sphinx](https://www.sphinx-doc.org/) and deployed with GitHub Actions to the [docs.Spyder-IDE.org](https://docs.spyder-ide.org/) domain. -The ``master`` branch contains the in-development docs for Spyder 5, while the ``4.x`` branch with the Spyder 4 docs is still maintained, and the frozen ``3.x`` branch retains the docs for the legacy Spyder 3. +[Nox](https://nox.thea.codes/) is used to automate setup, building and numerous other project tasks. +The ``master`` branch contains the in-development docs for Spyder 5, while the frozen ``4.x`` and ``3.x`` branches retain the docs for Spyder 4 and Spyder 3. ## Contributing We welcome your contributions of corrections, additions and enhancements to these docs, as they are very much a work in progress, and we appreciate getting our broad community involved wherever possible. -To do so, simply submit a PR with your changes and we'll be happy to review it; make sure to read our [Contributing Guide](https://github.com/spyder-ide/spyder-docs/blob/master/CONTRIBUTING.md) in mind to ensure the process of getting your revisions integrated goes smoothly. +Its easy to build a local copy in one or two steps with Nox, or you can also just check your changes with our live build previews on PRs. +Simply submit a PR with your changes and we'll be happy to review it; make sure to read our [Contributing Guide](https://github.com/spyder-ide/spyder-docs/blob/master/CONTRIBUTING.md) in mind to ensure the process of getting your revisions integrated goes smoothly. Thanks for your interest in Spyder and its documentation, and we appreciate your support of the project! @@ -60,9 +63,6 @@ Thanks for your interest in Spyder and its documentation, and we appreciate your [Spyder Github](https://github.com/spyder-ide/spyder) -[Troubleshooting Guide and FAQ]( -https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) - [Development Wiki](https://github.com/spyder-ide/spyder/wiki/Dev:-Index) [Google Group](https://groups.google.com/group/spyderlib) diff --git a/ci/build.sh b/ci/build.sh index 0786bda69..35a7754e9 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -1,3 +1,3 @@ #!/bin/bash -ex -make docs +nox -s build diff --git a/ci/install.sh b/ci/install.sh index f35d601cc..c2cb9dcf4 100755 --- a/ci/install.sh +++ b/ci/install.sh @@ -1,20 +1,4 @@ #!/bin/bash -ex python3 -m pip install --upgrade pip setuptools wheel -python3 -m pip install --upgrade -r requirements.txt - -# You can uncomment the command below to use a different version of the theme (but return it to the correct one before merging) -# python3 -m pip install --upgrade --force-reinstall --no-deps git+https://github.com/spyder-ide/spyder-docs-sphinx-theme.git@develop_spyder - -# Configure the username and email so Git doesn't complain -if [ "${CI-}" = "true" ]; then - git config --global user.email "spyder.python@gmail.com" - git config --global user.name "Spyder-Docs Deploy Bot" -fi - -# Needed to build PR previews using Netlify with the different versions of the docs available -if [ "${NETLIFY-}" = "true" ]; then - git config remote.upstream.url >&- || git remote add upstream https://github.com/spyder-ide/spyder-docs.git - git fetch --all - git update-ref -m "reset: Update master to latest commit" refs/heads/master upstream/master -fi +python3 -m pip install --upgrade nox diff --git a/doc/Makefile b/doc/Makefile deleted file mode 100644 index 384a3d617..000000000 --- a/doc/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# Minimal makefile for Sphinx documentation -# - -# You can set these variables from the command line. -SPHINXOPTS = -n -W --keep-going --color -SPHINXBUILD = sphinx-build -SPHINXPROJ = Spyder -SOURCEDIR = . -BUILDDIR = _build - -# Put it first so that "make" without argument is like "make help". -help: - @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) - -.PHONY: help Makefile - -# Catch-all target: route all unknown targets to Sphinx using the new -# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). -%: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/doc/make.bat b/doc/make.bat deleted file mode 100644 index 7ff20b55a..000000000 --- a/doc/make.bat +++ /dev/null @@ -1,37 +0,0 @@ -@ECHO OFF - -pushd %~dp0 - -REM Command file for Sphinx documentation - -if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=sphinx-build -) -set SOURCEDIR=. -set BUILDDIR=_build -set SPHINXPROJ=Spyder -set SPHINXOPTS=-n -W --keep-going - -if "%1" == "" goto help - -%SPHINXBUILD% >NUL 2>NUL -if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.http://sphinx-doc.org/ - exit /b 1 -) - -%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% -goto end - -:help -%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% - -:end -popd diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 000000000..3e058586f --- /dev/null +++ b/noxfile.py @@ -0,0 +1,292 @@ +"""Common tasks to build, check and publish Spyder-Docs.""" + +# Standard library imports +import os +import tempfile +import shutil +import sys +import webbrowser +from pathlib import Path + +# Third party imports +import nox # pylint: disable=import-error + + +# --- Global constants --- # + +nox.options.sessions = ["build"] +nox.options.default_venv_backend = "none" + +LATEST_VERSION = 5 +BASE_URL = "https://docs.spyder-ide.org" + +BUILD_INVOCATION = ("python", "-m", "sphinx", "--color") +SOURCE_DIR = Path("doc").resolve() +BUILD_DIR = Path("doc/_build").resolve() +BUILD_OPTIONS = ("-n", "-W", "--keep-going") + +HTML_BUILDER = "html" +HTML_BUILD_DIR = BUILD_DIR / "html" +HTML_INDEX_PATH = HTML_BUILD_DIR / "index.html" + +SCRIPT_DIR = Path("scripts").resolve() + +CI = "CI" in os.environ + + +# ---- Helpers ---- # + +def split_sequence(seq, sep="--"): + """Split a sequence by a single separator.""" + if sep not in seq: + seq.append(sep) + idx = seq.index(sep) + return seq[:idx], seq[idx + 1:] + + +def process_filenames(filenames, source_dir=SOURCE_DIR): + """If filepaths are missing the source directory, add it automatically.""" + source_dir = Path(source_dir) + filenames = [ + str(source_dir / filename) + if source_dir not in Path(filename).resolve().parents + else filename + for filename in filenames + ] + return filenames + + +def construct_sphinx_invocation( + posargs=(), + builder=HTML_BUILDER, + source_dir=SOURCE_DIR, + build_dir=BUILD_DIR, + build_options=BUILD_OPTIONS, + build_invocation=BUILD_INVOCATION, +): + """Reusably build a Sphinx invocation string from the given arguments.""" + extra_options, filenames = split_sequence(posargs) + filenames = process_filenames(filenames, source_dir=source_dir) + sphinx_invocation = [ + *build_invocation, + "-b", + builder, + *build_options, + *extra_options, + str(source_dir), + str(Path(build_dir) / builder), + *filenames, + ] + return sphinx_invocation + + +# ---- Dispatch ---- # + +# Workaround for Nox not (yet) supporting shared venvs +# See: https://github.com/wntrblm/nox/issues/167 +@nox.session(venv_backend="virtualenv", reuse_venv=True) +def _execute(session): + """Dispatch tasks to run in a common environment. Don not run directly.""" + _install(session) + if session.posargs: + for task in session.posargs[0]: + task(session) + + +# ---- Install ---- # + +def _install(session): + """Execute the dependency installation.""" + session.install("-r", "requirements.txt") + + +@nox.session +def install(session): + """Install the project's dependencies in a virtual environment.""" + session.notify("_execute", posargs=()) + + +# ---- Utility ---- # + +def _sphinx_help(session): + """Print Sphinx --help.""" + session.run(*BUILD_INVOCATION, "--help") + + +@nox.session(name="help") +def sphinx_help(session): + """Get help with Sphinx.""" + session.notify("_execute", posargs=([_sphinx_help],)) + + +def _run(session): + """Run an arbitrary command in the project's venv.""" + session.run(*session.posargs[1:]) + + +@nox.session() +def run(session): + """Run any command.""" + session.notify("_execute", posargs=([_run], *session.posargs)) + + +def _clean(): + """Remove the Sphinx build directory.""" + try: + BUILD_DIR.unlink() + except FileNotFoundError: + pass + + +@nox.session +def clean(_session): + """Clean build artifacts.""" + _clean() + + +# ---- Build ---- # + +def _build(session): + """Execute the docs build.""" + sphinx_invocation = construct_sphinx_invocation( + posargs=session.posargs[1:]) + session.run(*sphinx_invocation) + + +@nox.session +def build(session): + """Build the project.""" + session.notify("_execute", posargs=([_build], *session.posargs)) + + +def _serve(): + """Open the docs in a web browser.""" + webbrowser.open(HTML_INDEX_PATH.as_uri()) + + +@nox.session +def serve(_session): + """Display the project.""" + _serve() + + +def _autobuild(session): + """Use Sphinx-Autobuild to rebuild the project and open in browser.""" + session.install("sphinx-autobuild") + + with tempfile.TemporaryDirectory() as destination: + sphinx_invocation = construct_sphinx_invocation( + posargs=session.posargs[1:], + build_dir=destination, + build_options=list(BUILD_OPTIONS) + ["-a"], + build_invocation=[ + "sphinx-autobuild", + "--port=0", + f"--watch={SOURCE_DIR}", + "--open-browser", + ] + ) + session.run(*sphinx_invocation) + + +@nox.session +def autobuild(session): + """Rebuild the project continuously as source files are changed.""" + session.notify("_execute", posargs=([_autobuild], *session.posargs)) + + +# ---- Deploy ---- # + +def _deploy(): + """Execute the pre-deployment steps for multi-version support.""" + # pylint: disable=import-outside-toplevel + + sys.path.append(str(SCRIPT_DIR)) + import generateredirects + import safecopy + + latest_version_dir = HTML_BUILD_DIR / str(LATEST_VERSION) + shutil.copytree( + HTML_BUILD_DIR, latest_version_dir, copy_function=shutil.move) + safecopy.copy_dir_if_not_existing( + source_dir=str(LATEST_VERSION), + target_dir="current", + base_path=HTML_BUILD_DIR, + verbose=True, + ) + generateredirects.generate_redirects( + canonical_dir="current", + base_path=HTML_BUILD_DIR, + verbose=True, + base_url=BASE_URL, + ) + + +@nox.session +def deploy(_session): + """Prepare the project for deployment.""" + _deploy() + + +# ---- Check ---- # + +def _install_hooks(session): + """Run pre-commit install to install the project's hooks.""" + session.run( + "pre-commit", + "install", + "--hook-type", + "pre-commit", + "--hook-type", + "commit-msg", + ) + + +@nox.session(name="install-hooks") +def install_hooks(session): + """Install the project's pre-commit hooks.""" + session.notify("_execute", posargs=([_install_hooks],)) + + +def _uninstall_hooks(session): + """Run pre-commit uninstall to uninstall the project's hooks.""" + session.run( + "pre-commit", + "uninstall", + "--hook-type", + "pre-commit", + "--hook-type", + "commit-msg", + ) + + +@nox.session(name="uninstall-hooks") +def uninstall_hooks(session): + """Uninstall the project's pre-commit hooks.""" + session.notify("_execute", posargs=([_uninstall_hooks],)) + + +def _lint(session): + """Run linting on the project via pre-commit.""" + extra_options = ["--show-diff-on-failure"] if CI else [] + session.run( + "pre-commit", "run", "--all", *extra_options, *session.posargs[1:]) + + +@nox.session +def lint(session): + """Lint the project.""" + session.notify("_execute", posargs=([_lint], *session.posargs)) + + +def _linkcheck(session): + """Run Sphinx linkcheck on the docs.""" + sphinx_invocation = construct_sphinx_invocation( + posargs=session.posargs[1:], builder="linkcheck") + session.run(*sphinx_invocation) + + +@nox.session +def linkcheck(session): + """Check that links in the project are valid.""" + session.notify("_execute", posargs=([_linkcheck], *session.posargs)) diff --git a/scripts/safecopy.py b/scripts/safecopy.py index aba05c8ac..1dd4ab578 100755 --- a/scripts/safecopy.py +++ b/scripts/safecopy.py @@ -12,9 +12,10 @@ def copy_dir_if_not_existing( """Copy a directory to another path if the target doesn't already exist.""" base_path = Path(base_path) source_dir = Path(source_dir) + target_dir = Path(target_dir) + if not source_dir.is_absolute(): source_dir = base_path / source_dir - target_dir = Path(target_dir) if not target_dir.is_absolute(): target_dir = base_path / target_dir