Skip to content

Commit

Permalink
Merge branch 'main' into docs_processors_link
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop authored Aug 5, 2024
2 parents 3661b7d + d8e82d4 commit ada67a2
Show file tree
Hide file tree
Showing 36 changed files with 595 additions and 721 deletions.
1 change: 0 additions & 1 deletion .github/FUNDING.yml

This file was deleted.

37 changes: 19 additions & 18 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: x64
Expand All @@ -26,7 +26,7 @@ jobs:
virtualenvs-in-project: true

- name: Cache Poetry virtualenv
uses: actions/cache@v2
uses: actions/cache@v4
id: cached-poetry-dependencies
with:
path: .venv
Expand All @@ -36,16 +36,14 @@ jobs:
run: poetry install
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'

- name: Run pylama
run: make pylama
- name: Run black
run: make black
- name: Run ruff
run: make ruff
- name: Run mypy
run: make mypy
- name: Run sphinx
run: |
sudo apt-get install pandoc
make sphinx
make docs
pytest:
name: Testing on Python ${{ matrix.python-version }} (${{ matrix.platform}})
Expand All @@ -54,16 +52,15 @@ jobs:
shell: bash
strategy:
matrix:
python-version: [ '3.8', '3.9', '3.10', '3.11' ]
platform: [ubuntu-latest, macOS-latest, windows-latest]
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ]
platform: [ubuntu-latest, macos-13, windows-2019]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: x64

- name: Install Poetry
uses: snok/install-poetry@v1
Expand All @@ -73,28 +70,32 @@ jobs:
virtualenvs-in-project: true

- name: Cache Poetry virtualenv
uses: actions/cache@v2
uses: actions/cache@v4
id: cached-poetry-dependencies
with:
path: .venv
key: venv-${{ matrix.python-version }}-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
if: ${{ matrix.platform != 'windows-latest' }} # windows hangs if using a cached venv
if: ${{ matrix.platform != 'windows-2019' }} # windows hangs if using a cached venv

- name: Install Dependencies
run: poetry install
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'

- name: Run pytest
run: make pytest
if: ${{ matrix.platform != 'windows-latest' }}
if: ${{ matrix.platform != 'windows-2019' }}

- name: Run pytest
run: poetry run pytest --cov=nornir --cov-report=term-missing
if: ${{ matrix.platform == 'windows-latest' }}
if: ${{ matrix.platform == 'windows-2019' }}

- name: Run nbval
run: make nbval
if: ${{ matrix.platform != 'windows-latest' }}
if: ${{ matrix.platform != 'windows-2019' }}

- name: Report coverage
uses: coverallsapp/github-action@v2
if: ${{ matrix.platform == 'ubuntu-latest' && matrix.python-version == '3.11' }}

# release:
# name: Releasing to pypi
Expand Down
6 changes: 2 additions & 4 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ build:
jobs:
post_create_environment:
- pip install poetry
- poetry config virtualenvs.create false
post_install:
# Install dependencies with 'docs' dependency group
# https://python-poetry.org/docs/managing-dependencies/#dependency-groups
- poetry install --with docs
# Instructs Poetry to use RTD venv
- VIRTUAL_ENV=$READTHEDOCS_VIRTUALENV_PATH poetry install --with docs

sphinx:
configuration: docs/conf.py
10 changes: 5 additions & 5 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ The guidelines to pin dependencies are:
a. if semver is supported we pin to major release
b. if semver is not supported we pin to specific version
2. For development:
a. black is pinned to a specific version
a. ruff is pinned to a specific version
b. everything is set to *

Then, to update them:
Expand Down Expand Up @@ -109,17 +109,17 @@ You can then stop them with:
Coding style
------------

Nornir uses `Black <https://github.com/ambv/black>`_, the uncompromising Python code formatter. Black makes it easy for you to format your code as you can do so automatically after installing it.
Nornir uses `Ruff <https://docs.astral.sh/ruff/>`_. Ruff makes it easy for you to format your code as you can do so automatically after installing it.

.. code-block:: bash
poetry run black .
poetry run ruff format --check .
The Black GitHub repo has information about how you can integrate Black in your editor.
The Ruff GitHub repo has information about how you can integrate Ruff in your editor.

Tests
-------------
As part of the automatic CI on every pull request, besides coding style checks with ``black``, we also do linting with ``pylama``, static type checking with ``mypy``, unit tests with ``pytest``, docs generation with ``sphinx`` and ``nbsphinx`` (for Jupyter notebooks) and verification of outputs in Jupyter notebook tutorials with pytest plugin ``nbval``.
As part of the automatic CI on every pull request, besides coding style checks and linting with ``ruff``, static type checking with ``mypy``, unit tests with ``pytest``, docs generation with ``sphinx`` and ``nbsphinx`` (for Jupyter notebooks) and verification of outputs in Jupyter notebook tutorials with pytest plugin ``nbval``.

After modifying any code in the core, at first, we recommend running unit tests locally before running the whole test suite (which takes longer time):

Expand Down
27 changes: 8 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,7 @@ docker:

.PHONY: pytest
pytest:
poetry run pytest --cov=nornir --cov-report=term-missing -vs ${ARGS}

.PHONY: black
black:
poetry run black --check ${NORNIR_DIRS}
poetry run isort --profile black --check ${NORNIR_DIRS}

.PHONY: sphinx
sphinx:
# TODO REPLACE with: sphinx-build -n -E -q -N -b dummy -d docs/_build/doctrees docs asd
# poetry run sphinx-build -W -b html -d docs/_build/doctrees docs docs/_build/html
echo "WARNING: sphinx needs to be added here!!!"

.PHONY: pylama
pylama:
poetry run pylama ${NORNIR_DIRS}
poetry run pytest --cov=nornir --cov-report=term-missing --cov-report xml -vs ${ARGS}

.PHONY: mypy
mypy:
Expand All @@ -39,14 +24,18 @@ nbval:
docs/tutorial/ \
docs/howto/

.PHONY: ruff
ruff:
poetry run ruff check .

.PHONY: tests
tests: black pylama mypy nbval pytest sphinx
tests: ruff mypy nbval pytest sphinx

.PHONY: docker-tests
docker-tests: docker
docker run --name nornir-tests --rm $(NAME):latest make tests

.PHONY: docs
docs:
./docs/build_api.sh
make -C docs clean html
poetry run ./docs/build_api.sh
poetry run make -C docs clean html
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![Build Status](https://github.com/nornir-automation/nornir/workflows/test%20nornir/badge.svg) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black) [![Coverage Status](https://coveralls.io/repos/github/nornir-automation/nornir/badge.svg?branch=develop)](https://coveralls.io/github/nornir-automation/nornir?branch=develop)
![Build Status](https://github.com/nornir-automation/nornir/workflows/test%20nornir/badge.svg) [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![Coverage Status](https://coveralls.io/repos/github/nornir-automation/nornir/badge.svg?branch=main)](https://coveralls.io/github/nornir-automation/nornir?branch=main)


Nornir
Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ Only latest version is supported.

## Reporting a Vulnerability

To report a vulnerability feel free to reach out on [slack](https://github.com/nornir-automation/nornir#contact--support) so we can fix before a public disclosure.
To report a vulnerability feel free to reach out privately on [GitHub](https://github.com/nornir-automation/nornir/security/advisories/new) so we can fix before a public disclosure.
If the issue is on a dependency feel free to open a PR bumping such depdency without contacting us first.
16 changes: 3 additions & 13 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# nornir documentation build configuration file, created by
# sphinx-quickstart on Sun Nov 19 10:41:40 2017.
#
Expand All @@ -21,8 +18,6 @@
import sys
from typing import Dict

from sphinx.application import Sphinx

from nornir import __version__

sys.path.insert(0, os.path.abspath("../"))
Expand Down Expand Up @@ -70,7 +65,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down Expand Up @@ -142,9 +137,7 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, "nornir.tex", "nornir Documentation", "David Barroso", "manual")
]
latex_documents = [(master_doc, "nornir.tex", "nornir Documentation", "David Barroso", "manual")]


# -- Options for manual page output ---------------------------------------
Expand Down Expand Up @@ -173,7 +166,4 @@

issues_github_path = "nornir-automation/nornir"


def setup(app: Sphinx) -> None:
"""Map methods to states of the documentation build."""
app.add_stylesheet("css/custom.css")
html_css_files = ["css/custom.css"]
4 changes: 2 additions & 2 deletions docs/highlighter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from IPython.core.display import HTML
from IPython.core.magic import register_line_magic
from IPython.display import HTML
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import get_lexer_for_filename
Expand All @@ -17,7 +17,7 @@


@register_line_magic
def highlight_file(filename):
def highlight_file(filename: str) -> HTML:
lexer = get_lexer_for_filename(filename)

linenos = "inline"
Expand Down
8 changes: 4 additions & 4 deletions docs/howto/filtering_deep_dive.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@
"print(\"=\" * 50)\n",
"\n",
"\n",
"# Use Case 3 - filter hosts by site_type of tertiary\n",
"# Use Case 3 - filter hosts by site_type of secondary\n",
"# Assign site_type of secondary to variable for later usage\n",
"site_type=\"secondary\"\n",
"# Execute filter based on site_type\n",
Expand Down Expand Up @@ -2056,7 +2056,7 @@
" :return bool: True if it matches, False if it doesn't match\n",
" \"\"\"\n",
" # Perform regex match on host name and return boolean\n",
" if re.match(\".+\\-[0-9][2,4,6,8,0].+\", host.name):\n",
" if re.match(r\".*-\\d[24680].*\", host.name):\n",
" return True\n",
" else:\n",
" return False\n",
Expand All @@ -2074,7 +2074,7 @@
" :return bool: True if it matches, False if it doesn't match\n",
" \"\"\"\n",
" # Perform regex match on host name and return boolean\n",
" if re.match(\"\\w{3}\\-\\w+\\-\\d{2}.\\w{3}.norn.local\", host.name):\n",
" if re.match(r\"\\w{3}-\\w+-\\d{2}\\.\\w{3}\\.norn\\.local\", host.name):\n",
" return True\n",
" else:\n",
" return False\n",
Expand All @@ -2092,7 +2092,7 @@
" :return bool: True if does not match, False if it matches the convention\n",
" \"\"\"\n",
" # Perform regex match on host name and return boolean\n",
" if re.match(\"\\w{3}\\-\\w+\\-\\d{2}.\\w{3}.norn.local\", host.name):\n",
" if re.match(r\"\\w{3}-\\w+-\\d{2}\\.\\w{3}\\.norn\\.local\", host.name):\n",
" return False\n",
" else:\n",
" return True\n",
Expand Down
Loading

0 comments on commit ada67a2

Please sign in to comment.