Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def jekyllify(self):
logging.info('Now creating a Jekyll site out of this repo.')
with CdContext(self.directory):
# Copy Jekyll skeleton files to our new directory.
try:
skel_dir = resource_filename(__name__, 'jekyll-skel/')
except:
logging.warn("Couldn't find Jekyll skel directory.")
raise IOError("Couldn't find Jekyll skel directory!")
sh.cp('-a', skel_dir+'.', '.')
# Create header from template.
header = self.template_header()
# Prepend header to book markdown file.
doc = self.basename+'.md'
with open(doc, 'r') as origFile:
origContent = origFile.read()
with open(doc, 'w') as modifiedFile:
modifiedFile.write(header + '\n' + origContent)
sh.mv(doc, 'index.md')
# Remove it from git, since we've renamed it to index.md
sh.git('rm', doc)
for f in ['_config.yml', 'about.md']:
out = self.template_file(f)
def cythonize_build(self, env, build_dir='.'):
super(KivyRecipe, self).cythonize_build(env, build_dir=build_dir)
if not exists(join(build_dir, 'kivy', 'include')):
return
# If kivy is new enough to use the include dir, copy it
# manually to the right location as we bypass this stage of
# the build
with current_directory(build_dir):
build_libs_dirs = glob.glob(join('build', 'lib.*'))
for dirn in build_libs_dirs:
shprint(sh.cp, '-r', join('kivy', 'include'),
join(dirn, 'kivy'))
hostpython = sh.Command(self.ctx.hostpython)
try:
shprint(hostpython, '-OO', '-m', 'compileall', self.ctx.get_python_install_dir(),
_tail=10, _filterout="^Listing")
except sh.ErrorReturnCode:
pass
if not exists('python-install'):
shprint(sh.cp, '-a', self.ctx.get_python_install_dir(), './python-install')
self.distribute_libs(arch, [join(self.build_dir, 'libs', arch.arch), self.ctx.get_libs_dir(arch.arch)]);
self.distribute_aars(arch)
self.distribute_javaclasses(self.ctx.javaclass_dir)
info('Filling private directory')
if not exists(join('private', 'lib')):
shprint(sh.cp, '-a', join('python-install', 'lib'), 'private')
shprint(sh.mkdir, '-p', join('private', 'include', 'python2.7'))
shprint(sh.mv, join('libs', arch.arch, 'libpymodules.so'), 'private/')
shprint(sh.cp, join('python-install', 'include' , 'python2.7', 'pyconfig.h'), join('private', 'include', 'python2.7/'))
info('Removing some unwanted files')
shprint(sh.rm, '-f', join('private', 'lib', 'libpython2.7.so'))
shprint(sh.rm, '-rf', join('private', 'lib', 'pkgconfig'))
with current_directory(join(self.dist_dir, 'private', 'lib', 'python2.7')):
# shprint(sh.xargs, 'rm', sh.grep('-E', '*\.(py|pyx|so\.o|so\.a|so\.libs)$', sh.find('.')))
removes = []
for dirname, something, filens in walk('.'):
for filename in filens:
for suffix in ('py', 'pyc', 'so.o', 'so.a', 'so.libs'):
if filename.endswith(suffix):
def update_mace_run_binary(build_tmp_binary_dir, link_dynamic=False):
if link_dynamic:
mace_run_filepath = build_tmp_binary_dir + "/mace_run_dynamic"
else:
mace_run_filepath = build_tmp_binary_dir + "/mace_run_static"
if os.path.exists(mace_run_filepath):
sh.rm("-rf", mace_run_filepath)
if link_dynamic:
sh.cp("-f", "bazel-bin/mace/tools/mace_run_dynamic",
build_tmp_binary_dir)
else:
sh.cp("-f", "bazel-bin/mace/tools/mace_run_static",
build_tmp_binary_dir)
user = "mands"
password = 'abc' # input("Enter password for github user {}: ".format(user))
make.clean()
try:
# update code to latest tag
git.reset("--hard")
git.clean("-f", "-d")
git.pull("origin", "master", "--tags")
version = str(git.describe("--abbrev=0", "--tags")).strip()
git.checkout(version)
# run pyinstaller
sh.mkdir("-p", "./scripts/release")
sh.cp("../../toolkit/stackhut.py", "./")
sh.cp("../../toolkit/scripts/release/stackhut_lin.spec", "./scripts/release/")
pyinstaller('-y', '--clean', "./scripts/release/stackhut_lin.spec")
# TODO - run tests on bin version...
# build tarball
rel_name = "stackhut-{}-linux-x86_64.txz".format(version)
os.chdir("dist")
sh.tar("-cJf", rel_name, "./stackhut")
# upload to github releases
header = {'Accept': 'application/vnd.github.v3+json'}
# get the release info
r = requests.get("https://api.github.com/repos/StackHut/stackhut-toolkit/releases/tags/{}".format(version),
def create_python_bundle(self, dirn, arch):
ndk_dir = self.ctx.ndk_dir
py_recipe = self.ctx.python_recipe
python_dir = join(ndk_dir, 'sources', 'python',
py_recipe.version, 'libs', arch.arch)
shprint(sh.cp, '-r', join(python_dir,
'stdlib.zip'), dirn)
shprint(sh.cp, '-r', join(python_dir,
'modules'), dirn)
shprint(sh.cp, '-r', self.ctx.get_python_install_dir(),
join(dirn, 'site-packages'))
info('Renaming .so files to reflect cross-compile')
self.reduce_object_file_names(join(dirn, "site-packages"))
return join(dirn, 'site-packages')
def build_arch(self, arch):
env = self.get_recipe_env(arch)
with current_directory(join(self.get_build_dir(arch.arch), 'libmysqlclient')):
shprint(sh.cp, '-t', '.', join(self.get_recipe_dir(), 'p4a.cmake'))
# shprint(sh.mkdir, 'Platform')
# shprint(sh.cp, '-t', 'Platform', join(self.get_recipe_dir(), 'Linux.cmake'))
shprint(sh.rm, '-f', 'CMakeCache.txt')
shprint(sh.cmake, '-G', 'Unix Makefiles',
# '-DCMAKE_MODULE_PATH=' + join(self.get_build_dir(arch.arch), 'libmysqlclient'),
'-DCMAKE_INSTALL_PREFIX=./install',
'-DCMAKE_TOOLCHAIN_FILE=p4a.cmake', _env=env)
shprint(sh.make, _env=env)
self.install_libs(arch, join('libmysql', 'libmysql.so'))
arch = self.ctx.archs[0]
if len(self.ctx.archs) > 1:
raise ValueError('built for more than one arch, but bootstrap cannot handle that yet')
info('Bootstrap running with arch {}'.format(arch))
with current_directory(self.dist_dir):
info('Creating initial layout')
for dirname in ('assets', 'bin', 'private', 'res', 'templates'):
if not exists(dirname):
shprint(sh.mkdir, dirname)
info('Copying default files')
shprint(sh.cp, '-a', join(self.build_dir, 'project.properties'), '.')
shprint(sh.cp, '-a', join(src_path, 'build.py'), '.')
shprint(sh.cp, '-a', join(src_path, 'buildlib'), '.')
shprint(sh.cp, '-a', join(src_path, 'src'), '.')
shprint(sh.cp, '-a', join(src_path, 'templates'), '.')
shprint(sh.cp, '-a', join(src_path, 'res'), '.')
shprint(sh.cp, '-a', join(src_path, 'blacklist.txt'), '.')
shprint(sh.cp, '-a', join(src_path, 'whitelist.txt'), '.')
with open('local.properties', 'w') as fileh:
fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir))
info('Copying python distribution')
python_bundle_dir = join('_python_bundle', '_python_bundle')
if 'python2legacy' in self.ctx.recipe_build_order:
# a special case with its own packaging location
python_bundle_dir = 'private'
def run(self):
logger.info("Installing kubeyard completion...")
if self.completion_dst.exists() and not self.force:
logger.warning('File {} already exists. Skipping.'.format(str(self.completion_dst)))
else:
with tempfile.NamedTemporaryFile(mode='r') as f:
completion_dst_tmp = pathlib.Path(f.name)
kubeyard.files_generator.copy_template('kubeyard-completion.sh', completion_dst_tmp, replace=True)
completion_dst_tmp.chmod(0o644)
with sh.contrib.sudo(_with=True):
sh.cp(str(completion_dst_tmp), str(self.completion_dst))
input_name_list.append(input_nodes)
common.mace_check(len(input_file_list) == len(input_name_list),
common.ModuleName.RUN,
'If input_files set, the input files should '
'match the input names.')
for i in range(len(input_file_list)):
if input_file_list[i] is not None:
dst_input_file = model_output_dir + '/' + \
common.formatted_file_name(input_file_name,
input_name_list[i])
if input_file_list[i].startswith("http://") or \
input_file_list[i].startswith("https://"):
six.moves.urllib.request.urlretrieve(input_file_list[i],
dst_input_file)
else:
sh.cp("-f", input_file_list[i], dst_input_file)
else:
# generate random input files
input_nodes_str = ",".join(input_nodes)
input_shapes_str = ":".join(input_shapes)
input_ranges_str = ":".join(input_ranges)
input_data_types_str = ",".join(input_data_types)
generate_input_data("%s/%s" % (model_output_dir, input_file_name),
input_nodes_str,
input_shapes_str,
input_ranges_str,
input_data_types_str)