Skip to content

Commit d1ac782

Browse files
Add Flake8 and isort config files (#12)
We need these config files for a followup change. It's also a good demo of how to hook up config files.
1 parent 02a2f5b commit d1ac782

File tree

10 files changed

+38
-17
lines changed

10 files changed

+38
-17
lines changed

.flake8

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
extend-ignore:
3+
E203, # whitespace before ':' (conflicts with Black)
4+
E231, # Bad trailing comma (conflicts with Black)
5+
E501, # line too long (conflicts with Black)

.isort.cfg

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[settings]
2+
# This is to make isort compatible with Black. See
3+
# https://black.readthedocs.io/en/stable/the_black_code_style.html#how-black-wraps-lines.
4+
line_length=88
5+
multi_line_output=3
6+
include_trailing_comma=True
7+
force_grid_wrap=0
8+
use_parentheses=True
9+
10+
known_first_party=helloworld
11+
default_section=THIRDPARTY

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ env:
1010
os: linux
1111
dist: bionic
1212
language: python
13+
python: 3.7
1314

1415
cache:
1516
directories:

helloworld/greet/BUILD

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
# Copyright 2020 Pants project contributors.
22
# Licensed under the Apache License, Version 2.0 (see LICENSE).
33

4-
54
python_library(
6-
# name defaults to the name of this directory, i.e., `greet`.
7-
# sources defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py'].
5+
# `name` defaults to the name of this directory, i.e., `greet`.
6+
# `sources` defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py'].
87
dependencies = [
98
"//:translate",
109
":greetings",
1110
"helloworld/util"
1211
],
13-
compatibility = ">=3.6",
1412
)
1513

16-
1714
python_tests(
1815
name = 'tests',
19-
# sources defaults to ['*_test.py', 'test_*.py', 'conftest.py'].
16+
# `sources` defaults to ['*_test.py', 'test_*.py', 'conftest.py'].
2017
dependencies = [
2118
":greet"
2219
]
2320
)
2421

25-
2622
resources(
2723
name = 'greetings',
2824
sources = ['greetings.txt'],

helloworld/main.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Licensed under the Apache License, Version 2.0 (see LICENSE).
33

44
from colors import green
5+
56
from helloworld.greet.greeting import Greeter
67

78

helloworld/main_py2.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Licensed under the Apache License, Version 2.0 (see LICENSE).
33

44
from colors import green
5+
56
from helloworld.greet_py2.greeting_py2 import greet_py2
67

78

helloworld/util/lang.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
import random
55

6-
from helloworld.util.resources import get_lines
76
from translate import Translator
87

8+
from helloworld.util.resources import get_lines
9+
910

1011
class LanguageTranslator:
1112
class UnknownLanguage(Exception):

helloworld/util/lang_test.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Licensed under the Apache License, Version 2.0 (see LICENSE).
33

44
import pytest
5+
56
from helloworld.util.lang import LanguageTranslator
67

78

pants.ci.toml

-7
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,3 @@ process_execution_local_parallelism = 4
1414
# party dependencies. The total level of parallelism will be
1515
# `process_execution_local_parallelism x resolver_jobs`.
1616
resolver_jobs = 1
17-
18-
[lint]
19-
# We use `per_target_caching` because we have some Python 2-only targets and some Python 3-only
20-
# targets, so we need to run each target as a separate process to avoid interpreter compatibility
21-
# conflicts. If you only have one Python version in your repository, do not use this setting. See
22-
# https://pants.readme.io/docs/python-lint-goal.
23-
per_target_caching = true

pants.toml

+13-2
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,29 @@ backend_packages2 = [
2222
# List v2 plugins here.
2323
plugins2 = []
2424

25-
2625
[source]
2726
# The Python source root is the repo root. See https://pants.readme.io/docs/source-roots.
2827
source_roots = """{
2928
'': ('python',),
3029
}"""
3130

32-
3331
[python-setup]
3432
# The default interpreter compatibility for code in this repo. Individual targets can ovverride
3533
# this with the `compatibility` field. See
3634
# https://pants.readme.io/docs/python-interpreter-compatibility.
3735
interpreter_constraints = [">=3.7"]
3836
# Use a lockfile. See https://pants.readme.io/docs/python-third-party-dependencies.
3937
requirement_constraints = "constraints.txt"
38+
39+
[lint]
40+
# We use `per_target_caching` because we have some Python 2-only targets and some Python 3-only
41+
# targets, so we need to run each target as a separate process to avoid interpreter compatibility
42+
# conflicts. If you only have one Python version in your repository, do not use this setting. See
43+
# https://pants.readme.io/docs/python-lint-goal.
44+
per_target_caching = true
45+
46+
[flake8]
47+
config = ".flake8"
48+
49+
[isort]
50+
config = [".isort.cfg"]

0 commit comments

Comments
 (0)