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

ModuleNotFoundError: No module named 'flit_core.dummy' #530

Closed
nschloe opened this issue Feb 22, 2022 · 22 comments · Fixed by #531
Closed

ModuleNotFoundError: No module named 'flit_core.dummy' #530

nschloe opened this issue Feb 22, 2022 · 22 comments · Fixed by #531
Labels
Milestone

Comments

@nschloe
Copy link

nschloe commented Feb 22, 2022

I'm building my project with

[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"

and since earlier today I'm getting the error message

      [...]
      ModuleNotFoundError: No module named 'flit_core.dummy'
      [end of output]

when running pip install . on the repo. Perhaps I messed up something in the package, but the error message points towards flit. Any idea what's going on?

@uSpike
Copy link

uSpike commented Feb 22, 2022

This is hitting my projects as well which use pre-commit to install flakeheaven. A debug log is attached

pre-commit.log

@takluyver takluyver added the bug label Feb 22, 2022
@takluyver
Copy link
Member

This is almost certainly related to #499. Based on the logs here and in #529, I'd guess this occurs when a) it can't get __version__ by static analysis, so it falls back to running code, and b) __init__.py contains a relative import.

It looks like this is going to hit a load of people - sorry about that. I'll ask people now: please don't comment just to say it affects you too (you can click the 👍 under the first comment).

I am pretty busy, so any help working out how to deal with this is welcome. Besides #499, you might want to look at commit 432dc76 where the 'dummy' module names were introduced, and the backwards-compatibility implementation of load_module in importlib which we were using before the changes in #499.

@nschloe
Copy link
Author

nschloe commented Feb 22, 2022

I'd guess this occurs when a) it can't get version by static analysis,

Indeed! I set the version to static in pyproject.toml and pip install . shows some import errors that I can work with. I guess flit bumped into those when trying to resolve dynamic=["version"], and just didn't manage to forward the error message.

@takluyver
Copy link
Member

I should have mentioned, there are two levels of static vs dynamic in getting the version number. You can set it in pyproject.toml, you can have a plain __version__ = '1.0' statement in __init__.py which Flit will read without executing the code, or you can have something more complex which requires Flit to execute the code. This issue only affects the last case (look for the function get_docstring_and_version_via_import in the traceback).

@nschloe
Copy link
Author

nschloe commented Feb 22, 2022

Yup, I have the version number in __about__.py, and it's imported from there in __init__.py and other places. That's how I ran into the issue.

@taut-and-yare
Copy link

I am getting it from csselect2 due to relative imports in init here

@takluyver
Copy link
Member

Again, I know this issue is going to affect a lot of people. There will hopefully be a fix soon. In the meantime, please 👍 the initial comment if you just want to say 'me too'. Thanks!

@takluyver
Copy link
Member

Based on a tiny test case, I think #531 fixes this. It would be great if some people affected by it on real projects could try it out and see if there are other issues lurking. Install from that branch, and then try either flit build or pip install . --no-build-isolation.

@takluyver takluyver added this to the 3.7.1 milestone Feb 22, 2022
@henryiii
Copy link
Contributor

FYI, the docs seem to be out of date. The "3.7.1" milestone confused me for a second, because the "current" version in the docs is 3.5.1.

@liZe
Copy link

liZe commented Feb 22, 2022

It would be great if some people affected by it on real projects could try it out and see if there are other issues lurking.

It seems to work well for me. Thanks a lot for the quick fix.

@takluyver
Copy link
Member

It looks like the docs stopped building when we renamed master to main (readthedocs/readthedocs.org#7907). I've just updated the RTD config, hopefully it will be happy now.

@nschloe
Copy link
Author

nschloe commented Feb 22, 2022

It would be great if some people affected by it on real projects could try it out

Still not working for me with dynamic = ["version"].

@takluyver
Copy link
Member

@nschloe could I ask you to give a bit more detail of what your code is like, what you're doing and what you see (more of the traceback)? If you're using pip, pass --no-build-isolation just to test this, otherwise it will set up a temporary build environment and install flit_core 3.7.0 from PyPI.

@henryiii
Copy link
Contributor

henryiii commented Feb 22, 2022

You can also just set the URL in the pyproject.toml's requires section, like:

requires = ["flit_core @ git+https://github.com/pypa/flit@i530"]

(Hmm, at least I think so - haven't tried that with a dual package yet like flit/flit_core - I think there's a way to set a subdirectory. Maybe add &subdirectory=flit_core?)

Edit: Yeah, I don't know how to put a subdirectory in here. :(

@nschloe
Copy link
Author

nschloe commented Feb 22, 2022

I just run any flit command, e.g., flit publish, on nschloe/colorio to get the error. I can provide more details tomorrow.

@henryiii
Copy link
Contributor

The correct syntax (thanks @layday) is:

requires = ["flit-core @ git+https://github.com/pypa/flit@i530#subdirectory=flit_core"]

I tried this out:

$ brew install git-lfs
$ gh repo clone nschloe/colorio
$ cd colorio

Removing the cap on flit version causes pip install . to fail. Changing to the line above fixes it!

🚢

gentoo-bot pushed a commit to gentoo/gentoo that referenced this issue Feb 23, 2022
Fixes emerging e.g. pyparsing.

Bug: pypa/flit#530
Bug: pypa/flit#531
Signed-off-by: Sam James <sam@gentoo.org>
@nschloe
Copy link
Author

nschloe commented Feb 23, 2022

Thanks @henryiii for looking up the correct syntax! With this, it also works for me.

@createcandle
Copy link

Same issue here. I'd be happy to test the fix if there is a clear step by step explanation of how to try that.

@nschloe
Copy link
Author

nschloe commented Feb 23, 2022

@createcandle
Copy link

@nschloe Thanks, but for me that's missing a few steps ':-)

@takluyver
Copy link
Member

OK, it seems like #531 fixes this. I'll merge that and make a new release (3.7.1).

@takluyver
Copy link
Member

& thanks for testing it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants