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
13 changes: 9 additions & 4 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ jobs:
run: uv sync --locked --all-extras --dev

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

pytest:
name: Testing on Python ${{ matrix.python-version }} (${{ matrix.platform}})
Expand All @@ -34,7 +36,10 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
platform: [ubuntu-latest, macos-13, windows-latest]
platform:
- ubuntu-latest
- macos-15
- windows-2022
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v5
Expand Down Expand Up @@ -63,9 +68,9 @@ jobs:
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
python-version: "3.10"
python-version: "3.13"

- name: Build release
- name: build release
run: uv build

- name: Publish package to PyPI
Expand Down
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 -s`\" # From Makefile|g" ${PROJECT}/__init__.py
sed -i -E "s|\"\b[0-9]+.\b[0-9]+.\b[0-9]+\" # From Makefile|\"`uv version -s`\" # 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.1.4" # From Makefile
6 changes: 3 additions & 3 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 Down
10 changes: 5 additions & 5 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 @@ -13,22 +13,22 @@ def http_method(
**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
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[project]
name = "nornir_http"
version = "0.1.3"
version = "0.1.4"
description = "http plugins for nornir"
authors = [{ name = "ubaumann", email = "github@m.ubaumann.ch" }]
license = { text = "Apache-2.0" }
readme = "README.md"
requires-python = ">=3.10"
keywords = ["nornir", "http", "nornir-plugin"]
dependencies = ["httpx>=0.24,>=0.25,>=0.26,>=0.27,>=0.28", "nornir>=3"]
dependencies = ["httpx2>=2.5.0", "nornir>=3"]

[dependency-groups]
dev = ["pytest>=8", "black", "mypy>=1", "pytest-httpx"]
dev = ["pytest>=8", "black", "mypy>=1", "httpx2-pytest>=1.0.1"]
2 changes: 1 addition & 1 deletion tests/test_nornir_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


def test_version():
assert __version__ == "0.1.3" # From Makefile
assert __version__ == "0.1.4" # From Makefile
6 changes: 3 additions & 3 deletions tests/test_task_http_method.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import httpx
from pytest_httpx import HTTPXMock # type: ignore
import httpx2
from pytest_httpx2 import HTTPXMock
from nornir_http.tasks import http_method


Expand Down Expand Up @@ -47,7 +47,7 @@ def test_disable_is_error(httpx_mock: HTTPXMock, status_code: int):
@pytest.mark.parametrize("status_code", [404, 401, 500])
def test_enable_raise_for_status(httpx_mock: HTTPXMock, status_code: int):
httpx_mock.add_response(status_code=status_code)
with pytest.raises(httpx.HTTPStatusError):
with pytest.raises(httpx2.HTTPStatusError):
http_method(method="get", url="http://localhost/", raise_for_status=True)


Expand Down
Loading
Loading