-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrecipe_from_setup.py
65 lines (43 loc) · 1.63 KB
/
recipe_from_setup.py
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
"""Add the missing informations to the conda recipe and build the conda package
This script fills in the necessary informations into meta.yaml and builds the
conda package of the given package in the psyplot framework.
Call signature::
python build_package.py <path-to-package>
"""
import os.path as osp
import yaml
import argparse
def get_directory(s):
return osp.dirname(osp.join(s, ''))
parser = argparse.ArgumentParser(
description='Create a conda receipt from python source files')
parser.add_argument('package', help="The path to the Python package",
type=get_directory)
parser.add_argument('outdir', type=get_directory, help="""
The output directory. The recipe will be in `outdir`/`basename package`.
""")
args = parser.parse_args()
# Will be set down below from version.py
__version__ = None
#: The path to the package
path = args.package
#: The path for the output. It already has to include a file called
#: 'meta.template'. Otherwise, conda skeleton will be run
outdir = args.outdir
#: The name of the package
package = osp.basename(path)
# set __version__
with open(osp.join(path, package.replace('-', '_'), 'version.py')) as f:
exec(f.read())
assert __version__ is not None, (
"__version__ has not been set in version.py!")
version = __version__
template_file = osp.join(outdir, package, 'meta.template')
# Read the meta.template
with open(template_file) as f:
meta = yaml.load(f)
# fill in the missing informations
meta['package']['version'] = version
# write out the recipe
with open(osp.join(outdir, package, 'meta.yaml'), 'w') as f:
yaml.dump(meta, f, default_flow_style=False)