-
-
Notifications
You must be signed in to change notification settings - Fork 443
add check if there is mix of local and non local installation #7745
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7745 +/- ##
==========================================
+ Coverage 92.99% 93.03% +0.03%
==========================================
Files 648 648
Lines 61457 61457
==========================================
+ Hits 57155 57179 +24
+ Misses 4302 4278 -24 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion to make function name less specific.
napari/__main__.py
Outdated
def main(): | ||
# There a number of macOS issues we can fix with env vars | ||
# and/or relaunching a subprocess | ||
_check_editable_installation() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is not a macOS specific issue, it should go above the line comment.
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
for more information, see https://pre-commit.ci
@Czaki why not do it in napari init rather than main so that it works in all cases? |
(but I like the idea very much) |
Hm. I need to fix this PR as this code will never be executed. The exception is raised before calling of added function. Traceback (most recent call last):
File "/Users/horst/miniconda3/envs/dingens/bin/napari", line 5, in <module>
from napari.__main__ import main
File "/Users/horst/Documents/python/napari/napari/__main__.py", line 18, in <module>
from napari.errors import ReaderPluginError
File "/Users/horst/Documents/python/napari/napari/errors/__init__.py", line 1, in <module>
from napari.errors.reader_errors import (
File "/Users/horst/Documents/python/napari/napari/errors/reader_errors.py", line 1, in <module>
from napari.types import PathLike
File "/Users/horst/Documents/python/napari/napari/types.py", line 191, in <module>
_register_types_with_magicgui()
File "/Users/horst/Documents/python/napari/napari/types.py", line 158, in _register_types_with_magicgui
from napari.utils import _magicgui as _mgui
ImportError: cannot import name '_magicgui' from 'napari.utils' (unknown location)
I do not want to be too aggressive. But maybe I should move this check on top of |
Understood. Yeah it's a tricky question. But I think it's worth a check, especially if it's cheap. |
moved |
I will open PR to move to src layout just after 0.6.1 release |
😮 Not opposed just... Lots of emotions 😂 |
# References and relevant issues # Description This PR moves napari into `src` layout that prevents from multiple problems from mixing local installation that led to multiple confusion in the past. After this, PR `python -m napari` or `import napari` should always use napari version installed in the current environment. It should unblock #7745 --------- Co-authored-by: Peter Sobolewski <76622105+psobolewskiPhD@users.noreply.github.com> Co-authored-by: TimMonko <47310455+TimMonko@users.noreply.github.com> Co-authored-by: Lorenzo Gaifas <brisvag@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggesting improved error message for user understanding and comments for maintainability. Marking approved since code works.
# Skip the check during testing | ||
# we need to move to src layout to fix this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the comment about src layout?
|
||
import numpy as np | ||
|
||
site_packages_path = Path(np.__file__).absolute().parent.parent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
site_packages_path = Path(np.__file__).absolute().parent.parent | |
# Use numpy location to determine site packages path | |
site_packages_path = Path(np.__file__).absolute().parent.parent |
# numpy is not installed in site-packages | ||
return | ||
|
||
problematic_napari_path = site_packages_path / 'napari' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
problematic_napari_path = site_packages_path / 'napari' | |
napari_site_packages_path = site_packages_path / 'napari' |
if problematic_napari_path.exists(): | ||
print( # noqa: T201 | ||
f'Found a napari directory: {problematic_napari_path}, ' | ||
'but napari is installed in editable mode. ' | ||
'Please remove napari directory from site-packages.', | ||
file=sys.stderr, | ||
) | ||
raise RuntimeError('Mix of local and non local installation') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if problematic_napari_path.exists(): | |
print( # noqa: T201 | |
f'Found a napari directory: {problematic_napari_path}, ' | |
'but napari is installed in editable mode. ' | |
'Please remove napari directory from site-packages.', | |
file=sys.stderr, | |
) | |
raise RuntimeError('Mix of local and non local installation') | |
if napari_site_packages_path.exists(): | |
print( # noqa: T201 | |
f'Found napari installed in a site-packages directory: {napari_site_packages_path}, ' | |
'but napari is also installed in editable mode. ' | |
'To prevent mixing local, editable and non-local, site-packages installation, | |
' please remove napari directory from site-packages.', | |
file=sys.stderr, | |
) | |
raise RuntimeError('Conflict found where napari is present in local, editable location and non-local site-packages installation') |
@Czaki does this work now? if so, how can I know/test it? Happy to also stick this in 0.6.2 if its ready |
Will recreate problematic environments today and report. |
References and relevant issues
https://napari.zulipchat.com/#narrow/channel/212875-general/topic/ImportError.3A.20cannot.20import.20name.20'_magicgui'/near/508102720
Description
Check if there is a mix of local and non-local installation of napari and then stop process.
Works only if run napari as module
python -m napari
not when start napari from script.