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

👌 IMPROVE: Replace deprecated imp with importlib #4848

Merged
merged 7 commits into from
May 6, 2021
Merged

👌 IMPROVE: Replace deprecated imp with importlib #4848

merged 7 commits into from
May 6, 2021

Conversation

DirectriX01
Copy link
Contributor

I've replaced it according to the official Importlib documentation

@chrisjsewell
Copy link
Member

thanks @DirectriX01, note your link in the comment above is pointing to the wrong thing

Copy link
Member

@ltalirz ltalirz left a comment

Choose a reason for hiding this comment

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

thanks for the PR @DirectriX01 !

The link under "importlib documentation" currently links to the AiiDA source code, I guess you meant to insert a different link here?
A reference on how to adequately replace the load_package and load_source functions would indeed be useful, perhaps also for the commit message.
I guess you've looked at the imp source code and taken what seemed necessary?

Anyhow, the tests seem to pass...

@ltalirz
Copy link
Member

ltalirz commented Apr 6, 2021

Anyhow, the tests seem to pass...

Hm... the failing django test does look like it might have to do with this change.
If there is really no easy replacement for these functions, should we vendor them?

@DirectriX01
Copy link
Contributor Author

I'm really sorry for overlooking and copying the wrong link. Here is the Importlib documentation

# I could use load_module but it takes lots of arguments,
# then I use load_source
app_module = imp.load_source(f'rst{name}', full_path)
spec = importlib.util.spec_from_file_location(f'rst{name}', full_path)
Copy link
Member

Choose a reason for hiding this comment

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

typo?

Suggested change
spec = importlib.util.spec_from_file_location(f'rst{name}', full_path)
spec = importlib.util.spec_from_file_location(f'{name}', full_path)

app_module = imp.load_source(f'rst{name}', full_path)
spec = importlib.util.spec_from_file_location(f'rst{name}', full_path)
app_module = importlib.util.module_from_spec(spec)
sys.modules[f'rst{name}'] = app_module
Copy link
Member

Choose a reason for hiding this comment

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

same here (or perhaps I don't understand what this does).

is this some weird autocomplete of "firstname" in the editor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, and I have changed them accordingly

@ltalirz
Copy link
Member

ltalirz commented Apr 6, 2021

@DirectriX01 By the way, I believe the tests should also run on your fork after you push, i.e. this is an easy way to check whether all tests pass before making a pull request (no worries about this one).

@codecov
Copy link

codecov bot commented Apr 13, 2021

Codecov Report

Merging #4848 (798775d) into develop (5f87661) will increase coverage by 0.01%.
The diff coverage is 95.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4848      +/-   ##
===========================================
+ Coverage    80.02%   80.03%   +0.01%     
===========================================
  Files          515      515              
  Lines        36557    36574      +17     
===========================================
+ Hits         29252    29269      +17     
  Misses        7305     7305              
Flag Coverage Δ
django 74.48% <95.00%> (-0.01%) ⬇️
sqlalchemy 73.44% <95.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiida/restapi/translator/nodes/node.py 85.90% <95.00%> (+0.47%) ⬆️
aiida/transports/util.py 65.63% <0.00%> (+3.13%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5f87661...798775d. Read the comment docs.

@DirectriX01
Copy link
Contributor Author

The previous errors were because it couldn't load a package from the __init__ file. Since there was no direct way in importlib module, I had to implement imp.load_package() from the source code

Copy link
Member

@ltalirz ltalirz left a comment

Choose a reason for hiding this comment

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

thanks for fixing @DirectriX01 , just some minor comments then good to go from my side
@chrisjsewell you agree?

I'm surprised that importlib provides no easier non-deprecated path for this - this is going to cause headaches for a lot of python packages when the functionality is removed...

This made the issue quite a bit more complicated than expected, so in retrospect it was not really a "good first issue" - apologies.

aiida/restapi/translator/nodes/node.py Outdated Show resolved Hide resolved
aiida/restapi/translator/nodes/node.py Show resolved Hide resolved
aiida/restapi/translator/nodes/node.py Show resolved Hide resolved
@ltalirz
Copy link
Member

ltalirz commented Apr 13, 2021

Hey Abhinav, thanks for taking on this issue and bringing the PR to completion (I consider the work done; just waiting for approval from @chrisjsewell ).

I was wondering: are you still planning to submit a GSOC proposal? As you may be aware, the deadline is in ~3 hours, i.e. it's still possible but a bit tight ;-)
Feel free to drop me a line via email (you'll find it via my website linked on my github profile).

Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

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

cheers!

@chrisjsewell chrisjsewell changed the title Replaced the deprecated imp with importlib 👌 IMPROVE: Replace deprecated imp with importlib May 6, 2021
@chrisjsewell chrisjsewell merged commit 870274c into aiidateam:develop May 6, 2021
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.

4 participants