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

Set upper limits on code complexity #6339

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
exclude: .patch

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.0
rev: v0.9.3
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
11 changes: 5 additions & 6 deletions pipenv/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,12 +816,11 @@ def activated(self):
if self.is_venv:
os.environ["PYTHONPATH"] = self.base_paths["PYTHONPATH"]
os.environ["VIRTUAL_ENV"] = prefix
else:
if not self.project.s.PIPENV_USE_SYSTEM and not os.environ.get(
"VIRTUAL_ENV"
):
os.environ["PYTHONPATH"] = self.base_paths["PYTHONPATH"]
os.environ.pop("PYTHONHOME", None)
elif not self.project.s.PIPENV_USE_SYSTEM and not os.environ.get(
"VIRTUAL_ENV"
):
os.environ["PYTHONPATH"] = self.base_paths["PYTHONPATH"]
os.environ.pop("PYTHONHOME", None)
sys.path = self.sys_path
sys.prefix = self.sys_prefix
try:
Expand Down
10 changes: 4 additions & 6 deletions pipenv/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1430,9 +1430,8 @@ def which(self, search, as_path=True):
result = next(iter(filter(None, (find(finder) for finder in self.finders))), None)
if not result:
result = self._which(search)
else:
if as_path:
result = str(result.path)
elif as_path:
result = str(result.path)
return result

def python(self, system=False) -> str:
Expand All @@ -1457,9 +1456,8 @@ def _which(self, command, location=None, allow_global=False):
p = find_windows_executable(os.path.join(location, "Scripts"), command)
else:
p = os.path.join(location, "bin", command)
else:
if is_python:
p = sys.executable
elif is_python:
p = sys.executable
if not os.path.exists(p):
if is_python:
p = sys.executable or system_which("python")
Expand Down
21 changes: 10 additions & 11 deletions pipenv/utils/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -1261,17 +1261,16 @@ def get_constraints_from_deps(deps):
c = f"{canonicalize_name(dep_name)}{dep_version}"
else:
c = canonicalize_name(dep_name)
else:
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)
if version and not is_star(version):
if COMPARE_OP.match(version) is None:
version = f"=={dep_version}"
c = f"{canonicalize_name(dep_name)}{version}"
else:
c = canonicalize_name(dep_name)
elif 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)
if version and not is_star(version):
if COMPARE_OP.match(version) is None:
version = f"=={dep_version}"
c = f"{canonicalize_name(dep_name)}{version}"
else:
c = canonicalize_name(dep_name)
if c:
constraints.add(c)
return constraints
Expand Down
95 changes: 47 additions & 48 deletions pipenv/utils/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,58 +252,57 @@ def abort(msg=""):

if not installer:
abort("Neither 'pyenv' nor 'asdf' could be found to install Python.")
else:
if environments.SESSION_IS_INTERACTIVE or project.s.PIPENV_YES:
try:
version = installer.find_version_to_install(python)
except ValueError:
abort()
except InstallerError as e:
abort(f"Something went wrong while installing Python:\n{e.err}")
s = (
"Would you like us to install ",
f"[green]CPython {version}[/green] ",
f"with {installer}?",
)
elif environments.SESSION_IS_INTERACTIVE or project.s.PIPENV_YES:
try:
version = installer.find_version_to_install(python)
except ValueError:
abort()
except InstallerError as e:
abort(f"Something went wrong while installing Python:\n{e.err}")
s = (
"Would you like us to install ",
f"[green]CPython {version}[/green] ",
f"with {installer}?",
)

# Prompt the user to continue...
if not (project.s.PIPENV_YES or Confirm.ask("".join(s), default=True)):
abort()
else:
# Tell the user we're installing Python.
console.print(
f"[bold]Installing [green]CPython[/green] {version} with {installer.cmd}[/bold]"
)
console.print("(this may take a few minutes)[bold]...[/bold]")
with console.status(
"Installing python...", spinner=project.s.PIPENV_SPINNER
):
try:
c = installer.install(version)
except InstallerError as e:
err.print(
environments.PIPENV_SPINNER_FAIL_TEXT.format("Failed...")
)
err.print("Something went wrong...")
err.print(f"[cyan]{e.err}[/cyan]")
else:
console.print(
environments.PIPENV_SPINNER_OK_TEXT.format("Success!")
)
# Print the results, in a beautiful blue...
err.print(f"[cyan]{c.stdout}[/cyan]")
# Find the newly installed Python, hopefully.
version = str(version)
path_to_python = find_a_system_python(version)
# Prompt the user to continue...
if not (project.s.PIPENV_YES or Confirm.ask("".join(s), default=True)):
abort()
else:
# Tell the user we're installing Python.
console.print(
f"[bold]Installing [green]CPython[/green] {version} with {installer.cmd}[/bold]"
)
console.print("(this may take a few minutes)[bold]...[/bold]")
with console.status(
"Installing python...", spinner=project.s.PIPENV_SPINNER
):
try:
assert python_version(path_to_python) == version
except AssertionError:
c = installer.install(version)
except InstallerError as e:
err.print(
"[bold][red]Warning:[/red][/bold]"
" The Python you just installed is not available "
"on your [bold]PATH[/bold], apparently."
environments.PIPENV_SPINNER_FAIL_TEXT.format("Failed...")
)
err.print("Something went wrong...")
err.print(f"[cyan]{e.err}[/cyan]")
else:
console.print(
environments.PIPENV_SPINNER_OK_TEXT.format("Success!")
)
sys.exit(1)
# Print the results, in a beautiful blue...
err.print(f"[cyan]{c.stdout}[/cyan]")
# Find the newly installed Python, hopefully.
version = str(version)
path_to_python = find_a_system_python(version)
try:
assert python_version(path_to_python) == version
except AssertionError:
err.print(
"[bold][red]Warning:[/red][/bold]"
" The Python you just installed is not available "
"on your [bold]PATH[/bold], apparently."
)
sys.exit(1)
return path_to_python


Expand Down
15 changes: 6 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,9 @@ lint.select = [
"YTT",
]
lint.ignore = [
"B904",
"PIE790",
"PLR0912", # Too many branches
"PLR0913", # Too many arguments
"PLR2004", # Magic numbers
"PLR5501",
"PLW2901",
"B904", # `raise` without `from` inside `except`
"PIE790", # Unnecessary `pass` statement
"PLW2901", # `for` loop variable overwritten
"TID252", # Relative imports
]
lint.per-file-ignores = { "pipenv/cli/command.py" = [
Expand Down Expand Up @@ -182,8 +178,9 @@ lint.per-file-ignores = { "pipenv/cli/command.py" = [
"B015",
] }
lint.mccabe.max-complexity = 44
lint.pylint.max-args = 9
lint.pylint.max-branches = 20
lint.pylint.allow-magic-value-types = [ "int", "str" ]
lint.pylint.max-args = 18
lint.pylint.max-branches = 34
lint.pylint.max-returns = 38
lint.pylint.max-statements = 155

Expand Down
Loading