Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci

Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
  • Loading branch information
pre-commit-ci[bot] authored and gaborbernat committed Jul 3, 2024
1 parent a02a658 commit e65951c
Show file tree
Hide file tree
Showing 17 changed files with 97 additions and 79 deletions.
9 changes: 4 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.3
rev: 0.28.6
hooks:
- id: check-github-workflows
args: [ "--verbose" ]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
rev: v2.3.0
hooks:
- id: codespell
args: ["--write-changes"]
Expand All @@ -20,12 +20,11 @@ repos:
- id: tox-ini-fmt
args: ["-p", "fix"]
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "2.0.4"
rev: "2.1.4"
hooks:
- id: pyproject-fmt
additional_dependencies: ["tox>=4.12.1"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.4.4"
rev: "v0.5.0"
hooks:
- id: ruff-format
- id: ruff
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def setup(app):
root, exe = here.parent, Path(sys.executable)
towncrier = exe.with_name(f"towncrier{exe.suffix}")
cmd = [str(towncrier), "build", "--draft", "--version", "NEXT"]
new = subprocess.check_output(cmd, cwd=root, text=True, stderr=subprocess.DEVNULL, encoding="UTF-8") # noqa: S603
new = subprocess.check_output(cmd, cwd=root, text=True, stderr=subprocess.DEVNULL, encoding="UTF-8")
(root / "docs" / "_draft.rst").write_text("" if "No significant changes" in new else new, encoding="UTF-8")

# the CLI arguments are dynamically generated
Expand Down
124 changes: 72 additions & 52 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ keywords = [
"virtual",
]
license = "MIT"
maintainers = [{ name = "Bernat Gabor", email = "gaborjbernat@gmail.com" }]
maintainers = [
{ name = "Bernat Gabor", email = "gaborjbernat@gmail.com" },
]
requires-python = ">=3.7"
classifiers = [
"Development Status :: 5 - Production/Stable",
Expand All @@ -31,7 +33,6 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Software Development :: Libraries",
Expand All @@ -44,7 +45,7 @@ dynamic = [
dependencies = [
"distlib<1,>=0.3.7",
"filelock<4,>=3.12.2",
'importlib-metadata>=6.6; python_version < "3.8"',
"importlib-metadata>=6.6; python_version<'3.8'",
"platformdirs<5,>=3.9.1",
]
optional-dependencies.docs = [
Expand All @@ -63,91 +64,102 @@ optional-dependencies.test = [
"packaging>=23.1",
"pytest>=7.4",
"pytest-env>=0.8.2",
'pytest-freezer>=0.4.8; platform_python_implementation == "PyPy"',
"pytest-freezer>=0.4.8; platform_python_implementation=='PyPy'",
"pytest-mock>=3.11.1",
"pytest-randomly>=3.12",
"pytest-timeout>=2.1",
"setuptools>=68",
'time-machine>=2.10; platform_python_implementation == "CPython"',
"time-machine>=2.10; platform_python_implementation=='CPython'",
]
urls.Documentation = "https://virtualenv.pypa.io"
urls.Homepage = "https://github.com/pypa/virtualenv"
urls.Source = "https://github.com/pypa/virtualenv"
urls.Tracker = "https://github.com/pypa/virtualenv/issues"
scripts.virtualenv = "virtualenv.__main__:run_with_catch"
[project.entry-points."virtualenv.activate"]
bash = "virtualenv.activation.bash:BashActivator"
batch = "virtualenv.activation.batch:BatchActivator"
cshell = "virtualenv.activation.cshell:CShellActivator"
fish = "virtualenv.activation.fish:FishActivator"
nushell = "virtualenv.activation.nushell:NushellActivator"
powershell = "virtualenv.activation.powershell:PowerShellActivator"
python = "virtualenv.activation.python:PythonActivator"
[project.entry-points."virtualenv.create"]
cpython3-mac-brew = "virtualenv.create.via_global_ref.builtin.cpython.mac_os:CPython3macOsBrew"
cpython3-mac-framework = "virtualenv.create.via_global_ref.builtin.cpython.mac_os:CPython3macOsFramework"
cpython3-posix = "virtualenv.create.via_global_ref.builtin.cpython.cpython3:CPython3Posix"
cpython3-win = "virtualenv.create.via_global_ref.builtin.cpython.cpython3:CPython3Windows"
pypy3-posix = "virtualenv.create.via_global_ref.builtin.pypy.pypy3:PyPy3Posix"
pypy3-win = "virtualenv.create.via_global_ref.builtin.pypy.pypy3:Pypy3Windows"
venv = "virtualenv.create.via_global_ref.venv:Venv"
[project.entry-points."virtualenv.discovery"]
builtin = "virtualenv.discovery.builtin:Builtin"
[project.entry-points."virtualenv.seed"]
app-data = "virtualenv.seed.embed.via_app_data.via_app_data:FromAppData"
pip = "virtualenv.seed.embed.pip_invoke:PipInvoke"
entry-points."virtualenv.activate".bash = "virtualenv.activation.bash:BashActivator"
entry-points."virtualenv.activate".batch = "virtualenv.activation.batch:BatchActivator"
entry-points."virtualenv.activate".cshell = "virtualenv.activation.cshell:CShellActivator"
entry-points."virtualenv.activate".fish = "virtualenv.activation.fish:FishActivator"
entry-points."virtualenv.activate".nushell = "virtualenv.activation.nushell:NushellActivator"
entry-points."virtualenv.activate".powershell = "virtualenv.activation.powershell:PowerShellActivator"
entry-points."virtualenv.activate".python = "virtualenv.activation.python:PythonActivator"
entry-points."virtualenv.create".cpython3-mac-brew = "virtualenv.create.via_global_ref.builtin.cpython.mac_os:CPython3macOsBrew"
entry-points."virtualenv.create".cpython3-mac-framework = "virtualenv.create.via_global_ref.builtin.cpython.mac_os:CPython3macOsFramework"
entry-points."virtualenv.create".cpython3-posix = "virtualenv.create.via_global_ref.builtin.cpython.cpython3:CPython3Posix"
entry-points."virtualenv.create".cpython3-win = "virtualenv.create.via_global_ref.builtin.cpython.cpython3:CPython3Windows"
entry-points."virtualenv.create".pypy3-posix = "virtualenv.create.via_global_ref.builtin.pypy.pypy3:PyPy3Posix"
entry-points."virtualenv.create".pypy3-win = "virtualenv.create.via_global_ref.builtin.pypy.pypy3:Pypy3Windows"
entry-points."virtualenv.create".venv = "virtualenv.create.via_global_ref.venv:Venv"
entry-points."virtualenv.discovery".builtin = "virtualenv.discovery.builtin:Builtin"
entry-points."virtualenv.seed".app-data = "virtualenv.seed.embed.via_app_data.via_app_data:FromAppData"
entry-points."virtualenv.seed".pip = "virtualenv.seed.embed.pip_invoke:PipInvoke"

[tool.hatch]
build.hooks.vcs.version-file = "src/virtualenv/version.py"
build.targets.sdist.include = ["/src", "/tests", "/tasks", "/tox.ini"]
build.targets.sdist.include = [
"/src",
"/tests",
"/tasks",
"/tox.ini",
]
version.source = "vcs"

[tool.ruff]
line-length = 120
target-version = "py37"
lint.isort = { known-first-party = ["virtualenv"], required-imports = ["from __future__ import annotations"] }
lint.select = ["ALL"]
line-length = 120
format.preview = true
format.docstring-code-line-length = 100
format.docstring-code-format = true
lint.select = [
"ALL",
]
lint.ignore = [
"CPY", # No copyright header
"ANN", # no type checking added yet
"COM812", # conflict with formatter
"CPY", # No copyright header
"D10", # no docstrings
"D40", # no imperative mode for docstrings
"PTH", # no pathlib, <=39 has problems on Windows with absolute/resolve, can revisit once we no longer need 39
"INP001", # ignore implicit namespace packages
"D203", # `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible
"D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible
"S104", # Possible binding to all interfaces
"S404", # Using subprocess is alright
"INP001", # ignore implicit namespace packages
"ISC001", # conflict with formatter
"PLR0914", # Too many local variables
"PLR0917", # Too many positional arguments
"PLR6301", # Method could be a function, class method, or static method
"COM812", # conflict with formatter
"ISC001", # conflict with formatter
"PTH", # no pathlib, <=39 has problems on Windows with absolute/resolve, can revisit once we no longer need 39
"S104", # Possible binding to all interfaces
"S404", # Using subprocess is alright
"S603", # subprocess calls are fine
]
lint.preview = true
format.preview = true
format.docstring-code-format = true
format.docstring-code-line-length = 100
[tool.ruff.lint.per-file-ignores]
"tests/**/*.py" = [
"S101", # asserts allowed in tests...
lint.per-file-ignores."tests/**/*.py" = [
"D", # don't care about documentation in tests
"FBT", # don"t care about booleans as positional arguments in tests
"INP001", # no implicit namespace
"D", # don't care about documentation in tests
"S603", # `subprocess` call: check for execution of untrusted input
"PLR2004", # Magic value used in comparison, consider replacing with a constant variable
"PLC2701", # Private import
"PLR2004", # Magic value used in comparison, consider replacing with a constant variable
"S101", # asserts allowed in tests...
"S603", # `subprocess` call: check for execution of untrusted input
]
lint.isort = { known-first-party = [
"virtualenv",
], required-imports = [
"from __future__ import annotations",
] }
lint.preview = true

[tool.codespell]
builtin = "clear,usage,en-GB_to_en-US"
count = true

[tool.pytest.ini_options]
markers = ["slow"]
markers = [
"slow",
]
timeout = 600
addopts = "--showlocals --no-success-flaky-report"
env = ["PYTHONIOENCODING=utf-8"]
env = [
"PYTHONIOENCODING=utf-8",
]

[tool.coverage]
html.show_contexts = true
Expand All @@ -159,12 +171,20 @@ report.omit = [
"**/src/virtualenv/activation/python/activate_this.py",
"**/src/virtualenv/seed/wheels/embed/pip-*.whl/pip/**",
]
paths.source = ["src", "**/site-packages"]
paths.source = [
"src",
"**/site-packages",
]
report.fail_under = 76
run.source = ["${_COVERAGE_SRC}", "tests"]
run.source = [
"${_COVERAGE_SRC}",
"tests",
]
run.dynamic_context = "test_function"
run.parallel = true
run.plugins = ["covdefaults"]
run.plugins = [
"covdefaults",
]
run.relative_files = true

[tool.towncrier]
Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/create/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def encode_list_path(value):
return [encode_path(i) for i in value]


def run(): # noqa: PLR0912
def run():
"""Print debug data about the virtual environment."""
try:
from collections import OrderedDict # noqa: PLC0415
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def fix_mach_o(exe, current, new, max_size):
logging.warning("Could not call _builtin_change_mac_o: %s. Trying to call install_name_tool instead.", e)
try:
cmd = ["install_name_tool", "-change", current, new, exe]
subprocess.check_call(cmd) # noqa: S603
subprocess.check_call(cmd)
except Exception:
logging.fatal("Could not call install_name_tool -- you must have Apple's development tools installed")
raise
Expand Down
9 changes: 4 additions & 5 deletions src/virtualenv/discovery/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,10 @@ def get_paths(env: Mapping[str, str]) -> Generator[Path, None, None]:
path = os.confstr("CS_PATH")
except (AttributeError, ValueError):
path = os.defpath
if not path:
return None
for p in map(Path, path.split(os.pathsep)):
if p.exists():
yield p
if path:
for p in map(Path, path.split(os.pathsep)):
if p.exists():
yield p


class LazyPathDump:
Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/discovery/cached_py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _run_subprocess(cls, exe, app_data, env):
logging.debug("get interpreter info via cmd: %s", LogCmd(cmd))
try:
process = Popen(
cmd, # noqa: S603
cmd,
universal_newlines=True,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/discovery/py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def from_exe( # noqa: PLR0913
if isinstance(proposed, PythonInfo) and resolve_to_host:
try:
proposed = proposed._resolve_to_system(app_data, proposed) # noqa: SLF001
except Exception as exception: # noqa: BLE001
except Exception as exception:
if raise_on_error:
raise
logging.info("ignore %s due cannot resolve system due to %r", proposed.original_executable, exception)
Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/seed/embed/pip_invoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def run(self, creator):
@staticmethod
def _execute(cmd, env):
logging.debug("pip seed by running: %s", LogCmd(cmd, env))
process = Popen(cmd, env=env) # noqa: S603
process = Popen(cmd, env=env)
process.communicate()
if process.returncode != 0:
msg = f"failed seed with code {process.returncode}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def _sync(self, src, dst):
def _generate_new_files(self):
# create the pyc files, as the build image will be R/O
cmd = [str(self._creator.exe), "-m", "compileall", str(self._image_dir)]
process = Popen(cmd, stdout=PIPE, stderr=PIPE) # noqa: S603
process = Popen(cmd, stdout=PIPE, stderr=PIPE)
process.communicate()
# the root pyc is shared, so we'll not symlink that - but still add the pyc files to the RECORD for close
root_py_cache = self._image_dir / "__pycache__"
Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/seed/wheels/acquire.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def download_wheel(distribution, version_spec, for_py_version, search_dirs, app_
]
# pip has no interface in python - must be a new sub-process
env = pip_wheel_env_run(search_dirs, app_data, env)
process = Popen(cmd, env=env, stdout=PIPE, stderr=PIPE, universal_newlines=True, encoding="utf-8") # noqa: S603
process = Popen(cmd, env=env, stdout=PIPE, stderr=PIPE, universal_newlines=True, encoding="utf-8")
out, err = process.communicate()
if process.returncode != 0:
kwargs = {"output": out, "stderr": err}
Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/seed/wheels/periodic_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def trigger_update(distribution, for_py_version, wheel, search_dirs, app_data, e
kwargs = {"stdout": pipe, "stderr": pipe}
if not debug and sys.platform == "win32":
kwargs["creationflags"] = CREATE_NO_WINDOW
process = Popen(cmd, **kwargs) # noqa: S603
process = Popen(cmd, **kwargs)
logging.info(
"triggered periodic upgrade of %s%s (for python %s) via background process having PID %d",
distribution,
Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/util/subprocess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def run_cmd(cmd):
try:
process = subprocess.Popen(
cmd, # noqa: S603
cmd,
universal_newlines=True,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand Down
4 changes: 2 additions & 2 deletions tasks/make_zipapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def create_zipapp(dest, packages):
print(f"zipapp created at {dest}") # noqa: T201


def write_packages_to_zipapp(base, dist, modules, packages, zip_app): # noqa: C901
def write_packages_to_zipapp(base, dist, modules, packages, zip_app): # noqa: C901, PLR0912
has = set()
for name, p_w_v in packages.items(): # noqa: PLR1702
for platform, w_v in p_w_v.items():
Expand Down Expand Up @@ -239,7 +239,7 @@ def _build_sdist(self, folder, target):

def run_suppress_output(cmd, stop_print_on_fail=False): # noqa: FBT002
process = subprocess.Popen(
cmd, # noqa: S603
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
Expand Down
2 changes: 1 addition & 1 deletion tasks/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_upstream(repo: Repo) -> Remote:

def release_changelog(repo: Repo, version: Version) -> Commit:
print("generate release commit") # noqa: T201
check_call(["towncrier", "build", "--yes", "--version", version.public], cwd=str(ROOT_SRC_DIR)) # noqa: S603, S607
check_call(["towncrier", "build", "--yes", "--version", version.public], cwd=str(ROOT_SRC_DIR)) # noqa: S607
return repo.index.commit(f"release {version}")


Expand Down
6 changes: 3 additions & 3 deletions tasks/upgrade_wheels.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

def download(ver, dest, package):
subprocess.call(
[ # noqa: S603
[
sys.executable,
"-m",
"pip",
Expand Down Expand Up @@ -121,11 +121,11 @@ def get_embed_wheel(distribution, for_py_version):
dest_target.write_text(msg, encoding="utf-8")

subprocess.run(
[sys.executable, "-m", "ruff", "check", str(dest_target), "--fix", "--unsafe-fixes"], # noqa: S603
[sys.executable, "-m", "ruff", "check", str(dest_target), "--fix", "--unsafe-fixes"],
check=False,
)
subprocess.run(
[sys.executable, "-m", "ruff", "format", str(dest_target), "--preview"], # noqa: S603
[sys.executable, "-m", "ruff", "format", str(dest_target), "--preview"],
check=False,
)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/activation/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_version(self, raise_on_fail):
encoding="utf-8",
)
out, err = process.communicate()
except Exception as exception: # noqa: BLE001
except Exception as exception:
self._version = exception
if raise_on_fail:
raise
Expand Down

0 comments on commit e65951c

Please sign in to comment.