Code Monkey home page Code Monkey logo

Comments (10)

naiquevin avatar naiquevin commented on July 28, 2024 1

I don't think any such complex logic would be necessary. It would be just the global pipdeptree calling the one from the virtualenv, that's it.

This sounds like a better approach than replacing the current process.

So feel free to close this if you believe this is out of scope.

Not sure if it's out of scope entirely, need to think about it. Will check mvn dependency:tree. Keeping the issue open.

from pipdeptree.

sschuberth avatar sschuberth commented on July 28, 2024

To implement this, pipdeptree could internally probably do something like the following when being passed a project directory:

  1. Create a virtualenv
  2. Install pipdeptree in the virtualenv
  3. Remember the installed packages in the virtualenv at this point
  4. Install all packages required by the project in the virtualenv
  5. Run pipdeptree -l in the virtualenv
  6. Remove all packages from the list that were in 3. but are no project dependencies
  7. Report the project dependencies

from pipdeptree.

naiquevin avatar naiquevin commented on July 28, 2024

Not sure if I have understood what you mean by a project directory. But I am guessing you want to get all direct dependencies of a particular package, let's say foo. It can be achieved using the -p flag and grep as follows,

$ pipdeptree -p foo | grep -E '^(foo|\s\s-)'

Here, -p will restrict the output to dependencies of foo. Then grep is used to match for two things:

  1. Two spaces followed by a hyphen to match only those lines which are 1st level children (direct dependencies)
  2. line containing the package name itself

This however is not possible without installing the package. The tmp virtualenv approach you've mentioned above should work though.

from pipdeptree.

sschuberth avatar sschuberth commented on July 28, 2024

But I am guessing you want to get all direct dependencies of a particular package

Not quite. By "project directory" I mean the root directory containing the source code of any Python project. Let's take https://github.com/nexB/scancode-toolkit as an example. After git clone, my Git working tree would be the project directory. Now I'd like to programmatically get the transitive dependency tree for this project. If you're familiar with Maven, that would be pretty much what mvn dependency:tree does. I.e. there is no installed / published package for what I want dependencies to be listed for, just a local directory with the source code to a Python project.

from pipdeptree.

naiquevin avatar naiquevin commented on July 28, 2024

If your repo has a setup.py file, you can try this:

  1. Create a new virtualenv
  2. Run pip install . from the project root.
  3. Run the above command (pipdeptree + grep)

from pipdeptree.

sschuberth avatar sschuberth commented on July 28, 2024

Right, except that I don't need the grep, I believe, as I'm interested in all / transitive dependencies, and there is no package to grep for. I was just thinking that it would make sense to add this use case straight to pipdeptree so only a single command needs to be run. What do you think?

from pipdeptree.

naiquevin avatar naiquevin commented on July 28, 2024

This is a very specific use case and I don't think the code for it belongs inside pipdeptree. But even if we decide to add it, it would be extremely tricky because pipdeptree works in a virtualenv only after it's manually installed inside it first. This makes the whole thing cyclic - pipdeptree creating virtualenv, then installing pipdeptree inside it and then replacing the current process with that executable.

Also, if you have the setup.py file, that itself would be the source of truth for first level dependencies of the project, right?

from pipdeptree.

sschuberth avatar sschuberth commented on July 28, 2024

[...] replacing the current process with that executable.

I don't think any such complex logic would be necessary. It would be just the global pipdeptree calling the one from the virtualenv, that's it.

Also, if you have the setup.py file, that itself would be the source of truth for first level dependencies of the project, right?

Correct. But like I said, I'm interested in transitive dependencies as well. Also, I'd like to investigate arbitrary projects, so some might have a requirements.txt file instead of a setup.py file.

So feel free to close this if you believe this is out of scope.

from pipdeptree.

sschuberth avatar sschuberth commented on July 28, 2024

Thanks for considering. FYI, see how the docs for mvn dependency:tree say "Displays the dependency tree for this project".

from pipdeptree.

gaborbernat avatar gaborbernat commented on July 28, 2024

I don't think we plan to support this for now.

from pipdeptree.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.