forked from psyplot/psyplot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin_template.py
More file actions
67 lines (57 loc) · 1.91 KB
/
plugin_template.py
File metadata and controls
67 lines (57 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Module for creating a new template for a psyplot plugin
"""
import funcargparse
import os
import os.path as osp
import shutil
def new_plugin(odir, py_name=None, version='0.0.1.dev0',
description='New plugin'):
"""
Create a new plugin for the psyplot package
Parameters
----------
odir: str
The name of the directory where the data will be copied to. The
directory must not exist! The name of the directory also defines the
name of the package.
py_name: str
The name of the python package. If None, the basename of `odir` is used
(and ``'-'`` is replaced by ``'_'``)
version: str
The version of the package
description: str
The description of the plugin"""
name = osp.basename(odir)
if py_name is None:
py_name = name.replace('-', '_')
src = osp.join(osp.dirname(__file__), 'plugin-template-files')
# copy the source files
shutil.copytree(src, odir)
os.rename(osp.join(odir, 'plugin_template'), osp.join(odir, py_name))
replacements = {'PLUGIN_NAME': name,
'PLUGIN_PYNAME': py_name,
'PLUGIN_VERSION': version,
'PLUGIN_DESC': description,
}
files = [
'README.md',
'setup.py',
osp.join(py_name, 'plugin.py'),
osp.join(py_name, 'plotters.py'),
osp.join(py_name, '__init__.py'),
]
for fname in files:
with open(osp.join(odir, fname)) as f:
s = f.read()
for key, val in replacements.items():
s = s.replace(key, val)
with open(osp.join(odir, fname), 'w') as f:
f.write(s)
def main(args=None):
parser = funcargparse.FuncArgParser()
parser.setup_args(new_plugin)
parser.update_short(version='v', description='d')
parser.create_arguments()
parser.parse2func(args)
if __name__ == '__main__':
main()