Comments (3)
Thanks for the example.
Issues I see immediately (there may be more):
- pyt is handling
from . import app
asimport .app
rather than first tryingfrom .__init__ import app
. https://github.com/python-security/pyt/blob/master/pyt/cfg/stmt_visitor.py#L986-L990
# e.g. from . import X
else:
name_with_dir = no_file
# We do not want to analyse the init file of the current directory
skip_init = True
- When that is solved, there will be a
RecursionError
due to the files' mutual dependency which pyt doesn't cope nicely with. You managed to avoid the circular dependency when running the code by sandwichingapp
between import lines.
from pyt.
This will probably be awkward to debug. Anyway...
Does the file it's looking for (app.py
) exist?
Does one of your files try to import it e.g. from compiq_api import app
?
Also you can try adding more logging with the -vvv
flag. This might help you narrow down which file it's getting confused about.
from pyt.
I created a stripped down example of the issue.
# test/__init__.py
from flask import Flask
app = Flask(__name__)
# -----------------------------------------------------------------------------
from . import ( # noqa # isort:skip
models,
)
# test/models.py
from . import app
yields (cwd: /Users/alex/git/compiq-api2/test
):
$ python -m pyt -r test/ -vvv
[DEBUG] __main__: Discovered file: test/models.py
[DEBUG] __main__: Discovered file: test/__init__.py
[INFO] __main__: Processing test/__init__.py
Traceback (most recent call last):
File "/Users/alex/.pyenv/versions/3.7.0/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/Users/alex/.pyenv/versions/3.7.0/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/alex/.pyenv/versions/compiq-api2/lib/python3.7/site-packages/pyt/__main__.py", line 156, in <module>
main()
File "/Users/alex/.pyenv/versions/compiq-api2/lib/python3.7/site-packages/pyt/__main__.py", line 106, in main
allow_local_directory_imports=args.allow_local_imports
File "/Users/alex/.pyenv/versions/compiq-api2/lib/python3.7/site-packages/pyt/cfg/make_cfg.py", line 42, in make_cfg
allow_local_directory_imports
File "/Users/alex/.pyenv/versions/compiq-api2/lib/python3.7/site-packages/pyt/cfg/expr_visitor.py", line 69, in __init__
self.init_cfg(node)
File "/Users/alex/.pyenv/versions/compiq-api2/lib/python3.7/site-packages/pyt/cfg/expr_visitor.py", line 76, in init_cfg
module_statements = self.visit(node)
File "/Users/alex/.pyenv/versions/3.7.0/lib/python3.7/ast.py", line 262, in visit
return visitor(node)
File "/Users/alex/.pyenv/versions/compiq-api2/lib/python3.7/site-packages/pyt/cfg/stmt_visitor.py", line 67, in visit_Module
return self.stmt_star_handler(node.body)
File "/Users/alex/.pyenv/versions/compiq-api2/lib/python3.7/site-packages/pyt/cfg/stmt_visitor.py", line 88, in stmt_star_handler
node = self.visit(stmt)
File "/Users/alex/.pyenv/versions/3.7.0/lib/python3.7/ast.py", line 262, in visit
return visitor(node)
File "/Users/alex/.pyenv/versions/compiq-api2/lib/python3.7/site-packages/pyt/cfg/stmt_visitor.py", line 1042, in visit_ImportFrom
return self.handle_relative_import(node)
File "/Users/alex/.pyenv/versions/compiq-api2/lib/python3.7/site-packages/pyt/cfg/stmt_visitor.py", line 998, in handle_relative_import
skip_init=skip_init
File "/Users/alex/.pyenv/versions/compiq-api2/lib/python3.7/site-packages/pyt/cfg/stmt_visitor.py", line 931, in from_directory_import
from_from=True
File "/Users/alex/.pyenv/versions/compiq-api2/lib/python3.7/site-packages/pyt/cfg/stmt_visitor.py", line 807, in add_module
self.visit(tree)
File "/Users/alex/.pyenv/versions/3.7.0/lib/python3.7/ast.py", line 262, in visit
return visitor(node)
File "/Users/alex/.pyenv/versions/compiq-api2/lib/python3.7/site-packages/pyt/cfg/stmt_visitor.py", line 67, in visit_Module
return self.stmt_star_handler(node.body)
File "/Users/alex/.pyenv/versions/compiq-api2/lib/python3.7/site-packages/pyt/cfg/stmt_visitor.py", line 88, in stmt_star_handler
node = self.visit(stmt)
File "/Users/alex/.pyenv/versions/3.7.0/lib/python3.7/ast.py", line 262, in visit
return visitor(node)
File "/Users/alex/.pyenv/versions/compiq-api2/lib/python3.7/site-packages/pyt/cfg/stmt_visitor.py", line 1042, in visit_ImportFrom
return self.handle_relative_import(node)
File "/Users/alex/.pyenv/versions/compiq-api2/lib/python3.7/site-packages/pyt/cfg/stmt_visitor.py", line 998, in handle_relative_import
skip_init=skip_init
File "/Users/alex/.pyenv/versions/compiq-api2/lib/python3.7/site-packages/pyt/cfg/stmt_visitor.py", line 931, in from_directory_import
from_from=True
File "/Users/alex/.pyenv/versions/compiq-api2/lib/python3.7/site-packages/pyt/cfg/stmt_visitor.py", line 803, in add_module
tree = generate_ast(module_path)
File "/Users/alex/.pyenv/versions/compiq-api2/lib/python3.7/site-packages/pyt/core/ast_helper.py", line 49, in generate_ast
raise IOError('Input needs to be a file. Path: ' + path)
OSError: Input needs to be a file. Path: /Users/alex/git/compiq-api2/test/test/app.py
from pyt.
Related Issues (20)
- python3.7 support HOT 1
- AttributeError: 'IgnoredNode' object has no attribute 'first_statement'
- RecursionError: maximum recursion depth exceeded while calling a Python object HOT 3
- Control flow incorrect if imported functions have the same name HOT 2
- Sources and sinks should propagate
- Inappropriate ioctl using Ubuntu and pty HOT 3
- How to put it inside the proxy? HOT 1
- How to handle callbacks HOT 2
- Fails on Python 3.9.0 HOT 7
- o HOT 1
- pyt usually picks the wrong encoding to load files HOT 1
- args is empty in BBorBInode when CFG generated
- RFH: jsonpickle security detection HOT 1
- .
- Teste
- H
- real
- Vulnerable python code HOT 1
- Tic tac toe
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 pyt.