Skip to content

Commit 49c931f

Browse files
Expose only modules on include directory
1 parent 7f9a32a commit 49c931f

5 files changed

Lines changed: 24 additions & 10 deletions

File tree

myplugin/include/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import mymodule
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import os
2+
import sys
3+
4+
sys.path.append('../src/')
5+
6+
import calculator
17
import vim
28

39
def foo():
@@ -6,7 +12,7 @@ def foo():
612
return "Hello World!\n\n"
713

814
def bar(x, y):
9-
return str(int(x) + int(y))
15+
return calculator.sum(int(x), int(y))
1016

1117
def none():
1218
print('ok')

myplugin/plugin/myplugin.vim

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
" myplugin.vim
22

3-
let current_dir = expand('<sfile>:p:h')
4-
let relative_path = '../python'
5-
let g:myplugin_python_dir = resolve(current_dir . '/' . relative_path)
6-
set rtp+=myplugin_python_dir
3+
let current_dir = expand('<sfile>:p:h/')
74

5+
let g:include_path = resolve(current_dir . '/' . '../include')
6+
let g:src_path = resolve(current_dir . '/' . '../src')
87

9-
function! CallPythonFunction(command_name, module_name, ...)
10-
python3 << EOF
8+
let $PYTHONPATH = expand("%:p:h") . ":" . $PYTHONPATH
9+
10+
python3 << EOF
1111
import sys
12-
sys.path.append(vim.eval('g:myplugin_python_dir'))
12+
13+
sys.path.append(vim.eval('g:include_path'))
14+
sys.path.append(vim.eval('g:src_path'))
1315

1416
import vim
17+
EOF
1518

19+
function! CallPythonFunction(command_name, module_name, ...)
20+
python3 << EOF
1621
# Get the function name and arguments from Vim script
1722
args = vim.eval('a:000')
1823

@@ -39,12 +44,11 @@ endfunction
3944

4045
function! CreatePythonCommands()
4146
python3 << EOF
42-
import vim
4347
import os
4448
import importlib.util
4549

4650
# Get the Python directory from Vim script
47-
python_dir = vim.eval('g:myplugin_python_dir')
51+
python_dir = vim.eval('g:include_path')
4852

4953
# Find all Python modules in the directory
5054
modules = [f for f in os.listdir(python_dir) if f.endswith('.py') and not f.startswith('__')]

myplugin/src/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import calculator

myplugin/src/calculator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def sum(x: int, y: int):
2+
return x + y

0 commit comments

Comments
 (0)