Skip to content

Commit

Permalink
Merge branch 'main' into inject-requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
huxuan authored May 14, 2024
2 parents 25adc77 + 5589b69 commit 92e1660
Show file tree
Hide file tree
Showing 32 changed files with 117 additions and 91 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ repos:
- id: trailing-whitespace
- id: check-yaml
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "1.8.0"
rev: "2.0.4"
hooks:
- id: pyproject-fmt
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.3
rev: v0.4.4
hooks:
- id: ruff-format
- id: ruff
args: [ "--fix", "--unsafe-fixes", "--exit-non-zero-on-fix"]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
hooks:
Expand Down
1 change: 1 addition & 0 deletions changelog.d/1397.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move `--global` option into shared parser, such that it can be passed after the subcommand, for example `pipx ensurepath --global`.
1 change: 1 addition & 0 deletions changelog.d/1400.misc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enable and apply ruff rule `RUF100`.
43 changes: 33 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ keywords = [
"workflow",
]
license = "MIT"
authors = [{ name = "Chad Smith", email = "[email protected]" }]
authors = [
{ name = "Chad Smith", email = "[email protected]" },
]
requires-python = ">=3.8"
classifiers = [
"License :: OSI Approved :: MIT License",
Expand All @@ -35,11 +37,11 @@ dynamic = [
]
dependencies = [
"argcomplete>=1.9.4",
'colorama>=0.4.4; sys_platform == "win32"',
"colorama>=0.4.4; sys_platform=='win32'",
"packaging>=20",
"platformdirs>=2.1",
'tomli; python_version < "3.11"',
"userpath!=1.9.0,>=1.6",
"tomli; python_version<'3.11'",
"userpath!=1.9,>=1.6",
]
urls."Bug Tracker" = "https://github.com/pypa/pipx/issues"
urls.Documentation = "https://pipx.pypa.io"
Expand All @@ -50,25 +52,38 @@ scripts.pipx = "pipx.main:cli"

[tool.hatch]
build.hooks.vcs.version-file = "src/pipx/version.py"
build.targets.sdist.include = ["/src", "/logo.png", "/pipx_demo.gif", "/*.md"]
build.targets.sdist.include = [
"/src",
"/logo.png",
"/pipx_demo.gif",
"/*.md",
]
version.source = "vcs"

[tool.ruff]
line-length = 121
src = ["src"]
src = [
"src",
]
lint.extend-select = [
"A",
"B",
"C4",
"C9",
"I",
"ISC",
"PLC",
"PLE",
"PLW",
"RSE",
"RUF100",
"W",
]
lint.isort = {known-first-party = ["helpers", "package_info", "pipx"]}
lint.isort = { known-first-party = [
"helpers",
"package_info",
"pipx",
] }
lint.mccabe.max-complexity = 15

[tool.codespell]
Expand All @@ -79,17 +94,25 @@ check-hidden = true
ignore-regex = '\b(UE|path/doesnt/exist)\b'

[tool.pytest.ini_options]
markers = ["all_packages: test install with maximum number of packages"]
markers = [
"all_packages: test install with maximum number of packages",
]

[tool.towncrier]
directory = "changelog.d"
filename = "CHANGELOG.md"
start_string = "<!-- towncrier release notes start -->\n"
underlines = ["", "", ""]
underlines = [
"",
"",
"",
]
title_format = "## [{version}](https://github.com/pypa/pipx/tree/{version}) - {project_date}"
issue_format = "[#{issue}](https://github.com/pypa/pipx/issues/{issue})"
package = "pipx"

[[tool.mypy.overrides]]
module = ["pycowsay.*"]
module = [
"pycowsay.*",
]
ignore_missing_imports = true
2 changes: 1 addition & 1 deletion scripts/list_test_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def process_command_line(argv: List[str]) -> argparse.Namespace:
# required arguments
parser.add_argument(
"primary_package_list",
help="Main packages to examine, getting list of " "matching distribution files and dependencies.",
help="Main packages to examine, getting list of matching distribution files and dependencies.",
)
parser.add_argument("package_list_dir", help="Directory to output package distribution lists.")

Expand Down
6 changes: 2 additions & 4 deletions scripts/migrate_pipsi_to_pipx.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def main():
ret = subprocess.run(["pipsi", "uninstall", "--yes", package], check=False)
if ret.returncode:
error = True
print(f"Failed to uninstall {package!r} with pipsi. " "Not attempting to install with pipx.")
print(f"Failed to uninstall {package!r} with pipsi. Not attempting to install with pipx.")
else:
print(f"uninstalled {package!r} with pipsi. Now attempting to install with pipx.")
ret = subprocess.run(["pipx", "install", package], check=False)
Expand All @@ -52,9 +52,7 @@ def main():
print(f"Successfully installed {package} with pipx")

print(f"Done migrating {len(packages)} packages!")
print(
"You may still need to run `pipsi uninstall pipsi` or `pip uninstall pipsi`. " "Refer to pipsi's documentation."
)
print("You may still need to run `pipsi uninstall pipsi` or `pip uninstall pipsi`. Refer to pipsi's documentation.")

if error:
print("Note: Finished with errors. Review output to manually complete migration.")
Expand Down
14 changes: 7 additions & 7 deletions scripts/update_package_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def process_command_line(argv: List[str]) -> argparse.Namespace:
"-c",
"--check-only",
action="store_true",
help="Only check to see if needed packages are in PACKAGES_DIR, do not " "download or delete files.",
help="Only check to see if needed packages are in PACKAGES_DIR, do not download or delete files.",
)

return parser.parse_args(argv)
Expand All @@ -63,7 +63,7 @@ def update_test_packages_cache(package_list_dir_path: Path, pipx_package_cache_p

if not platform_package_list_path.exists():
print(
f"WARNING. File {str(platform_package_list_path)}\n" " does not exist. Creating now...",
f"WARNING. File {platform_package_list_path!s}\n does not exist. Creating now...",
file=sys.stderr,
)
create_list_returncode = create_test_packages_list(
Expand All @@ -73,14 +73,14 @@ def update_test_packages_cache(package_list_dir_path: Path, pipx_package_cache_p
)
if create_list_returncode == 0:
print(
f"File {str(platform_package_list_path)}\n"
f"File {platform_package_list_path!s}\n"
" successfully created. Please check this file in to the"
" repository for future use.",
file=sys.stderr,
)
else:
print(
f"ERROR. Unable to create {str(platform_package_list_path)}\n" " Cannot continue.\n",
f"ERROR. Unable to create {platform_package_list_path!s}\n Cannot continue.\n",
file=sys.stderr,
)
return 1
Expand All @@ -89,17 +89,17 @@ def update_test_packages_cache(package_list_dir_path: Path, pipx_package_cache_p
platform_package_list_fh = platform_package_list_path.open("r")
except OSError:
print(
f"ERROR. File {str(platform_package_list_path)}\n" " is not readable. Cannot continue.\n",
f"ERROR. File {platform_package_list_path!s}\n is not readable. Cannot continue.\n",
file=sys.stderr,
)
return 1
else:
platform_package_list_fh.close()

print("Using the following file to specify needed package files:")
print(f" {str(platform_package_list_path)}")
print(f" {platform_package_list_path!s}")
print("Ensuring the following directory contains necessary package files:")
print(f" {str(packages_dir_path)}")
print(f" {packages_dir_path!s}")

packages_dir_hits = []
packages_dir_missing = []
Expand Down
2 changes: 1 addition & 1 deletion src/pipx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import sys

if sys.version_info < (3, 8, 0):
sys.exit("Python 3.8 or later is required. " "See https://github.com/pypa/pipx " "for installation instructions.")
sys.exit("Python 3.8 or later is required. See https://github.com/pypa/pipx for installation instructions.")
2 changes: 1 addition & 1 deletion src/pipx/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
pipx_package_source_path = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, pipx_package_source_path)

from pipx.main import cli # noqa
from pipx.main import cli

if __name__ == "__main__":
sys.exit(cli())
20 changes: 10 additions & 10 deletions src/pipx/commands/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _copy_package_resource(dest_dir: Path, path: Path, suffix: str = "") -> None
if not dest.parent.is_dir():
mkdir(dest.parent)
if dest.exists():
logger.warning(f"{hazard} Overwriting file {str(dest)} with {str(src)}")
logger.warning(f"{hazard} Overwriting file {dest!s} with {src!s}")
safe_unlink(dest)
if src.exists():
shutil.copy(src, dest)
Expand All @@ -129,7 +129,7 @@ def _symlink_package_resource(
mkdir(symlink_path.parent)

if force:
logger.info(f"Force is true. Removing {str(symlink_path)}.")
logger.info(f"Force is true. Removing {symlink_path!s}.")
try:
symlink_path.unlink()
except FileNotFoundError:
Expand All @@ -141,21 +141,21 @@ def _symlink_package_resource(
is_symlink = symlink_path.is_symlink()
if exists:
if symlink_path.samefile(path):
logger.info(f"Same path {str(symlink_path)} and {str(path)}")
logger.info(f"Same path {symlink_path!s} and {path!s}")
else:
logger.warning(
pipx_wrap(
f"""
{hazard} File exists at {str(symlink_path)} and points
to {symlink_path.resolve()}, not {str(path)}. Not
{hazard} File exists at {symlink_path!s} and points
to {symlink_path.resolve()}, not {path!s}. Not
modifying.
""",
subsequent_indent=" " * 4,
)
)
return
if is_symlink and not exists:
logger.info(f"Removing existing symlink {str(symlink_path)} since it " "pointed non-existent location")
logger.info(f"Removing existing symlink {symlink_path!s} since it pointed non-existent location")
symlink_path.unlink()

if executable:
Expand Down Expand Up @@ -186,22 +186,22 @@ def venv_health_check(venv: Venv, package_name: Optional[str] = None) -> Tuple[V
if not python_path.is_file():
return (
VenvProblems(invalid_interpreter=True),
f" package {red(bold(venv_dir.name))} has invalid " f"interpreter {str(python_path)}\r{hazard}",
f" package {red(bold(venv_dir.name))} has invalid interpreter {python_path!s}\r{hazard}",
)
if not venv.package_metadata:
return (
VenvProblems(missing_metadata=True),
f" package {red(bold(venv_dir.name))} has missing " f"internal pipx metadata.\r{hazard}",
f" package {red(bold(venv_dir.name))} has missing internal pipx metadata.\r{hazard}",
)
if venv_dir.name != canonicalize_name(venv_dir.name):
return (
VenvProblems(bad_venv_name=True),
f" package {red(bold(venv_dir.name))} needs its " f"internal data updated.\r{hazard}",
f" package {red(bold(venv_dir.name))} needs its internal data updated.\r{hazard}",
)
if venv.package_metadata[package_name].package_version == "":
return (
VenvProblems(not_installed=True),
f" package {red(bold(package_name))} {red('is not installed')} " f"in the venv {venv_dir.name}\r{hazard}",
f" package {red(bold(package_name))} {red('is not installed')} in the venv {venv_dir.name}\r{hazard}",
)
return (VenvProblems(), "")

Expand Down
2 changes: 1 addition & 1 deletion src/pipx/commands/list_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def list_packages(
)
if all_venv_problems.invalid_interpreter:
logger.warning(
"\nOne or more packages have a missing python interpreter.\n" " To fix, execute: pipx reinstall-all"
"\nOne or more packages have a missing python interpreter.\n To fix, execute: pipx reinstall-all"
)
if all_venv_problems.missing_metadata:
logger.warning(
Expand Down
4 changes: 2 additions & 2 deletions src/pipx/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,15 @@ def _is_temporary_venv_expired(venv_dir: Path) -> bool:
def _prepare_venv_cache(venv: Venv, bin_path: Optional[Path], use_cache: bool) -> None:
venv_dir = venv.root
if not use_cache and (bin_path is None or bin_path.exists()):
logger.info(f"Removing cached venv {str(venv_dir)}")
logger.info(f"Removing cached venv {venv_dir!s}")
rmdir(venv_dir)
_remove_all_expired_venvs()


def _remove_all_expired_venvs() -> None:
for venv_dir in Path(paths.ctx.venv_cache).iterdir():
if _is_temporary_venv_expired(venv_dir):
logger.info(f"Removing expired venv {str(venv_dir)}")
logger.info(f"Removing expired venv {venv_dir!s}")
rmdir(venv_dir)


Expand Down
6 changes: 3 additions & 3 deletions src/pipx/commands/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _upgrade_package(
pipx_wrap(
f"""
{display_name} is already at latest version {old_version}
(location: {str(venv.root)})
(location: {venv.root!s})
"""
)
)
Expand All @@ -88,7 +88,7 @@ def _upgrade_package(
pipx_wrap(
f"""
upgraded package {display_name} from {old_version} to
{new_version} (location: {str(venv.root)})
{new_version} (location: {venv.root!s})
"""
)
)
Expand Down Expand Up @@ -133,7 +133,7 @@ def _upgrade_venv(
else:
raise PipxError(
f"""
Package is not installed. Expected to find {str(venv_dir)}, but it
Package is not installed. Expected to find {venv_dir!s}, but it
does not exist.
"""
)
Expand Down
2 changes: 1 addition & 1 deletion src/pipx/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

def has_venv() -> bool:
try:
import venv # noqa
import venv # noqa: F401

return True
except ImportError:
Expand Down
Loading

0 comments on commit 92e1660

Please sign in to comment.