Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run linters and formatters via pre-commit #797

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- checkout
- run: pip install tox
- run: tox


workflows:
version: 2
Expand Down
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ source =
.tox/pypy/site-packages/prometheus_client

[report]
show_missing = True
show_missing = True
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ dist
.coverage
.tox
.*cache
htmlcov
htmlcov
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 7 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,25 @@ 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
[Developer Certificate of Origin]: https://github.com/prometheus/prometheus/wiki/DCO-signing
[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/
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion prometheus_client/exposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion prometheus_client/gc_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
2 changes: 1 addition & 1 deletion prometheus_client/openmetrics/exposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions prometheus_client/openmetrics/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 = []
Expand Down
2 changes: 1 addition & 1 deletion prometheus_client/platform_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ def _java(self):
}


# PlatformCollector in default Registry REGISTRY
PLATFORM_COLLECTOR = PlatformCollector()
"""PlatformCollector in default Registry REGISTRY"""
2 changes: 1 addition & 1 deletion prometheus_client/process_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
2 changes: 1 addition & 1 deletion tests/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down