Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create proof of concept that the napari sphinx theme doesn't need to be maintained separatedly #592

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v5.0.0"
hooks:
- id: trailing-whitespace
- id: check-builtin-literals
- id: check-case-conflict
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.7
hooks:
- id: ruff-format
exclude: examples
- id: ruff
args: ["--fix", "--show-fixes"]

- repo: https://github.com/rbubley/mirrors-prettier
rev: "v3.4.2"
hooks:
- id: prettier
types_or: [yaml, markdown, html, css, scss, javascript, json]

- repo: https://github.com/abravalheri/validate-pyproject
rev: "v0.23"
hooks:
- id: validate-pyproject
additional_dependencies: ["validate-pyproject-schema-store[all]"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: docs clean
make.PHONY: docs clean

SPHINXOPTS =

Expand Down
47 changes: 39 additions & 8 deletions docs/_scripts/prep_docs.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,70 @@
"""ALL pre-rendering and pre-preparation of docs should occur in this file.

This script is called **before** Sphinx builds the documentation.

Note: make no assumptions about the working directory
from which this script will be called.
"""

import os
import sys
from pathlib import Path
from importlib.metadata import version
from pathlib import Path

from packaging.version import parse

from scripts_logger import setup_logger

logger = setup_logger(__name__)

# Set up paths to docs and npe2 docs source
DOCS = Path(__file__).parent.parent.absolute()
NPE = DOCS.parent.absolute() / 'npe2'
logger.debug(f"DOCS: {DOCS}")
NPE = DOCS.parent.absolute() / "npe2"
logger.debug(f"NPE: {NPE}")


def prep_npe2():
# some plugin docs live in npe2 for testing purposes
"""Preps the npe2 plugin engine prior to Sphinx docs build.

Some plugin-related docs live in the npe2 repo to simplify
plugin testing.
"""
logger.debug("Preparing npe2 plugin")
# Checks if the path to npe2 repo exist. If so, bail.
if NPE.exists():
logger.debug("NPE2 plugin already present")
return
from subprocess import check_call

npe2_version = version("npe2")

logger.debug(f"npe2 version: {npe2_version}")
check_call(f"rm -rf {NPE}".split())
logger.debug("removing NPE directory succeeded")
check_call(f"git clone https://github.com/napari/npe2 {NPE}".split())

if not parse(npe2_version).is_devrelease:
check_call(f"git checkout tags/v{npe2_version}".split(), cwd=NPE)
check_call([sys.executable, f"{NPE}/_docs/render.py", DOCS / 'plugins'])

check_call([sys.executable, f"{NPE}/_docs/render.py", DOCS / "plugins"])
check_call(f"rm -rf {NPE}".split())


def main():
prep_npe2()
__import__('update_preference_docs').main()
__import__('update_event_docs').main()
__import__('update_ui_sections_docs').main()
logger.debug("Prep npe2 complete")
__import__("update_preference_docs").main()
logger.debug("update_preference_docs succeeded")
__import__("update_event_docs").main()
logger.debug("update_event_docs succeeded")
__import__("update_ui_sections_docs").main()
logger.debug("update_ui_sections_docs succeeded")


if __name__ == "__main__":
# Example usage within a script
current_script_name = os.path.basename(__file__)
# Get the name of the current script
logger = setup_logger(current_script_name)

main()
59 changes: 59 additions & 0 deletions docs/_scripts/scripts_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Create a logger for a directory of scripts to aid in debugging."""

import logging
import os
import sys


def setup_logger(script_name, log_directory="logs"):
"""Sets up a logger for a specific script.

Args:
script_name (str): The name of the script (e.g., "my_script.py").
log_directory (str, optional): The directory to store log files. Defaults to "logs".

Returns:
logging.Logger: A configured logger instance.
"""
# Create log directory if it doesn't exist
if not os.path.exists(log_directory):
os.makedirs(log_directory)

# Extract the script name without the extension
script_name_no_ext = os.path.splitext(script_name)[0]

# Create a logger
logger = logging.getLogger(script_name_no_ext)
logger.setLevel(logging.DEBUG) # Set the minimum logging level

# Create a file handler
# log_file_path = os.path.join(log_directory, f"{script_name_no_ext}.log")
# file_handler = logging.FileHandler(log_file_path)
# file_handler.setLevel(logging.DEBUG)

handler = logging.StreamHandler(sys.stdout)

# Create a formatter
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
# file_handler.setFormatter(formatter)
handler.setFormatter(formatter)

# Add the file handler to the logger
# logger.addHandler(file_handler)
logger.addHandler(handler)
return logger


if __name__ == "__main__":
# Example usage within a script
current_script_name = os.path.basename(__file__)
# Get the name of the current script
logger = setup_logger(current_script_name)

logger.debug("This is a debug message.")
logger.info("This is an info message.")
logger.warning("This is a warning message.")
logger.error("This is an error message.")
logger.critical("This is a critical message.")
Loading
Loading