Skip to main content

Link Checker for Mkdocs-based static generated sites

Project status: in active development. Not recommended for production use.

This project was originally conceived at RingCentral to help automate the validation and testing of the code samples contained within its mkdocs-powered Developer Guide.

Install

For latest release:

% python -m pip install mkdocs-codecheck

Or, for latest development version.

% git clone https://github.com/byrnereese/codechecker-mkdocs
% cd codechecker-mkdocs
% python setup.py install 

Usage

Setting up your environment

Each programming language you will be running tests for will likely have their own unique requirements for executing these tests. For example, to test Java, the javac and/or java programs will need to be in your path. The following are instructions on how you setup your testing environment for each supported language:

Python

Setup a virtual environment for your python code samples. Navigate to your mkdocs-powered repository, and run the following command:

% pip install venv
% python -m venv .

Then activate your virtual environment:

% source ./bin/activate

Finally, consult the documentation associated with the code samples you will be testing, and install any prerequisites or python libraries into this virtual environment that your code samples rely on.

Currently supported languages

Language Syntax checking Code execution
C# No No
Java Yes No
JavaScript Yes Experimental
PHP Yes Yes
Python Yes Yes
Ruby Yes Experimental

How to structure your documentation

A core design requirement for this system to work is that the code samples you wish to embed in your documentation have been fully aabstracted out of the documentation itself. That means that each individual code sample be placed in a dedicated file, and then included or inserted into your documentation when your docs are built.

In mkdocs, for example, the mdx_include plugin can be used to insert a code sample located in a separate file. Let's take a look:

This is my documentation for my developer platform. Here is a simple 
"Hello World" script you can use to get started:

```python
{!> code-samples/hello-world.py ln:10- !}
```

The above code inserts the contents of the hello-world.py file into the current markdown file. It inserts the contents of the file starting on line #10. Starting on line #10 is not always necessary, but in case you include a header section in your code denoting the author, copyright, license, etc, you may choose to omit this content when rendering the code sample inline with your documentation.

How to structure a code sample

Each individual code sample must:

  • Be contained in its own dedicated file
  • Be a fully self-contained, and executable file
  • Not require input from the user
  • Catch all errors, and return a system exit code greater than 0 to signal to the framework that an error occurred
  • Return a system exit code of 0 upon successful completion of the code sample

It is recommended:

  • Environment variables be used for passing input into a code sample
  • Boilerpate content be added to the top of your code samples to guide others in how to use them

Examples:

Ignoring files

Using the same syntax as a .gitignore file, you can create a .codetest-ignore file to exclude certain files from being tested. This is helpful if you need to exclude node modules, python modules and other libraries from being tested.

Running mkdocs-codecheck from within a python script

import mkdocs-codecheck as cc
cc.process_code("~/docs", recurse=True)

Running mkdocs-codecheck from the command-line

This program may be invoked by either:

mkdocs-codecheck --recurse ~/docs

or

python -m mkdocs-codecheck

Usage

mkdocs-codecheck [-h] [-v] [--dotenv PATH_TO_DOTENV] [--exclude EXCLUDE] [--recurse] path

Positional arguments:

  • path - root path to code samples

Optional arguments:

  • -h, --help - show a help message and exit
  • --exclude <str> - a pattern for a file or path to exclude from being checked; use this argument multiple times to exclude multiple files. Regular expressions are ok.
  • --dotenv <str> - a fully qualified path to a .env file containing environment variables to source prior to executing code samples
  • --languages <str> - a comma-delimitted list of languages you will test, e.g. java, php, python, et al.
  • --syntax-only - do not attempt to run code samples, simply check them for syntax errors only
  • -r, --recurse - recurse through all directories under path
  • -v or --verbose -prints the URLs as they are checked

Example

mkdocs-codecheck --languages python,php --dotenv ~/.env ~/github/

Release files for mkdocs-codecheck 0.9.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mkdocs-codecheck 0.9.5
File Size Uploaded
mkdocs_codecheck-0.9.5.tar.gz 12.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mkdocs-codecheck 0.9.5
File Interpreter ABI Platform
mkdocs_codecheck-0.9.5-py3-none-any.whl Python 3 none any Details

Total release size: 41.3 kB

Release files / mkdocs_codecheck-0.9.5.tar.gz

Download URL mkdocs_codecheck-0.9.5.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4089eb0af676338448503ca462267483019f2e46462da1dd6b663a3c790e21d3
BLAKE2b-256 checksum
How to use checksums
fa37738197ce299775ccef1b9636abfadaac6f13bb2c94312bb6d5acad3ddeea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.10

Release files / mkdocs_codecheck-0.9.5-py3-none-any.whl

Download URL mkdocs_codecheck-0.9.5-py3-none-any.whl
Size 28.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3aff03800bf7150544427472e70e83de796146420b0b47a44086c1d19d416999
BLAKE2b-256 checksum
How to use checksums
33366f050a3be4fe7f88263cdb0a5f879f96105b485d1ea86b4431f39d2e21c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.9.5 This release

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page