Metadata-Version: 2.4
Name: pytest_check_links
Version: 0.10.1
Summary: Check links in files
Project-URL: Homepage, https://github.com/jupyterlab/pytest-check-links
Author-email: Jupyter Development Team <jupyter@googlegroups.com>
License: Copyright (c) 2019 Project Jupyter Contributors
        All rights reserved.
        
        Copyright (c) 2017, Min RK
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its
           contributors may be used to endorse or promote products derived from
           this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License-File: LICENSE
Keywords: documentation,html,links,testing
Classifier: Framework :: Jupyter
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Documentation
Classifier: Topic :: Documentation :: Sphinx
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Software Development :: Testing
Classifier: Typing :: Typed
Requires-Python: >=3.8
Requires-Dist: docutils>=0.20.1
Requires-Dist: html5lib>=1.1
Requires-Dist: nbconvert>=7.1
Requires-Dist: nbformat>=5.1
Requires-Dist: pytest<9,>=7.0
Requires-Dist: requests>=2.22
Provides-Extra: cache
Requires-Dist: requests-cache>=0.9.7; extra == 'cache'
Provides-Extra: test
Requires-Dist: flaky; extra == 'test'
Requires-Dist: pre-commit; extra == 'test'
Requires-Dist: requests-cache>=0.9.7; extra == 'test'
Description-Content-Type: text/markdown

# pytest-check-links

pytest plugin that checks URLs for HTML-containing files.

[![Tests](https://github.com/jupyterlab/pytest-check-links/workflows/Tests/badge.svg)](https://github.com/jupyterlab/pytest-check-links/actions?query=workflow%3ATests+branch%3Amaster)
[![PyPI version](https://badge.fury.io/py/pytest-check-links.svg)](https://badge.fury.io/py/pytest-check-links)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pytest-check-links)

## Supported files

- `.html`
- `.rst`
- `.md` (TODO: select renderer)
- `.ipynb` (requires `nbconvert`)

## Install

```
pip install pytest-check-links
```

## Use

```
pytest --check-links mynotebook.ipynb
```

## Configure

#### --links-ext

> default: `md,rst,html,ipynb`

A comma-separated list of extensions to check

#### --check-anchors

Also check whether links with `#anchors` HTML files (either local, or with
served with `html` in the `Content-Type`) actually exist, and point to _exactly one_
named anchor.

#### --check-links-ignore

A regular expression that matches URIs that should not be checked.
Can be specified multiple times for multiple ignore patterns.
This can be used for files that have a lot of links to GitHub pages,
such as a Changelog. GitHub has rate limiting, which would normally cause these files to take up to an hour to complete for larger repositories. For example:

```
pytest --check-links --check-links-ignore "https://github.com/.*/pull/.*" CHANGELOG.md
```

### Cache

Caching requires the installation of `requests-cache`.

```
pip install requests-cache
```

If enabled, each occurrence of a link will be checked, no matter how many times
it appears in a collection of files to check.

#### --check-links-cache

Cache requests when checking links. Caching is disabled by default, and this option
must be provided, even if other cache configuration options are provided.

#### --check-links-cache-name

> default: `.pytest-check-links-cache`

Name of link cache, either the base name of a file or similar, depending on backend.

#### --check-links-cache-backend

> default: `sqlite3`

Cache persistence backend. The other known backends are:

- `memory`
- `redis`
- `mongodb`

See the [requests-cache documentation](https://requests-cache.readthedocs.io)
for more information.

#### --check-links-cache-expire-after

> default: `None` (unlimited)

Time to cache link responses (seconds).

#### --check-links-cache-backend-opt

Backend-specific options for link cache, provided as `key:value`. These are passed
directly to the `requests_cache.CachedSession` constructor, as they vary depending
on the backend.

Values will be parsed as JSON first, so to overload the default of caching all
HTTP response codes (which requires a list of `int`s):

```bash
--check-links-backend-opt allowable_codes:[200]
```

## Code Styling

`pytest-check-links` has adopted automatic code formatting so you shouldn't
need to worry too much about your code style.
As long as your code is valid,
the pre-commit hook should take care of how it should look.
You can invoke the pre-commit hook by hand at any time with:

```bash
pre-commit run
```

which should run any autoformatting on your code
and tell you about any errors it couldn't fix automatically.
You may also install [black integration](https://black.readthedocs.io/en/stable/integrations/editors.html)
into your text editor to format code automatically.

If you have already committed files before setting up the pre-commit
hook with `pre-commit install`, you can fix everything up using
`pre-commit run --all-files`. You need to make the fixing commit
yourself after that.

Some of the hooks only run on CI by default, but you can invoke them by
running with the `--hook-stage manual` argument.

## TODO

- pick a markdown renderer (probably commonmark) or make the markdown renderer pluggable
- options for validating links (allow absolute links, only remote or local, etc.)
- find URLs in Python docstrings
