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

Use importlib instead of imp #168

Merged
merged 3 commits into from
Aug 1, 2024
Merged

Conversation

MarcellPerger1
Copy link
Contributor

Use importlib instead of imp, fixes #166

@Waszker
Copy link
Contributor

Waszker commented Oct 25, 2023

@syrusakbary would you mind taking a look and merging the PR? This issue is currently blocking my effort in one of the projects to move to Python 3.12

def _load_source(module_name, filepath):
spec = importlib.util.spec_from_file_location(module_name, filepath)
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it necessary to write to sys.modules for this to work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, writing to sys.modules is not required for this to work (it just improves performance if the same python module is loaded multiple times)

Copy link
Contributor

@Waszker Waszker Oct 25, 2023

Choose a reason for hiding this comment

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

@paulmelnikow I'm not the owner of the PR, but I've found a similar problem and question on official Python mailing lists: https://discuss.python.org/t/how-do-i-migrate-from-imp/27885

It looks like writing to sys.modules is indeed correct, see this answer

EDIT: Didn't see the reply by @MarcellPerger1. My bad, sorry

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess my ask here is that it would be good to add some links to the imp documentation, mailing list, etc. to explain this implementation, which otherwise seems somewhat peculiar.

Copy link
Contributor

@Waszker Waszker left a comment

Choose a reason for hiding this comment

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

@paulmelnikow I've made some comment/documentation suggestions to the PR as suggested in https://github.com/syrusakbary/snapshottest/pull/168/files#r1372331751

Let me know what you think of them.

snapshottest/module.py Show resolved Hide resolved
snapshottest/module.py Show resolved Hide resolved
Copy link
Collaborator

@paulmelnikow paulmelnikow left a comment

Choose a reason for hiding this comment

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

This looks good to me. Leaving open for a moment in case @MarcellPerger1 or anyone else would like to comment.

@Jan-Jasek
Copy link

Jan-Jasek commented Nov 21, 2023

Any chance in merging this one? 🙏
@paulmelnikow

@crest42
Copy link

crest42 commented Dec 6, 2023

Tested with both python3.10 and python3.12. Can confirm 3.10 is still working and 3.12 is now also working. Any change of merging?

@bassco
Copy link

bassco commented Jan 4, 2024

I used the following in our Pipenv file to reference this branch, to run our tests

snapshottest = { git = "https://github.com/syrusakbary/snapshottest.git", ref ="refs/pull/168/head"}

@rares-urdea
Copy link

Hello 👋 ! Is there any chance this might merged soon? Would love to have the package ready for py 3.12. Much appreciated!

@QuinnyPig
Copy link

Yeah, tripping over this as soon as I try to use python 3.12; approving it would be swell.

@RobinTail
Copy link

RobinTail commented Apr 8, 2024

@Waszker || @paulmelnikow || @syrusakbary ,
please merge and release.
This fix is critical for supporting python 3.12.

@Waszker
Copy link
Contributor

Waszker commented Apr 10, 2024

@Waszker || @paulmelnikow || @syrusakbary , please merge and release. This fix is critical for supporting python 3.12.

Sorry @RobinTail I gave my approval but I don't have write access to merge the changes.
I'm also waiting for the fix to be finally deployed (it's been 6 months now), in the meantime I suggest using the suggestion from #168 (comment)

@torarvid
Copy link

I just changed to use syrupy instead. Migration was easy as 🍰

@Waszker
Copy link
Contributor

Waszker commented Apr 10, 2024

I just changed to use syrupy instead. Migration was easy as 🍰

What about Django support? I have one project that uses django test runner which seems not supported by syrup. I'd be happy to make a switch as well!

@RobinTail
Copy link

I just changed to use syrupy instead. Migration was easy as 🍰

it does not support unittest, only pytest, right, @torarvid ?

@RobinTail
Copy link

RobinTail commented Apr 10, 2024

it's been 6 months now

Almost 9 since the PR date.
And more than 11 since the issue #166 opening.

@intgr
Copy link

intgr commented Apr 10, 2024

And 3.5 years from the last 1.0.0a0 alpha release.

Maybe it's time to talk about forking, if anyone is interested in undertaking the commitment of continued maintenance.

@torarvid
Copy link

it does not support unittest, only pytest, right, @torarvid ?

I don't know, @RobinTail. But we use pytest, so if you're correct, I wouldn't have noticed any problem 😊

@Kilo59
Copy link

Kilo59 commented Apr 11, 2024

I opened another PR before I saw this one.

@paulmelnikow @syrusakbary
My implementation is much simpler, and therefore, I hope more likely to be accepted.

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.

Replace deprecated imp module with importlib