Skip to content
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

10230 work around bpo-44070 by making filenames absolute before calling spec_from_file_location #1628

Merged
merged 9 commits into from
Jul 16, 2021

Conversation

graingert
Copy link
Member

@graingert graingert commented Jul 15, 2021

Scope and purpose

fix test_moduleNotInPath and test_packageNotInPath as well as their TODOs'

Contributor Checklist:

  • The associated ticket in Trac is here: https://twistedmatrix.com/trac/ticket/10230
  • I ran tox -e lint to format my patch to meet the Twisted Coding Standard
  • I have created a newsfragment in src/twisted/newsfragments/ (see: News files)
  • The title of the PR starts with the associated Trac ticket number (without the # character).
  • I have updated the automated tests and checked that all checks for the PR are green.
  • I have submitted the associated Trac ticket for review by adding the word review to the keywords field in Trac, and putting a link to this PR in the comment; it shows up in https://twisted.reviews/ now.
  • The merge commit will use the below format
    The first line is automatically generated by GitHub based on PR ID and branch name.
    The other lines generated by GitHub should be replaced.
Merge pull request #123 from twisted/4356-branch-name-with-trac-id

Author: <github_username>, <github_usernames_if_more_authors>
Reviewer: <github_username>, <github_username_if_more_reviewers>
Fixes: ticket:<trac_ticket_number>, ticket:<another_if_more_in_one_PR>

Long description providing a summary of these changes.
(as long as you wish)

@graingert
Copy link
Member Author

@graingert
Copy link
Member Author

graingert commented Jul 15, 2021

https://www.irccloud.com/pastebin/Yx1hHCUh/3.8.10.pdb
https://www.irccloud.com/pastebin/63ckKfI3/3.9.6.pdb

10:34:11 <graingert> https://www.irccloud.com/pastebin/Yx1hHCUh/3.8.10.pdb
10:34:27 <graingert> https://www.irccloud.com/pastebin/63ckKfI3/3.9.6.pdb
10:34:52 <graingert> ModuleSpec(name='test_sample', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f0b8eb7fd00>, origin='twisted.trial.test.test_loader/FileTests/test_moduleNotInPath/ygwayv_e/temp/goodpackage/test_sample.py') is different from how the actual "import " keyword works adiroiban 
10:35:42 <graingert> I think on 3.8+ we're responsible for abspathing the path to spec_from_file_location
10:35:48 <graingert> but I'm not sure

@graingert graingert changed the title try ci on 3.8.10 and 3.9.5 10230 work around bpo-44070 by making filenames absolute before calling spec_from_file_location Jul 15, 2021

self.assertEqual(goodpackage, package1)
self.assertIs(package1, sys.modules["goodpackage"])
Copy link
Member Author

Choose a reason for hiding this comment

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

part of "properly import and return that package." is adding the package to sys.modules

Copy link
Member

Choose a reason for hiding this comment

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

but isn't import goodpackage doing the same thing?
just asking :)

Copy link
Member Author

@graingert graingert Jul 15, 2021

Choose a reason for hiding this comment

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

import goodpackage will set the "goodpackage" in sys.modules key if we forgot to set it

@graingert graingert marked this pull request as ready for review July 15, 2021 12:59
Copy link
Member

@adiroiban adiroiban left a comment

Choose a reason for hiding this comment

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

All good. Thanks for the quick fix.

Only a minor comment regarding the release notes.

@@ -0,0 +1 @@
trial.runner.filenameToModule now sets the correct module.__name__ and sys.modules key
Copy link
Member

Choose a reason for hiding this comment

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

Minor comment...
I am not 100% I understand this release note.

Suggested change
trial.runner.filenameToModule now sets the correct module.__name__ and sys.modules key
trial.runner.filenameToModule now sets an absolute path to the module when updating module.__name__ and sys.modules key

Copy link
Member Author

@graingert graingert Jul 16, 2021

Choose a reason for hiding this comment

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

This PR fixes the whole module.__spec__. before the algorithm only got the module.__file__ correct on 3.7- and 3.10+

The module.__name__ was set incorrectly as the stem of the path passed to filenameToModule

@graingert graingert merged commit d0c7e19 into twisted:trunk Jul 16, 2021
@graingert graingert deleted the try-ci-on-38-10-and-39-5 branch July 16, 2021 14:43
adiroiban pushed a commit that referenced this pull request Jul 20, 2021
10230 work around bpo-44070 by making filenames absolute before calling spec_from_file_location
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.

None yet

2 participants