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

Decide handling of unusual file names #736

Closed

Description

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

Activity

  1. AlexanderSher commented on Mar 12, 2019

    @AlexanderSher
    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).

  2. jakebailey commented on Mar 12, 2019

    @jakebailey
    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.

  3. AlexanderSher commented on Mar 12, 2019

    @AlexanderSher
    Contributor

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

    cannot import name 'a' from '__main__' (my-script.py)
    
  4. jakebailey commented on Mar 12, 2019

    @jakebailey
    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()!
    
  5. jakebailey commented on Mar 18, 2019

    @jakebailey
    Member

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

  6. tmab2003 commented on Mar 21, 2019

    @tmab2003

    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

  7. kyjanond commented on Aug 21, 2020

    @kyjanond

    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?

  8. AngelontheRoad commented on Sep 2, 2020

    @AngelontheRoad

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

  9. kushaldas commented on Nov 20, 2020

    @kushaldas

    I am having same problem on a Linux box:

    Unable to find document file:///home/kdas/code/johnnycanencrypt/johnnycanencrypt/utils.py
    
  10. kushaldas commented on Nov 20, 2020

    @kushaldas
    :CocCommand python.upgradePythonLanguageServer
    

    Upgrading to latest stable solved the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions