Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Import woes #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
KevinHock merged 4 commits into python-security:master from bcaller:imports
Jul 24, 2018
Merged

Import woes #151

KevinHock merged 4 commits into python-security:master from bcaller:imports
Jul 24, 2018

Conversation

@bcaller
Copy link
Collaborator

@bcaller bcaller commented Jul 23, 2018
edited
Loading

I have had some trouble with imports due to my project setup.

By adding 2 new flags, we can alter how pyt expects a project to be setup. I hope you don't think it makes things too complicated.

For a project with root in /app, currently pyt expects that all of the imports are of the form:

from app.folder.module import thing

But actually a project could not be expecting the module root to be prepended.

My projects use:

from folder.module import thing

I also had a problem where one of my directories had a file called flask.py.

Because of this, any imports of the package flask were causing pyt to import from the local file flask.py. In my project this caused a circular import and RecursionError which crashed pyt.

My projects always either use relative imports with from .somewhere.else import ... or import relative to the project root. They never import a local file just by the filename.

KevinHock reacted with thumbs up emoji KevinHock reacted with hooray emoji KevinHock reacted with heart emoji
@KevinHock KevinHock self-requested a review July 24, 2018 01:04
('.'.join((module_root, filename.replace('.py', ''))), os.path.join(root, filename))
)
modules.append((
'.'.join(p for p in (module_root, directory, _filename_to_module(filename)) if p),
Copy link
Collaborator

@KevinHock KevinHock Jul 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe path instead of p? I realize the existing code is guilty of this though.

)


def valid_date(s):
Copy link
Collaborator

@KevinHock KevinHock Jul 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Copy link
Collaborator

@KevinHock KevinHock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks so much for making this :D

)


def valid_date(s):
Copy link
Collaborator

@KevinHock KevinHock Jul 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove

def valid_date
from .coveragerc as well?

Separate files with commas
--dont-prepend-root In project root e.g. /app, imports are not prepended
with app.*
--no-local-imports If not set, allow imports of files in the current
Copy link
Collaborator

@KevinHock KevinHock Jul 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Double negative feels slightly weird, maybe: If not set, allow -> If set, disallows

bcaller added 3 commits July 24, 2018 13:55
from test_project.folder import ...
should import module in test_project/folder/__init__.py
and all the modules within the folder
for working out if taint propagates.
For a project with root in /app,
currently pyt expects that all of the imports are of the form:
from app.folder.module import thing
But actually a project could not be expecting the module root to
be prepended.
My projects use:
from folder.module import thing
This adds an optional boolean flag to change the behaviour of
get_modules.
Copy link
Collaborator Author

bcaller commented Jul 24, 2018
edited
Loading

Thanks.

I actually rewrote the first commit (__init__) since actually we want

from some.directory import ...

to look in not just the __init__.py but also all modules within some.directory.

KevinHock reacted with thumbs up emoji KevinHock reacted with laugh emoji KevinHock reacted with hooray emoji KevinHock reacted with heart emoji

I had a problem where one of my folders had a file called flask.py.
Because of this, any imports of the package flask were causing pyt to
import from the local file flask.py. In my project this caused a
circular import and RecursionError which crashed pyt.
Adds a flag so that imports relative to the project root still work:
from some.directory.flask import ...
but
from flask import ...
will now only import from project root or treat as an IgnoredNode().
Relative imports:
from .flask import ...
are not affected and will still work.
@KevinHock KevinHock merged commit fbca4d2 into python-security:master Jul 24, 2018
Copy link
Collaborator

Thanks so much for making this, it's awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@KevinHock KevinHock KevinHock left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /