diff --git a/conda/cli/common.py b/conda/cli/common.py index 449e53f5413..701c325b3f3 100644 --- a/conda/cli/common.py +++ b/conda/cli/common.py @@ -56,7 +56,7 @@ def confirm_yn(message="Proceed", default='yes', dry_run=NULL): return True try: choice = confirm(message=message, choices=('yes', 'no'), default=default) - except KeyboardInterrupt as e: # pragma: no cover + except KeyboardInterrupt: # pragma: no cover from ..exceptions import CondaSystemExit raise CondaSystemExit("\nOperation aborted. Exiting.") if choice == 'no': diff --git a/conda/cli/conda_argparse.py b/conda/cli/conda_argparse.py index 7e8b482d647..fcd0b4955d1 100644 --- a/conda/cli/conda_argparse.py +++ b/conda/cli/conda_argparse.py @@ -78,6 +78,7 @@ def do_call(args, parser): # func_name should always be 'execute' from importlib import import_module module = import_module(relative_mod, __name__.rsplit('.', 1)[0]) + exit_code = getattr(module, func_name)(args, parser) return exit_code diff --git a/conda/cli/main.py b/conda/cli/main.py index 3d028d318a4..307b8bc384a 100644 --- a/conda/cli/main.py +++ b/conda/cli/main.py @@ -107,7 +107,7 @@ def main(*args, **kwargs): import conda.cli.activate as activate activate.main() return - except Exception as e: + except Exception: _, exc_val, exc_tb = sys.exc_info() init_loggers() from ..exceptions import ExceptionHandler diff --git a/conda/cli/main_clean.py b/conda/cli/main_clean.py index bd1068b6e13..4a052f6ec6f 100644 --- a/conda/cli/main_clean.py +++ b/conda/cli/main_clean.py @@ -4,12 +4,14 @@ from __future__ import absolute_import, division, print_function, unicode_literals from collections import defaultdict +import fnmatch from logging import getLogger -from os import listdir, lstat, walk +from os import listdir, lstat, walk, unlink from os.path import getsize, isdir, join, exists import sys from ..base.constants import CONDA_TARBALL_EXTENSION +from ..common.constants import CONDA_TEMP_EXTENSION from ..base.context import context log = getLogger(__name__) @@ -205,15 +207,16 @@ def rm_rf_pkgs_dirs(): def clean_tmp_files(path=None): if not path: path = sys.prefix - for root, dirs, fns in os.walk(path): + for root, dirs, fns in walk(path): for fn in fns: if (fnmatch.fnmatch(fn, "*.trash") or - fnmatch.fnmatch(fn, "*" + CONDA_TEMP_EXTENSION)): - file_path = os.path.join(root, fn) + fnmatch.fnmatch(fn, "*" + CONDA_TEMP_EXTENSION)): + file_path = join(root, fn) try: - os.unlink(file_path) + unlink(file_path) except EnvironmentError: - log.warn("File at {} could not be cleaned up. It's probably still in-use.".format(file_path)) + log.warn("File at {} could not be cleaned up. " + "It's probably still in-use.".format(file_path)) def _execute(args, parser): json_result = { @@ -269,10 +272,10 @@ def _execute(args, parser): one_target_ran = True if args.all: - clean_tempfiles(sys.prefix) + clean_tmp_files(sys.prefix) elif args.tempfiles: for path in args.tempfiles: - clean_tempfiles(path) + clean_tmp_files(path) if not one_target_ran: from ..exceptions import ArgumentError diff --git a/conda/cli/main_create.py b/conda/cli/main_create.py index 3a1608b988e..84c8e7c306f 100644 --- a/conda/cli/main_create.py +++ b/conda/cli/main_create.py @@ -11,7 +11,7 @@ from ..base.context import context from ..common.path import paths_equal from ..exceptions import CondaValueError -from ..gateways.disk.delete import delete_trash, rm_rf +from ..gateways.disk.delete import rm_rf from ..gateways.disk.test import is_conda_environment log = getLogger(__name__) diff --git a/conda/cli/main_info.py b/conda/cli/main_info.py index 44368dc6b36..ab4e4376b5e 100644 --- a/conda/cli/main_info.py +++ b/conda/cli/main_info.py @@ -28,7 +28,7 @@ def get_user_site(): # pragma: no cover try: if not on_win: if exists(expanduser('~/.local/lib')): - python_re = re.compile('python\d\.\d') + python_re = re.compile(r'python\d\.\d') for path in os.listdir(expanduser('~/.local/lib/')): if python_re.match(path): site_dirs.append("~/.local/lib/%s" % path) diff --git a/conda/cli/main_remove.py b/conda/cli/main_remove.py index 764ce382f09..a97c09f0a20 100644 --- a/conda/cli/main_remove.py +++ b/conda/cli/main_remove.py @@ -4,7 +4,6 @@ from __future__ import absolute_import, division, print_function, unicode_literals import logging -from os.path import isdir import sys from .common import check_non_admin, specs_from_args @@ -15,8 +14,7 @@ from ..core.prefix_data import PrefixData from ..core.solve import Solver from ..exceptions import CondaEnvironmentError, CondaValueError -from ..gateways.disk.delete import delete_trash, rm_rf, path_is_clean -from ..gateways.disk.test import is_conda_environment +from ..gateways.disk.delete import rm_rf, path_is_clean from ..models.match_spec import MatchSpec log = logging.getLogger(__name__) diff --git a/conda/cli/python_api.py b/conda/cli/python_api.py index 171552ebfd7..dabb86fb4bc 100644 --- a/conda/cli/python_api.py +++ b/conda/cli/python_api.py @@ -91,7 +91,7 @@ def run_command(command, *arguments, **kwargs): with ExitStack() as context_stack: try: context_stack.enter_context(argv(['python_api'] + split_command_line)) - if kwargs.get("no_capture") != True: + if kwargs.get("no_capture") is not True: c = context_stack.enter_context(captured(stdout, stderr)) if use_exception_handler: return_code = conda_exception_handler(do_call, args, p) diff --git a/conda/core/link.py b/conda/core/link.py index 8f79a0f051e..b21eacd64e3 100644 --- a/conda/core/link.py +++ b/conda/core/link.py @@ -1013,7 +1013,7 @@ def run_script(prefix, prec, action='post-link', env_prefix=None): log.debug("for %s at %s, executing script: $ %s", prec.dist_str(), env['PREFIX'], ' '.join(command_args)) subprocess_call(command_args, env=env, path=dirname(path)) - except CalledProcessError as e: # pragma: no cover + except CalledProcessError: m = messages(prefix) if action in ('pre-link', 'post-link'): if 'openssl' in prec.dist_str(): diff --git a/conda/core/path_actions.py b/conda/core/path_actions.py index 4822715e35a..790f4b4ff06 100644 --- a/conda/core/path_actions.py +++ b/conda/core/path_actions.py @@ -53,7 +53,6 @@ 'hold_path', ) - @with_metaclass(ABCMeta) class PathAction(object): diff --git a/conda/core/subdir_data.py b/conda/core/subdir_data.py index 00c332840c7..7fa8eaf262a 100644 --- a/conda/core/subdir_data.py +++ b/conda/core/subdir_data.py @@ -51,7 +51,7 @@ REPODATA_PICKLE_VERSION = 28 MAX_REPODATA_VERSION = 1 -REPODATA_HEADER_RE = b'"(_etag|_mod|_cache_control)":[ ]?"(.*?[^\\\\])"[,\}\s]' +REPODATA_HEADER_RE = rb'"(_etag|_mod|_cache_control)":[ ]?"(.*?[^\\\\])"[,\}\s]' class SubdirDataType(type): @@ -284,7 +284,7 @@ def _read_pickled(self, etag, mod_stamp): log.debug("found pickle file %s", self.cache_path_pickle) with open(self.cache_path_pickle, 'rb') as fh: _pickled_state = pickle.load(fh) - except Exception as e: + except Exception: log.debug("Failed to load pickled repodata.", exc_info=True) rm_rf(self.cache_path_pickle) return None diff --git a/conda/gateways/disk/create.py b/conda/gateways/disk/create.py index c63e6281bfc..81cb14a49d4 100644 --- a/conda/gateways/disk/create.py +++ b/conda/gateways/disk/create.py @@ -46,7 +46,7 @@ if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) sys.exit(%(func)s()) -""") +""") # NOQA application_entry_point_template = dals(""" # -*- coding: utf-8 -*- diff --git a/conda/gateways/disk/delete.py b/conda/gateways/disk/delete.py index 124e68919a0..530d3b35e87 100644 --- a/conda/gateways/disk/delete.py +++ b/conda/gateways/disk/delete.py @@ -18,7 +18,6 @@ from ...base.context import context from ...common.compat import on_win from ...common.constants import CONDA_TEMP_EXTENSION -from ...base.context import context log = getLogger(__name__) diff --git a/conda/gateways/disk/link.py b/conda/gateways/disk/link.py index a26ea52b5db..269abe88c07 100644 --- a/conda/gateways/disk/link.py +++ b/conda/gateways/disk/link.py @@ -214,7 +214,7 @@ def _patch_path(path): \\?\ in order to work with API calls. See http://msdn.microsoft.com/en-us/library/aa365247%28v=vs.85%29.aspx for details. - """ + """ # NOQA if path.startswith('\\\\?\\'): return path path = abspath(path) @@ -242,7 +242,7 @@ def is_symlink(path): path = _patch_path(path) try: return _is_symlink(next(find_files(path))) - except WindowsError as orig_error: + except WindowsError as orig_error: # NOQA tmpl = "Error accessing {path}: {orig_error.message}" raise builtins.WindowsError(local_format(tmpl)) @@ -257,7 +257,7 @@ def find_files(spec): >>> # This test might fail on a non-standard installation >>> 'Windows' in (fd.filename for fd in root_files) True - """ + """ # NOQA fd = WIN32_FIND_DATA() handle = FindFirstFile(spec, byref(fd)) while True: diff --git a/conda/gateways/disk/update.py b/conda/gateways/disk/update.py index 03b3f0ee58a..f3eb76cbeff 100644 --- a/conda/gateways/disk/update.py +++ b/conda/gateways/disk/update.py @@ -61,7 +61,8 @@ def rename(source_path, destination_path, force=False): rename_script = join(condabin_dir, 'rename_tmp.bat') _dirname, _src_fn = split(source_path) _dest_fn = basename(destination_path) - p = Popen(['cmd.exe', '/C', rename_script, _dirname, _src_fn, _dest_fn], stdout=PIPE, stderr=PIPE) + p = Popen(['cmd.exe', '/C', rename_script, _dirname, + _src_fn, _dest_fn], stdout=PIPE, stderr=PIPE) stdout, stderr = p.communicate() elif e.errno in (EINVAL, EXDEV): # https://github.com/conda/conda/issues/6811 diff --git a/conda/resolve.py b/conda/resolve.py index 291363db6f2..dcb1907cf90 100644 --- a/conda/resolve.py +++ b/conda/resolve.py @@ -128,7 +128,7 @@ def v_fkey_(prec): filter[prec] = True try: depends = self.ms_depends(prec) - except InvalidSpec as e: + except InvalidSpec: val = filter[prec] = False else: val = filter[prec] = all(v_ms_(ms) for ms in depends) @@ -155,7 +155,7 @@ def is_valid_prec(prec): filter_out[prec] = False try: has_valid_deps = all(is_valid_spec(ms) for ms in self.ms_depends(prec)) - except InvalidSpec as e: + except InvalidSpec: val = filter_out[prec] = "invalid dep specs" else: val = filter_out[prec] = False if has_valid_deps else "invalid depends specs" diff --git a/conda_env/cli/main_create.py b/conda_env/cli/main_create.py index 0364bf7f0ab..c692b7f12c7 100644 --- a/conda_env/cli/main_create.py +++ b/conda_env/cli/main_create.py @@ -11,7 +11,7 @@ from conda._vendor.auxlib.path import expand from conda.cli import install as cli_install from conda.cli.conda_argparse import add_parser_json, add_parser_prefix -from conda.gateways.disk.delete import delete_trash, rm_rf +from conda.gateways.disk.delete import rm_rf from conda.misc import touch_nonadmin from .common import get_prefix from .. import exceptions, specs diff --git a/conda_env/cli/main_remove.py b/conda_env/cli/main_remove.py index 36c3d025434..999f08f6974 100644 --- a/conda_env/cli/main_remove.py +++ b/conda_env/cli/main_remove.py @@ -4,7 +4,6 @@ from __future__ import absolute_import, print_function from argparse import Namespace, RawDescriptionHelpFormatter -from os.path import isdir from conda.cli.conda_argparse import add_output_and_prompt_options, add_parser_prefix diff --git a/setup.cfg b/setup.cfg index a4575bef80b..be26c946b16 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,13 +28,13 @@ markers = [pycodestyle] max-line-length = 99 ignore = E126,E133,E226,E241,E242,E302,E704,E731,E722,W503 -exclude = build/*,.tox/*,env/*,test_data/*,tests/*,ve/*,utils/*,*/_vendor/*,conda/compat.py,conda/common/compat.py,conda_env/compat.py +exclude = build/*,.tox/*,devenv*/*,env/*,test_data/*,tests/*,ve/*,utils/*,*/_vendor/*,conda/compat.py,conda/common/compat.py,conda_env/compat.py [flake8] max-line-length = 99 -ignore = E126,E133,E226,E241,E242,E302,E704,E731,E722,W503,E402 -exclude = .asv*,build/*,.tox/*,devenv/*,env/*,test_data/*,tests/*,ve/*,utils/*,*/_vendor/*,conda/compat.py,conda/common/compat.py,conda_env/compat.py +ignore = E126,E133,E226,E241,E242,E302,E704,E731,E722,W503,E402,W504 +exclude = .asv*,build/*,.tox/*,devenv*/*,env/*,test_data/*,tests/*,ve/*,utils/*,*/_vendor/*,conda/compat.py,conda/common/compat.py,conda_env/compat.py [coverage:report]