◐ Shell
reader mode source ↗
Skip to content

Sym two#814

Merged
thomasballinger merged 24 commits into
bpython:masterfrom
etiennerichart:sym-two
Jul 22, 2020
Merged

Sym two#814
thomasballinger merged 24 commits into
bpython:masterfrom
etiennerichart:sym-two

Conversation

@etiennerichart

@etiennerichart etiennerichart commented Jun 26, 2020

Copy link
Copy Markdown
Contributor

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

@thomasballinger thomasballinger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hide comment

Thanks for exploring a few options here, I think I like this last one best.

@etiennerichart

Copy link
Copy Markdown
Contributor Author

@thomasballinger I am trying to write the test file but am having an issue with the try: on line 12. Also, I was wondering if the files made in the temp directory will be erased after the temp directory is closed or if they will keep taking up space.

@thomasballinger thomasballinger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hide comment

See the docs for tempfile.TemporaryDirectory - the files in the temp directory will be erased along with the directory after exiting the context manager.

@etiennerichart

Copy link
Copy Markdown
Contributor Author

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.

@etiennerichart

etiennerichart commented Jul 8, 2020

Copy link
Copy Markdown
Contributor Author

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
.tmptz3ajosr

.....S..............S.....SSS..........................S.....SS.SSSSSS.....................................................................SS....................SSSS...SS..............................S.S..........' Is there anything else I should do to integrate the test with the rest of the test files? Also, should I get rid of the print statements in the except, and is there something better than sys.exit to use since I am worried that it may interrupt the temp dir's auto cleanup. Would a break (out of the with) work?

@sebastinas

Copy link
Copy Markdown
Contributor

Please move the test file to bpython/test.

@etiennerichart etiennerichart marked this pull request as ready for review July 8, 2020 20:08

@sebastinas sebastinas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hide comment

Sorry, I've some more comments that I missed earlier.

@sebastinas sebastinas added this to the release-0.20 milestone Jul 11, 2020
@thomasballinger

Copy link
Copy Markdown
Member

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 /var/folders/ty/d8c6t0c176db_ll_xh2jqn_80000gn/T/tmp5kxo1jhg (this will be different every time) and it looks like this:

tomb ~$ tree /var/folders/ty/d8c6t0c176db_ll_xh2jqn_80000gn/T/tmp5kxo1jhg
/var/folders/ty/d8c6t0c176db_ll_xh2jqn_80000gn/T/tmp5kxo1jhg
├── Left
│   ├── __init__.py
│   └── toRight -> import_test_folder/Right
├── Level0
│   ├── Level1
│   │   ├── Level2
│   │   │   ├── Level3 -> import_test_folder/Level0/Level1
│   │   │   └── __init__.py
│   │   └── __init__.py
│   └── __init__.py
└── Right
    ├── __init__.py
    └── toLeft -> import_test_folder/Left

5 directories, 8 files
```

One this to fix would be these symlink target filenames, and then check that the test fails without your fix, but passes with it.

@thomasballinger

Copy link
Copy Markdown
Member

This fails for me locally now, but it looks close. If I sort both lists and print them, I get

actual: ['Left', 'Level0', 'Level0.Level1', 'Level0.Level1.Level2', 'Level0.Level1.Level2.Level3', 'Right', 'Right.toLeft', 'Right.toLeft.toRight']
expected: ['Left', 'Left.toRight', 'Left.toRight.toLeft', 'Level0', 'Level0.Level1', 'Level0.Level1.Level2', 'Level0.Level1.Level2.Level3', 'Right']

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 os.listdir() returned files in a different order we could end up with different names for the same modules. If this isn't passing for you yet either then we may not need to do this, but if it is and this is something nondeterministic we want to control we could sort the results of os.listdir() in the import completion code to ensure the same results each time.

@etiennerichart

Copy link
Copy Markdown
Contributor Author

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
your computer : ['Right.toLeft', 'Right.toLeft.toRight']
mine: [ 'Left.toRight', 'Left.toRight.toLeft']

@thomasballinger

Copy link
Copy Markdown
Member

Got it, I think we want to change the implementation then to sort. I think wrapping the os.listdir() call with sorted() like sorted(os.listdir()) would do it.

@thomasballinger

Copy link
Copy Markdown
Member

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?

@sebastinas sebastinas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hide comment

Looks good to me, but please squash the commits when merging the changes.

@thomasballinger thomasballinger merged commit b2111bd into bpython:master Jul 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

High CPU load when bpython is in use

3 participants