Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Decide handling of unusual file names #736

Closed
MikhailArkhipov opened this issue Mar 12, 2019 · 10 comments
Closed

Decide handling of unusual file names #736

MikhailArkhipov opened this issue Mar 12, 2019 · 10 comments
Assignees
Labels
enhancement New feature or request feature: imports
Milestone

Comments

@MikhailArkhipov
Copy link

MikhailArkhipov commented Mar 12, 2019

Technically file names are module names and names like 1.py or a-b.py are unimportable. Currently we fail with Unable to find document message which is not informative.

Options:

  1. Give informative warning message (or make it error and then fail).
  2. Make files work in standalone way (with warning).

Related:
https://stackoverflow.com/questions/761519/is-it-ok-to-use-dashes-in-python-files-when-trying-to-import-them

@AlexanderSher
Copy link
Contributor

It is actually one fix for this one and #597: file that has name that can't be a module can have name and be analyzed (including absolute imports).

@jakebailey
Copy link
Member

I'm not sure they're completely identical; I could have a file in some directory called a.py and my-script.py next to it which does from .a import foo and execute the latter just fine, right? The difference I'm seeing is that I think the assumption we'd make for #597 is to pretend untitled files are at the root, but I don't think that's so for the my-script.py case. I'd need to test and see what'd happen; this is just my initial thought.

@AlexanderSher
Copy link
Contributor

If you do python my-script.py, you'll get an error:

cannot import name 'a' from '__main__' (my-script.py)

@jakebailey
Copy link
Member

Yes, I did some testing and things do seem to break. Though it looks like you can actually do python -m my-script and it works. My choice in using a relative import was probably a bad one; so I tested using absolute which also failed. Maybe it won't matter all that much, I was just worried about removing potentially important info about where a file exists.

For completion's sake, if you're curious:

 %  ~/weird2  tree                 
.
├── a│   ├── __init__.py
│   ├── __init__.pyc
│   └── b
│       ├── __init__.py
│       ├── __init__.pyc
│       └── c
│           ├── __init__.py
│           ├── __init__.pyc
│           └── __pycache__
│               └── __init__.cpython-37.pyc
├── runme.py
└── scripts
    ├── __pycache__
    │   └── my-script.cpython-37.pyc
    └── my-script.py

6 directories, 10 files
 %  ~/weird2  python scripts/my-script.py 
Traceback (most recent call last):
  File "scripts/my-script.py", line 1, in <module>
    from a.b.c import foo
ImportError: No module named a.b.c
 %  ~/weird2  python -m scripts.my-script   
/usr/local/opt/python@2/bin/python2.7: No module named scripts
 %  ~/weird2  python3 scripts/my-script.py
Traceback (most recent call last):
  File "scripts/my-script.py", line 1, in <module>
    from a.b.c import foo
ModuleNotFoundError: No module named 'a'
 %  ~/weird2  python3 -m scripts.my-script   
hi from a.b.c.foo()!

@jakebailey
Copy link
Member

#778 too: We should be handling files without .py at the end in a similar fashion.

@tmab2003
Copy link

Files that start with [0-9] also don't seem to be working..Keep getting the following prints:
[Error - 2:08:08 PM] Unable to find document file:///c:/Users/../../08_HMI/08_011_HMI.py

@kyjanond
Copy link

Unfortunately I am still getting errors Unable to find document file

[Info - 1:36:02 PM] Analysis cache path: C:\Users\Ondrej Kyjanek\AppData\Local\Microsoft\Python Language Server
[Info - 1:36:02 PM] Microsoft Python Language Server version 0.5.51.0
[Info - 1:36:02 PM] Workspace root: c:\Dropbox\06_Repos\0_TESTS\mqttPahoTest
[Info - 1:36:03 PM] GetCurrentSearchPaths C:\Anaconda3\python36.exe
[Info - 1:36:03 PM] Interpreter search paths:
[Info - 1:36:03 PM] c:\anaconda3\dlls
[Info - 1:36:03 PM] c:\anaconda3\lib
[Info - 1:36:03 PM] C:\Anaconda3\Lib\site-packages
[Info - 1:36:03 PM] C:\Anaconda3
[Info - 1:36:03 PM] c:\users\ondrej kyjanek\appdata\roaming\python\python36\site-packages
[Info - 1:36:03 PM] c:\anaconda3\lib\site-packages\sphinx-1.5.1-py3.6.egg
[Info - 1:36:03 PM] c:\anaconda3\lib\site-packages\win32
[Info - 1:36:03 PM] c:\anaconda3\lib\site-packages\win32\lib
[Info - 1:36:03 PM] c:\anaconda3\lib\site-packages\pythonwin
[Info - 1:36:03 PM] c:\anaconda3\lib\site-packages\setuptools-27.2.0-py3.6.egg
[Info - 1:36:03 PM] User search paths:
2020-08-21 12:36:04.4069127 [W:onnxruntime:, graph.cc:814 onnxruntime::Graph::Graph] Initializer embeddings_matrix:0_quantized appears in graph inputs and will not be treated as constant value/weight. This may fail some of the graph optimizations, like const folding. Move it out of graph inputs if there is no need to override it, by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.
2020-08-21 12:36:04.4075653 [W:onnxruntime:, graph.cc:814 onnxruntime::Graph::Graph] Initializer embeddings_matrix:0_scale appears in graph inputs and will not be treated as constant value/weight. This may fail some of the graph optimizations, like const folding. Move it out of graph inputs if there is no need to override it, by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.
2020-08-21 12:36:04.4075926 [W:onnxruntime:, graph.cc:814 onnxruntime::Graph::Graph] Initializer embeddings_matrix:0_zero_point appears in graph inputs and will not be treated as constant value/weight. This may fail some of the graph optimizations, like const folding. Move it out of graph inputs if there is no need to override it, by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.
2020-08-21 12:36:04.4076159 [W:onnxruntime:, graph.cc:814 onnxruntime::Graph::Graph] Initializer fixed_quantization_range_uint8 appears in graph inputs and will not be treated as constant value/weight. This may fail some of the graph optimizations, like const folding. Move it out of graph inputs if there is no need to override it, by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.
2020-08-21 12:36:04.4076395 [W:onnxruntime:, graph.cc:814 onnxruntime::Graph::Graph] Initializer fixed_zero appears in graph inputs and will not be treated as constant value/weight. This may fail some of the graph optimizations, like const folding. Move it out of graph inputs if there is no need to override it, by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.
[Error - 1:36:15 PM] Request textDocument/documentSymbol failed.
Message: Object reference not set to an instance of an object.
Code: -32000
at Microsoft.Python.LanguageServer.Implementation.Server.HierarchicalDocumentSymbol(DocumentSymbolParams params, CancellationToken cancellationToken) in E:\A_work\3\s\src\LanguageServer\Impl\Implementation\Server.Symbols.cs:line 37
at Microsoft.Python.LanguageServer.Implementation.LanguageServer.DocumentSymbol(JToken token, CancellationToken cancellationToken) in E:\A_work\3\s\src\LanguageServer\Impl\LanguageServer.cs:line 229
[Error - 1:36:15 PM] Unable to find document file:///c:/Dropbox/06_Repos/0_TESTS/mqttPahoTest/test.py

Any suggestions?

@AngelontheRoad
Copy link

I got the same problem
Unable to find document file:///d:/A_Items/NP/np.py

@kushaldas
Copy link

I am having same problem on a Linux box:

Unable to find document file:///home/kdas/code/johnnycanencrypt/johnnycanencrypt/utils.py

@kushaldas
Copy link

:CocCommand python.upgradePythonLanguageServer

Upgrading to latest stable solved the issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request feature: imports
Projects
None yet
Development

No branches or pull requests

7 participants