diff --git a/.circleci/config.yml b/.circleci/config.yml index f3712da7..7f140b23 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -62,7 +62,7 @@ jobs: - checkout - run: pip install tox - run: tox - + workflows: version: 2 diff --git a/.coveragerc b/.coveragerc index 69a0f522..b38e1ddb 100644 --- a/.coveragerc +++ b/.coveragerc @@ -11,4 +11,4 @@ source = .tox/pypy/site-packages/prometheus_client [report] -show_missing = True \ No newline at end of file +show_missing = True diff --git a/.gitignore b/.gitignore index 0ba244f6..72d23b11 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ dist .coverage .tox .*cache -htmlcov \ No newline at end of file +htmlcov diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..b26ad5c9 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,26 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.2.0 + hooks: + - id: check-added-large-files + - id: check-ast + - id: check-builtin-literals + - id: check-case-conflict + - id: check-docstring-first + - id: check-merge-conflict + - id: check-toml + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + - repo: https://github.com/pycqa/flake8 + rev: 4.0.1 + hooks: + - id: flake8 + additional_dependencies: + - 'flake8-docstrings==1.5.0' + - repo: https://github.com/pycqa/isort + rev: 5.10.1 + hooks: + - id: isort diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0db5b9a2..283bc306 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,19 +19,20 @@ Prometheus uses GitHub to manage reviews of pull requests. Submitted changes should pass the current tests, and be covered by new test cases when adding functionality. +* [Install `pre-commit`](https://pre-commit.com/index.html#installation) + and run `pre-commit install` in the repository. + * Run the tests locally using [tox] which executes the full suite on all supported Python versions installed. -* Each pull request is gated using [Travis CI] with the results linked on the - github page. This must pass before the change can land, note pushing a new +* Each pull request is gated using [CircleCI] with the results linked on the + GitHub page. This must pass before the change can land, note pushing a new change will trigger a retest. ## Style * Code style should follow [PEP 8] generally, and can be checked by running: - ``tox -e flake8``. - -* Import statements can be automatically formatted using [isort]. + `pre-commit run`. [our mailing list]: https://groups.google.com/forum/?fromgroups#!forum/prometheus-developers @@ -39,4 +40,4 @@ cases when adding functionality. [isort]: https://pypi.org/project/isort/ [PEP 8]: https://www.python.org/dev/peps/pep-0008/ [tox]: https://tox.readthedocs.io/en/latest/ -[Travis CI]: https://docs.travis-ci.com/ +[CircleCI]: https://circleci.com/ diff --git a/README.md b/README.md index d9721a58..5489cd9f 100644 --- a/README.md +++ b/README.md @@ -274,8 +274,8 @@ ProcessCollector(namespace='mydaemon', pid=lambda: open('/var/run/daemon.pid').r ### Platform Collector The client also automatically exports some metadata about Python. If using Jython, -metadata about the JVM in use is also included. This information is available as -labels on the `python_info` metric. The value of the metric is 1, since it is the +metadata about the JVM in use is also included. This information is available as +labels on the `python_info` metric. The value of the metric is 1, since it is the labels that carry information. ## Exporting @@ -367,7 +367,7 @@ Such an application can be useful when integrating Prometheus metrics with ASGI apps. By default, the WSGI application will respect `Accept-Encoding:gzip` headers used by Prometheus -and compress the response if such a header is present. This behaviour can be disabled by passing +and compress the response if such a header is present. This behaviour can be disabled by passing `disable_compression=True` when creating the app, like this: ```python diff --git a/prometheus_client/exposition.py b/prometheus_client/exposition.py index 86a9be48..0630e1be 100644 --- a/prometheus_client/exposition.py +++ b/prometheus_client/exposition.py @@ -34,8 +34,9 @@ 'write_to_textfile', ) +# Content type of the latest text format CONTENT_TYPE_LATEST = 'text/plain; version=0.0.4; charset=utf-8' -"""Content type of the latest text format""" + PYTHON376_OR_NEWER = sys.version_info > (3, 7, 5) diff --git a/prometheus_client/gc_collector.py b/prometheus_client/gc_collector.py index 4e80fa09..b73160b3 100644 --- a/prometheus_client/gc_collector.py +++ b/prometheus_client/gc_collector.py @@ -41,5 +41,5 @@ def collect(self) -> Iterable[Metric]: return [collected, uncollectable, collections] +# Default GCCollector in default Registry REGISTRY. GC_COLLECTOR = GCCollector() -"""Default GCCollector in default Registry REGISTRY.""" diff --git a/prometheus_client/openmetrics/exposition.py b/prometheus_client/openmetrics/exposition.py index d1c1f062..a28908b8 100644 --- a/prometheus_client/openmetrics/exposition.py +++ b/prometheus_client/openmetrics/exposition.py @@ -3,8 +3,8 @@ from ..utils import floatToGoString +# Content type of the latest OpenMetrics text format CONTENT_TYPE_LATEST = 'application/openmetrics-text; version=0.0.1; charset=utf-8' -"""Content type of the latest OpenMetrics text format""" def _is_valid_exemplar_metric(metric, sample): diff --git a/prometheus_client/openmetrics/parser.py b/prometheus_client/openmetrics/parser.py index fc25f080..f7f96692 100644 --- a/prometheus_client/openmetrics/parser.py +++ b/prometheus_client/openmetrics/parser.py @@ -196,7 +196,7 @@ def _parse_labels(text): label_name = sub_labels[:value_start] sub_labels = sub_labels[value_start + 1:] - # Check for missing quotes + # Check for missing quotes if not sub_labels or sub_labels[0] != '"': raise ValueError @@ -240,7 +240,7 @@ def _parse_labels(text): # Check for missing commas if sub_labels and next_comma == 0: raise ValueError - + return labels except ValueError: @@ -283,7 +283,7 @@ def _parse_remaining_text(text): val = _parse_value(split_text[0]) if len(split_text) == 1: # We don't have timestamp or exemplar - return val, None, None + return val, None, None timestamp = [] exemplar_value = [] diff --git a/prometheus_client/platform_collector.py b/prometheus_client/platform_collector.py index f99caa68..dbfa9a65 100644 --- a/prometheus_client/platform_collector.py +++ b/prometheus_client/platform_collector.py @@ -55,5 +55,5 @@ def _java(self): } +# PlatformCollector in default Registry REGISTRY PLATFORM_COLLECTOR = PlatformCollector() -"""PlatformCollector in default Registry REGISTRY""" diff --git a/prometheus_client/process_collector.py b/prometheus_client/process_collector.py index 8a38d056..48a1ec79 100644 --- a/prometheus_client/process_collector.py +++ b/prometheus_client/process_collector.py @@ -97,5 +97,5 @@ def collect(self) -> Iterable[Metric]: return result +# Default ProcessCollector in default Registry REGISTRY. PROCESS_COLLECTOR = ProcessCollector() -"""Default ProcessCollector in default Registry REGISTRY.""" diff --git a/tests/test_asgi.py b/tests/test_asgi.py index 50d76d6d..1fae7ee4 100644 --- a/tests/test_asgi.py +++ b/tests/test_asgi.py @@ -48,7 +48,7 @@ def tearDown(self): asyncio.get_event_loop().run_until_complete( self.communicator.wait() ) - + def seed_app(self, app): self.communicator = ApplicationCommunicator(app, self.scope)