-
-
Notifications
You must be signed in to change notification settings - Fork 245
Sym two #814
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
Sym two #814
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for exploring a few options here, I think I like this last one best.
bpython/importcompletion.py
Outdated
for subname in find_modules(pathname): | ||
if subname != "__init__": | ||
yield "%s.%s" % (name, subname) | ||
pathReal = os.path.realpath(pathname) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small nit, but in this project (and most Python projects) we use snake_case
instead of camelCase
bpython/importcompletion.py
Outdated
if subname != "__init__": | ||
yield "%s.%s" % (name, subname) | ||
pathReal = os.path.realpath(pathname) | ||
if not pathReal in paths: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in Python not needle in haystack
is parsed as (not needle) in haystack
, so
>>> not "/some/path"
False
>>> not "/some/path" in ["/some/path"]
False
>>> False in [False]
True
>>> not "/some/path" in [False]
True
so instead, this should be
if pathReal not in paths:
bpython/importcompletion.py
Outdated
@@ -134,6 +137,7 @@ def complete(cursor_offset, line): | |||
|
|||
def find_modules(path): | |||
"""Find all modules (and packages) for a given directory.""" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra blank line
yield name | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the convention being followed here is two lines between top-level statements. You should pip install black
and run black on this file; that will autoformat it, dealing with these details. Or better you can set up VSCode to run black automatically.
@thomasballinger I am trying to write the test file but am having an issue with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the docs for tempfile.TemporaryDirectory - the files in the temp directory will be erased along with the directory after exiting the context manager.
I have almost finished turning the test class into a test file but for some reason the test is passing when it should not. In the temp directory setup I have it print out what should appear and in what order and the 'Left' file is first. In the actual test 'Left' is last and yet the test still passes. |
I have made the changes so that importtest now works. While I was debugging I used the nosetests -s command and it seems that the temp directory is showing up in (I bolded what I think is the temp dir), '..SS.S...........S..S.......................S...SSSSS......................................................tmpfaxxkuhx |
Please move the test file to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I've some more comments that I missed earlier.
@@ -71,7 +71,7 @@ def test_simple_symbolic_link_loop(self): | |||
self.filepaths.remove(thing) | |||
|
|||
else: | |||
@unittest.skip() | |||
@unittest.skip("test doesn't work in python 2") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be something like skipIf with a condition that is true for Python 2.
Now when I run this test after commenting out your fix, it still passes; so I'm worried this isn't testing what we think it is. One problem I see is that sometimes you're using the string 'import_test_folder' when there's no folder that exists with that name. When I run your setup function (and then pause in it so I have time to examine the files) I see that the temporary directory is named
|
This fails for me locally now, but it looks close. If I sort both lists and print them, I get
Is this passing for you? It occurs to me that this could be nondeterministic since a given module can be referred to mulitple ways based on which filepath got our import discoverer there first, say if |
I think that the problem is that when going between left and right it went right first whereas on my computer it went left first |
Got it, I think we want to change the implementation then to sort. I think wrapping the |
This alternative approach works for me, import completion will traverse the filesystem in the nondeterministic order determined by os.listdir() but both orders work in the test. @sebastinas thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, but please squash the commits when merging the changes.
Use os.path.realpath to see the source of symbolic links and makes sure that we are not in a loop. Also include importtest.py and importtestfolder to test if program gets stuck in a loop.
Resolves #806