Skip to content
Merged
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
1 change: 1 addition & 0 deletions changelog.d/1333.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow importing `pipx.util` before `pipx.paths`.
2 changes: 1 addition & 1 deletion src/pipx/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from pipx.constants import LINUX, WINDOWS
from pipx.emojis import hazard, strtobool
from pipx.util import pipx_wrap
from pipx.wrap import pipx_wrap

if LINUX:
DEFAULT_PIPX_HOME = Path(user_data_path("pipx"))
Expand Down
29 changes: 1 addition & 28 deletions src/pipx/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import string
import subprocess
import sys
import textwrap
from collections.abc import Sequence
from dataclasses import dataclass
from pathlib import Path
Expand All @@ -20,6 +19,7 @@
from pipx import paths
from pipx.animate import show_cursor
from pipx.constants import MINGW, WINDOWS
from pipx.wrap import pipx_wrap

_LOGGER: Final[logging.Logger] = logging.getLogger(__name__)

Expand Down Expand Up @@ -419,33 +419,6 @@ def full_package_description(package_name: str, package_spec: str) -> str:
return f"{package_name} from spec {package_spec!r}"


def pipx_wrap(text: str, subsequent_indent: str = "", keep_newlines: bool = False) -> str:
"""Dedent, strip, wrap to shell width. Don't break on hyphens, only spaces"""
minimum_width = 40
width = max(shutil.get_terminal_size((80, 40)).columns, minimum_width) - 2

text = textwrap.dedent(text).strip()
if keep_newlines:
return "\n".join(
[
textwrap.fill(
line,
width=width,
subsequent_indent=subsequent_indent,
break_on_hyphens=False,
)
for line in text.splitlines()
]
)
else:
return textwrap.fill(
text,
width=width,
subsequent_indent=subsequent_indent,
break_on_hyphens=False,
)


def is_paths_relative(path: Path, parent: Path):
return path.is_relative_to(parent)

Expand Down
29 changes: 29 additions & 0 deletions src/pipx/wrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import shutil
import textwrap


def pipx_wrap(text: str, subsequent_indent: str = "", keep_newlines: bool = False) -> str:
"""Dedent, strip, wrap to shell width. Don't break on hyphens, only spaces"""
minimum_width = 40
width = max(shutil.get_terminal_size((80, 40)).columns, minimum_width) - 2

text = textwrap.dedent(text).strip()
if keep_newlines:
return "\n".join(
[
textwrap.fill(
line,
width=width,
subsequent_indent=subsequent_indent,
break_on_hyphens=False,
)
for line in text.splitlines()
]
)
else:
return textwrap.fill(
text,
width=width,
subsequent_indent=subsequent_indent,
break_on_hyphens=False,
)
19 changes: 19 additions & 0 deletions tests/test_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import subprocess
import sys


def test_importing_util_first_succeeds(root):
env = {**os.environ, "PYTHONPATH": str(root / "src")}

result = subprocess.run(
[sys.executable, "-c", "import pipx.util; print('Success!')"],
check=False,
capture_output=True,
cwd=root,
env=env,
text=True,
)

assert result.returncode == 0, result.stderr
assert result.stdout == "Success!\n"