Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
fschuch committed Jun 7, 2024
1 parent 449f3b6 commit 4f05d13
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 202 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
name: ci
name: CI

on:
push:
tags:
- "[0-9].[0-9].[0-9]*"
- "v*.*.*"
branches:
- "main"
- "release/**"
pull_request:
paths:
- .github/workflows/ci.yaml
- hatch.toml
- pyproject.toml
- tests/**
- wizard_template/**
Expand All @@ -23,6 +22,7 @@ concurrency:

jobs:
qa:
# Static code analysis and linting powered by pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:

release:
needs: build
# upload to PyPI on every tag
# upload to PyPI on every tag and ensure it does not run on forks
if: github.event_name == 'push' && github.ref_type == 'tag' && github.repository == 'fschuch/wizard_template'
runs-on: ubuntu-latest
environment:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: Docs
on:
push:
tags:
- "[0-9].[0-9].[0-9]*"
- "v*.*.*"
branches:
- main
- release/**
Expand All @@ -14,7 +14,6 @@ on:
- .github/workflows/docs.yaml
- docs/**
- wizard_template/**
- hatch.toml
- pyproject.toml

jobs:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ instance/

# Sphinx documentation
docs/_build/
docs/conf.py

# PyBuilder
.pybuilder/
Expand Down
89 changes: 26 additions & 63 deletions README.md

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,25 @@ repository:
# Add GitHub buttons to your book
# See https://jupyterbook.org/customize/config.html#add-a-link-to-your-repository
html:
home_page_in_navbar: false
use_edit_page_button: true
use_issues_button: true
use_repository_button: true

sphinx:
extra_extensions:
- sphinx.ext.autodoc
- sphinx.ext.intersphinx
- sphinx.ext.napoleon
config:
#https://github.com/executablebooks/jupyter-book/issues/1950#issuecomment-1454801479
suppress_warnings: ["mystnb.unknown_mime_type"]

intersphinx_mapping:
python:
- "https://docs.python.org/3"
- null

napoleon_include_special_with_doc: true
napoleon_google_docstring: False
napoleon_numpy_docstring: True
13 changes: 9 additions & 4 deletions docs/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

format: jb-book
root: intro
chapters:
- file: markdown
- file: notebooks
- file: markdown-notebooks
parts:
- caption: Base
chapters:
- file: markdown
- file: notebooks
- file: markdown-notebooks
- caption: References
chapters:
- file: api-reference.rst
10 changes: 10 additions & 0 deletions docs/api-reference.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
API reference
==================


Core
----

.. automodule:: wizard_template.core
:members:
:show-inheritance:
73 changes: 0 additions & 73 deletions docs/conf.py

This file was deleted.

Empty file removed docs/requirements.txt
Empty file.
47 changes: 0 additions & 47 deletions hatch.toml

This file was deleted.

57 changes: 52 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

[build-system]
requires = ["hatchling>=1.21.0", "hatch-vcs>=0.3.0"]
build-backend = "hatchling.build"

[project]
name = "wizard-template"
description = "A template for a python project containing a library, tests, docs, and CI/CD."
description = "A template for a python project containing a package, tests, docs, and CI/CD."
readme = "README.md"
license = "MIT"
requires-python = ">=3.8"
Expand All @@ -9,7 +14,6 @@ classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Private :: Do Not Upload", # Prevent accidental upload to PyPI, remove before publishing
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
Expand Down Expand Up @@ -68,6 +72,49 @@ exclude = ["docs/conf.py"]
skip = "docs/conf.py"
check-filenames = true

[build-system]
requires = ["hatchling>=1.21.0", "hatch-vcs>=0.3.0"]
build-backend = "hatchling.build"
[tool.hatch.version]
source = "vcs"

[tool.hatch.build.hooks.vcs]
version-file = "wizard_template/_version.py"

[tool.hatch.envs.default]
installer = "uv"
description = "Base development environment"
dependencies = ["coverage[toml]", "pre-commit", "pytest-cov", "pytest"]

[tool.hatch.envs.default.scripts]
_wizard = ["python ./scripts/rename_project_content.py"]
pre-commit-install = "pre-commit install {args}"
pre-commit-uninstall = "pre-commit uninstall {args}"
check = "pre-commit run {args} --all-files"
type = "check mypy {args}"
lint = "check ruff {args}"
format = "check ruff-format {args}"
test = "pytest --cov --cov-report=term {args}"
test-no-cov = "test --no-cov {args}"
qa = ["check", "test", "echo '✅ QA passed'"]

[tool.hatch.envs.test]
description = "Extended test environment"
extra-dependencies = ["pytest-randomly", "pytest-rerunfailures", "pytest-xdist"]

[tool.hatch.envs.test.scripts]
extended = "test -n auto --reruns 7 --reruns-delay 1 {args}"

[[tool.hatch.envs.test.matrix]]
python = ["3.8", "3.9", "3.10", "3.11", "3.12"]

[tool.hatch.envs.docs]
description = "Documentation environment"
template = "docs"
install = true
dependencies = ["docutils", "jupyter-book", "sphinx-autobuild"]

[tool.hatch.envs.docs.scripts]
config = "jupyter-book config sphinx docs {args}"
build = ["config", "jupyter-book build docs --path-output build {args}"]
serve = [
"config",
"sphinx-autobuild docs build/_build/html --open-browser --watch wizard_template {args}",
]
17 changes: 16 additions & 1 deletion scripts/rename_project_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
CWD = Path.cwd()
THIS_FILE = Path(__file__)

COMMUNITY_BADGE_TEMPLATE = (
"[![Wizard Template]"
"(https://img.shields.io/badge/Wizard-Template-%23447CAA)]"
"(https://github.com/{}/{})"
)

ORIGINAL_BADGE = COMMUNITY_BADGE_TEMPLATE.format(
ORIGINAL_USERNAME, ORIGINAL_PROJECT_NAME
)


class GitInfo(NamedTuple):
"""Named tuple to store the git info."""
Expand Down Expand Up @@ -49,7 +59,7 @@ def from_repo_info_with_fallback() -> GitInfo:
"""Get the repository information."""
try:
return GitInfo.from_repo_info()
except ValueError:
except (ValueError, subprocess.CalledProcessError):
print("Could not parse git URL, please enter the information manually.")
username = input("Enter your username: ")
repo = input("Enter your repo: ")
Expand All @@ -67,6 +77,8 @@ def main() -> None:
project_name_dash = project_name.replace("_", "-")
project_name_underscore = project_name.replace("-", "_")

tmp_badge = COMMUNITY_BADGE_TEMPLATE.format(username, project_name)

# Map new values to the patterns to be replaced
patterns = {
username: re.compile(ORIGINAL_USERNAME),
Expand All @@ -88,6 +100,9 @@ def main() -> None:
for new_value, pattern in patterns.items():
filedata = pattern.sub(new_value, filedata)

# Revert back the badge to support the original project
filedata = filedata.replace(tmp_badge, ORIGINAL_BADGE)

# Write the file out again
filepath.write_text(filedata)

Expand Down
9 changes: 6 additions & 3 deletions wizard_template/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ def demo_function(incoming_int: int) -> int:
Args
----
incoming_int: The input to be doubled.
incoming_int
The input to be doubled
Returns
-------
The doubled input.
int
The doubled input
Raises
------
TypeError: If the input is not an integer.
NotAnIntegerError
If tried with an invalid input
Examples
--------
Expand Down

0 comments on commit 4f05d13

Please sign in to comment.