diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..e989deb --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*.py] +indent_style = space +tab_width = 4 + +[*.toml] +indent_style = space +tab_width = 2 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..25930c9 --- /dev/null +++ b/.flake8 @@ -0,0 +1,13 @@ +[flake8] +# E241 multiple spaces after ':' [ want to align stuff ] +# E266 too many leading '#' for block comment [ I like marking disabled code blocks with '### ' ] +# E402 module level import not at top of file [ usually on purpose. might use individual overrides instead? ] +# E701 multiple statements on one line (colon) [ perfectly readable ] +# E713 test for membership should be ‘not in’ [ disagree: want `not a in x` ] +# E714 test for object identity should be 'is not' [ disagree: want `not a is x` ] +# W503 line break before binary operator [ gotta pick one way ] +extend-ignore = E241,E266,E402,E701,E713,E714,W503 +exclude = 00*.py,generated.py,incremental_patch +# we sometimes have long comments, and there is only one limit for all +max-line-length = 120 +# max-complexity = 20 diff --git a/.gitignore b/.gitignore index 2a45ed7..84f13f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.pyc .vscode +poetry.lock diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..c10574c --- /dev/null +++ b/poetry.lock @@ -0,0 +1,146 @@ +# This file is automatically @generated by Poetry 2.1.1 and should not be changed by hand. + +[[package]] +name = "flake8" +version = "7.2.0" +description = "the modular source code checker: pep8 pyflakes and co" +optional = true +python-versions = ">=3.9" +groups = ["main"] +markers = "extra == \"dev\"" +files = [ + {file = "flake8-7.2.0-py2.py3-none-any.whl", hash = "sha256:93b92ba5bdb60754a6da14fa3b93a9361fd00a59632ada61fd7b130436c40343"}, + {file = "flake8-7.2.0.tar.gz", hash = "sha256:fa558ae3f6f7dbf2b4f22663e5343b6b6023620461f8d4ff2019ef4b5ee70426"}, +] + +[package.dependencies] +mccabe = ">=0.7.0,<0.8.0" +pycodestyle = ">=2.13.0,<2.14.0" +pyflakes = ">=3.3.0,<3.4.0" + +[[package]] +name = "mccabe" +version = "0.7.0" +description = "McCabe checker, plugin for flake8" +optional = true +python-versions = ">=3.6" +groups = ["main"] +markers = "extra == \"dev\"" +files = [ + {file = "mccabe-0.7.0-py2.py3-none-any.whl", hash = "sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e"}, + {file = "mccabe-0.7.0.tar.gz", hash = "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325"}, +] + +[[package]] +name = "mypy" +version = "1.15.0" +description = "Optional static typing for Python" +optional = true +python-versions = ">=3.9" +groups = ["main"] +markers = "extra == \"dev\"" +files = [ + {file = "mypy-1.15.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:979e4e1a006511dacf628e36fadfecbcc0160a8af6ca7dad2f5025529e082c13"}, + {file = "mypy-1.15.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:c4bb0e1bd29f7d34efcccd71cf733580191e9a264a2202b0239da95984c5b559"}, + {file = "mypy-1.15.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:be68172e9fd9ad8fb876c6389f16d1c1b5f100ffa779f77b1fb2176fcc9ab95b"}, + {file = "mypy-1.15.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c7be1e46525adfa0d97681432ee9fcd61a3964c2446795714699a998d193f1a3"}, + {file = "mypy-1.15.0-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:2e2c2e6d3593f6451b18588848e66260ff62ccca522dd231cd4dd59b0160668b"}, + {file = "mypy-1.15.0-cp310-cp310-win_amd64.whl", hash = "sha256:6983aae8b2f653e098edb77f893f7b6aca69f6cffb19b2cc7443f23cce5f4828"}, + {file = "mypy-1.15.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:2922d42e16d6de288022e5ca321cd0618b238cfc5570e0263e5ba0a77dbef56f"}, + {file = "mypy-1.15.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:2ee2d57e01a7c35de00f4634ba1bbf015185b219e4dc5909e281016df43f5ee5"}, + {file = "mypy-1.15.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:973500e0774b85d9689715feeffcc980193086551110fd678ebe1f4342fb7c5e"}, + {file = "mypy-1.15.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:5a95fb17c13e29d2d5195869262f8125dfdb5c134dc8d9a9d0aecf7525b10c2c"}, + {file = "mypy-1.15.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:1905f494bfd7d85a23a88c5d97840888a7bd516545fc5aaedff0267e0bb54e2f"}, + {file = "mypy-1.15.0-cp311-cp311-win_amd64.whl", hash = "sha256:c9817fa23833ff189db061e6d2eff49b2f3b6ed9856b4a0a73046e41932d744f"}, + {file = "mypy-1.15.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:aea39e0583d05124836ea645f412e88a5c7d0fd77a6d694b60d9b6b2d9f184fd"}, + {file = "mypy-1.15.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:2f2147ab812b75e5b5499b01ade1f4a81489a147c01585cda36019102538615f"}, + {file = "mypy-1.15.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ce436f4c6d218a070048ed6a44c0bbb10cd2cc5e272b29e7845f6a2f57ee4464"}, + {file = "mypy-1.15.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:8023ff13985661b50a5928fc7a5ca15f3d1affb41e5f0a9952cb68ef090b31ee"}, + {file = "mypy-1.15.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:1124a18bc11a6a62887e3e137f37f53fbae476dc36c185d549d4f837a2a6a14e"}, + {file = "mypy-1.15.0-cp312-cp312-win_amd64.whl", hash = "sha256:171a9ca9a40cd1843abeca0e405bc1940cd9b305eaeea2dda769ba096932bb22"}, + {file = "mypy-1.15.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:93faf3fdb04768d44bf28693293f3904bbb555d076b781ad2530214ee53e3445"}, + {file = "mypy-1.15.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:811aeccadfb730024c5d3e326b2fbe9249bb7413553f15499a4050f7c30e801d"}, + {file = "mypy-1.15.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:98b7b9b9aedb65fe628c62a6dc57f6d5088ef2dfca37903a7d9ee374d03acca5"}, + {file = "mypy-1.15.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c43a7682e24b4f576d93072216bf56eeff70d9140241f9edec0c104d0c515036"}, + {file = "mypy-1.15.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:baefc32840a9f00babd83251560e0ae1573e2f9d1b067719479bfb0e987c6357"}, + {file = "mypy-1.15.0-cp313-cp313-win_amd64.whl", hash = "sha256:b9378e2c00146c44793c98b8d5a61039a048e31f429fb0eb546d93f4b000bedf"}, + {file = "mypy-1.15.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:e601a7fa172c2131bff456bb3ee08a88360760d0d2f8cbd7a75a65497e2df078"}, + {file = "mypy-1.15.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:712e962a6357634fef20412699a3655c610110e01cdaa6180acec7fc9f8513ba"}, + {file = "mypy-1.15.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f95579473af29ab73a10bada2f9722856792a36ec5af5399b653aa28360290a5"}, + {file = "mypy-1.15.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:8f8722560a14cde92fdb1e31597760dc35f9f5524cce17836c0d22841830fd5b"}, + {file = "mypy-1.15.0-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:1fbb8da62dc352133d7d7ca90ed2fb0e9d42bb1a32724c287d3c76c58cbaa9c2"}, + {file = "mypy-1.15.0-cp39-cp39-win_amd64.whl", hash = "sha256:d10d994b41fb3497719bbf866f227b3489048ea4bbbb5015357db306249f7980"}, + {file = "mypy-1.15.0-py3-none-any.whl", hash = "sha256:5469affef548bd1895d86d3bf10ce2b44e33d86923c29e4d675b3e323437ea3e"}, + {file = "mypy-1.15.0.tar.gz", hash = "sha256:404534629d51d3efea5c800ee7c42b72a6554d6c400e6a79eafe15d11341fd43"}, +] + +[package.dependencies] +mypy_extensions = ">=1.0.0" +typing_extensions = ">=4.6.0" + +[package.extras] +dmypy = ["psutil (>=4.0)"] +faster-cache = ["orjson"] +install-types = ["pip"] +mypyc = ["setuptools (>=50)"] +reports = ["lxml"] + +[[package]] +name = "mypy-extensions" +version = "1.1.0" +description = "Type system extensions for programs checked with the mypy type checker." +optional = true +python-versions = ">=3.8" +groups = ["main"] +markers = "extra == \"dev\"" +files = [ + {file = "mypy_extensions-1.1.0-py3-none-any.whl", hash = "sha256:1be4cccdb0f2482337c4743e60421de3a356cd97508abadd57d47403e94f5505"}, + {file = "mypy_extensions-1.1.0.tar.gz", hash = "sha256:52e68efc3284861e772bbcd66823fde5ae21fd2fdb51c62a211403730b916558"}, +] + +[[package]] +name = "pycodestyle" +version = "2.13.0" +description = "Python style guide checker" +optional = true +python-versions = ">=3.9" +groups = ["main"] +markers = "extra == \"dev\"" +files = [ + {file = "pycodestyle-2.13.0-py2.py3-none-any.whl", hash = "sha256:35863c5974a271c7a726ed228a14a4f6daf49df369d8c50cd9a6f58a5e143ba9"}, + {file = "pycodestyle-2.13.0.tar.gz", hash = "sha256:c8415bf09abe81d9c7f872502a6eee881fbe85d8763dd5b9924bb0a01d67efae"}, +] + +[[package]] +name = "pyflakes" +version = "3.3.2" +description = "passive checker of Python programs" +optional = true +python-versions = ">=3.9" +groups = ["main"] +markers = "extra == \"dev\"" +files = [ + {file = "pyflakes-3.3.2-py2.py3-none-any.whl", hash = "sha256:5039c8339cbb1944045f4ee5466908906180f13cc99cc9949348d10f82a5c32a"}, + {file = "pyflakes-3.3.2.tar.gz", hash = "sha256:6dfd61d87b97fba5dcfaaf781171ac16be16453be6d816147989e7f6e6a9576b"}, +] + +[[package]] +name = "typing-extensions" +version = "4.13.2" +description = "Backported and Experimental Type Hints for Python 3.8+" +optional = true +python-versions = ">=3.8" +groups = ["main"] +markers = "extra == \"dev\"" +files = [ + {file = "typing_extensions-4.13.2-py3-none-any.whl", hash = "sha256:a439e7c04b49fec3e5d3e2beaa21755cadbbdc391694e28ccdd36ca4a1408f8c"}, + {file = "typing_extensions-4.13.2.tar.gz", hash = "sha256:e6c81219bd689f51865d9e372991c540bda33a0379d5573cddb9a3a23f7caaef"}, +] + +[extras] +dev = ["flake8", "mypy"] + +[metadata] +lock-version = "2.1" +python-versions = "~=3.11" +content-hash = "596c29b3a42200dd29263138060c0256a2184d7f8f7329685a1db6b44593dd63" diff --git a/prometheus/__init__.py b/prometheus/__init__.py deleted file mode 100644 index 8d943c3..0000000 --- a/prometheus/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from prometheus.registry import Registry, Path, GLOBAL_REGISTRY -from prometheus.metrics import * -from prometheus.metric_base import NOW diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..c7e2bbf --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,41 @@ +[build-system] +requires = ["flit_core >=3.2,<4"] +build-backend = "flit_core.buildapi" + +[project] +name = "prometheus_rus" +version = "0.1.0" +authors = [ + {name = "Stefan Bühler", email = "stefan.buehler@tik.uni-stuttgart.de"}, +] +license = "Apache Software License 2.0" +classifiers = [ + "Private :: Do Not Upload", + "License :: OSI Approved :: Apache Software License", +] +dynamic = ["version", "description"] + +requires-python = "~=3.11" +dependencies = [] + +[project.urls] +Home = "https://github.tik.uni-stuttgart.de/NKS/python-prometheus/" + +[project.optional-dependencies] +dev = [ + "flake8", + "mypy", +] + +[tool.black] +line-length = 120 + +[tool.mypy] +mypy_path = "src" +files = "src" + +[tool.pyright] +include = ["src"] + +[tool.isort] +profile = "black" diff --git a/setup.py b/setup.py deleted file mode 100644 index 4a2dffb..0000000 --- a/setup.py +++ /dev/null @@ -1,34 +0,0 @@ -from setuptools import setup - -setup( - name="prometheus_client_rus", - version="0.1.0", - author="Stefan Buehler", - author_email="stefan.buehler@tik.uni-stuttgart.de", - description="Python client for the Prometheus monitoring system (RUS version).", - long_description=( - "See https://github.tik.uni-stuttgart.de/NKS/python-prometheus/blob/master/README.md" - " for documentation."), - license="Apache Software License 2.0", - keywords="prometheus monitoring instrumentation client", - url="https://github.tik.uni-stuttgart.de/NKS/python-prometheus/", - packages=[ - 'prometheus', - ], - classifiers=[ - "Development Status :: 4 - Beta", - "Intended Audience :: Developers", - "Intended Audience :: Information Technology", - "Intended Audience :: System Administrators", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.4", - "Programming Language :: Python :: 3.5", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", - "Topic :: System :: Monitoring", - "License :: OSI Approved :: Apache Software License", - ], -) diff --git a/src/prometheus_rus/__init__.py b/src/prometheus_rus/__init__.py new file mode 100644 index 0000000..d0376d9 --- /dev/null +++ b/src/prometheus_rus/__init__.py @@ -0,0 +1,13 @@ +from ._registry import ( # noqa: reexport + Registry as Registry, + Path as Path, + GLOBAL_REGISTRY as GLOBAL_REGISTRY, +) +from ._metrics import ( # noqa: reexport + Counter as Counter, + Gauge as Gauge, + Summary as Summary, +) +from ._metric_base import ( # noqa: reexport + NOW as NOW, +) diff --git a/prometheus/metric_base.py b/src/prometheus_rus/_metric_base.py similarity index 98% rename from prometheus/metric_base.py rename to src/prometheus_rus/_metric_base.py index 4b572d5..338c888 100644 --- a/prometheus/metric_base.py +++ b/src/prometheus_rus/_metric_base.py @@ -3,7 +3,7 @@ import typing import time import abc -from .path import Path +from ._path import Path class Now(typing.NamedTuple): diff --git a/prometheus/metrics.py b/src/prometheus_rus/_metrics.py similarity index 89% rename from prometheus/metrics.py rename to src/prometheus_rus/_metrics.py index 882f496..1689734 100644 --- a/prometheus/metrics.py +++ b/src/prometheus_rus/_metrics.py @@ -1,13 +1,7 @@ import typing -from .metric_base import MetricBase, MetricGroupBase, MetricGroupDefinition, MetricMutableValue, Now, NOW -from .registry import Path, GLOBAL_REGISTRY - -__all__ = [ - 'Counter', - 'Gauge', - 'Summary', -] +from ._metric_base import MetricBase, MetricGroupBase, MetricGroupDefinition, MetricMutableValue, Now, NOW +from ._registry import Path, GLOBAL_REGISTRY class Counter(MetricBase): diff --git a/prometheus/path.py b/src/prometheus_rus/_path.py similarity index 100% rename from prometheus/path.py rename to src/prometheus_rus/_path.py diff --git a/prometheus/registry.py b/src/prometheus_rus/_registry.py similarity index 98% rename from prometheus/registry.py rename to src/prometheus_rus/_registry.py index 62b10a5..1156188 100644 --- a/prometheus/registry.py +++ b/src/prometheus_rus/_registry.py @@ -5,8 +5,8 @@ import collections import time import math -from .metric_base import MetricValue, MetricBase, MetricGroupDefinition, MetricGroupBase, EMPTY_GROUP_DEFINITION -from .path import Path, Labels +from ._metric_base import MetricValue, MetricBase, MetricGroupDefinition, MetricGroupBase, EMPTY_GROUP_DEFINITION +from ._path import Path, Labels class _MetricGroup: diff --git a/test.py b/test.py index 493520c..71c9ed2 100644 --- a/test.py +++ b/test.py @@ -1,4 +1,4 @@ -from prometheus import Path, Counter, Gauge, Summary, GLOBAL_REGISTRY, NOW +from prometheus_rus import Path, Counter, Gauge, Summary, GLOBAL_REGISTRY, NOW g1 = Gauge(value=20, path=Path("foobar_g1", {"server": "[host:xy]"}), help="foo help with bar") g2 = Gauge(path=Path("foobar_g2", {"server": "[host:xy]"}), help="foo help with bar") diff --git a/venv-lints.sh b/venv-lints.sh new file mode 100755 index 0000000..4e9bc4d --- /dev/null +++ b/venv-lints.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +set -e + +cd "$(dirname "$(readlink "$0")")" + +sources=($@) +if [ "${#sources[@]}" -eq 0 ]; then + sources=(src) +fi + +rc=0 + +run() { + # remember last failure + if "$@"; then :; else rc=$?; fi +} + +export PYTHONDONTWRITEBYTECODE=1 + +poetry sync --extras=dev --quiet || poetry sync --extras=dev + +echo "flake8:" +run poetry run flake8 "${sources[@]}" +echo "mypy:" +run poetry run mypy + +# run formatters? +# black . && isort . + +exit $rc