Giter Club home page Giter Club logo

findpydeps's Introduction

Downloads Downloads Downloads

findpydeps

Find the python dependencies used by your python files and projects.

Installation

Simply install it via pip:

pip install findpydeps

If you are having trouble with the pip installation, you can use the source file :

git clone https://github.com/Nicolas-Reyland/findpydeps
cp findpydeps/src/findpydeps/findpydeps.py ~/.local/bin/findpydeps

Usage

Example usage:

findpydeps -i "$HOME"/python/example-project/ test.py ../test2.py

The output of findpydeps -i main.py -l --no-header could look like that :

tensorflow
pandas
numpy
pillow
requests

You could then use the output like this :

cd your_python_project
findpydeps -i main.py --follow-local-imports > requirements.txt
pip install -r requirements.txt

For exhaustive usage information, please refer to the findpydeps -h output (or python3 -m findpydeps -h) :

usage: findpydeps.py [-h] [-i input [input ...]] [-d expr] [-r policy] [-l] [-s] [--blocks] [--no-blocks] [--functions] [--no-functions] [--submodules-as-modules] [-v] [--header]
                     [--no-header]

Find the python dependencies used by your python files

options:
  -h, --help            show this help message and exit
  -i input [input ...], --input input [input ...]
                        input files and/or directories (directories will be scanned for *.py files)
  -d expr, --dir-scanning-expr expr
                        only process files with this expression in scanned directories [default: *.py]
  -r policy, --removal-policy policy
                        removal policy for modules (0: local & stdlib, 1: local only, 2: stdlib only, 3: no removal) [default: 0]
  -l, --follow-local-imports
                        also scan files which are imported locally (not libraries)
  -s, --strict          raise an error on SyntaxErrors in the input python files
  --blocks              scan contents of 'if', 'try' and 'with' blocks
  --no-blocks           don't scan contents of 'if', 'try' and 'with' blocks
  --functions           scan contents of functions
  --no-functions        don't scan contents of functions
  --submodules-as-modules
                        submodule imports are treated as module-imports (e.g. "import random.shuffle" generates "random.shuffle", not "random", which is the default behavior)
  -v, --verbose         verbose mode (all messages prepended with '#')
  --header              show the greeting header
  --no-header           don't show the greeting header

Todo

  • Option to manually exclude/include modules

findpydeps's People

Contributors

nicolas-reyland avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

findpydeps's Issues

What does --follow-local-imports do?

In my last issue, I noted that I just tried out findpydeps on one of my work repos, using a command line like this:

findpydeps -i . --blocks --functions --follow-local-imports --removal-policy 0 --strict --no-header > ./requirements_from_findpydeps.txt

I think that I understand exactly what these options do:
--blocks --functions
they tell findpydeps to include imports that are locally defined inside blocks and functions (in addition to always including imports at the start of your module).

But what exactly does that
--follow-local-imports
option do?

From your home page, or from using its --help option, I am aware of the brief description:
follow imports for local files

But I still have no idea what it does.

Is it related to the local imports that I am already specifying in
--blocks --functions
?

Or is it something totally different?

package names only parsed up to the first '.' (i.e. period char)

First, Nicolas, thank you very much for writing this software and making it available on PyPi. I am grateful.

I just tried out findpydeps on one of my work repos, using a command line like this:

findpydeps -i . --blocks --functions --follow-local-imports --removal-policy 0 --strict --no-header > ./requirements_from_findpydeps.txt

I am confused about the results that findpydeps gave me.

In particular, my files have import lines involving opentelemetry like this:

from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
from opentelemetry.instrumentation.logging import LoggingInstrumentor
from opentelemetry.propagate import set_global_textmap
from opentelemetry.propagators.cloud_trace_propagator import CloudTraceFormatPropagator
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import Tracer, TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter

But findpydeps summarizes all those imports merely as
opentelemetry

In other words, instead of listing

opentelemetry.exporter.cloud_trace
opentelemetry.instrumentation.logging
etc

it seems as if findpydeps drops everything after the first '.' (i.e. period char).

That is a bug, right? I need the full package names to be listed, not just the first part.

I note that with opentelemetry, even if findpydeps gave me the fully parsed names, like opentelemetry.exporter.cloud_trace, that that would only be half the battle. For reasons that I cannot fathom, Google uses different names for the packages that you need to specify in your requirments.txt file. For example, instead of listing something like
opentelemetry-exporter-cloud-trace
in your requirments.txt, you actually need to use
opentelemetry-exporter-gcp-trace

Dependency tree

Hi,

this is a great package you have here. I assume my wish isn't easy.

It would help a lot of I could see a dependency graph. I would like to know on what my dependencies are depending on and so on.

Use-case: One of my dependencies seems to import pandas or numpy. But I don't know which one.

Simplify code using NodeVisitor?

I love that you use Python's AST to parse Python source files in this prokject.

I recently stumbled across this article: https://www.mattlayman.com/blog/2018/decipher-python-ast/

Check out its section "ast by example" or this code listing: https://www.mattlayman.com/2018/ast_example.py

This guy used the ast.NodeVisitor to extract data about imports in a very small amount of code.

Would using NodeVisitor in your code help simplify it too? (I have not thought deeply about this. Maybe features that your code supports, like not including imports in functions, might be hard to do if use a _NodeVisitor.)

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.