Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 37 additions & 51 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,95 +5,81 @@ on: [push, pull_request]
jobs:
linters:
name: linters
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.13"]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- name: Setup python
uses: actions/setup-python@v1
- uses: actions/checkout@v5

- name: Install Poetry
uses: snok/install-poetry@v1
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v6
with:
virtualenvs-create: true
virtualenvs-in-project: true

- name: Cache Poetry virtualenv
uses: actions/cache@v2
id: cached-poetry-dependencies
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
enable-cache: true
python-version: ${{ matrix.python-version }}

- name: Install Dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Install the project
run: uv sync --locked --all-extras --dev

- name: Run black
run: poetry run black --check .
run: make black
- name: Run mypy
run: make mypy

pytest:
name: Testing on Python ${{ matrix.python-version }} (${{ matrix.platform}})
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
platform: [ubuntu-latest, macOS-latest, windows-latest]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
platform:
- ubuntu-latest
- macos-15
- windows-2022
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- name: Setup python
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
architecture: x64

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- uses: actions/checkout@v5

- name: Cache Poetry virtualenv
uses: actions/cache@v2
id: cached-poetry-dependencies
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v6
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
enable-cache: true
python-version: ${{ matrix.python-version }}

- name: Install Dependencies
run: poetry install --no-interaction --no-root
- name: Install the project
run: uv sync --locked --all-extras --dev

- name: Run pytest
run: poetry run pytest -vv
run: uv run pytest -vs

release:
name: Releasing to pypi
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
needs: [linters, pytest]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup python
uses: actions/setup-python@v1
with:
python-version: 3.8
- uses: actions/checkout@v5

- name: Install Poetry
uses: snok/install-poetry@v1
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
python-version: "3.13"

- name: build release
run: poetry build
run: uv build

- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: build
path: dist/*
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
.pytest_cache/
.vscode/
dist/
nornir.log
nornir.log
.venv/
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ CODE_DIRS=${PROJECT} tests
# Run pytest
.PHONY: pytest
pytest:
poetry run pytest -vs ${ARGS}
uv run pytest -vs ${ARGS}

# Check if the python code needs to be reformatted
.PHONY: black
black:
poetry run black --check ${CODE_DIRS}
uv run black --check ${CODE_DIRS}

# Python type check
.PHONY: mypy
mypy:
poetry run mypy ${CODE_DIRS}
uv run mypy ${CODE_DIRS}

# Runn pytest, black and mypy
.PHONY: tests
Expand All @@ -23,6 +23,6 @@ tests: pytest black mypy
# use "make bump ARGS=patch" to bump the version. ARGS can be patch, minor or major.
.PHONY: bump
bump:
poetry version ${ARGS}
sed -i -E "s|\"\b[0-9]+.\b[0-9]+.\b[0-9]+\" # From Makefile|\"`poetry version -s`\" # From Makefile|g" ${PROJECT}/__init__.py
sed -i -E "s|\"\b[0-9]+.\b[0-9]+.\b[0-9]+\" # From Makefile|\"`poetry version -s`\" # From Makefile|g" tests/test_${PROJECT}.py
uv version --bump ${ARGS}
sed -i -E "s|\"\b[0-9]+.\b[0-9]+.\b[0-9]+\" # From Makefile|\"`uv version --short`\" # From Makefile|g" ${PROJECT}/__init__.py
sed -i -E "s|\"\b[0-9]+.\b[0-9]+.\b[0-9]+\" # From Makefile|\"`uv version --short`\" # From Makefile|g" tests/test_${PROJECT}.py
5 changes: 1 addition & 4 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
[mypy]
python_version = 3.8
python_version = 3.10
warn_return_any = True
warn_unused_configs = True

# Per-module options:

[mypy-nornir_http]
disallow_untyped_defs = True

[mypy-httpx]
ignore_missing_imports = True
2 changes: 1 addition & 1 deletion nornir_http/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.3" # From Makefile
__version__ = "0.2.0" # From Makefile
8 changes: 4 additions & 4 deletions nornir_http/result.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Any, Union
from httpx import Response
from httpx2 import Response
from nornir.core.task import Result
from nornir.core.inventory import Host

Expand All @@ -11,13 +11,13 @@ class HTTPResult(Result):

Arguments:
result (obj): Result of the task execution, see task's documentation for details
response (:obj:`httpx.Response`): Response of the http request
response (:obj:`httpx2.Response`): Response of the http request
host (:obj:`nornir.core.inventory.Host`): Reference to the host
failed (bool): Whether the execution failed or not

Attributes:
result (obj): Result of the task execution, see task's documentation for details
response (:obj:`httpx.Response`): Response of the http request
response (:obj:`httpx2.Response`): Response of the http request
host (:obj:`nornir.core.inventory.Host`): Reference to the host
failed (bool): Whether the execution failed or not
"""
Expand All @@ -28,7 +28,7 @@ def __init__(
response: Response,
result: Any = None,
failed: bool = False,
**kwargs: Any
**kwargs: Any,
):
super().__init__(host=host, result=result, failed=failed, **kwargs)
self.response = response
12 changes: 6 additions & 6 deletions nornir_http/tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import httpx
import httpx2
from typing import Optional, Any
from nornir.core.task import Task
from nornir_http.result import HTTPResult
Expand All @@ -10,25 +10,25 @@ def http_method(
url: str = "",
raise_for_status: bool = False,
is_error: bool = True,
**kwargs: Any
**kwargs: Any,
) -> HTTPResult:
"""
This is a helper task that uses `httpx <https://www.python-httpx.org/api/>`_ to
This is a helper task that uses `httpx2 <https://www.python-httpx2.org/api/>`_ to
interact with an HTTP server.
Arguments:
method: HTTP method to call
url: URL to connect to
raise_for_status: Whether to call `raise_for_status` method or not
is_error: Whether to set Result.failed or not based on status code
**kwargs: Keyword arguments will be passed to the request `httpx.request` method
**kwargs: Keyword arguments will be passed to the request `httpx2.request` method
Returns:
Result.result dict with the following keys set:
* result (``str/dict``): Body of the response. Either text or a dict
if the response was a json object
* response (``httpx.Response``): Original `Response`
* response (``httpx2.Response``): Original `Response`
* failed (``bool``): set to `response.is_failed` if is_error is true
"""
response = httpx.request(method, url, **kwargs)
response = httpx2.request(method, url, **kwargs)

if raise_for_status:
response.raise_for_status()
Expand Down
Loading
Loading