spyder icon indicating copy to clipboard operation
spyder copied to clipboard

Outline not showing functions or erroneously showing imports as functions

Open mluerig opened this issue 3 years ago • 20 comments

Issue Report Checklist

  • [x ] Searched the issues page for similar reports
  • [ x] Read the relevant sections of the Spyder Troubleshooting Guide and followed its advice
  • [ x] Reproduced the issue after updating with conda update spyder (or pip, if not using Anaconda)
  • [ ] Could not reproduce inside jupyter qtconsole (if console-related)
  • [x ] Tried basic troubleshooting (if a bug/error)
    • [x ] Restarted Spyder
    • [x ] Reset preferences with spyder --reset
    • [x ] Reinstalled the latest version of Anaconda
    • [ ] Tried the other applicable steps from the Troubleshooting Guide
  • [x ] Completed the Problem Description, Steps to Reproduce and Version sections below

Problem Description

What steps reproduce the problem?

  1. outline not listing functions, doesn't matter if they are in code cells or not image
  2. outline listing module imports as generic functions when they are moved to a new line with "" image

What is the expected output? What do you see instead?

Paste Traceback/Error Below (if applicable)


PASTE TRACEBACK HERE

Versions

  • Spyder version: 5.1.3
  • Python version: 3.7.11
  • Qt version: 5.9.7
  • PyQt version: 5.9.2
  • Operating System name/version: windows 10

Dependencies


# Mandatory:
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  4.0.0 (OK)
cloudpickle >=0.5.0           :  1.6.0 (OK)
cookiecutter >=1.6.0          :  1.7.2 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.1.0 (OK)
IPython >=7.6.0               :  7.26.0 (OK)
jedi >=0.17.2;<0.19.0         :  0.17.2 (OK)
jsonschema >=3.2.0            :  3.2.0 (OK)
keyring >=17.0.0              :  23.0.1 (OK)
nbconvert >=4.0               :  6.1.0 (OK)
numpydoc >=0.6.0              :  1.1.0 (OK)
paramiko >=2.4.0              :  2.7.2 (OK)
parso >=0.7.0;<0.9.0          :  0.7.0 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.8.0 (OK)
pygments >=2.0                :  2.10.0 (OK)
pylint >=2.5.0;<2.10.0        :  2.9.6 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.2.2;<1.3.0          :  1.2.2 (OK)
pylsp_black >=1.0.0           :  None (OK)
qdarkstyle =3.0.2             :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.1.10 (OK)
qtawesome >=1.0.2             :  1.0.2 (OK)
qtconsole >=5.1.0             :  5.1.0 (OK)
qtpy >=1.5.0                  :  1.10.0 (OK)
rtree >=0.9.7                 :  0.9.7 (OK)
setuptools >=49.6.0           :  52.0.0.post20210125 (OK)
sphinx >=0.6.6                :  4.0.2 (OK)
spyder_kernels >=2.1.1;<2.2.0 :  2.1.1 (OK)
textdistance >=4.2.0          :  4.2.1 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  2.1.3 (OK)
zmq >=17                      :  22.2.1 (OK)

# Optional:
cython >=0.21                 :  None (OK)
matplotlib >=2.0.0            :  3.4.2 (OK)
numpy >=1.7                   :  1.18.5 (OK)
pandas >=1.1.1                :  1.1.2 (OK)
scipy >=0.17.0                :  1.6.3 (OK)
sympy >=0.7.3                 :  None (OK)

mluerig avatar Sep 12 '21 15:09 mluerig

Hey @mluerig, thanks for reporting. I'm afraid that in order to understand why that's happening, you'd need to upload your entire code project (not just the files you're showing us), so we can reproduce the problem in our side.

If you don't feel comfortable sharing it in public, you can send it to my email (it's on my Github profile). Also, please let us know if you're using a Spyder project or not.

ccordoba12 avatar Sep 12 '21 16:09 ccordoba12

no problem - it's public: https://github.com/mluerig/phenopype

Started happening after I moved from 5.0.5 to 5.1.3. I am not using a Spyder project.

mluerig avatar Sep 12 '21 19:09 mluerig

Maybe this is an issue on Windows because I can't reproduce it on Linux. I'll take a look at it soon and let you know.

Another question for you: how did install Spyder?

ccordoba12 avatar Sep 12 '21 22:09 ccordoba12

ok thanks - let me know if there is anything else you need or if I should test stuff.

I installed manually from conda forge because the latest version wasn't available yet through the anaconda main channel

mluerig avatar Sep 13 '21 08:09 mluerig

I'm seeing a similar issue and I think I could at least identify part of the problem, maybe the whole problem: It seems like any module that is part of a namespace package does not have its functions and classes listed in the outline. I made a test project that contains a module with the exact same content once in a namespace package and once in a "normal" package. The "normal" package works correctly with the outline panel, but the namespace package does not show anything.

The test project is here (I also made a spyder project in the top-level directory): TestProject.zip

I've installed spyder from the official installer and I'm using version 5.1.4. I just upgraded from 5.1.2 where I'm pretty sure the outline was working correctly. I can double-check that if it helps. I'm using Spyder on Windows 10.

@mluerig Your phenopype.core package is a namespace package. Is that intentional? At least I think that explains why the outline is not working for any module in phenopype.core.

Brow71189 avatar Sep 13 '21 09:09 Brow71189

curious...

Your phenopype.core package is a namespace package. Is that intentional?

I guess not, because I don't know what a namespace package is. at least, I couldn't guess from your example...

mluerig avatar Sep 13 '21 14:09 mluerig

A bit off topic here but just in short: The python import system considers each package (i.e. folder) that dies not contain a "init.py" file a "namespace package". You don't need that for standalone projects normally. It is only useful if you want to have multiple projects to be importable from the same namespace. This is the (lenghty but detailed) description of namespace packages: https://www.python.org/dev/peps/pep-0420/

