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

sys.path does not include subdirectory #259

Open
achalddave opened this issue Sep 27, 2018 · 6 comments
Open

sys.path does not include subdirectory #259

achalddave opened this issue Sep 27, 2018 · 6 comments

Comments

@achalddave
Copy link

In python and ipython, when running a script from a parent directory (e.g. python foo/bar.py), sys.path contains the script's immediate parent directory. However, this does not seem to be the case for ptpython.

I thought this might be related to davidhalter/jedi#1148 and #246 , but downgrading to jedi <0.12 (0.11.1 specifically) does not fix the issue.

~/tmp/ptpython-path-debug ~ mkdir foo
~/tmp/ptpython-path-debug ~ cat <<EOF >foo/bar.py
import sys
print(sys.path)
EOF

~/tmp/ptpython-path-debug ~ python foo/bar.py
['/home/achald/tmp/ptpython-path-debug/foo', <global_paths>]

~/tmp/ptpython-path-debug ~ ipython foo/bar.py
['/home/achald/tmp/ptpython-path-debug/foo', '', <global_paths>]

~/tmp/ptpython-path-debug ~ ptpython foo/bar.py
['', <global_paths>]

Note the lack of /home/achald/tmp/ptpython-path-debug/foo in the last sys.path.

@jonathanslenders
Copy link
Member

Hi @achalddave,

Can you try to upgrade to the latest ptpython version and try again? I just pushed a new version to pypi.
There was indeed a bug in Jedi, and now we have a workaround that ensures that the current directory is always in sys.path.

@achalddave
Copy link
Author

achalddave commented Sep 30, 2018

I just upgraded and tried, and the issue still seems to exist. Note that ptpython does always add the current directory in sys.path (although I'm unsure if that's expected or a bug: python by default only adds the directory that the file is in, while ipython adds the current directory and the directory that the file is in), but fails to add the directory the file is in.

That is, the following things are always in the path for each of the interpreters:

python <script>: parent directory of <script>
ipython <script>: parent directory of <script>, current working directory
ptpython <script>: current working directory (after jedi bug fix)

~ pip show ptpython
Name: ptpython
Version: 2.0.1
Summary: Python REPL build on top of prompt_toolkit
Home-page: https://github.com/jonathanslenders/ptpython
Author: Jonathan Slenders
Author-email: UNKNOWN
License: UNKNOWN
Location: /home/achald/local/anaconda3/envs/pytorch-caffe2/lib/python3.6/site-packages
Requires: docopt, prompt-toolkit, jedi, pygments
Required-by:
~/tmp/ptpython-path-debug ~ ptpython foo/bar.py
['', <global paths>]

~/tmp/ptpython-path-debug ~ ipython foo/bar.py
['/home/achald/tmp/ptpython-debug/foo', '', <global paths>]```

@jonathanslenders
Copy link
Member

I believe a new Jedi version has been released. Can you try again upgrading both ptpython and Jedi to the latest version?

@achalddave
Copy link
Author

achalddave commented Oct 14, 2018

Just upgraded both. Still seeing the same issue.
python

~/t/ptpython-debug ~ py foo/bar.py
['/home/achald/tmp/ptpython-debug/foo', <global paths>]

ptpython

~/t/ptpython-debug ~ ptpy foo/bar.py
['', <global paths>]

Versions:

~/t/ptpython-debug ~ pip show ptpython
Name: ptpython
Version: 2.0.3
Summary: Python REPL build on top of prompt_toolkit
Home-page: https://github.com/jonathanslenders/ptpython
Author: Jonathan Slenders
Author-email: UNKNOWN
License: UNKNOWN
Location: /home/achald/local/anaconda3/envs/pytorch-caffe2/lib/python3.6/site-packages
Requires: docopt, pygments, prompt-toolkit, jedi
Required-by:
~/t/ptpython-debug ~ pip show jedi
Name: jedi
Version: 0.13.1
Summary: An autocompletion tool for Python that can be used for text editors.
Home-page: https://github.com/davidhalter/jedi
Author: David Halter
Author-email: davidhalter88@gmail.com
License: MIT
Location: /home/achald/local/anaconda3/envs/pytorch-caffe2/lib/python3.6/site-packages
Requires: parso
Required-by: ptpython, ipython

@jonathanslenders
Copy link
Member

@achalddave, Are you sure that the same environment is used for both pip and ptpython?

Can you run the pip-show commands using the python -m pip show ptpython syntax, and start ptpython by running python -m ptpython? I wonder if that shows the same results.

@achalddave
Copy link
Author

achalddave commented Oct 14, 2018

Yeah they should be the same environment. Does this issue not show up for you? I can debug this more on my end, if you're not seeing the issue (maybe with a separate python install or try removing and re-installing).

~ ~ which ptpy
ptpy=ptpython

~ ~ which ptpython
~/local/anaconda3/envs/pytorch-caffe2/bin/ptpython

~/tmp/ptpython-debug ~ which python
~/local/anaconda3/envs/pytorch-caffe2/bin/python

~ ~ python -m pip show ptpython
Name: ptpython
Version: 2.0.3
Summary: Python REPL build on top of prompt_toolkit
Home-page: https://github.com/jonathanslenders/ptpython
Author: Jonathan Slenders
Author-email: UNKNOWN
License: UNKNOWN
Location: /home/achald/local/anaconda3/envs/pytorch-caffe2/lib/python3.6/site-packages
Requires: jedi, docopt, prompt-toolkit, pygments
Required-by:

~ ~ cd tmp/ptpython-debug

~/tmp/ptpython-debug ~ ls
foo/

~/tmp/ptpython-debug ~ python -m ptpython foo/bar.py
['', <global paths>]

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

2 participants