Skip to content
This repository was archived by the owner on Mar 27, 2019. It is now read-only.

Commit ba96703

Browse files
authored
fix module resolution when external pkg has module with same name (#43)
1 parent a4862be commit ba96703

File tree

6 files changed

+92
-1
lines changed

6 files changed

+92
-1
lines changed

langserver/workspace.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def find_internal_module(self, name: str, qualified_name: str, dirs: List[str]):
357357
elif self.folder_exists(os.path.join(parent, name)):
358358
# there's a folder at this level that implements a namespace package with the name we're looking for
359359
module_paths.append(os.path.join(parent, name))
360-
elif os.path.basename(parent) == name:
360+
elif self.folder_exists(parent) and os.path.basename(parent) == name:
361361
# we're already in a namespace package with the name we're looking for
362362
module_paths.append(parent)
363363
if not module_paths:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[packages]
2+
3+
libfarhan = "==0.6"

test/repos/dep_pkg_module_same_name/Pipfile.lock

+38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"packages": [
3+
{
4+
"package_name": "django",
5+
"version": ">0.5.0",
6+
"source" : {
7+
"name": "pypi",
8+
"verify_ssl": "True",
9+
"url": "https://pypi.python.org/simple"
10+
}
11+
},
12+
{
13+
"package_name": "eventlet",
14+
"version": ">=0.16.1,<0.19.0",
15+
"source" : {
16+
"name": "pypi",
17+
"verify_ssl": "True",
18+
"url": "https://pypi.python.org/simple"
19+
}
20+
}
21+
]
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from libfarhan import libfarhan.testfunc
2+
3+
print(libfarhan.testfunc())

test/test_modpkgsamename.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from .harness import Harness
2+
import uuid
3+
import pytest
4+
5+
@pytest.fixture()
6+
def workspace():
7+
workspace = Harness("repos/dep_pkg_module_same_name")
8+
workspace.initialize("repos/dep_pkg_module_same_name" + str(uuid.uuid4()))
9+
yield workspace
10+
workspace.exit()
11+
12+
class TestExtPkgHasModuleWithSameName:
13+
def test_hover_pkg_module_same_name(self, workspace):
14+
uri = "file:///test.py"
15+
line, col = 2, 18
16+
result = workspace.hover(uri, line, col)
17+
assert result == {
18+
'contents': [
19+
{
20+
'language': 'python',
21+
'value': 'def testfunc()'
22+
},
23+
'this is version 0.6'
24+
]
25+
}

0 commit comments

Comments
 (0)