Giter Club home page Giter Club logo

mudkip's Introduction

Mudkip

GitHub Actions PyPI PyPI - Python Version Code style: black

A friendly Sphinx wrapper.

Mudkip is a small wrapper around Sphinx that bundles essential tools and extensions, providing everything needed for building rich documentation for Python projects.

$ mudkip --help
Usage: mudkip [OPTIONS] COMMAND [ARGS]...

  A friendly Sphinx wrapper.

Options:
  --version  Show the version and exit.
  --help     Show this message and exit.

Commands:
  build    Build documentation.
  clean    Remove output directory.
  develop  Start development server.
  init     Initialize documentation.
  test     Test documentation.

Features

Mudkip intends to provide an out-of-the-box solution for most Python projects. The command-line utility lets you build and check your documentation, launch a development server with live reloading, run doctests and more!

Mudkip enables the following Sphinx extensions:

Installation

The package can be installed with pip.

$ pip install mudkip

Getting started

You can forget everything about sphinx-quickstart, conf.py and intimidating Makefiles. After installing the package, no need to configure anything you can run the develop command right away and start writing docs.

$ mudkip develop
Watching "docs"...
Server running on http://localhost:5500

The command will create the "docs" directory if it doesn't already exist and launch a development server with live reloading. If you create an index.rst file and open the link in your browser, you'll see that mudkip uses the Read the Docs theme by default.

Note that mudkip enables the myst_parser extension, allowing you to use both reStructuredText and markdown files. You can create an index.md file if you want to use markdown instead of reStructuredText.

Press Ctrl+C at any time to exit.

Building and checking documentation

The build command invokes the dirhtml builder and builds your documentation. By default, the generated files are in "docs/_build".

$ mudkip build

Running the command with the --check or -c flag will exit with code 1 if Sphinx reports any error or warning.

$ mudkip build --check

The --check flag also makes sure that there are no broken links by running the linkcheck builder on your documentation. You can disable this with the --skip-broken-links flag.

The build command also features a really handy flag if you're deploying the documentation to GitHub Pages. The --update-gh-pages flag will invoke Sphinx with the sphinx.ext.githubpages extension and then force push the output directory to the gh-pages branch of your repository.

$ mudkip build --update-gh-pages

The remote branch will be created if it doesn't already exist.

Running doctests

Mudkip enables the sphinx.ext.doctest extension, making it possible to test interactive code examples. You can try it out by adding the following code snippet to your index document:

.. doctest::

    >>> import this
    The Zen of Python, by Tim Peters
    <BLANKLINE>
    Beautiful is better than ugly.
    ...

The test command will run the code example and make sure that the output matches the documentation.

$ mudkip test
Testing "docs"...

Document: index
---------------
1 items passed all tests:
   1 tests in default
1 tests in 1 items.
1 passed and 0 failed.
Test passed.

Doctest summary
===============
    1 test
    0 failures in tests
    0 failures in setup code
    0 failures in cleanup code

Passed.

Using Jupyter notebooks

The myst-nb extension provides support for Jupyter notebooks. This means that in addition to .rst and .md files, Sphinx will also generate pages for .ipynb files.

The develop command can launch the Jupyter notebook in the "docs" directory and open it in your browser with the --notebook or -n flag.

$ mudkip develop --notebook
Watching "docs"...
Server running on http://localhost:5500
Notebook running on http://localhost:8888/?token=5e64df6...

Notebooks are executed during the build process. The --check flag will make sure that there are no uncaught exceptions in any cell.

Integration with npm and yarn

Mudkip can help you go beyond traditional Sphinx themes by running npm scripts for you and integrate with the build process of a custom front-end. If your docs contain a package.json file, Mudkip will run Sphinx and then invoke the appropriate npm script using your preferred npm client.

$ mudkip build

Here, Mudkip would try to run either npm run build or yarn build before exiting the command. Similarly, mudkip clean would try to run either npm run clean or yarn clean.

$ mudkip develop

The develop command will try to run one of the following scripts: develop, dev, start or serve. If you don't have a dedicated script to run your project in development mode, Mudkip will simply execute the build script after running Sphinx each time you make a modification.

Configuration

Mudkip doesn't really require any configuration but you can change some of the default settings with command-line options or a configuration file.

For example, when running a command, you can set the --preset or -p option to furo if you want to use the Furo theme instead of the default Read the Docs theme.

$ mudkip build --preset furo

It's also possible to change the default source and output directories with the --source-dir and --output-dir options respectively.

$ mudkip build --source-dir path/to/docs --output-dir path/to/output

Passing these options to every single command can become tedious so you can use a configuration file to save your custom settings.

Running the init command will either add a [tool.mudkip] section to your pyproject.toml or create a mudkip.toml file with some basic configuration.

$ mudkip init

Available options

  • preset

    default: "rtd"

    Presets configure Mudkip and Sphinx to enable specific features. The rtd, furo and alabaster presets enable the development server and configure Sphinx to use the dirhtml builder. The rtd preset changes the html theme to the Read the Docs theme and the furo preset to the Furo theme.

    The xml preset configures Sphinx to use the xml builder. This is useful for more advanced use-cases when you have a separate static site generator that can process a hierarchy of docutils documents.

  • source_dir

    default: "docs"

    This is the directory containing the source files for your documentation. Sphinx is configured to use it as its source directory and when the development server is enabled, Mudkip will watch the directory for changes to rebuild your documentation.

  • output_dir

    default: "docs/_build"

    The output directory is where Sphinx will output the generated files. This is also the directory served by the development server.

  • base_url

    default: None

    The base url used by Sphinx when building the documentation. You can use it to specify a custom domain when deploying to GitHub Pages and make sure Sphinx generates the appropriate CNAME file.

  • repository

    default: The repository field in pyproject.toml

    The repository url of the remote when updating GitHub Pages.

    If you're not using poetry, you will need to set it manually.

  • verbose

    default: false

    This option can also be enabled on the command-line with the --verbose flag. Setting it to true will tell Mudkip to display the entire Sphinx output as well as the Jupyter notebook output when running the develop command with the --notebook flag.

  • project_name

    default: The name of the project you're documenting in pyproject.toml

    If you're not using poetry, you will need to set it manually.

  • project_dir

    default: The value of the project_name option

    Mudkip will watch the Python files in your project directory when using the development server. This enables live reloading even when you're editing docstrings.

  • title

    default: The value of the project_name option

    The project title used by Sphinx when building the documentation.

  • copyright

    default: The current year followed by the value of the author option

    The copyright notice used by Sphinx when building the documentation.

  • author

    default: The concatenated list of authors in pyproject.toml

    If you're not using poetry, you will need to set it manually.

  • version

    default: The first two numbers of the release option

    The version used by Sphinx when building the documentation.

  • release

    default: The project version in pyproject.toml

    If you're not using poetry, you will need to set it manually.

  • override

    default: An empty dictionary

    The override option lets you override sphinx configuration directly. You can use it to specify a custom theme or a logo for instance.

  • section_label_depth

    Enables sphinx.ext.autosectionlabel and sets the autosectionlabel_maxdepth option.

Contributing

Contributions are welcome. Make sure to first open an issue discussing the problem or the new feature before creating a pull request. The project uses poetry.

$ poetry install

The code follows the black code style.

$ poetry run black mudkip

License - MIT

mudkip's People

Contributors

actions-user avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar vberlier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mudkip's Issues

preset flag as combination of theme and builder

Currently preset flag seems a combination of builders and themes - if there is both -t | --theme and -b | --builder flag, then presets can be defined in their terms: -p rtd is -t rtd -b html and -p xml is -b xml

  -p, --preset [xml|latex|dirhtml|alabaster|rtd|furo|pydata|vitepress]
                                  Documentation preset.

Users for quickstart could use -p and later refine their pipelines with -t / -b.

can rely on ghp-import instead github.py

mudkip/mudkip/github.py

Lines 1 to 24 in e0740e9

import shutil
import subprocess
from functools import partial
from pathlib import Path
from tempfile import TemporaryDirectory
class GitHubPagesUpdater:
def __init__(self, upload_dir, repository):
self.upload_dir = Path(upload_dir).absolute()
self.repository = repository
def update(self):
with TemporaryDirectory() as tmp:
shutil.copytree(self.upload_dir, tmp, dirs_exist_ok=True)
run = partial(subprocess.run, check=True, cwd=tmp)
run(["git", "init"])
run(["git", "checkout", "-b", "gh-pages"])
run(["git", "add", "."])
run(["git", "commit", "-m", "Update GitHub Pages"])
run(["git", "remote", "add", "origin", self.repository])
run(["git", "push", "-f", "origin", "gh-pages"])

https://github.com/c-w/ghp-import#python-usage

List of topics for Github

Here is a list of tags one can use to enhance Mudkip visibility on Github

python 
documentation 
documentation-tool 
sphinx 
sphinx-doc
sphinx-theme
sphinxcontrib
sphinx-extension 
mudkip

The list is from sphinx itself and projects around it.

cannot generate latex without conf.py

I tried building latex with sphinx-build - but for that I miss conf.py

λ sphinx-build -b latex docs/ docs/_latex/
Running Sphinx v4.5.0

Configuration error:
missing conf.py file (q:\chaos\docs)

Should mudkip be able to write temporary conf.py or there is a different way to invoke labex build without conf.py?

[bug]: mudkip develop issues error trace but keeps working

This is not a big pain, but takes few tries to get used to - on Windows mudkip develop starts with error message:

Watching "docs"...
Server running on http://localhost:5500
q:\chaos\docs\index.rst:4: WARNING: toctree contains reference to nonexisting document 'README'
q:\chaos\docs\link.md: WARNING: document isn't included in any toctree
Process Process-1:
Traceback (most recent call last):
  File "c:\users\epogr\anaconda3\lib\multiprocessing\process.py", line 315, in _bootstrap
    self.run()
  File "c:\users\epogr\anaconda3\lib\multiprocessing\process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "c:\users\epogr\anaconda3\lib\site-packages\mudkip\server.py", line 32, in serve_directory
    server.serve(port=port, host=host, root=directory)
  File "c:\users\epogr\anaconda3\lib\site-packages\livereload\server.py", line 339, in serve
    self.application(
  File "c:\users\epogr\anaconda3\lib\site-packages\livereload\server.py", line 291, in application
    app.listen(port, address=host)
  File "c:\users\epogr\anaconda3\lib\site-packages\tornado\web.py", line 2116, in listen
    server.listen(port, address)
  File "c:\users\epogr\anaconda3\lib\site-packages\tornado\tcpserver.py", line 151, in listen
    sockets = bind_sockets(port, address=address)
  File "c:\users\epogr\anaconda3\lib\site-packages\tornado\netutil.py", line 174, in bind_sockets
    sock.bind(sockaddr)
OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted

lightweight HTML to PDF generation with puppeteer

Found that jupyterbook in addition to latex+pdflatex builder has a lightweight builder for PDF using puppeteer, a headleass browser that can emulate printing, and puppeteer port is available as python package.

So on jupyterbook lightweight pdf generation will look like:

pip install pyppeteer
jupyter-book build mybookname/ --builder pdfhtml

Possible mudkip version is, with new builder flag:

mudkip build -b pdfhtml
mudkip build --builder pdfhtml

`pygments_dark_style` and maybe other theme options fail

It seems to me that setting some values for the override (aka the conf.py file) don't override theme set options. Example:

[tool.mudkip]
preset = "furo"
title = "my-epic-docs"

[tool.mudkip.override]
...
pygments_style = "material"

Here, I wish to change the code highlighting style for pygments to material as furo uses a different theme. Removing preset = "furo" enables for my code highlighting theme to work while enabling furo causes my option to effectively get ignored. It seems to me that my overrides get set first, and then the furo preset gets set, but I can't be too certain.

Edit: furo has pygments_dark_style but it seems to me that mudkip isn't recognizing or letting sphinx recognize this field based on how the config is getting parsed or something.

Mudkip fails to use repo specific git config

Since mudkip creates a git repo in a temp directory, it only listens to the --global git config. This means any values in the repo specific (or local) git config don't work which is either unexpected behavior or forces the command to fail (mostly when using it locally).

@ mudkip build --update-gh-pages 
Updating GitHub Pages with "docs"...
Initialized empty Git repository in /private/var/folders/6q/ybrmmgj52znd2g6xrm4w68sw0000gn/T/tmp10jw9dl6/.git/
Switched to a new branch 'gh-pages'
Author identity unknown

*** Please tell me who you are.

Run

  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

Even though the message indicates that you can "omit" --global, it's incorrectly show since the git repo's location is in a different location.

Suggest updates for documentation

  • pokemon / naming story with wiki link
  • pip install update git+https://github.com/vberlier/mudkip.git for dev version
  • index.rst already created by develop command
  • brush README.md with npx prettier
  • overrides as conf.py replacement #205

Aspect: new user of sphinx who would like a jump start with pshinx and would like to start using mudkip quickly

Running sphinx-apidoc equivalent

Hi! Currently playing around with mudkip with the hope of using the tool for documenting my projects going forward.

I was wondering how to invoke the autodoc extension using mudkip. In my current sphinx setup, I run the sphinx-apidoc command, which automatically generates the .rst files for my modules and I would like to recover this behavior with mudkip.

I tried running sphinx-apidoc separately before mudkip develop, but then I get some import errors (those are fixed in my current setup by modifying the sys.path variable in conf.py).

Thanks!

[bug]: Update gh-pages fails

mudkip build --update-gh-pages fails with following trace:

Traceback (most recent call last):
  File "/opt/python/3.10.4/lib/python3.10/site-packages/mudkip/cli.py", line 22, in exception_handler
    yield
  File "/opt/python/3.10.4/lib/python3.10/site-packages/mudkip/cli.py", line 135, in build
    application.build(
  File "/opt/python/3.10.4/lib/python3.10/site-packages/mudkip/application.py", line 313, in build
    GitHubPagesUpdater(self.sphinx.outdir, self.config.repository).update()
  File "/opt/python/3.10.4/lib/python3.10/site-packages/mudkip/github.py", line 23, in update
    run(["git", "remote", "add", "origin", self.repository])
  File "/opt/python/3.10.4/lib/python3.10/subprocess.py", line 501, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/opt/python/3.10.4/lib/python3.10/subprocess.py", line 966, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/opt/python/3.10.4/lib/python3.10/subprocess.py", line 1775, in _execute_child
    self.pid = _posixsubprocess.fork_exec(
TypeError: expected str, bytes or os.PathLike object, not NoneType

provide example of [mudkip.override] in documentation

I tried to relay something I needed for conf.py in mudkip and it worked:

[mudkip.override]
myst_enable_extensions = ["smartquotes", "tasklist"]

Maybe describe in a bit more detail in the documentation the powers of override, also tell it can be a separate section in TOML like [mudkip.override] or [tool.mudkip.override]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.