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

Update pipdeptree which solves issue 5652 #5720

Merged
merged 3 commits into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 news/5720.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Upgrades to ``pipdeptree==2.8.0`` which fixes edge cases of the ``pipenv graph`` command.
3 changes: 3 additions & 0 deletions pipenv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
warnings.filterwarnings("ignore", category=ResourceWarning)
warnings.filterwarnings("ignore", category=UserWarning)
PIPENV_ROOT = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
PIPENV_VENDOR = os.sep.join([PIPENV_ROOT, "vendor"])
PIP_VENDOR = os.sep.join([PIPENV_ROOT, "patched", "pip", "_vendor"])

# Load patched pip instead of system pip
os.environ["PIP_DISABLE_PIP_VERSION_CHECK"] = "1"
sys.path.insert(0, PIPENV_ROOT)
sys.path.insert(0, PIPENV_VENDOR)
sys.path.insert(0, PIP_VENDOR)

if os.name == "nt":
Expand Down
80 changes: 77 additions & 3 deletions pipenv/vendor/pipdeptree/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,16 +462,90 @@ def render_text(tree, list_all=True, frozen=False):
:param bool list_all: whether to list all the pgks at the root level or only those that are the sub-dependencies
:param bool frozen: show the names of the pkgs in the output that's favourable to pip --freeze
:returns: None

"""
tree = tree.sort()
nodes = tree.keys()
branch_keys = {r.key for r in chain.from_iterable(tree.values())}
use_bullets = not frozen

if not list_all:
nodes = [p for p in nodes if p.key not in branch_keys]

if sys.stdout.encoding.lower() in ("utf-8", "utf-16", "utf-32"):
_render_text_with_unicode(tree, nodes, frozen)
else:
_render_text_without_unicode(tree, nodes, frozen)


def _render_text_with_unicode(tree, nodes, frozen):
use_bullets = not frozen

def aux(
node,
parent=None,
indent=0,
cur_chain=None,
prefix="",
depth=0,
has_grand_parent=False,
is_last_child=False,
parent_is_last_child=False,
):
cur_chain = cur_chain or []
node_str = node.render(parent, frozen)
next_prefix = ""
next_indent = indent + 2

if parent:
bullet = "├── "
if is_last_child:
bullet = "└── "

line_char = "│"
if not use_bullets:
line_char = ""
# Add 2 spaces so direct dependencies to a project are indented
bullet = " "

if has_grand_parent:
next_indent -= 1
if parent_is_last_child:
offset = 0 if len(line_char) == 1 else 1
prefix += " " * (indent + 1 - offset - depth)
else:
prefix += line_char + " " * (indent - depth)
# Without this extra space, bullets will point to the space just before the project name
prefix += " " if use_bullets else ""
next_prefix = prefix
node_str = prefix + bullet + node_str
result = [node_str]

children = tree.get_children(node.key)
children_strings = [
aux(
c,
node,
indent=next_indent,
cur_chain=cur_chain + [c.project_name],
prefix=next_prefix,
depth=depth + 1,
has_grand_parent=parent is not None,
is_last_child=c is children[-1],
parent_is_last_child=is_last_child,
)
for c in children
if c.project_name not in cur_chain
]

result += list(chain.from_iterable(children_strings))
return result

lines = chain.from_iterable([aux(p) for p in nodes])
print("\n".join(lines))


def _render_text_without_unicode(tree, nodes, frozen):
use_bullets = not frozen

def aux(node, parent=None, indent=0, cur_chain=None):
cur_chain = cur_chain or []
node_str = node.render(parent, frozen)
Expand Down Expand Up @@ -886,7 +960,7 @@ def get_parser():
"--mermaid",
action="store_true",
default=False,
help=("Display dependency tree as a Maermaid graph. " "This option overrides all other options."),
help=("Display dependency tree as a Mermaid graph. " "This option overrides all other options."),
)
parser.add_argument(
"--graph-output",
Expand Down
4 changes: 2 additions & 2 deletions pipenv/vendor/pipdeptree/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# file generated by setuptools_scm
# don't change, don't track in version control
__version__ = version = '2.7.0'
__version_tuple__ = version_tuple = (2, 7, 0)
__version__ = version = '2.8.0'
__version_tuple__ = version_tuple = (2, 8, 0)
2 changes: 1 addition & 1 deletion pipenv/vendor/vendor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dparse==0.6.2
markupsafe==2.1.2
pep517==0.13.0
pexpect==4.8.0
pipdeptree==2.7.0
pipdeptree==2.8.0
plette==0.4.4
ptyprocess==0.7.0
pydantic==1.10.8
Expand Down