diff --git a/CHANGELOG.md b/CHANGELOG.md index cdfd9bf..a0b6f85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/README.md b/README.md index 9988750..729e252 100644 --- a/README.md +++ b/README.md @@ -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 + ```mermaid flowchart LR R["Incoming request"] --> I["IpWare().get_client_ip(...)"] @@ -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. + ```mermaid sequenceDiagram participant A as Attacker (real IP 8.8.8.8) @@ -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). + ```mermaid flowchart TD A["Request headers (...)"] --> B["Take the next header in precedence order"] @@ -255,6 +258,7 @@ ip, trusted_route = ipw.get_client_ip(request.META) ip, trusted_route = ipw.get_client_ip(request.META, strict=True) ``` + ```mermaid flowchart LR RC["Real client
8.8.8.8"] --> LB["Trusted proxy
198.84.193.157"] @@ -278,6 +282,7 @@ ip, trusted_route = ipw.get_client_ip(request.META) ip, trusted_route = ipw.get_client_ip(request.META, strict=True) ``` + ```mermaid flowchart LR C["Client
8.8.8.8"] --> P1["Proxy 1
104.16.0.1"] --> P2["Proxy 2
34.120.0.1"] --> APP["Your app
proxy_count=2"] @@ -300,6 +305,7 @@ originating client left-most. For the rare network that puts it right-most: ipw = IpWare(leftmost=False) ``` + ```mermaid flowchart LR S["Standard: client, proxy1, proxy2"] -->|"leftmost=True (default)"| A["client = first entry"] diff --git a/docs/diagrams/proxy-count.png b/docs/diagrams/proxy-count.png new file mode 100644 index 0000000..5b22aba Binary files /dev/null and b/docs/diagrams/proxy-count.png differ diff --git a/docs/diagrams/right-most-client-networks.png b/docs/diagrams/right-most-client-networks.png new file mode 100644 index 0000000..d8d701f Binary files /dev/null and b/docs/diagrams/right-most-client-networks.png differ diff --git a/docs/diagrams/security-notice.png b/docs/diagrams/security-notice.png new file mode 100644 index 0000000..74d7156 Binary files /dev/null and b/docs/diagrams/security-notice.png differ diff --git a/docs/diagrams/selection-rules.png b/docs/diagrams/selection-rules.png new file mode 100644 index 0000000..88b0708 Binary files /dev/null and b/docs/diagrams/selection-rules.png differ diff --git a/docs/diagrams/trusted-proxies.png b/docs/diagrams/trusted-proxies.png new file mode 100644 index 0000000..489750d Binary files /dev/null and b/docs/diagrams/trusted-proxies.png differ diff --git a/docs/diagrams/what-it-s-used-for.png b/docs/diagrams/what-it-s-used-for.png new file mode 100644 index 0000000..be99f18 Binary files /dev/null and b/docs/diagrams/what-it-s-used-for.png differ diff --git a/pyproject.toml b/pyproject.toml index 09f59b8..dbcb337 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"] @@ -25,7 +24,7 @@ keywords = [ "x-forwarded-for", "proxy", ] -dynamic = ["version"] +dynamic = ["version", "readme"] classifiers = [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", @@ -70,6 +69,20 @@ dev = [ [tool.hatch.version] path = "python_ipware/__version__.py" +# PyPI cannot render Mermaid. The long description swaps each marked diagram +# (`` 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)\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"] diff --git a/python_ipware/__version__.py b/python_ipware/__version__.py index ba7be38..2fe5fde 100644 --- a/python_ipware/__version__.py +++ b/python_ipware/__version__.py @@ -1 +1 @@ -__version__ = "5.0.0" +__version__ = "5.0.1" diff --git a/tests/tests_packaging.py b/tests/tests_packaging.py new file mode 100644 index 0000000..4630c60 --- /dev/null +++ b/tests/tests_packaging.py @@ -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"^\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()