Skip to content

Commit 7e1ce4d

Browse files
committed
lint the code with pylint
This also adds a pylintrc for future PRs.
1 parent c65262e commit 7e1ce4d

File tree

10 files changed

+184
-129
lines changed

10 files changed

+184
-129
lines changed

.pylintrc

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[REPORTS]
2+
output-format=text
3+
4+
5+
[BASIC]
6+
#missing-docstring=no
7+
8+
9+
[FORMAT]
10+
max-line-length=100
11+
ignore-long-lines=^\s*(# )?<?https?://\S+>?$
12+
13+
14+
[MESSAGES CONTROL]
15+
disable=
16+
fixme,
17+
too-many-locals,
18+
missing-docstring,
19+
trailing-newlines,
20+
invalid-name,
21+
bad-continuation,
22+
too-few-public-methods,
23+
too-many-branches,
24+
too-many-statements,
25+
deprecated-method,
26+
wrong-import-order,
27+
ungrouped-imports,
28+
unused-import,
29+
useless-object-inheritance, # doesn't like class Foo(object) but required for py2
30+
super-init-not-called,
31+
protected-access,
32+
33+
34+
[DESIGN]
35+
#too-few-public-methods=no
36+
#too-many-branches=no
37+
#too-many-statements=no
38+
max-args=10
39+
40+
41+
[CLASSES]
42+
#useless-object-inheritance=no
43+
#super-init-not-called=no
44+
valid-classmethod-first-arg=cls
45+
46+
47+
[IMPORTS]
48+
#wrong-import-order=no
49+
#ungrouped-imports=no
50+
#unused-import=no
51+
52+
53+
[STDLIB]
54+
#deprecated-method=no
55+
56+
57+
[MISCELLANEOUS]
58+
notes=FIXME,FIX,XXX,TODO

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ test:
22
docker-compose build test
33
docker-compose run test
44

5+
lint:
6+
pip install pylint
7+
pylint bumpversion
8+
59
debug_test:
610
docker-compose build test
711
docker-compose run test /bin/bash

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# bump2version
22

3-
[![Build Status](https://travis-ci.org/c4urself/bump2version.svg?branch=master)](https://travis-ci.org/c4urself/bump2version)
3+
[![image](https://img.shields.io/pypi/v/bump2version.svg)](https://pypi.org/project/bump2version/)
4+
[![image](https://img.shields.io/pypi/l/bump2version.svg)](https://pypi.org/project/bump2version/)
5+
[![image](https://img.shields.io/pypi/pyversions/bump2version.svg)](https://pypi.org/project/bump2version/)
6+
[![Travis](https://img.shields.io/travis/c4urself/bump2version/master.svg?logo=travis)](https://travis-ci.org/c4urself/bump2version)
7+
[![AppVeyor](https://img.shields.io/appveyor/ci/c4urself/bump2version.svg?logo=appveyor)](https://ci.appveyor.com/project/c4urself/bump2version)
48

59
## NOTE
610

@@ -25,10 +29,11 @@ commits and tags:
2529
* just handles text files, so it's not specific to any programming language
2630
* supports Python2, Python3 and Pypy
2731

28-
32+
<!---
2933
## Screencast
3034
3135
<a href="https://asciinema.org/a/3828">Watch a screencast here</a>.
36+
-->
3237

3338
## Installation
3439

bumpversion/cli.py

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ def main(original_args=None):
9797

9898
if len(positionals[1:]) > 2:
9999
warnings.warn(
100-
"Giving multiple files on the command line will be deprecated, please use [bumpversion:file:...] in a config file.",
100+
"Giving multiple files on the command line will be deprecated,"
101+
" please use [bumpversion:file:...] in a config file.",
101102
PendingDeprecationWarning,
102103
)
103104

@@ -139,7 +140,7 @@ def main(original_args=None):
139140

140141
logformatter = logging.Formatter("%(message)s")
141142

142-
if len(logger_list.handlers) == 0:
143+
if not logger_list.handlers:
143144
ch2 = logging.StreamHandler(sys.stdout)
144145
ch2.setFormatter(logformatter)
145146
logger_list.addHandler(ch2)
@@ -155,7 +156,7 @@ def main(original_args=None):
155156
root_logger = logging.getLogger('')
156157
root_logger.setLevel(log_level)
157158

158-
logger.debug("Starting {}".format(DESCRIPTION))
159+
logger.debug("Starting %s", DESCRIPTION)
159160

160161
defaults = {}
161162
vcs_info = {}
@@ -195,7 +196,7 @@ def main(original_args=None):
195196

196197
if config_file_exists:
197198

198-
logger.info("Reading config file {}:".format(config_file))
199+
logger.info("Reading config file %s:", config_file)
199200
# TODO: this is a DEBUG level log
200201
with io.open(config_file, "rt", encoding="utf-8") as f:
201202
logger.info(f.read())
@@ -381,15 +382,15 @@ def main(original_args=None):
381382

382383
if "new_version" not in defaults and known_args.current_version:
383384
try:
384-
if current_version and len(positionals) > 0:
385-
logger.info("Attempting to increment part '{}'".format(positionals[0]))
385+
if current_version and positionals:
386+
logger.info("Attempting to increment part '%s'", positionals[0])
386387
new_version = current_version.bump(positionals[0], vc.order())
387-
logger.info("Values are now: " + keyvaluestring(new_version._values))
388+
logger.info("Values are now: %s", keyvaluestring(new_version._values))
388389
defaults["new_version"] = vc.serialize(new_version, context)
389390
except MissingValueForSerializationException as e:
390-
logger.info("Opportunistic finding of new_version failed: " + e.message)
391+
logger.info("Opportunistic finding of new_version failed: %s", e.message)
391392
except IncompleteVersionRepresentationException as e:
392-
logger.info("Opportunistic finding of new_version failed: " + e.message)
393+
logger.info("Opportunistic finding of new_version failed: %s", e.message)
393394
except KeyError as e:
394395
logger.info("Opportunistic finding of new_version failed")
395396

@@ -518,7 +519,7 @@ def main(original_args=None):
518519
if args.new_version:
519520
new_version = vc.parse(args.new_version)
520521

521-
logger.info("New version will be '{}'".format(args.new_version))
522+
logger.info("New version will be '%s'", args.new_version)
522523

523524
file_names = file_names or positionals[1:]
524525

@@ -532,9 +533,8 @@ def main(original_args=None):
532533
except WorkingDirectoryIsDirtyException as e:
533534
if not defaults["allow_dirty"]:
534535
logger.warning(
535-
"{}\n\nUse --allow-dirty to override this if you know what you're doing.".format(
536-
e.message
537-
)
536+
"%s\n\nUse --allow-dirty to override this if you know what you're doing.",
537+
e.message
538538
)
539539
raise
540540
break
@@ -544,9 +544,8 @@ def main(original_args=None):
544544
# make sure files exist and contain version string
545545

546546
logger.info(
547-
"Asserting files {} contain the version string:".format(
548-
", ".join([str(f) for f in files])
549-
)
547+
"Asserting files %s contain the version string...",
548+
", ".join([str(f) for f in files])
550549
)
551550

552551
for f in files:
@@ -561,7 +560,7 @@ def main(original_args=None):
561560
config.set("bumpversion", "new_version", args.new_version)
562561

563562
for key, value in config.items("bumpversion"):
564-
logger_list.info("{}={}".format(key, value))
563+
logger_list.info("%s=%s", key, value)
565564

566565
config.remove_option("bumpversion", "new_version")
567566

@@ -573,9 +572,9 @@ def main(original_args=None):
573572
write_to_config_file = (not args.dry_run) and config_file_exists
574573

575574
logger.info(
576-
"{} to config file {}:".format(
577-
"Would write" if not write_to_config_file else "Writing", config_file
578-
)
575+
"%s to config file %s:",
576+
"Would write" if not write_to_config_file else "Writing",
577+
config_file
579578
)
580579

581580
config.write(new_config)
@@ -605,16 +604,17 @@ def main(original_args=None):
605604
do_tag = args.tag and not args.dry_run
606605

607606
logger.info(
608-
"{} {} commit".format(
609-
"Would prepare" if not do_commit else "Preparing", vcs.__name__
610-
)
607+
"%s %s commit",
608+
"Would prepare" if not do_commit else "Preparing",
609+
vcs.__name__,
611610
)
612611

613612
for path in commit_files:
614613
logger.info(
615-
"{} changes in file '{}' to {}".format(
616-
"Would add" if not do_commit else "Adding", path, vcs.__name__
617-
)
614+
"%s changes in file '%s' to %s",
615+
"Would add" if not do_commit else "Adding",
616+
path,
617+
vcs.__name__,
618618
)
619619

620620
if do_commit:
@@ -630,11 +630,10 @@ def main(original_args=None):
630630
commit_message = args.message.format(**vcs_context)
631631

632632
logger.info(
633-
"{} to {} with message '{}'".format(
634-
"Would commit" if not do_commit else "Committing",
635-
vcs.__name__,
636-
commit_message,
637-
)
633+
"%s to %s with message '%s'",
634+
"Would commit" if not do_commit else "Committing",
635+
vcs.__name__,
636+
commit_message,
638637
)
639638

640639
if do_commit:
@@ -644,13 +643,12 @@ def main(original_args=None):
644643
tag_name = args.tag_name.format(**vcs_context)
645644
tag_message = args.tag_message.format(**vcs_context)
646645
logger.info(
647-
"{} '{}' {} in {} and {}".format(
648-
"Would tag" if not do_tag else "Tagging",
649-
tag_name,
650-
"with message '{}'".format(tag_message) if tag_message else "without message",
651-
vcs.__name__,
652-
"signing" if sign_tags else "not signing",
653-
)
646+
"%s '%s' %s in %s and %s",
647+
"Would tag" if not do_tag else "Tagging",
648+
tag_name,
649+
"with message '{}'".format(tag_message) if tag_message else "without message",
650+
vcs.__name__,
651+
"signing" if sign_tags else "not signing",
654652
)
655653

656654
if do_tag:

bumpversion/compat.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,20 @@
1111
def _command_args(args):
1212
if IS_WINDOWS and IS_PY2:
1313
return [a.encode("utf-8") for a in args]
14-
else:
15-
return args
14+
return args
1615

1716

1817
if IS_PY2:
1918
sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
20-
from StringIO import StringIO # noqa
19+
from StringIO import StringIO # noqa # pylint: disable=import-error
2120
from ConfigParser import ( # noqa
2221
RawConfigParser,
2322
SafeConfigParser as ConfigParser,
2423
NoOptionError,
2524
)
2625

2726
elif IS_PY3:
28-
from io import StringIO # noqa
27+
from io import StringIO # noqa # pylint: disable=import-error
2928

3029
# On Py2, "SafeConfigParser" is the same as "ConfigParser" on Py3
3130
from configparser import ( # noqa

bumpversion/functions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ class NumericFunction(object):
1515
considered (e.g. 'r3-001' --> 'r4-001').
1616
"""
1717

18-
FIRST_NUMERIC = re.compile("([^\d]*)(\d+)(.*)")
18+
FIRST_NUMERIC = re.compile(r"([^\d]*)(\d+)(.*)")
1919

2020
def __init__(self, first_value=None):
2121

2222
if first_value is not None:
2323
try:
24-
part_prefix, part_numeric, part_suffix = self.FIRST_NUMERIC.search(
24+
_, _, _ = self.FIRST_NUMERIC.search(
2525
first_value
2626
).groups()
2727
except AttributeError:
@@ -59,7 +59,7 @@ class ValuesFunction(object):
5959

6060
def __init__(self, values, optional_value=None, first_value=None):
6161

62-
if len(values) == 0:
62+
if not values:
6363
raise ValueError("Version part values cannot be empty")
6464

6565
self._values = values

bumpversion/utils.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class DiscardDefaultIfSpecifiedAppendAction(_AppendAction):
2121
def __call__(self, parser, namespace, values, option_string=None):
2222
if getattr(self, "_discarded_default", None) is None:
2323
setattr(namespace, self.dest, [])
24-
self._discarded_default = True
24+
self._discarded_default = True # pylint: disable=attribute-defined-outside-init
2525

2626
super(DiscardDefaultIfSpecifiedAppendAction, self).__call__(
2727
parser, namespace, values, option_string=None
@@ -77,12 +77,11 @@ def contains(self, search):
7777
and search_lines[1:-1] == lookbehind[1:-1]
7878
):
7979
logger.info(
80-
"Found '{}' in {} at line {}: {}".format(
81-
search,
82-
self.path,
83-
lineno - (len(lookbehind) - 1),
84-
line.rstrip()
85-
)
80+
"Found '%s' in %s at line %s: %s",
81+
search,
82+
self.path,
83+
lineno - (len(lookbehind) - 1),
84+
line.rstrip(),
8685
)
8786
return True
8887
return False
@@ -110,11 +109,7 @@ def replace(self, current_version, new_version, context, dry_run):
110109
)
111110

112111
if file_content_before != file_content_after:
113-
logger.info(
114-
"{} file {}:".format(
115-
"Would change" if dry_run else "Changing", self.path
116-
)
117-
)
112+
logger.info("%s file %s:", "Would change" if dry_run else "Changing", self.path)
118113
logger.info(
119114
"\n".join(
120115
list(
@@ -129,11 +124,7 @@ def replace(self, current_version, new_version, context, dry_run):
129124
)
130125
)
131126
else:
132-
logger.info(
133-
"{} file {}".format(
134-
"Would not change" if dry_run else "Not changing", self.path
135-
)
136-
)
127+
logger.info("%s file %s", "Would not change" if dry_run else "Not changing", self.path)
137128

138129
if not dry_run:
139130
with io.open(self.path, "wt", encoding="utf-8", newline=file_new_lines) as f:

bumpversion/vcs.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@
77
import subprocess
88
from tempfile import NamedTemporaryFile
99

10-
from bumpversion.exceptions import WorkingDirectoryIsDirtyException, MercurialDoesNotSupportSignedTagsException
10+
from bumpversion.exceptions import (
11+
WorkingDirectoryIsDirtyException,
12+
MercurialDoesNotSupportSignedTagsException
13+
)
1114
from bumpversion.compat import _command_args
1215

1316

1417
logger = logging.getLogger(__name__)
1518

1619

1720
class BaseVCS(object):
21+
22+
_TEST_USABLE_COMMAND = None
23+
_COMMIT_COMMAND = None
24+
1825
@classmethod
1926
def commit(cls, message):
2027
with NamedTemporaryFile("wb", delete=False) as f:

0 commit comments

Comments
 (0)