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

Update Script/Main.py so it uses importlib #3399

Closed
wants to merge 4 commits into from

Conversation

mwichmann
Copy link
Collaborator

instead of deprecated imp module. This approach is different than the one proposed in PR #3159. I find this more straightforward, but open to suggestions.

This is in support of issue #3299, since DeprecationWarnings are thrown.

Signed-off-by: Mats Wichmann mats@linux.com

Contributor Checklist:

  • I have created a new test or updated the unit tests to cover the new/changed functionality.
  • I have updated master/src/CHANGES.txt directory (and read the README.txt in that directory)
  • I have updated the appropriate documentation

[site_dir])
if PY3:
spec = importlib.util.find_spec(site_init_modname)
fp = open(spec.origin, 'r')
Copy link
Contributor

@bdbaddog bdbaddog Jun 26, 2019

Choose a reason for hiding this comment

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

Will would this find modules in the site_dir?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

existing code adds it to sys.path above. it seems to work for the tests at least. importlib method doesn't have way to pass same arg.

@mwichmann mwichmann force-pushed the main-importlib branch 2 times, most recently from b05ec41 to 993b7c7 Compare August 8, 2019 17:54
# we don't want a "hit" from a mod elsewhere in sys.path
save_syspath = sys.path
sys.path = [sys.path[0]]
spec = importlib.util.find_spec(site_init_modname)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can do this even more simply by using importlib.spec_from_file_location (don't have to fiddle the path while doing it) if that's preferred. Tests come out the same.

mwichmann added a commit to mwichmann/scons that referenced this pull request Aug 17, 2019
Tweaks: find spec for the site file by path rather than by fiddling
sys.path to restrict the search.  Rearrange a bit more and improve
the comment a bit more.

Signed-off-by: Mats Wichmann <mats@linux.com>
@mwichmann
Copy link
Collaborator Author

Is there still a concern about this one?

mwichmann added a commit to mwichmann/scons that referenced this pull request Oct 16, 2019
Tweaks: find spec for the site file by path rather than by fiddling
sys.path to restrict the search.  Rearrange a bit more and improve
the comment a bit more.

Signed-off-by: Mats Wichmann <mats@linux.com>
mwichmann added a commit to mwichmann/scons that referenced this pull request Dec 16, 2019
Tweaks: find spec for the site file by path rather than by fiddling
sys.path to restrict the search.  Rearrange a bit more and improve
the comment a bit more.

Signed-off-by: Mats Wichmann <mats@linux.com>
instead of deprecated imp module.

Signed-off-by: Mats Wichmann <mats@linux.com>
Py3: address the problem that we might get a "site_init.py" from
somewhere else in sys.path.

Clean up excess indentation / try nesting; adjust comment.

Signed-off-by: Mats Wichmann <mats@linux.com>
Tweaks: find spec for the site file by path rather than by fiddling
sys.path to restrict the search.  Rearrange a bit more and improve
the comment a bit more.

Signed-off-by: Mats Wichmann <mats@linux.com>
Signed-off-by: Mats Wichmann <mats@linux.com>
@bdbaddog
Copy link
Contributor

Can you purge the non PY3 code here and update the PR?

@mwichmann
Copy link
Collaborator Author

rebase is proving a little challenging, will come back to it in a bit.

@mwichmann
Copy link
Collaborator Author

mwichmann commented Feb 11, 2020

This is withdrawn in favor of #3552

@mwichmann mwichmann closed this Feb 11, 2020
@mwichmann mwichmann deleted the main-importlib branch June 8, 2020 15:52
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