Comments (10)
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.
To implement this, pipdeptree
could internally probably do something like the following when being passed a project directory:
- Create a virtualenv
- Install pipdeptree in the virtualenv
- Remember the installed packages in the virtualenv at this point
- Install all packages required by the project in the virtualenv
- Run
pipdeptree -l
in the virtualenv - Remove all packages from the list that were in 3. but are no project dependencies
- Report the project dependencies
from pipdeptree.
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:
- Two spaces followed by a hyphen to match only those lines which are 1st level children (direct dependencies)
- 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.
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.
If your repo has a setup.py
file, you can try this:
- Create a new virtualenv
- Run
pip install .
from the project root. - Run the above command (pipdeptree + grep)
from pipdeptree.
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.
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.
[...] 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.
Thanks for considering. FYI, see how the docs for mvn dependency:tree say "Displays the dependency tree for this project".
from pipdeptree.
I don't think we plan to support this for now.
from pipdeptree.
Related Issues (20)
- Missing dependencies HOT 1
- package list doesn't match pyproject.toml HOT 6
- pipdeptree user Python2 HOT 2
- Flag for packages with native components (C, Rust etc.) HOT 4
- Release missing versions in Conda Forge HOT 2
- Slightly different output for --json-tree and --json
- Add an option to show the license HOT 2
- Several package missing from the output HOT 3
- Issue with packages built with pdm-backend 2.x HOT 2
- `tests/_models/test_dag.py::test_package_dag_from_pkgs_uses_pep503normalize` fails if `flufl.lock` is installed HOT 1
- Graphviz Not Recognized in Virtual Env on Mac M1 HOT 3
- Add a --depth parameter
- Using pipdeptree in tox with tox-uv gives ModuleNotFoundError for pip HOT 2
- Depend on pip HOT 4
- duplicate packages when using `importlib.metadata` HOT 6
- `test_custom_interpreter` fails HOT 11
- Error with a certain version constraint format HOT 1
- 2.17.0: pytest fails in 3 units HOT 8
- Streamline graph output (graphviz, mermaid, etc.) HOT 3
- Broken in python 3.10 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pipdeptree.