Skip to content

Commit 90831da

Browse files
author
Abhijit Sarkar
committed
Add black code formatter to project
1 parent 08f1aad commit 90831da

File tree

145 files changed

+8437
-2429
lines changed

Some content is hidden

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

145 files changed

+8437
-2429
lines changed

setup.cfg renamed to .flake8

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
[flake8]
2+
extend-ignore = E203
23
exclude = .git,.github,__pycache__,.pytest_cache,venv,*_test.py
34
max-complexity = 10
45
max-line-length = 120
5-
6-
[tool:pytest]
7-
addopts = --strict-markers
8-
markers =
9-
task: A concept exercise task.

.github/run.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,16 @@ if (( no_test == 0 )); then
4141
fi
4242

4343
if (( no_lint == 0 )); then
44+
if [[ -z "${CI}" ]]; then
45+
"$bin_dir"black "$basedir"
46+
else
47+
"$bin_dir"black --check "$basedir"
48+
fi
4449
"$bin_dir"flake8 "$basedir"
4550
"$bin_dir"pylint \
51+
--rcfile ./.pylintrc \
4652
--score n \
4753
--ignore-patterns '^.*_test\.py$, ^test_.*\.py$' \
48-
--disable C0103,C0104,C0114,C0115,C0116 \
54+
--disable C0103,C0104,C0114,C0115,C0116,W0311 \
4955
"$basedir"/**/*.py
5056
fi

.pylintrc

Lines changed: 116 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
1-
###########################################################################
2-
# https://github.com/exercism/python-analyzer/blob/main/lib/common/.pylintrc
1+
# This Pylint rcfile contains a best-effort configuration to uphold the
2+
# best-practices and style described in the Google Python style guide:
3+
# https://google.github.io/styleguide/pyguide.html
34
#
4-
# This common pylintrc file contains a best-effort configuration to uphold the
5-
# best-practices and style for the Python track exercises of exercism.org.
6-
#
7-
# This file is used when there is no exercise-specific pylintrc.
8-
# When there is an exercise-specific pylintrc, this config file is ignored
9-
# in favor of the exercise-specific config.
10-
#
11-
# As a default, all warnings and checks are "turned on", although that may
12-
# change in the future, as we decide which rules to enforce for all exercises.
13-
#
14-
# **A note on single letter variable names.**
15-
# See this Stack Overflow discussion:
16-
# https://stackoverflow.com/questions/21833872/why-does-pylint-object-to-single-character-variable-names
17-
# for why this is enforced.
18-
###########################################################################
19-
5+
# Its canonical open-source location is:
6+
# https://google.github.io/styleguide/pylintrc
207

218
[MASTER]
229

@@ -58,63 +45,115 @@ confidence=
5845
# can either give multiple identifiers separated by comma (,) or put this
5946
# option multiple times (only on the command line, not in the configuration
6047
# file where it should appear only once).You can also use "--disable=all" to
61-
# disable everything first and then re-enable specific checks. For example, if
48+
# disable everything first and then reenable specific checks. For example, if
6249
# you want to run only the similarities checker, you can use "--disable=all
6350
# --enable=similarities". If you want to run only the classes checker, but have
6451
# no Warning level messages displayed, use"--disable=all --enable=classes
6552
# --disable=W"
66-
# inconsistent-return-statements,
67-
# disable=arguments-differ,
68-
# attribute-defined-outside-init,
69-
# duplicate-code,
70-
# filter-builtin-not-iterating,
71-
# fixme,
72-
# global-statement,
73-
# implicit-str-concat-in-sequence,
74-
# import-error,
75-
# import-self,
76-
# input-builtin,
77-
# locally-disabled,
78-
# misplaced-comparison-constant,
79-
# missing-class-docstring,
80-
# missing-function-docstring,
81-
# missing-module-docstring,
82-
# no-absolute-import,
83-
# no-else-break,
84-
# no-else-continue,
85-
# no-else-raise,
86-
# no-else-return,
87-
# no-member,
88-
# no-name-in-module,
89-
# no-self-use,
90-
# raising-string,
91-
# relative-import,
92-
# round-builtin,
93-
# signature-differs,
94-
# suppressed-message,
95-
# too-few-public-methods,
96-
# too-many-ancestors,
97-
# too-many-arguments,
98-
# too-many-boolean-expressions,
99-
# too-many-branches,
100-
# too-many-instance-attributes,
101-
# too-many-locals,
102-
# too-many-nested-blocks,
103-
# too-many-public-methods,
104-
# too-many-return-statements,
105-
# too-many-statements,
106-
# unused-argument,
107-
# unused-import,
108-
# useless-suppression
109-
disable=trailing-whitespace,missing-final-newline
53+
disable=abstract-method,
54+
apply-builtin,
55+
arguments-differ,
56+
attribute-defined-outside-init,
57+
backtick,
58+
bad-option-value,
59+
basestring-builtin,
60+
buffer-builtin,
61+
c-extension-no-member,
62+
consider-using-enumerate,
63+
cmp-builtin,
64+
cmp-method,
65+
coerce-builtin,
66+
coerce-method,
67+
delslice-method,
68+
div-method,
69+
duplicate-code,
70+
eq-without-hash,
71+
execfile-builtin,
72+
file-builtin,
73+
filter-builtin-not-iterating,
74+
fixme,
75+
getslice-method,
76+
global-statement,
77+
hex-method,
78+
idiv-method,
79+
implicit-str-concat,
80+
import-error,
81+
import-self,
82+
import-star-module-level,
83+
inconsistent-return-statements,
84+
input-builtin,
85+
intern-builtin,
86+
invalid-str-codec,
87+
locally-disabled,
88+
long-builtin,
89+
long-suffix,
90+
map-builtin-not-iterating,
91+
misplaced-comparison-constant,
92+
missing-function-docstring,
93+
metaclass-assignment,
94+
next-method-called,
95+
next-method-defined,
96+
no-absolute-import,
97+
no-else-break,
98+
no-else-continue,
99+
no-else-raise,
100+
no-else-return,
101+
no-init, # added
102+
no-member,
103+
no-name-in-module,
104+
no-self-use,
105+
nonzero-method,
106+
oct-method,
107+
old-division,
108+
old-ne-operator,
109+
old-octal-literal,
110+
old-raise-syntax,
111+
parameter-unpacking,
112+
print-statement,
113+
raising-string,
114+
range-builtin-not-iterating,
115+
raw_input-builtin,
116+
rdiv-method,
117+
reduce-builtin,
118+
relative-import,
119+
reload-builtin,
120+
round-builtin,
121+
setslice-method,
122+
signature-differs,
123+
standarderror-builtin,
124+
suppressed-message,
125+
sys-max-int,
126+
too-few-public-methods,
127+
too-many-ancestors,
128+
too-many-arguments,
129+
too-many-boolean-expressions,
130+
too-many-branches,
131+
too-many-instance-attributes,
132+
too-many-locals,
133+
too-many-nested-blocks,
134+
too-many-public-methods,
135+
too-many-return-statements,
136+
too-many-statements,
137+
trailing-newlines,
138+
unichr-builtin,
139+
unicode-builtin,
140+
unnecessary-pass,
141+
unpacking-in-except,
142+
useless-else-on-loop,
143+
useless-object-inheritance,
144+
useless-suppression,
145+
using-cmp-argument,
146+
wrong-import-order,
147+
xrange-builtin,
148+
zip-builtin-not-iterating,
110149

111150

112151
[REPORTS]
113152

114153
# Set the output format. Available formats are text, parseable, colorized, msvs
115154
# (visual studio) and html. You can also give a reporter class, eg
116155
# mypackage.mymodule.MyReporterClass.
117-
# output-format=colorized
156+
output-format=text
118157

119158
# Tells whether to display a full report or only the messages
120159
reports=no
@@ -134,17 +173,17 @@ evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / stateme
134173
[BASIC]
135174

136175
# Good variable names which should always be accepted, separated by a comma
137-
good-names=main,_, item, element, index
176+
good-names=main,_
138177

139178
# Bad variable names which should always be refused, separated by a comma
140-
bad-names=x,y,i,l,L,O,j,m,n,k
179+
bad-names=
141180

142181
# Colon-delimited sets of names that determine each other's naming style when
143182
# the name regexes allow several styles.
144183
name-group=
145184

146185
# Include a hint for the correct naming format with invalid-name
147-
include-naming-hint=y
186+
include-naming-hint=no
148187

149188
# List of decorators that produce properties, such as abc.abstractproperty. Add
150189
# to this list to register other decorators that produce valid properties.
@@ -154,7 +193,7 @@ property-classes=abc.abstractproperty,cached_property.cached_property,cached_pro
154193
function-rgx=^(?:(?P<exempt>setUp|tearDown|setUpModule|tearDownModule)|(?P<camel_case>_?[A-Z][a-zA-Z0-9]*)|(?P<snake_case>_?[a-z][a-z0-9_]*))$
155194

156195
# Regular expression matching correct variable names
157-
variable-rgx=^[a-z_][a-z0-9_]{1,30}$
196+
variable-rgx=^[a-z][a-z0-9_]*$
158197

159198
# Regular expression matching correct constant names
160199
const-rgx=^(_?[A-Z][A-Z0-9_]*|__[a-z0-9_]+__|_?[a-z][a-z0-9_]*)$
@@ -163,7 +202,7 @@ const-rgx=^(_?[A-Z][A-Z0-9_]*|__[a-z0-9_]+__|_?[a-z][a-z0-9_]*)$
163202
attr-rgx=^_{0,2}[a-z][a-z0-9_]*$
164203

165204
# Regular expression matching correct argument names
166-
argument-rgx=^[a-z][a-z0-9_]{1,30}$
205+
argument-rgx=^[a-z][a-z0-9_]*$
167206

168207
# Regular expression matching correct class attribute names
169208
class-attribute-rgx=^(_?[A-Z][A-Z0-9_]*|__[a-z0-9_]+__|_?[a-z][a-z0-9_]*)$
@@ -234,19 +273,14 @@ ignore-long-lines=(?x)(
234273
# else.
235274
single-line-if-stmt=yes
236275

237-
# List of optional constructs for which whitespace checking is disabled. `dict-
238-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
239-
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
240-
# `empty-line` allows space-only lines.
241-
# As of Pylint 2.6+, this option has been disabled, so this is commented out.
242-
# no-space-check=
243-
244276
# Maximum number of lines in a module
245277
max-module-lines=99999
246278

247-
# String used as indentation unit. Currently 4, consistent with
248-
# PEP 8.
249-
indent-string=' '
279+
# String used as indentation unit. The internal Google style guide mandates 2
280+
# spaces. Google's externaly-published style guide says 4, consistent with
281+
# PEP 8. Here, we use 2 spaces, for conformity with many open-sourced Google
282+
# projects (like TensorFlow).
283+
indent-string=' '
250284

251285
# Number of spaces of indent required inside a hanging or continued line.
252286
indent-after-paren=4
@@ -283,7 +317,7 @@ additional-builtins=
283317

284318
# List of strings which can identify a callback function by name. A callback
285319
# name must start or end with one of those strings.
286-
callbacks=
320+
callbacks=cb_,_cb
287321

288322
# List of qualified module names which can have objects that can redefine
289323
# builtins.
@@ -294,7 +328,7 @@ redefining-builtins-modules=six,six.moves,past.builtins,future.builtins,functool
294328

295329
# Logging modules to check that the string format arguments are in logging
296330
# function parameter format
297-
logging-modules=logging,absl.logging
331+
logging-modules=logging,absl.logging,tensorflow.io.logging
298332

299333

300334
[SIMILARITIES]
@@ -392,4 +426,4 @@ valid-metaclass-classmethod-first-arg=mcs
392426
# "Exception"
393427
overgeneral-exceptions=builtins.StandardError,
394428
builtins.Exception,
395-
builtins.BaseException
429+
builtins.BaseException

acronym/acronym.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
def abbreviate(words: str) -> str:
22
xs = []
33
for i, ch in enumerate(words):
4-
prev = '' if i == 0 else words[i - 1]
5-
fst = ch.isalpha() and (i == 0 or prev.isspace() or prev == '-')
4+
prev = "" if i == 0 else words[i - 1]
5+
fst = ch.isalpha() and (i == 0 or prev.isspace() or prev == "-")
66
if fst or (ch.isupper() and not prev.isupper()):
77
xs.append(ch.upper())
88

9-
return ''.join(xs)
9+
return "".join(xs)

acronym/acronym_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ def test_punctuation_without_whitespace(self):
2525

2626
def test_very_long_abbreviation(self):
2727
self.assertEqual(
28-
abbreviate(
29-
"Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me"
30-
),
28+
abbreviate("Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me"),
3129
"ROTFLSHTMDCOALM",
3230
)
3331

affine-cipher/affine_cipher.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,39 @@
55

66
def encode(plain_text: str, a: int, b: int) -> str:
77
if not __mmi(a, M):
8-
raise ValueError('a and m must be coprime.')
8+
raise ValueError("a and m must be coprime.")
99

1010
result = []
1111
i = 0
1212
for ch in plain_text:
1313
if c := __xcode(ch.lower(), lambda x: (a * x + b) % M):
1414
if i > 0 and (i % 5) == 0:
15-
result.append(' ')
15+
result.append(" ")
1616
result.append(c)
1717
i += 1
1818

19-
return ''.join(result)
19+
return "".join(result)
2020

2121

2222
def decode(ciphered_text: str, a: int, b: int) -> str:
2323
m = __mmi(a, M)
2424
if not m:
25-
raise ValueError('a and m must be coprime.')
25+
raise ValueError("a and m must be coprime.")
2626
result = []
2727
for ch in ciphered_text:
2828
if c := __xcode(ch, lambda x: ((x - b) * m) % M):
2929
result.append(c)
3030

31-
return ''.join(result)
31+
return "".join(result)
3232

3333

3434
def __xcode(ch: str, fn: Callable[[int], int]) -> str | None:
3535
if ch.islower():
36-
x = ord(ch) - ord('a')
36+
x = ord(ch) - ord("a")
3737
i = fn(x)
3838
if i < 0:
3939
i += M
40-
return chr(i + ord('a'))
40+
return chr(i + ord("a"))
4141
if ch.isdigit():
4242
return ch
4343
return None
@@ -81,7 +81,7 @@ def __mmi(a: int, b: int) -> int | None:
8181
i = y if a == smaller else x
8282
if i < 0:
8383
i += larger
84-
assert (a * i) % b == 1, f'failed check (a->{a} * {i}<-mmi) % {b}<-b == 1'
84+
assert (a * i) % b == 1, f"failed check (a->{a} * {i}<-mmi) % {b}<-b == 1"
8585
return i
8686

8787

0 commit comments

Comments
 (0)