diff --git a/pipenv/cli/options.py b/pipenv/cli/options.py index e1ece8d7..78c30d2d 100644 --- a/pipenv/cli/options.py +++ b/pipenv/cli/options.py @@ -171,8 +171,7 @@ def categories_option(f): def callback(ctx, param, value): state = ctx.ensure_object(State) if value: - for opt in re.split(r", *| ", value): - state.installstate.categories.append(opt) + state.installstate.categories += re.split(r", *| ", value) return value return option( @@ -235,8 +234,7 @@ def extra_pip_args(f): def callback(ctx, param, value): state = ctx.ensure_object(State) if value: - for opt in value.split(" "): - state.installstate.extra_pip_args.append(opt) + state.installstate.extra_pip_args += value.split(" ") return value return option( diff --git a/pipenv/environment.py b/pipenv/environment.py index fa58d10e..4187ba13 100644 --- a/pipenv/environment.py +++ b/pipenv/environment.py @@ -346,16 +346,17 @@ class Environment: "value = u'{0}'.format(json.dumps(paths)); print(value)" ) sysconfig_line = "sysconfig.get_path('{0}')" + if python_lib: - for key in ("purelib", "platlib", "stdlib", "platstdlib"): - pylib_lines.append( - f"u'{key}': u'{{0}}'.format({sysconfig_line.format(key)})" - ) + pylib_lines += [ + f"u'{key}': u'{{0}}'.format({sysconfig_line.format(key)})" + for key in ("purelib", "platlib", "stdlib", "platstdlib") + ] if python_inc: - for key in ("include", "platinclude"): - pyinc_lines.append( - f"u'{key}': u'{{0}}'.format({sysconfig_line.format(key)})" - ) + pyinc_lines += [ + f"u'{key}': u'{{0}}'.format({sysconfig_line.format(key)})" + for key in ("include", "platinclude") + ] lines = pylib_lines + pyinc_lines if scripts: lines.append( @@ -810,7 +811,7 @@ class Environment: raise OSError(f"No such file: {activate_this!s}") with open(activate_this) as f: code = compile(f.read(), activate_this, "exec") - exec(code, dict(__file__=activate_this)) + exec(code, {"__file__": activate_this}) @contextlib.contextmanager def activated(self): diff --git a/pipenv/project.py b/pipenv/project.py index 7ef349f6..aafdc1ce 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -1095,12 +1095,12 @@ class Project: def remove_packages_from_pipfile(self, packages): parsed = self.parsed_pipfile - packages = set([pep423_name(pkg) for pkg in packages]) + packages = {pep423_name(pkg) for pkg in packages} for category in self.get_package_categories(): pipfile_section = parsed.get(category, {}) - pipfile_packages = set( - [pep423_name(pkg_name) for pkg_name in pipfile_section.keys()] - ) + pipfile_packages = { + pep423_name(pkg_name) for pkg_name in pipfile_section.keys() + } to_remove = packages & pipfile_packages for pkg in to_remove: pkg_name = self.get_package_name_in_pipfile(pkg, category=category) diff --git a/pipenv/routines/graph.py b/pipenv/routines/graph.py index 2095dba4..0a437303 100644 --- a/pipenv/routines/graph.py +++ b/pipenv/routines/graph.py @@ -96,9 +96,7 @@ def do_graph(project, bare=False, json=False, json_tree=False, reverse=False): except jsonlib.JSONDecodeError: raise exceptions.JSONParseError(c.stdout, c.stderr) else: - for d in parsed: - if d["package"]["key"] not in BAD_PACKAGES: - data.append(d) + data += [d for d in parsed if d["package"]["key"] not in BAD_PACKAGES] click.echo(simplejson.dumps(data, indent=4)) sys.exit(0) elif json_tree: diff --git a/pipenv/routines/install.py b/pipenv/routines/install.py index 37e5add4..4be447dd 100644 --- a/pipenv/routines/install.py +++ b/pipenv/routines/install.py @@ -152,7 +152,7 @@ def do_install( sys.exit(1) # Allow more than one package to be provided. - package_args = [p for p in packages] + [f"-e {pkg}" for pkg in editable_packages] + package_args = list(packages) + [f"-e {pkg}" for pkg in editable_packages] # Install all dependencies, if none was provided. # This basically ensures that we have a pipfile and lockfile, then it locks and # installs from the lockfile @@ -550,7 +550,7 @@ def batch_install( allow_global=allow_global, extra_pip_args=extra_pip_args, ) - except StopIteration: + except StopIteration: # noqa: PERF203 console.print( f"Unable to find {index_name} in sources, please check dependencies: {dependencies}", style="bold red", diff --git a/pipenv/routines/lock.py b/pipenv/routines/lock.py index a8593ce4..2ff90e44 100644 --- a/pipenv/routines/lock.py +++ b/pipenv/routines/lock.py @@ -101,8 +101,8 @@ def do_lock( def overwrite_with_default(default, dev): - dev_keys = set(list(dev.keys())) - prod_keys = set(list(default.keys())) + dev_keys = set(dev.keys()) + prod_keys = set(default.keys()) for pkg in dev_keys & prod_keys: dev[pkg] = default[pkg] return dev diff --git a/pipenv/routines/outdated.py b/pipenv/routines/outdated.py index 47567977..ecaeb716 100644 --- a/pipenv/routines/outdated.py +++ b/pipenv/routines/outdated.py @@ -42,7 +42,7 @@ def do_outdated(project, pypi_mirror=None, pre=False, clear=False): for package in lockfile.get(category, []): try: updated_packages[package] = lockfile[category][package]["version"] - except KeyError: + except KeyError: # noqa: PERF203 pass outdated = [] skipped = [] diff --git a/pipenv/routines/uninstall.py b/pipenv/routines/uninstall.py index 679d5d91..ac65bd79 100644 --- a/pipenv/routines/uninstall.py +++ b/pipenv/routines/uninstall.py @@ -86,7 +86,7 @@ def do_uninstall( # Remove known "bad packages" from the list. bad_pkgs = get_canonical_names(BAD_PACKAGES) - ignored_packages = bad_pkgs & set(list(package_map.keys())) + ignored_packages = bad_pkgs & set(package_map.keys()) for ignored_pkg in get_canonical_names(ignored_packages): if project.s.is_verbose(): click.echo(f"Ignoring {ignored_pkg}.", err=True) diff --git a/pipenv/routines/update.py b/pipenv/routines/update.py index 1ccf1348..6f4c5c46 100644 --- a/pipenv/routines/update.py +++ b/pipenv/routines/update.py @@ -123,7 +123,7 @@ def upgrade( if index_url: index_name = add_index_to_pipfile(project, index_url) - package_args = [p for p in packages] + [f"-e {pkg}" for pkg in editable_packages] + package_args = list(packages) + [f"-e {pkg}" for pkg in editable_packages] requested_install_reqs = defaultdict(dict) requested_packages = defaultdict(dict) @@ -184,7 +184,7 @@ def upgrade( pypi_mirror=pypi_mirror, ) # Mutate the existing lockfile with the upgrade data for the categories - for package_name, _ in upgrade_lock_data.items(): + for package_name in upgrade_lock_data.keys(): correct_package_lock = full_lock_resolution.get(package_name) if correct_package_lock: lockfile[category][package_name] = correct_package_lock diff --git a/pipenv/utils/dependencies.py b/pipenv/utils/dependencies.py index 06f39437..7df5952c 100644 --- a/pipenv/utils/dependencies.py +++ b/pipenv/utils/dependencies.py @@ -1054,7 +1054,7 @@ def get_constraints_from_deps(deps): else: c = canonicalize_name(dep_name) else: - if not any([k in dep_version for k in ["path", "file", "uri"]]): + if not any(k in dep_version for k in ["path", "file", "uri"]): if dep_version.get("skip_resolver") is True: continue version = dep_version.get("version", None) @@ -1097,7 +1097,7 @@ def prepare_constraint_file( constraints_file.write(f"{requirementstxt_sources}\n") if constraints: - constraints_file.write("\n".join([c for c in constraints])) + constraints_file.write("\n".join(list(constraints))) constraints_file.close() return constraints_file.name diff --git a/pipenv/utils/fileutils.py b/pipenv/utils/fileutils.py index afb92ffd..b0c69762 100644 --- a/pipenv/utils/fileutils.py +++ b/pipenv/utils/fileutils.py @@ -184,11 +184,11 @@ def temp_path(): '/home/user/.pyenv/versions/3.7.0/lib/python3.7/site-packages' ] """ - path = [p for p in sys.path] + path = list(sys.path) try: yield finally: - sys.path = [p for p in path] + sys.path = list(path) TRACKED_TEMPORARY_DIRECTORIES = [] diff --git a/pipenv/utils/funktools.py b/pipenv/utils/funktools.py index 3c8201d0..45994454 100644 --- a/pipenv/utils/funktools.py +++ b/pipenv/utils/funktools.py @@ -298,7 +298,7 @@ def set_write_bit(fn: str) -> None: for path in [fn, os.path.dirname(fn)]: try: os.chflags(path, 0) - except AttributeError: + except AttributeError: # noqa: PERF203 pass return None for root, dirs, files in os.walk(fn, topdown=False): diff --git a/pipenv/utils/internet.py b/pipenv/utils/internet.py index ec0c6d39..77c68302 100644 --- a/pipenv/utils/internet.py +++ b/pipenv/utils/internet.py @@ -138,6 +138,4 @@ class PackageIndexHTMLParser(HTMLParser): # If tag is an anchor if tag == "a": # find href attribute - for attr in attrs: - if attr[0] == "href": - self.urls.append(attr[1]) + self.urls += [attr[1] for attr in attrs if attr[0] == "href"] diff --git a/pipenv/utils/locking.py b/pipenv/utils/locking.py index c8bc8ad0..edad0ea4 100644 --- a/pipenv/utils/locking.py +++ b/pipenv/utils/locking.py @@ -259,7 +259,7 @@ class Lockfile(BaseModel): @property def extended_keys(self): - return [k for k in itertools.product(self.section_keys, ["", "vcs", "editable"])] + return list(itertools.product(self.section_keys, ["", "vcs", "editable"])) def get(self, k): return self.__getitem__(k) diff --git a/pipenv/utils/markers.py b/pipenv/utils/markers.py index 5b162877..52036006 100644 --- a/pipenv/utils/markers.py +++ b/pipenv/utils/markers.py @@ -62,7 +62,7 @@ class PipenvMarkers(BaseModel): @classmethod def from_pipfile(cls, name, pipfile): - attr_fields = [field_name for field_name in cls.__fields__] + attr_fields = list(cls.__fields__) found_keys = [k for k in pipfile.keys() if k in attr_fields] marker_strings = [f"{k} {pipfile[k]}" for k in found_keys] if pipfile.get("markers"): @@ -163,8 +163,7 @@ def _get_specs(specset): if op in ("in", "not in"): versions = version.split(",") op = "==" if op == "in" else "!=" - for ver in versions: - result.append((op, _tuplize_version(ver.strip()))) + result += [(op, _tuplize_version(ver.strip())) for ver in versions] else: result.append((spec.operator, _tuplize_version(spec.version))) return sorted(result, key=operator.itemgetter(1)) @@ -617,11 +616,7 @@ def merge_markers(m1, m2): # type: (Marker, Marker) -> Optional[Marker] if not all((m1, m2)): return next(iter(v for v in (m1, m2) if v), None) - m1 = _ensure_marker(m1) - m2 = _ensure_marker(m2) - _markers = [] # type: List[Marker] - for marker in (m1, m2): - _markers.append(str(marker)) + _markers = [str(_ensure_marker(marker)) for marker in (m1, m2)] marker_str = " and ".join([normalize_marker_str(m) for m in _markers if m]) return _ensure_marker(normalize_marker_str(marker_str)) @@ -654,9 +649,9 @@ def marker_from_specifier(spec) -> Marker: spec = "=={}".format(spec.lstrip("=")) if not spec: return None - marker_segments = [] - for marker_segment in cleanup_pyspecs(spec): - marker_segments.append(format_pyversion(marker_segment)) + marker_segments = [ + format_pyversion(marker_segment) for marker_segment in cleanup_pyspecs(spec) + ] marker_str = " and ".join(marker_segments).replace('"', "'") return Marker(marker_str) diff --git a/pipenv/utils/pip.py b/pipenv/utils/pip.py index 1f5d56d1..feb02ee7 100644 --- a/pipenv/utils/pip.py +++ b/pipenv/utils/pip.py @@ -139,8 +139,7 @@ def get_pip_args( for key in arg_map.keys(): if key in locals() and locals().get(key): arg_set.extend(arg_map.get(key)) - for extra_pip_arg in extra_pip_args: - arg_set.append(extra_pip_arg) + arg_set += extra_pip_args or [] return list(dict.fromkeys(arg_set)) diff --git a/pipenv/utils/pipfile.py b/pipenv/utils/pipfile.py index 32b7b473..e9b0786e 100644 --- a/pipenv/utils/pipfile.py +++ b/pipenv/utils/pipfile.py @@ -301,12 +301,9 @@ class Pipfile(BaseModel): @property def extended_keys(self): - return [ - k - for k in itertools.product( - ("packages", "dev-packages"), ("", "vcs", "editable") - ) - ] + return list( + itertools.product(("packages", "dev-packages"), ("", "vcs", "editable")) + ) def get_deps(self, dev=False, only=True): deps = {} # type: Dict[Text, Dict[Text, Union[List[Text], Text]]] diff --git a/pipenv/utils/requirementslib.py b/pipenv/utils/requirementslib.py index 3cb3e6f1..5bb46e78 100644 --- a/pipenv/utils/requirementslib.py +++ b/pipenv/utils/requirementslib.py @@ -371,7 +371,7 @@ def get_path(root, path, default=_UNSET): for seg in path: try: cur = cur[seg] - except (KeyError, IndexError) as exc: + except (KeyError, IndexError) as exc: # noqa: PERF203 raise PathAccessError(exc, seg, path) except TypeError: # either string index in a list, or a parent that diff --git a/pipenv/utils/resolver.py b/pipenv/utils/resolver.py index fbe2e7f1..b12bf422 100644 --- a/pipenv/utils/resolver.py +++ b/pipenv/utils/resolver.py @@ -377,10 +377,7 @@ class Resolver: ) for c in self.parsed_default_constraints ] - default_constraints = [] - for c in possible_default_constraints: - default_constraints.append(c) - return set(default_constraints) + return set(possible_default_constraints) @property def possible_constraints(self): diff --git a/pipenv/utils/shell.py b/pipenv/utils/shell.py index 36881cfa..77236525 100644 --- a/pipenv/utils/shell.py +++ b/pipenv/utils/shell.py @@ -310,11 +310,11 @@ def is_python_command(line): @contextmanager def temp_path(): """Allow the ability to set os.environ temporarily""" - path = [p for p in sys.path] + path = list(sys.path) try: yield finally: - sys.path = [p for p in path] + sys.path = list(path) def is_readonly_path(fn): diff --git a/pipenv/utils/toml.py b/pipenv/utils/toml.py index ddddc6c7..7fbdfcf1 100644 --- a/pipenv/utils/toml.py +++ b/pipenv/utils/toml.py @@ -17,13 +17,8 @@ TOML_DICT_NAMES = [o.__class__.__name__ for o in TOML_DICT_OBJECTS] def cleanup_toml(tml): - toml = tml.split("\n") - new_toml = [] # Remove all empty lines from TOML. - for line in toml: - if line.strip(): - new_toml.append(line) - toml = "\n".join(new_toml) + toml = "\n".join(line for line in tml.split("\n") if line.strip()) new_toml = [] # Add newlines between TOML sections. for i, line in enumerate(toml.split("\n")): diff --git a/pipenv/utils/virtualenv.py b/pipenv/utils/virtualenv.py index a8e90394..dd1bf128 100644 --- a/pipenv/utils/virtualenv.py +++ b/pipenv/utils/virtualenv.py @@ -425,7 +425,7 @@ def _inline_activate_virtualenv(project): raise exceptions.VirtualenvActivationException() with open(activate_this) as f: code = compile(f.read(), activate_this, "exec") - exec(code, dict(__file__=activate_this)) + exec(code, {"__file__": activate_this}) # Catch all errors, just in case. except Exception: click.echo( diff --git a/pyproject.toml b/pyproject.toml index 47dcaf59..448b4f2a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -95,13 +95,15 @@ exclude = [ select = [ "ASYNC", "B", - "C9", + "C4", + "C90", "E", "F", "FLY", "G", "I", "ISC", + "PERF", "PIE", "PL", "TID", diff --git a/tasks/vendoring/__init__.py b/tasks/vendoring/__init__.py index 886ddea4..6157b58e 100644 --- a/tasks/vendoring/__init__.py +++ b/tasks/vendoring/__init__.py @@ -265,7 +265,7 @@ def rename_if_needed(ctx, vendor_dir, item): def _ensure_package_in_requirements(ctx, requirements_file, package): requirement = None log("using requirements file: %s" % requirements_file) - req_file_lines = [line for line in requirements_file.read_text().splitlines()] + req_file_lines = list(requirements_file.read_text().splitlines()) if package: match = [r for r in req_file_lines if r.strip().lower().startswith(package)] matched_req = None @@ -720,7 +720,7 @@ def unpin_and_copy_requirements(ctx, requirement_file, name="requirements.txt"): ctx.run(f"pipenv install -r {target.as_posix()}", env=env, hide=True) result = ctx.run("pipenv lock -r", env=env, hide=True).stdout.strip() ctx.run("pipenv --rm", env=env, hide=True) - result = list(sorted(line.strip() for line in result.splitlines()[1:])) + result = sorted(line.strip() for line in result.splitlines()[1:]) new_requirements = requirement_file.parent.joinpath(name) requirement_file.rename(requirement_file.parent.joinpath(f"{name}.bak")) new_requirements.write_text("\n".join(result)) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 51cfadbc..1c8c0695 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -38,7 +38,7 @@ def check_internet(): for url in ("http://httpbin.org/ip", "http://clients3.google.com/generate_204"): try: try_internet(url) - except KeyboardInterrupt: + except KeyboardInterrupt: # noqa: PERF203 warnings.warn( f"Skipped connecting to internet: {url}", RuntimeWarning, stacklevel=1 ) diff --git a/tests/integration/test_install_twists.py b/tests/integration/test_install_twists.py index 5f410811..65989522 100644 --- a/tests/integration/test_install_twists.py +++ b/tests/integration/test_install_twists.py @@ -187,7 +187,7 @@ def test_local_tar_gz_file(pipenv_instance_private_pypi, testsroot): # This tests for a bug when installing a zipfile c = p.pipenv(f"install {requests_path}") assert c.returncode == 0 - key = [k for k in p.pipfile["packages"].keys()][0] + key = list(p.pipfile["packages"].keys())[0] dep = p.pipfile["packages"][key] assert "file" in dep or "path" in dep diff --git a/tests/integration/test_lock.py b/tests/integration/test_lock.py index 29d57262..7bc9ea68 100644 --- a/tests/integration/test_lock.py +++ b/tests/integration/test_lock.py @@ -628,7 +628,7 @@ six = "*" c = p.pipenv("lock --categories prereq") assert c.returncode == 0 assert p.lockfile["prereq"]["six"]["index"] == "test" - assert p.lockfile["default"] == dict() + assert p.lockfile["default"] == {} c = p.pipenv("lock --categories packages") assert c.returncode == 0 assert p.lockfile["prereq"]["six"]["index"] == "test" diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index f5add9a3..3c63971d 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -125,7 +125,7 @@ def test_convert_deps_to_pip_one_way(deps, expected): @pytest.mark.utils def test_convert_deps_to_pip_one_way(): - deps = {"uvicorn": dict()} + deps = {"uvicorn": {}} expected = "uvicorn" assert dependencies.convert_deps_to_pip(deps) == [expected.lower()]