Giter Club home page Giter Club logo

panoptisch's Introduction

Panoptisch: A recursive dependency scanner for Python projects

Downloads

⚠️🚨 Early stage! May not work as expected! Feedback welcome! 🚨⚠️

What?

Panoptisch scans your Python file or module to find it's imports (aka dependencies) and recursively does so for all dependencies and sub-dependencies. It then generates a dependency tree in JSON for you to parse and enforce import policies. Imports are resolved by mimicing Python's import system. It's completely static besides the importing of modules to find the location of its source file(s). Panoptisch also features a minimal sandbox to prevent side-effects when importing dependencies. Note that the sandbox is not foolproof!

Please NOTE:

There are known limitations and issues at this stage. Please read this before using Panoptisch.
See: LIMITATIONS.md LINK.

Motivation

I was not able to find a proper dependency scanner for Python. Panoptisch was born out of the need to accurately verify dependency usage accross an entire project.
It's aim is to generate a JSON report that can be parsed and evaluated to assert import policies.
For example, you may want to restrict os, socket, sys and importlib imports to selected packages.

Usage

  1. Install Panoptisch in the same virtual environment as your project, this is important!
pip install panoptisch
  1. Use
usage: panoptisch <module>

positional arguments:
  module                Name of module or file you wish to scan.

options:
  -h, --help            show this help message and exit.
  --show-stdlib-dir     Prints the automatically resolved stdlib directory.
  --max-depth MAX_DEPTH
                        Maximum dependency depth.
  --out OUT             File to output report.
  --auto-stdlib-dir     Ignore stdlib modules by automatically resolving their path. MAY BE BUGGY. Try running panoptisch <module_name> --show-stdlib-dir to see the directory before using this.
  --stdlib-dir STDLIB_DIR Ignore stdlib modules by providing their path.
  --omit-not-found      Do not include modules that could not be resolved in report.
  --no-sandbox          Ignore the minimal sandbox implementation.

A typical run may be

$ panoptisch <module or file> --max-depth 5 --omit-not-found
  1. See report
$ more out.json
  1. We might not be interested in the dependencies of standard library modules as we place an implicit trust in them.
    To filter them out, use the --show-stdlib-dir arguement to see if Panoptisch can automatically resolve your standard library directory, typically /usr/local/lib/python3.x on linux installations. Then you can exclude it using
$ panoptisch <module or file> --auto-stdlib-dir

If Panoptisch cannot automatically resolve your standard library directory, you can find it yourself and provide it as an argument to stdlib-dir

$ panoptisch <module or file> --stdlib-dir /the/path/to/your/standardlibrary/

LICENSE

All work is licensed under the GNU General Public License Version 3.

Contributing

Feedback, contributions and issues welcome.

panoptisch's People

Contributors

r9295 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

panoptisch's Issues

Introduce caching to speed up Panoptisch

Introduce some sort of caching mechanism. In django projects, many dependencies have django as a sub-dependency, causing repetitive scanning.
The cache should work with resolved module sources not module names!

ModuleNotFound None

I understand output like

{
    "reason": "ModuleNotFoundError",
    "name": "winreg"
 },

(I'm on Mac, so winreg won't be found. I don't understand this, however.

{
    "reason": "ModuleNotFoundError",
    "name": "None"
 },

It's not obvious to me why it should fail to find a module and not know its name. Is it finding calls to __import__() where it can't evaluate the module name?

Suppress ModuleNotFound for specific platforms

While it occurs to me, most of the ModuleNotFound reasons in my initial example run are for Windows-only modules. As I'm on Mac (or Linux), it would be nice to suppress missing platform-specific modules for other platforms. Even if I'm interested in winreg, it makes sense to suppress that warning on Linux or Mac, as it's simply never going to be found.

Introduce a failsafe option.

Currently, scanning is aborted if a module has issues on import. Allow a --ignore-import-errors option that continues the scan and logs the error in the output file, similar to reason: ModuleNotFoundError

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.