-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanacondabump
executable file
·119 lines (93 loc) · 3.33 KB
/
anacondabump
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python3
# -*- coding: utf8 -*-
"""
A script to automatically update python modules on anaconda.
See the README.md file for more information.
"""
# Built-in modules #
import os, sys, argparse, re
# First party modules #
from autopaths.tmp_path import new_temp_dir
from plumbing.check_cmd_found import check_cmd
# Third party modules #
import sh
sh_version = int(sh.__version__.split('.')[0])
if sh_version > 1: sh = sh.bake(_return_cmd=True)
# Constants #
__version__ = '1.3.0'
# Create a shell parser #
parser = argparse.ArgumentParser(description=sys.modules[__name__].__doc__)
# Ask for the main argument #
help_msg = "The name of the module to process."
parser.add_argument("module", help=help_msg, type=str)
# Optional testing mode
parser.add_argument("--test", action='store_true')
# Parse the shell arguments #
args = parser.parse_args()
pkg_name = args.module
test_mode = args.test
# Also we need to make sure that all executables are available #
check_cmd('conda')
check_cmd('conda-build')
check_cmd('grayskull')
check_cmd('anaconda')
# Create a new temporary directory and switch to it #
tmp_dir = new_temp_dir()
old_cwd = os.getcwd()
os.chdir(tmp_dir)
# Print start #
print("Packaging '%s' for anaconda distribution." % pkg_name)
print("---------------------------")
print("Using temporary directory '%s'." % tmp_dir)
################################################################################
# Create a skeleton #
print("---------------------------")
if test_mode:
print("-> Making a skeleton from the test PyPI index")
skeleton = sh.grayskull('pypi', '--pypi-url',
'https://test.pypi.io/pypi/', pkg_name,
_out=sys.stdout, _err=sys.stderr)
else:
print("-> Making a skeleton from the real PyPI index")
skeleton = sh.grayskull('pypi', pkg_name,
_out=sys.stdout, _err=sys.stderr)
# Get the metadata file #
meta_file = tmp_dir + pkg_name + '/meta.yaml'
assert meta_file.exists
# Add other dependencies to the metadata file depending on package #
#if pkg_name == 'crest4':
# meta_file.replace_line(" run:", " run:\n - blast\n - vsearch")
################################################################################
# Build #
print("---------------------------")
print("-> Building package")
# Launch command #
conda_build = sh.Command('conda-build')
build = conda_build(pkg_name, '-c', 'conda-forge',
'-c', 'xapple',
'-c', 'bioconda')
# Find the tar path #
text = str(build.stdout, "UTF-8")
# Get the path of the resulting tar files #
pattern = "(/.+\.tar\.bz2)$"
hits = re.findall(pattern, text, re.MULTILINE)
# Take the last hit #
assert len(hits) > 0
tar_path = hits[-1]
# Report the path #
print("---------------------------")
print("-> Tar path found: %s" % tar_path)
################################################################################
# Upload #
print("---------------------------")
print("-> Uploading package")
# Don't forget to run "$ anaconda login" first.
# The skip options will skip a package that already exists
# Switch to '--force' to overwrite existing packages
upload = sh.anaconda('upload', '--skip', tar_path)
# Optional message #
print(str(upload.stderr, "UTF-8"))
# Done #
print("Success.")
# Back to original directory #
os.chdir(old_cwd)