Skip to content

#69 Add '--exclude' arg to exclude CSV list of packages and children from output #94

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

Merged
merged 8 commits into from
May 15, 2018

Conversation

ciarancourtney
Copy link
Contributor

Any issues let me know, thanks

@naiquevin
Copy link
Contributor

👍 Will check in a couple of days.

pipdeptree.py Outdated
@@ -595,10 +602,15 @@ def main():
return_code = 1

show_only = set(args.packages.split(',')) if args.packages else None
exclude = set(args.exclude.split(',')) if args.exclude else []

if show_only and exclude:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

show_only and exclude can be used together as long as there are no packages in common between them. One use case of this is for eg. to show all dependencies of only "Flask" but except "Jinja2". I think it should be sufficient to validate that show_only and exclude are disjoint sets. It would be good to have a test case for this too.

@@ -122,6 +122,24 @@ def test_render_tree_list_all():
assert 'itsdangerous==0.23' in lines


def test_render_tree_exclude():
tree_str = render_tree(tree, list_all=True, exclude=['itsdangerous', 'SQLAlchemy', 'Flask', 'markupsafe'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a test case for exclude along with reversed tree as well?

@naiquevin
Copy link
Contributor

Please also rebase to get latest changes on master.

@ciarancourtney
Copy link
Contributor Author

@naiquevin changes pushed, thanks for fb

@naiquevin
Copy link
Contributor

set(show_only) & set(exclude) fails if show_only and exclude are None (default values)

@ciarancourtney
Copy link
Contributor Author

@naiquevin thanks, last commit rebased; made both vars empty sets and added testcase for same

pipdeptree.py Outdated
@@ -599,14 +605,21 @@ def main():
if args.warn == 'fail' and (conflicting or cyclic):
return_code = 1

show_only = set(args.packages.split(',')) if args.packages else None
show_only = set(args.packages.split(',')) if args.packages else set()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the variable name is show_only, I think it would be better to have its default value to be None and not empty set. On the other hand, it's ok for exclude to have set() as the default value because absence of --exclude, translates to "no packages should be excluded"

The condition to show error and exit can be modified as follows,

show_only and (show_only & exclude)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, didn't realize python stops evaluating once a condition is not met 👍

Copy link
Contributor

@naiquevin naiquevin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor suggestion. LGTM other than that.

…istinct

* pass args into main() to make testing easier
Copy link
Contributor

@naiquevin naiquevin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this PR today again and found some issues. Thanks.

PS: Sorry about the delay. Was really busy at work in the past couple of weeks.

pipdeptree.py Outdated
@@ -280,8 +280,8 @@ def as_dict(self):
'required_version': self.version_spec}


def render_tree(tree, list_all=True, show_only=None, frozen=False):
"""Convert to tree to string representation
def render_tree(tree, list_all=True, show_only=None, frozen=False, exclude=set()):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use exclude=None here and handle the case inside the function. Mutable default arguments don't behave as one would expect. Check this for more info - https://stackoverflow.com/questions/1132941/least-astonishment-and-the-mutable-default-argument

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @naiquevin I changed this is following commit, I'm aware of the minefield when using mutable default args, just didn't think it would matter here as render_tree is only called once, thanks 👍

pipdeptree.py Outdated
parser = get_parser()
args = parser.parse_args()

def main(args):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will break installation of the pkg because pipdeptree:main is specified as the console script entry point in setup.py. For ease of testing you can either define another intermediate function (say run) or use mocks.

@naiquevin
Copy link
Contributor

LGTM. However, tests are failing for me locally which is probably due to some problem with my setup and not the PR. Will investigate a bit more over the weekend and then merge it. Thanks.

@naiquevin naiquevin merged commit ba5d5e2 into tox-dev:master May 15, 2018
@naiquevin
Copy link
Contributor

Thank you! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants