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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 5.0.1

Docs and packaging only; no code changes.
- PyPI page shows the README diagrams as images (PyPI does not render Mermaid).
- Source formatted with ruff throughout (layout only).

## 5.0.0

Reported by Sang Nguyen (sangn6767@gmail.com).
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ On a newer Python that isn't in the test matrix yet? It should just work — if

## What it's used for

<!-- pypi-diagram: what-it-s-used-for -->
```mermaid
flowchart LR
R["Incoming request"] --> I["IpWare().get_client_ip(...)"]
Expand All @@ -62,6 +63,7 @@ clients and proxies, and can be forged. If you use `python-ipware` for authentic
anti-fraud, configure `proxy_count` and/or `proxy_list` for your network topology and treat it as one
layer alongside your firewall — never as the only defense.

<!-- pypi-diagram: security-notice -->
```mermaid
sequenceDiagram
participant A as Attacker (real IP 8.8.8.8)
Expand Down Expand Up @@ -134,6 +136,7 @@ Every default header can be sent by a client, and the modern engine now also rea
which sits above the CDN headers. Behind a CDN, pass an explicit `precedence` naming that CDN's
header (see below).

<!-- pypi-diagram: selection-rules -->
```mermaid
flowchart TD
A["Request headers (...)"] --> B["Take the next header in precedence order"]
Expand Down Expand Up @@ -255,6 +258,7 @@ ip, trusted_route = ipw.get_client_ip(request.META)
ip, trusted_route = ipw.get_client_ip(request.META, strict=True)
```

<!-- pypi-diagram: trusted-proxies -->
```mermaid
flowchart LR
RC["Real client<br/>8.8.8.8"] --> LB["Trusted proxy<br/>198.84.193.157"]
Expand All @@ -278,6 +282,7 @@ ip, trusted_route = ipw.get_client_ip(request.META)
ip, trusted_route = ipw.get_client_ip(request.META, strict=True)
```

<!-- pypi-diagram: proxy-count -->
```mermaid
flowchart LR
C["Client<br/>8.8.8.8"] --> P1["Proxy 1<br/>104.16.0.1"] --> P2["Proxy 2<br/>34.120.0.1"] --> APP["Your app<br/>proxy_count=2"]
Expand All @@ -300,6 +305,7 @@ originating client left-most. For the rare network that puts it right-most:
ipw = IpWare(leftmost=False)
```

<!-- pypi-diagram: right-most-client-networks -->
```mermaid
flowchart LR
S["Standard: client, proxy1, proxy2"] -->|"leftmost=True (default)"| A["client = first entry"]
Expand Down
Binary file added docs/diagrams/proxy-count.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/diagrams/right-most-client-networks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/diagrams/security-notice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/diagrams/selection-rules.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/diagrams/trusted-proxies.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/diagrams/what-it-s-used-for.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 16 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
[build-system]
requires = ["hatchling"]
requires = ["hatchling", "hatch-fancy-pypi-readme>=24"]
build-backend = "hatchling.build"

[project]
name = "python-ipware"
description = "A Python package to retrieve a client's real IP address."
readme = "README.md"
requires-python = ">=3.9"
license = "MIT"
license-files = ["LICENSE"]
Expand All @@ -25,7 +24,7 @@ keywords = [
"x-forwarded-for",
"proxy",
]
dynamic = ["version"]
dynamic = ["version", "readme"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
Expand Down Expand Up @@ -70,6 +69,20 @@ dev = [
[tool.hatch.version]
path = "python_ipware/__version__.py"

# PyPI cannot render Mermaid. The long description swaps each marked diagram
# (`<!-- pypi-diagram: NAME -->` above a ```mermaid block) for its pre-rendered
# docs/diagrams/NAME.png, pinned to this release's tag so old PyPI pages never
# change. The tag must match __version__ (tests/tests_packaging.py checks it).
[tool.hatch.metadata.hooks.fancy-pypi-readme]
content-type = "text/markdown"

[[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
path = "README.md"

[[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]]
pattern = '(?s)<!-- pypi-diagram: ([a-z0-9-]+) -->\n```mermaid\n.*?\n```'
replacement = '![\1 diagram](https://raw.githubusercontent.com/un33k/python-ipware/v5.0.1/docs/diagrams/\1.png)'

[tool.hatch.build.targets.wheel]
packages = ["python_ipware"]

Expand Down
2 changes: 1 addition & 1 deletion python_ipware/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "5.0.0"
__version__ = "5.0.1"
29 changes: 29 additions & 0 deletions tests/tests_packaging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""PyPI long-description diagrams stay in sync with the README and the version."""

import re
import unittest
from pathlib import Path

from python_ipware import __version__

ROOT = Path(__file__).resolve().parent.parent
MARKER = re.compile(r"^<!-- pypi-diagram: ([a-z0-9-]+) -->\n```mermaid$", re.M)


class TestPypiDiagrams(unittest.TestCase):
def test_image_links_pin_the_current_version(self):
pyproject = (ROOT / "pyproject.toml").read_text(encoding="utf-8")
self.assertIn(f"/v{__version__}/docs/diagrams/", pyproject)

def test_every_diagram_is_marked_and_rendered(self):
readme = (ROOT / "README.md").read_text(encoding="utf-8")
names = MARKER.findall(readme)
self.assertEqual(len(names), readme.count("```mermaid"), "every Mermaid block needs a marker")
self.assertEqual(len(names), len(set(names)), "marker names must be unique")
for name in names:
with self.subTest(name=name):
self.assertTrue((ROOT / "docs" / "diagrams" / f"{name}.png").is_file())


if __name__ == "__main__":
unittest.main()