Skip to content

Commit 5685765

Browse files
Add python package structure
1 parent d7afdbd commit 5685765

9 files changed

Lines changed: 79 additions & 0 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
!.gitignore
2+
3+
.*
4+
*.swp
5+
__*__
6+
*.egg-info

create_plugin.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import os
2+
import sys
3+
sys.path.append('./myplugin')
4+
import vim_python_framework as my_framework
5+
6+
def create_plugin(plugin_name):
7+
base_path = os.path.join(os.getcwd(), plugin_name)
8+
include_path = os.path.join(base_path, 'include')
9+
src_path = os.path.join(base_path, 'src')
10+
plugin_path = os.path.join(base_path, 'plugin')
11+
vim_script_path = my_framework.get_vim_framework_file()
12+
13+
os.makedirs(include_path, exist_ok=True)
14+
os.makedirs(src_path, exist_ok=True)
15+
os.makedirs(plugin_path, exist_ok=True)
16+
17+
with open(os.path.join(plugin_path, 'framework.vim') , 'w') as f:
18+
f.write("""
19+
let current_dir = expand('<sfile>:p:h/')
20+
let g:include_path = resolve(current_dir . '/' . '../include')
21+
22+
python3 << EOF
23+
import sys
24+
25+
sys.path.append(vim.eval('g:include_path'))
26+
EOF
27+
""")
28+
f.write("\nsource " + vim_script_path)
29+
30+
with open(os.path.join(include_path, 'hello.py') , 'w') as f:
31+
f.write("""
32+
import vim
33+
34+
def world():
35+
# Emulate text write using vim python module
36+
vim.command("normal! i>> ")
37+
vim.command("normal! iHello world!")
38+
39+
return "This is a sample output returned"
40+
""")
41+
42+
print(f'Created plugin "{plugin_name}" in "{base_path}".')
43+
44+
def main():
45+
if len(sys.argv) != 2:
46+
print('Usage: create-vim-python-plugin <plugin_name>')
47+
sys.exit(1)
48+
49+
plugin_name = sys.argv[1]
50+
create_plugin(plugin_name)
51+
52+
if __name__ == '__main__':
53+
main()

setup.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from setuptools import setup
2+
3+
setup(
4+
name='vim-python-framework',
5+
version='0.1.0',
6+
description='A framework to easily create Vim plugins using Python',
7+
author='Your Name',
8+
author_email='your.email@example.com',
9+
packages=['vim_python_framework'],
10+
install_requires=[],
11+
entry_points={
12+
'console_scripts': [
13+
'create-vim-python-plugin=create_plugin:main',
14+
],
15+
},
16+
)

vim_python_framework/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
3+
def get_vim_framework_file():
4+
return os.path.join(os.path.dirname(os.path.abspath(__file__)), 'plugin/myplugin.vim')

0 commit comments

Comments
 (0)