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

lint the code with pylint #67

Merged
merged 2 commits into from Jun 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 58 additions & 0 deletions .pylintrc
@@ -0,0 +1,58 @@
[REPORTS]
output-format=text


[BASIC]
#missing-docstring=no


[FORMAT]
max-line-length=100
ignore-long-lines=^\s*(# )?<?https?://\S+>?$


[MESSAGES CONTROL]
disable=
fixme,
too-many-locals,
missing-docstring,
trailing-newlines,
invalid-name,
bad-continuation,
too-few-public-methods,
too-many-branches,
too-many-statements,
deprecated-method,
wrong-import-order,
ungrouped-imports,
unused-import,
useless-object-inheritance, # doesn't like class Foo(object) but required for py2
super-init-not-called,
protected-access,


[DESIGN]
#too-few-public-methods=no
#too-many-branches=no
#too-many-statements=no
max-args=10


[CLASSES]
#useless-object-inheritance=no
#super-init-not-called=no
valid-classmethod-first-arg=cls


[IMPORTS]
#wrong-import-order=no
#ungrouped-imports=no
#unused-import=no


[STDLIB]
#deprecated-method=no


[MISCELLANEOUS]
notes=FIXME,FIX,XXX,TODO
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -2,6 +2,10 @@ test:
docker-compose build test
docker-compose run test

lint:
pip install pylint
pylint bumpversion

debug_test:
docker-compose build test
docker-compose run test /bin/bash
Expand Down
9 changes: 7 additions & 2 deletions README.md
@@ -1,6 +1,10 @@
# bump2version

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

## NOTE

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


<!---
## Screencast

<a href="https://asciinema.org/a/3828">Watch a screencast here</a>.
-->

## Installation

Expand Down
74 changes: 36 additions & 38 deletions bumpversion/cli.py
Expand Up @@ -97,7 +97,8 @@ def main(original_args=None):

if len(positionals[1:]) > 2:
warnings.warn(
"Giving multiple files on the command line will be deprecated, please use [bumpversion:file:...] in a config file.",
"Giving multiple files on the command line will be deprecated,"
" please use [bumpversion:file:...] in a config file.",
PendingDeprecationWarning,
)

Expand Down Expand Up @@ -139,7 +140,7 @@ def main(original_args=None):

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

if len(logger_list.handlers) == 0:
if not logger_list.handlers:
ch2 = logging.StreamHandler(sys.stdout)
ch2.setFormatter(logformatter)
logger_list.addHandler(ch2)
Expand All @@ -155,7 +156,7 @@ def main(original_args=None):
root_logger = logging.getLogger('')
root_logger.setLevel(log_level)

logger.debug("Starting {}".format(DESCRIPTION))
logger.debug("Starting %s", DESCRIPTION)

defaults = {}
vcs_info = {}
Expand Down Expand Up @@ -195,7 +196,7 @@ def main(original_args=None):

if config_file_exists:

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

if "new_version" not in defaults and known_args.current_version:
try:
if current_version and len(positionals) > 0:
logger.info("Attempting to increment part '{}'".format(positionals[0]))
if current_version and positionals:
logger.info("Attempting to increment part '%s'", positionals[0])
new_version = current_version.bump(positionals[0], vc.order())
logger.info("Values are now: " + keyvaluestring(new_version._values))
logger.info("Values are now: %s", keyvaluestring(new_version._values))
defaults["new_version"] = vc.serialize(new_version, context)
except MissingValueForSerializationException as e:
logger.info("Opportunistic finding of new_version failed: " + e.message)
logger.info("Opportunistic finding of new_version failed: %s", e.message)
except IncompleteVersionRepresentationException as e:
logger.info("Opportunistic finding of new_version failed: " + e.message)
logger.info("Opportunistic finding of new_version failed: %s", e.message)
except KeyError as e:
logger.info("Opportunistic finding of new_version failed")

Expand Down Expand Up @@ -518,7 +519,7 @@ def main(original_args=None):
if args.new_version:
new_version = vc.parse(args.new_version)

logger.info("New version will be '{}'".format(args.new_version))
logger.info("New version will be '%s'", args.new_version)

file_names = file_names or positionals[1:]

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

logger.info(
"Asserting files {} contain the version string:".format(
", ".join([str(f) for f in files])
)
"Asserting files %s contain the version string...",
", ".join([str(f) for f in files])
)

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

for key, value in config.items("bumpversion"):
logger_list.info("{}={}".format(key, value))
logger_list.info("%s=%s", key, value)

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

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

logger.info(
"{} to config file {}:".format(
"Would write" if not write_to_config_file else "Writing", config_file
)
"%s to config file %s:",
"Would write" if not write_to_config_file else "Writing",
config_file
)

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

logger.info(
"{} {} commit".format(
"Would prepare" if not do_commit else "Preparing", vcs.__name__
)
"%s %s commit",
"Would prepare" if not do_commit else "Preparing",
vcs.__name__,
)

for path in commit_files:
logger.info(
"{} changes in file '{}' to {}".format(
"Would add" if not do_commit else "Adding", path, vcs.__name__
)
"%s changes in file '%s' to %s",
"Would add" if not do_commit else "Adding",
path,
vcs.__name__,
)

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

logger.info(
"{} to {} with message '{}'".format(
"Would commit" if not do_commit else "Committing",
vcs.__name__,
commit_message,
)
"%s to %s with message '%s'",
"Would commit" if not do_commit else "Committing",
vcs.__name__,
commit_message,
)

if do_commit:
Expand All @@ -644,13 +643,12 @@ def main(original_args=None):
tag_name = args.tag_name.format(**vcs_context)
tag_message = args.tag_message.format(**vcs_context)
logger.info(
"{} '{}' {} in {} and {}".format(
"Would tag" if not do_tag else "Tagging",
tag_name,
"with message '{}'".format(tag_message) if tag_message else "without message",
vcs.__name__,
"signing" if sign_tags else "not signing",
)
"%s '%s' %s in %s and %s",
"Would tag" if not do_tag else "Tagging",
tag_name,
"with message '{}'".format(tag_message) if tag_message else "without message",
vcs.__name__,
"signing" if sign_tags else "not signing",
)

if do_tag:
Expand Down
7 changes: 3 additions & 4 deletions bumpversion/compat.py
Expand Up @@ -11,21 +11,20 @@
def _command_args(args):
if IS_WINDOWS and IS_PY2:
return [a.encode("utf-8") for a in args]
else:
return args
return args


if IS_PY2:
sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
from StringIO import StringIO # noqa
from StringIO import StringIO # noqa # pylint: disable=import-error
from ConfigParser import ( # noqa
RawConfigParser,
SafeConfigParser as ConfigParser,
NoOptionError,
)

elif IS_PY3:
from io import StringIO # noqa
from io import StringIO # noqa # pylint: disable=import-error

# On Py2, "SafeConfigParser" is the same as "ConfigParser" on Py3
from configparser import ( # noqa
Expand Down
6 changes: 3 additions & 3 deletions bumpversion/functions.py
Expand Up @@ -15,13 +15,13 @@ class NumericFunction(object):
considered (e.g. 'r3-001' --> 'r4-001').
"""

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

def __init__(self, first_value=None):

if first_value is not None:
try:
part_prefix, part_numeric, part_suffix = self.FIRST_NUMERIC.search(
_, _, _ = self.FIRST_NUMERIC.search(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If all are unused, can you just remove the result? Wouldn't it be cleaner to do:

match = self.FIRST_NUMERIC.search(first_value)
if not match:
    raise ValueError("The given first value {} does not contain any digit".format(first_value))

first_value
).groups()
except AttributeError:
Expand Down Expand Up @@ -59,7 +59,7 @@ class ValuesFunction(object):

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

if len(values) == 0:
if not values:
raise ValueError("Version part values cannot be empty")

self._values = values
Expand Down
25 changes: 8 additions & 17 deletions bumpversion/utils.py
Expand Up @@ -21,7 +21,7 @@ class DiscardDefaultIfSpecifiedAppendAction(_AppendAction):
def __call__(self, parser, namespace, values, option_string=None):
if getattr(self, "_discarded_default", None) is None:
setattr(namespace, self.dest, [])
self._discarded_default = True
self._discarded_default = True # pylint: disable=attribute-defined-outside-init

super(DiscardDefaultIfSpecifiedAppendAction, self).__call__(
parser, namespace, values, option_string=None
Expand Down Expand Up @@ -77,12 +77,11 @@ def contains(self, search):
and search_lines[1:-1] == lookbehind[1:-1]
):
logger.info(
"Found '{}' in {} at line {}: {}".format(
search,
self.path,
lineno - (len(lookbehind) - 1),
line.rstrip()
)
"Found '%s' in %s at line %s: %s",
search,
self.path,
lineno - (len(lookbehind) - 1),
line.rstrip(),
)
return True
return False
Expand Down Expand Up @@ -110,11 +109,7 @@ def replace(self, current_version, new_version, context, dry_run):
)

if file_content_before != file_content_after:
logger.info(
"{} file {}:".format(
"Would change" if dry_run else "Changing", self.path
)
)
logger.info("%s file %s:", "Would change" if dry_run else "Changing", self.path)
logger.info(
"\n".join(
list(
Expand All @@ -129,11 +124,7 @@ def replace(self, current_version, new_version, context, dry_run):
)
)
else:
logger.info(
"{} file {}".format(
"Would not change" if dry_run else "Not changing", self.path
)
)
logger.info("%s file %s", "Would not change" if dry_run else "Not changing", self.path)

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