Moritz Lürig @.***> schrieb am Mo., 13. Sep. 2021, 16:28:

curious...

Your phenopype.core package is a namespace package. Is that intentional?

I guess not, because I don't know what a namespace package is. at least, I couldn't guess from your example...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/spyder-ide/spyder/issues/16406#issuecomment-918250866, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD7SKK365XTAKSZO4QLV243UBYDBJANCNFSM5D4FXIAA .

Brow71189 avatar Sep 13 '21 14:09 Brow71189

I'm seeing a similar issue and I think I could at least identify part of the problem, maybe the whole problem: It seems like any module that is part of a namespace package does not have its functions and classes listed in the outline.

I can confirm that this is the issue - adding an __init__.py solved it for me

mluerig avatar Sep 13 '21 14:09 mluerig

@mluerig or @Brow71189, did you install your packages with pip install -e .?

ccordoba12 avatar Sep 13 '21 17:09 ccordoba12

yes I am working on my project in pip dev mode

mluerig avatar Sep 13 '21 17:09 mluerig

I was able to reproduce the problem with @Brow71189's example and will try to fix it in our next release. At least you have a workaround until then.

ccordoba12 avatar Sep 13 '21 19:09 ccordoba12

@mluerig or @Brow71189, did you install your packages with pip install -e .?

I don't have any of my packages installed in the python installation that spyder uses (since I'm using the installer, it is completely separate from any other installations on my system).

Great that you could reproduce the problem and thanks for taking it on!

Brow71189 avatar Sep 14 '21 05:09 Brow71189

I have the same problem! the .py files in the project folder is well, but the .py files in the subfolders of the project folder is bad

Versions

  • Spyder version: 5.1.5
  • Python version: 3.8.12
  • Qt version: 5.9.7
  • PyQt version: 5.9.2
  • Operating System name/version: win10

leavor avatar Sep 29 '21 08:09 leavor

@ccordoba12

Thanks for merging issues.

I also solved this issue by adding an init.py (sorry, I failed to input the right filename.)

suipz avatar Oct 13 '21 00:10 suipz

I got similar issues at spyder 5.1.5; after putting an empty init.py under the concerned directory, the outline come back again after restarting spyder.

guangyu-shi avatar Nov 02 '21 17:11 guangyu-shi

As a workaround I have downgraded python-lsp-server to version 1.2.1 (pip install python-lsp-server==1.2.1). Then the functions are shown again in the outline pane. (I didn't notice any drawbacks from this.)

glaida2020 avatar Jan 14 '22 09:01 glaida2020

@glaida2020, although there's no big harm in doing that, we fixed other problems related to the Outline in newer python-lsp-server versions, so it'll break it in other situations. That's why I'm going to hide your comment, as well as mine.

ccordoba12 avatar Jan 15 '22 17:01 ccordoba12

Adding a __init__.py file solved this problem for me one time in the past, but I'm having the same problem again adding a __init__.py file and restarting doesn't change anything.

Versions

Spyder: 5.2.2 Python: 3.9.10 Qt: 5.12.9 PyQt5: 5.12.3 OS: Debian 11 Linux kernel: 5.10.0-11-amd64

EDIT: The problem only occurs for files within a Spyder project folder. When I delete the corresponding project and restart Spyder the ouline works normally again.

mcnoat avatar Feb 15 '22 11:02 mcnoat

I have also encountered this problem with Spyder 5.2.2 on Windows 10.

Continuing discussion from comment on issue #15139 after some more testing.

Project directory structure (in summary)

Project_root/
├── some_directories ...
├── some_files ...
├── src/
│   ├── main_module.py
│   └── submodules/
│       ├── __init__.py
│       ├── submodule_1.py
│       ├── submodule_2.py
│       └── subsubmodules/
│           ├── __init__.py
│           └── subsubmodule_1.py
└── build_script.py

Versions

  • Spyder version: 5.2.2 None
  • Python version: 3.7.9 64-bit
  • Qt version: 5.12.10
  • PyQt5 version: 5.12.3
  • Operating System: Windows 10

Installed with .exe installer, same result with Spyder's own Python 3.7.9 and the system-wide Python 3.9.2 which I mainly use.

Results

The outline view works for modules placed in the project root directory (e.g. build_script.py), but not for anything under src/ and further down (only filename is shown).

Curiously, the outlines for src/ and its modules work and update even for new files after removing __init__.py from src/, changing the Python interpreter and restarting Spyder (?!)

Workaround

Putting an __init__.py into src/ and restarting Spyder (or the LSP language server) makes the outline work for all the modules in src/ and its subdirectories.

I didn't think about doing it at first, given that src/ is just my folder for keeping code and is not intended to be a package. But happily it looks workable.

yaaun avatar Mar 11 '22 10:03 yaaun

Hi @ccordoba12 thanks for linking my issue #18712 to this duplicate. I just wanted to add that I do also have a directory structure

Project_root/
├── app/
├── helpers/
├── logs/

putting __init__.py into the subdirs helped to get the correct content in the code outline. Although I have no idea what this file is for to be honest ;)

cg-mayrhofer avatar Jul 21 '22 06:07 cg-mayrhofer

Same problem here with Spyder 5.2.2. My folder structure is

mypackage
│   LICENSE
│   pyproject.toml
│   README.md
│   requiremets.txt            
├───docs
├───scripts          
├───src
│   └───mypackage
│          config.py
│          first_module.py
│          utils.py
│          second_module.py
│          __init__.py         
└───tests

all I had to do is to add an empty __init__.py file in src/ and the outline is back.

ubaldot avatar Sep 02 '22 13:09 ubaldot