Skip to content

Commit a83e3b6

Browse files
committed
Adapt "black" code formatter
this includes pre-commit hooks, and a linter step on Jenkins
1 parent 14190cc commit a83e3b6

File tree

126 files changed

+4068
-4194
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+4068
-4194
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[flake8]
22
exclude=elasticapm/utils/wrapt,build,src,tests,dist,conftest.py,setup.py
33
max-line-length=120
4-
ignore=E731
4+
ignore=E731,W503,E203

.pre-commit-config.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
repos:
2+
# seed-isort-config disabled for now, see https://github.com/asottile/seed-isort-config/issues/10
3+
#- repo: https://github.com/asottile/seed-isort-config
4+
# rev: v1.1.0
5+
# hooks:
6+
# - id: seed-isort-config
7+
- repo: https://github.com/pre-commit/mirrors-isort
8+
rev: v4.3.4
9+
hooks:
10+
- id: isort
11+
- repo: https://github.com/ambv/black
12+
rev: stable
13+
hooks:
14+
- id: black
15+
language_version: python3
16+
- repo: https://github.com/pre-commit/pre-commit-hooks
17+
rev: v1.3.0
18+
hooks:
19+
- id: flake8
20+
exclude: elasticapm\/utils\/wrapt|build|src|tests|dist|conftest.py|setup.py

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
[Check the diff](https://github.com/elastic/apm-agent-python/compare/v2.2.1...master)
66

7+
- adapted "black" code formatter for this repository (#262)
78
- **BREAKING**: dropped support for Python 3.3 (#242)
89
- **BREAKING**: changed order of precedence when evaluating configuration (#255, #261)
910
- **BREAKING**: changed default value of `span_frames_min_duration` setting

CONTRIBUTING.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,23 @@ Once your changes are ready to submit for review:
3333
We ask this of all contributors in order to assure our users of the origin and continuing existence of the code.
3434
You only need to sign the CLA once.
3535

36-
2. Test your changes
36+
1. Code style
37+
38+
This project uses several tools to maintain a consistent code style:
39+
40+
* the automatic code formatter [black](https://black.readthedocs.io/en/stable/)
41+
* sorting of imports via [isort](https://isort.readthedocs.io/en/latest/)
42+
* [flake8](http://flake8.pycqa.org/en/latest/)
43+
44+
The easiest way to make sure your pull request adheres to the the code style
45+
is to install [pre-commit](https://pre-commit.com/).
46+
47+
1. Test your changes
3748

3849
Run the test suite to make sure that nothing is broken.
3950
See [testing](#testing) for details.
4051

41-
3. Rebase your changes
52+
1. Rebase your changes
4253

4354
Update your local repository with the most recent code from the main repo,
4455
and rebase your branch on top of the latest master branch.
@@ -49,7 +60,7 @@ Once your changes are ready to submit for review:
4960
This makes them easier to review.
5061
As a final step before merging we will either ask you to squash all commits yourself or we'll do it for you.
5162

52-
4. Submit a pull request
63+
1. Submit a pull request
5364

5465
Push your local changes to your forked copy of the repository and [submit a pull request](https://help.github.com/articles/using-pull-requests).
5566
In the pull request,
@@ -58,7 +69,7 @@ Once your changes are ready to submit for review:
5869
Also mention the number of the issue where discussion has taken place,
5970
eg "Closes #123".
6071

61-
5. Be patient
72+
1. Be patient
6273

6374
We might not be able to review your code as fast as we would like to,
6475
but we'll do our best to dedicate it the attention it deserves.

conftest.py

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
import sys
33
from os.path import abspath, dirname, join
44

5-
from tests.fixtures import (elasticapm_client, instrument, not_so_random,
6-
sending_elasticapm_client, validating_httpserver,
7-
waiting_httpserver, waiting_httpsserver)
5+
from tests.fixtures import (
6+
elasticapm_client,
7+
instrument,
8+
not_so_random,
9+
sending_elasticapm_client,
10+
validating_httpserver,
11+
waiting_httpserver,
12+
waiting_httpsserver,
13+
)
814
from tests.utils.compat import middleware_setting
915

1016
try:
@@ -19,17 +25,17 @@
1925

2026
where_am_i = dirname(abspath(__file__))
2127

22-
BASE_TEMPLATE_DIR = join(where_am_i, 'tests', 'contrib', 'django', 'testapp',
23-
'templates')
28+
BASE_TEMPLATE_DIR = join(where_am_i, "tests", "contrib", "django", "testapp", "templates")
2429

2530
sys.path.insert(0, where_am_i)
2631

2732
# don't run tests of dependencies that land in "build" and "src"
28-
collect_ignore = ['build', 'src']
33+
collect_ignore = ["build", "src"]
2934

3035

3136
try:
3237
from psycopg2cffi import compat
38+
3339
compat.register()
3440
except ImportError:
3541
pass
@@ -42,32 +48,29 @@ def pytest_configure(config):
4248
settings = None
4349
if settings is not None and not settings.configured:
4450
import django
51+
4552
settings_dict = dict(
46-
SECRET_KEY='42',
53+
SECRET_KEY="42",
4754
DATABASES={
48-
'default': {
49-
'ENGINE': 'django.db.backends.sqlite3',
50-
'NAME': 'elasticapm_tests.db',
51-
'TEST_NAME': 'elasticapm_tests.db',
52-
'TEST': {
53-
'NAME': 'elasticapm_tests.db',
54-
}
55-
},
55+
"default": {
56+
"ENGINE": "django.db.backends.sqlite3",
57+
"NAME": "elasticapm_tests.db",
58+
"TEST_NAME": "elasticapm_tests.db",
59+
"TEST": {"NAME": "elasticapm_tests.db"},
60+
}
5661
},
57-
TEST_DATABASE_NAME='elasticapm_tests.db',
62+
TEST_DATABASE_NAME="elasticapm_tests.db",
5863
INSTALLED_APPS=[
59-
'django.contrib.auth',
60-
'django.contrib.admin',
61-
'django.contrib.sessions',
62-
'django.contrib.sites',
63-
'django.contrib.redirects',
64-
65-
'django.contrib.contenttypes',
66-
67-
'elasticapm.contrib.django',
68-
'tests.contrib.django.testapp',
64+
"django.contrib.auth",
65+
"django.contrib.admin",
66+
"django.contrib.sessions",
67+
"django.contrib.sites",
68+
"django.contrib.redirects",
69+
"django.contrib.contenttypes",
70+
"elasticapm.contrib.django",
71+
"tests.contrib.django.testapp",
6972
],
70-
ROOT_URLCONF='tests.contrib.django.testapp.urls',
73+
ROOT_URLCONF="tests.contrib.django.testapp.urls",
7174
DEBUG=False,
7275
SITE_ID=1,
7376
BROKER_HOST="localhost",
@@ -78,28 +81,29 @@ def pytest_configure(config):
7881
CELERY_ALWAYS_EAGER=True,
7982
TEMPLATE_DEBUG=False,
8083
TEMPLATE_DIRS=[BASE_TEMPLATE_DIR],
81-
ALLOWED_HOSTS=['*'],
84+
ALLOWED_HOSTS=["*"],
8285
TEMPLATES=[
8386
{
84-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
85-
'DIRS': [BASE_TEMPLATE_DIR],
86-
'OPTIONS': {
87-
'context_processors': [
88-
'django.contrib.auth.context_processors.auth',
89-
],
90-
'loaders': [
91-
'django.template.loaders.filesystem.Loader',
92-
],
93-
'debug': False,
87+
"BACKEND": "django.template.backends.django.DjangoTemplates",
88+
"DIRS": [BASE_TEMPLATE_DIR],
89+
"OPTIONS": {
90+
"context_processors": ["django.contrib.auth.context_processors.auth"],
91+
"loaders": ["django.template.loaders.filesystem.Loader"],
92+
"debug": False,
9493
},
95-
},
96-
]
94+
}
95+
],
96+
)
97+
settings_dict.update(
98+
**middleware_setting(
99+
django.VERSION,
100+
[
101+
"django.contrib.sessions.middleware.SessionMiddleware",
102+
"django.contrib.auth.middleware.AuthenticationMiddleware",
103+
"django.contrib.messages.middleware.MessageMiddleware",
104+
],
105+
)
97106
)
98-
settings_dict.update(**middleware_setting(django.VERSION, [
99-
'django.contrib.sessions.middleware.SessionMiddleware',
100-
'django.contrib.auth.middleware.AuthenticationMiddleware',
101-
'django.contrib.messages.middleware.MessageMiddleware',
102-
]))
103107
settings.configure(**settings_dict)
104-
if hasattr(django, 'setup'):
108+
if hasattr(django, "setup"):
105109
django.setup()

elasticapm/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99
:license: BSD, see LICENSE for more details.
1010
"""
1111

12-
__all__ = ('VERSION', 'Client')
12+
__all__ = ("VERSION", "Client")
1313

1414
try:
15-
VERSION = __import__('pkg_resources') \
16-
.get_distribution('elastic-apm').version
15+
VERSION = __import__("pkg_resources").get_distribution("elastic-apm").version
1716
except Exception as e:
18-
VERSION = 'unknown'
17+
VERSION = "unknown"
1918

2019
from elasticapm.base import Client
2120
from elasticapm.conf import setup_logging # noqa: F401

0 commit comments

Comments
 (0)