From 3be273b14035253a202ec58223ab62b75bcb5010 Mon Sep 17 00:00:00 2001 From: Amir Mohammadi <183.amir@gmail.com> Date: Wed, 3 May 2017 16:34:38 +0200 Subject: [PATCH] update recipes of other packages on bob.conda too --- gitlab/deploy.sh | 4 +- gitlab/update_feedstock.py | 218 +++++++++++++++++++------------------ 2 files changed, 114 insertions(+), 108 deletions(-) diff --git a/gitlab/deploy.sh b/gitlab/deploy.sh index dafa0aa..4302e07 100755 --- a/gitlab/deploy.sh +++ b/gitlab/deploy.sh @@ -56,5 +56,7 @@ condaforge_packages=("bob" \ "bob.db.iris") if contains_element ${CI_PROJECT_NAME} "${condaforge_packages[@]}"; then - run_cmd ${CONDA_FOLDER}/bin/python _ci/update_feedstock.py ${CI_PROJECT_NAME} + run_cmd ${CONDA_FOLDER}/bin/python _ci/update_feedstock.py ${CI_PROJECT_NAME} recipes +else + run_cmd ${CONDA_FOLDER}/bin/python _ci/update_feedstock.py ${CI_PROJECT_NAME} skeleton fi diff --git a/gitlab/update_feedstock.py b/gitlab/update_feedstock.py index 2e449c9..3ebf7e0 100755 --- a/gitlab/update_feedstock.py +++ b/gitlab/update_feedstock.py @@ -8,9 +8,9 @@ except ImportError: import requests import json try: - from packaging.version import parse + from packaging.version import parse except ImportError: - from pip._vendor.packaging.version import parse + from pip._vendor.packaging.version import parse import re import tempfile import shutil @@ -63,124 +63,128 @@ def get_remote_md5_sum(url, max_file_size=100 * 1024 * 1024): class Gitlab(object): - """A class that wraps Gitlab API using curl""" - - def __init__(self, token): - super(Gitlab, self).__init__() - self.token = token - self.base_url = 'https://gitlab.idiap.ch/api/v3/' - - def get_project(self, project_name, namespace='bob'): - cmd = ["curl", "--header", - "PRIVATE-TOKEN: {}".format(self.token), - self.base_url + "projects/{}%2F{}".format( - namespace, project_name)] - pipeline = subprocess.check_output(cmd) - return json.loads(pipeline.decode()) - - def create_pipeline(self, project_id): - cmd = ["curl", "--request", "POST", "--header", - "PRIVATE-TOKEN: {}".format(self.token), - self.base_url + "projects/{}/pipeline?ref=master".format( - project_id)] - pipeline = subprocess.check_output(cmd) - return json.loads(pipeline.decode()) - - def get_pipeline(self, project_id, pipeline_id): - cmd = ["curl", "--header", - "PRIVATE-TOKEN: {}".format(self.token), - self.base_url + "projects/{}/pipelines/{}".format( - project_id, pipeline_id)] - pipeline = subprocess.check_output(cmd) - return json.loads(pipeline.decode()) - - def create_merge_request(self, project_id, source_branch, target_branch, - title, assignee_id='', description='', - target_project_id='', labels='', milestone_id='', - remove_source_branch=''): - url = "projects/{}/merge_requests?" - url += "&".join(['source_branch={}', 'target_branch={}', 'title={}', - 'assignee_id={}', 'description={}', - 'target_project_id={}', 'labels={}', - 'milestone_id={}', 'remove_source_branch={}']) - url = url.format(project_id, source_branch, target_branch, title, - assignee_id, description, target_project_id, labels, - milestone_id, remove_source_branch) - cmd = ["curl", "--request", "POST", "--header", - "PRIVATE-TOKEN: {}".format(self.token), - self.base_url + url] - pipeline = subprocess.check_output(cmd) - return json.loads(pipeline.decode()) - - -def main(package, direct_push=False): + """A class that wraps Gitlab API using curl""" + + def __init__(self, token): + super(Gitlab, self).__init__() + self.token = token + self.base_url = 'https://gitlab.idiap.ch/api/v3/' + + def get_project(self, project_name, namespace='bob'): + cmd = ["curl", "--header", + "PRIVATE-TOKEN: {}".format(self.token), + self.base_url + "projects/{}%2F{}".format( + namespace, project_name)] + pipeline = subprocess.check_output(cmd) + return json.loads(pipeline.decode()) + + def create_pipeline(self, project_id): + cmd = ["curl", "--request", "POST", "--header", + "PRIVATE-TOKEN: {}".format(self.token), + self.base_url + "projects/{}/pipeline?ref=master".format( + project_id)] + pipeline = subprocess.check_output(cmd) + return json.loads(pipeline.decode()) + + def get_pipeline(self, project_id, pipeline_id): + cmd = ["curl", "--header", + "PRIVATE-TOKEN: {}".format(self.token), + self.base_url + "projects/{}/pipelines/{}".format( + project_id, pipeline_id)] + pipeline = subprocess.check_output(cmd) + return json.loads(pipeline.decode()) + + def create_merge_request(self, project_id, source_branch, target_branch, + title, assignee_id='', description='', + target_project_id='', labels='', milestone_id='', + remove_source_branch=''): + url = "projects/{}/merge_requests?" + url += "&".join(['source_branch={}', 'target_branch={}', 'title={}', + 'assignee_id={}', 'description={}', + 'target_project_id={}', 'labels={}', + 'milestone_id={}', 'remove_source_branch={}']) + url = url.format(project_id, source_branch, target_branch, title, + assignee_id, description, target_project_id, labels, + milestone_id, remove_source_branch) + cmd = ["curl", "--request", "POST", "--header", + "PRIVATE-TOKEN: {}".format(self.token), + self.base_url + url] + pipeline = subprocess.check_output(cmd) + return json.loads(pipeline.decode()) + + +def update_meta(meta_path, package): stable_version = get_version(package) print('latest stable version for {} is {}'.format(package, stable_version)) url = 'https://pypi.io/packages/source/{0}/{1}/{1}-{2}.zip'.format( - package[0], package, stable_version) - try: - md5 = get_remote_md5_sum(url) - except Exception: - raise + package[0], package, stable_version) + md5 = get_remote_md5_sum(url) + with open(meta_path) as f: + doc = f.read() + build_number = '0' + doc = re.sub(r'\{\s?%\s?set\s?version\s?=\s?".*"\s?%\s?\}', + '{% set version = "' + str(stable_version) + '" %}', + doc, count=1) + doc = re.sub(r'\s+number\:\s?[0-9]+', '\n number: ' + build_number, doc, + count=1) + doc = re.sub(r'\{\s?%\s?set\s?build_number\s?=\s?"[0-9]+"\s?%\s?\}', + '{% set build_number = "' + build_number + '" %}', + doc, count=1) + doc = re.sub(r'\s+md5\:.*', '\n md5: {}'.format(md5), doc, count=1) + doc = re.sub(r'\s+url\:.*', + '\n url: {}'.format( + url.replace(stable_version, '{{ version }}')), + doc, count=1) + doc = re.sub(r'\s+home\:.*', + '\n home: https://www.idiap.ch/software/bob/', + doc, count=1) + doc = doc.replace('Modified BSD License (3-clause)', 'BSD 3-Clause') + + if package == 'bob': + requrl = 'https://gitlab.idiap.ch/bob/bob/raw/master/requirements.txt' + remote = requests.get(requrl) + req = remote.content.decode() + req = '\n - '.join(req.replace('== ', '==').strip().split('\n')) + be_id = doc.find('bob.extension') + te_id = doc.find('test:\n', be_id) + template = '''{req} + +run: + - python + - {req} + +'''.format(req=req) + doc = doc[:be_id] + template + doc[te_id:] + + with open(meta_path, 'w') as f: + f.write(doc) + + return stable_version + + +def main(package, subfolder='recipes', direct_push=False): temp_dir = tempfile.mkdtemp() try: print("\nClonning bob.conda") root = os.path.join(temp_dir, 'bob.conda') - feedstock = os.path.join(root, 'recipes', package) + feedstock = os.path.join(root, subfolder, package) try: run_commands( - ['git', 'clone', - 'git@gitlab.idiap.ch:bob/bob.conda.git', - root]) + ['git', 'clone', + 'git@gitlab.idiap.ch:bob/bob.conda.git', + root]) except ValueError: print("\nFailed to clone `bob.conda`, Exiting ...") raise - branch_name = '{}-{}'.format(package, stable_version) os.chdir(feedstock) - if not direct_push: - run_commands( - ['git', 'checkout', '-b', branch_name]) # update meta.yaml meta_path = 'meta.yaml' - with open(meta_path) as f: - doc = f.read() - build_number = '0' - doc = re.sub(r'\{\s?%\s?set\s?version\s?=\s?".*"\s?%\s?\}', - '{% set version = "' + str(stable_version) + '" %}', - doc, count=1) - doc = re.sub(r'\s+number\:\s?[0-9]+', '\n number: ' + build_number, doc, - count=1) - doc = re.sub(r'\{\s?%\s?set\s?build_number\s?=\s?"[0-9]+"\s?%\s?\}', - '{% set build_number = "' + build_number + '" %}', - doc, count=1) - doc = re.sub(r'\s+md5\:.*', '\n md5: {}'.format(md5), doc, count=1) - doc = re.sub(r'\s+url\:.*', - '\n url: {}'.format( - url.replace(stable_version, '{{ version }}')), - doc, count=1) - doc = re.sub(r'\s+home\:.*', - '\n home: https://www.idiap.ch/software/bob/', - doc, count=1) - doc = doc.replace('Modified BSD License (3-clause)', 'BSD 3-Clause') - - if package == 'bob': - requrl = 'https://gitlab.idiap.ch/bob/bob/raw/master/requirements.txt' - remote = requests.get(requrl) - req = remote.content.decode() - req = '\n - '.join(req.replace('== ', '==').strip().split('\n')) - be_id = doc.find('bob.extension') - te_id = doc.find('test:\n', be_id) - template = '''{req} - - run: - - python - - {req} - -'''.format(req=req) - doc = doc[:be_id] + template + doc[te_id:] + stable_version = update_meta(meta_path, package) - with open(meta_path, 'w') as f: - f.write(doc) + branch_name = '{}-{}'.format(package, stable_version) + if not direct_push: + run_commands( + ['git', 'checkout', '-b', branch_name]) run_commands(['git', '--no-pager', 'diff'], ['git', 'config', 'user.email', @@ -198,7 +202,8 @@ def main(package, direct_push=False): if direct_push: print(feedstock) try: - answer = raw_input('Would you like to push directly to master?').lower() + answer = raw_input( + 'Would you like to push directly to master?').lower() except Exception: answer = input('Would you like to push directly to master?').lower() if answer.startswith('y') or answer == '': @@ -223,5 +228,4 @@ def main(package, direct_push=False): if __name__ == '__main__': import sys - pkg = sys.argv[1] - main(pkg) + main(*sys.argv[1:]) -- GitLab