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

test_jupyter_path_prefer_env fails #208

Open
mgorny opened this issue Nov 18, 2020 · 12 comments
Open

test_jupyter_path_prefer_env fails #208

mgorny opened this issue Nov 18, 2020 · 12 comments
Assignees

Comments

@mgorny
Copy link

mgorny commented Nov 18, 2020

I can reproduce this test failure both with 4.7.0 and git master (which is practically the same thing ;-)):

__________________________________________________________ test_jupyter_path_prefer_env ___________________________________________________________

    def test_jupyter_path_prefer_env():
        with patch.dict('os.environ', {'JUPYTER_PREFER_ENV_PATH': 'true'}):
            path = jupyter_path()
>       assert path[0] == paths.ENV_JUPYTER_PATH[0]
E       AssertionError: assert '/home/mgorny...share/jupyter' == '/usr/share/jupyter'
E         - /usr/share/jupyter
E         + /home/mgorny/.local/share/jupyter

jupyter_core/tests/test_paths.py:186: AssertionError

@kevin-bates
Copy link
Member

kevin-bates commented Nov 18, 2020

Hi @mgorny. Do you happen to run with JUPYTER_PATH defined? This will side-effect that particular test. FWIW, I can only reproduce the issue if I set JUPYTER_PATH.

@jasongrout - would it make sense to have some remove/restore logic for JUPYTER_PATH in that test? Perhaps it could issue a warning if it finds it set, prior to its temporary removal?

@mgorny
Copy link
Author

mgorny commented Nov 18, 2020

Hi @mgorny. Do you happen to run with JUPYTER_PATH defined? This will side-effect that particular test.

No, I don't have it set in the environment. Also, the mismatched path changes if I change HOME, so it seems to be established relative to the home directory.

@kevin-bates
Copy link
Member

Sorry about this Michał. I'm hoping Jason can take a look at this. In the meantime, could you please post the results of:

jupyter --paths --debug

@kevin-bates
Copy link
Member

Hmm - I suspect your ENV and SYSTEM paths are the same in that your python is installed is /usr/share/jupyter - which will also side-effect the test.

@mgorny
Copy link
Author

mgorny commented Nov 18, 2020

$ jupyter --paths --debug
JUPYTER_PREFER_ENV_PATH is not set, making the user-level path preferred over the environment-level path for data and config
JUPYTER_NO_CONFIG is not set, so we use the full path list for config
JUPYTER_CONFIG_PATH is not set, so we do not prepend anything to the config paths
JUPYTER_CONFIG_DIR is not set, so we use the default user-level config directory
JUPYTER_PATH is not set, so we do not prepend anything to the data paths
JUPYTER_DATA_DIR is not set, so we use the default user-level data directory
JUPYTER_RUNTIME_DIR is not set, so we use the default runtime directory

config:
    /home/mgorny/.jupyter
    /usr/etc/jupyter
    /usr/local/etc/jupyter
    /etc/jupyter
data:
    /home/mgorny/.local/share/jupyter
    /usr/local/share/jupyter
    /usr/share/jupyter
runtime:
    /home/mgorny/.local/share/jupyter/runtime

@mgorny
Copy link
Author

mgorny commented Nov 18, 2020

I am using a regular system IPython install (i.e. /usr/bin/python3.x, /usr/lib/python3.x etc.), and I have Jupyter installed to system site-packages with standard paths. I'll try uninstalling jupyter_core.

@mgorny
Copy link
Author

mgorny commented Nov 18, 2020

Uninstalling it doesn't help but also makes two more tests fail.

@kevin-bates
Copy link
Member

What does this python snippet produce?

import sys
sys.prefix

If either /usr/local/share/jupyter or /usr/share/jupyter, then that's the issue.

@jasongrout
Copy link
Member

jasongrout commented Nov 18, 2020

Hmm - I suspect your ENV and SYSTEM paths are the same in that your python is installed is /usr/share/jupyter - which will also side-effect the test.

Those lines were duplicating the logic from before:

for p in ENV_JUPYTER_PATH:
if p not in SYSTEM_JUPYTER_PATH:
paths.append(p)

I think it is the test that is wrong. What do we expect to happen if we set to prefer env paths, but really there are no env paths because they are system paths? I expect that the user will be the first, but the test is trying to insist on sysprefix (even though it is a system path).

So I think the test should also check to see if there are env paths that are not system paths, and if there are not any, it should see if the user path is first. Also, I agree with you that the test should temporarily reset the JUPYTER_PATH variable to cut out that side effect.

@mgorny
Copy link
Author

mgorny commented Nov 18, 2020

$ python
Python 3.9.0 (default, Oct  6 2020, 09:42:04) 
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.prefix
'/usr/lib/python-exec/python3.9/../../..'

@jasongrout
Copy link
Member

If either /usr/local/share/jupyter or /usr/share/jupyter, then that's the issue.

This answers it as well:

data:
    /home/mgorny/.local/share/jupyter
    /usr/local/share/jupyter
    /usr/share/jupyter

There are no non-system environment paths...

@mgorny
Copy link
Author

mgorny commented Nov 18, 2020

Also:

>>> sys.path
['', '/usr/lib/python39.zip', '/usr/lib/python3.9', '/usr/lib/python3.9/lib-dynload', '/home/mgorny/.local/lib/python3.9/site-packages', '/usr/lib/python3.9/site-packages']

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

No branches or pull requests

3 participants