Skip to content
Snippets Groups Projects
Commit 2a09fd12 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI
Browse files

Merge branch 'conda-install' into 'master'

Update readme-template.rst - advertise conda installation for all packages

See merge request !51
parents cb30501d 3be273b1
No related branches found
No related tags found
1 merge request!51Update readme-template.rst - advertise conda installation for all packages
...@@ -62,5 +62,7 @@ condaforge_packages=("bob" \ ...@@ -62,5 +62,7 @@ condaforge_packages=("bob" \
"bob.db.iris") "bob.db.iris")
if contains_element ${CI_PROJECT_NAME} "${condaforge_packages[@]}"; then 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 fi
...@@ -8,9 +8,9 @@ except ImportError: ...@@ -8,9 +8,9 @@ except ImportError:
import requests import requests
import json import json
try: try:
from packaging.version import parse from packaging.version import parse
except ImportError: except ImportError:
from pip._vendor.packaging.version import parse from pip._vendor.packaging.version import parse
import re import re
import tempfile import tempfile
import shutil import shutil
...@@ -63,124 +63,128 @@ def get_remote_md5_sum(url, max_file_size=100 * 1024 * 1024): ...@@ -63,124 +63,128 @@ def get_remote_md5_sum(url, max_file_size=100 * 1024 * 1024):
class Gitlab(object): class Gitlab(object):
"""A class that wraps Gitlab API using curl""" """A class that wraps Gitlab API using curl"""
def __init__(self, token): def __init__(self, token):
super(Gitlab, self).__init__() super(Gitlab, self).__init__()
self.token = token self.token = token
self.base_url = 'https://gitlab.idiap.ch/api/v3/' self.base_url = 'https://gitlab.idiap.ch/api/v3/'
def get_project(self, project_name, namespace='bob'): def get_project(self, project_name, namespace='bob'):
cmd = ["curl", "--header", cmd = ["curl", "--header",
"PRIVATE-TOKEN: {}".format(self.token), "PRIVATE-TOKEN: {}".format(self.token),
self.base_url + "projects/{}%2F{}".format( self.base_url + "projects/{}%2F{}".format(
namespace, project_name)] namespace, project_name)]
pipeline = subprocess.check_output(cmd) pipeline = subprocess.check_output(cmd)
return json.loads(pipeline.decode()) return json.loads(pipeline.decode())
def create_pipeline(self, project_id): def create_pipeline(self, project_id):
cmd = ["curl", "--request", "POST", "--header", cmd = ["curl", "--request", "POST", "--header",
"PRIVATE-TOKEN: {}".format(self.token), "PRIVATE-TOKEN: {}".format(self.token),
self.base_url + "projects/{}/pipeline?ref=master".format( self.base_url + "projects/{}/pipeline?ref=master".format(
project_id)] project_id)]
pipeline = subprocess.check_output(cmd) pipeline = subprocess.check_output(cmd)
return json.loads(pipeline.decode()) return json.loads(pipeline.decode())
def get_pipeline(self, project_id, pipeline_id): def get_pipeline(self, project_id, pipeline_id):
cmd = ["curl", "--header", cmd = ["curl", "--header",
"PRIVATE-TOKEN: {}".format(self.token), "PRIVATE-TOKEN: {}".format(self.token),
self.base_url + "projects/{}/pipelines/{}".format( self.base_url + "projects/{}/pipelines/{}".format(
project_id, pipeline_id)] project_id, pipeline_id)]
pipeline = subprocess.check_output(cmd) pipeline = subprocess.check_output(cmd)
return json.loads(pipeline.decode()) return json.loads(pipeline.decode())
def create_merge_request(self, project_id, source_branch, target_branch, def create_merge_request(self, project_id, source_branch, target_branch,
title, assignee_id='', description='', title, assignee_id='', description='',
target_project_id='', labels='', milestone_id='', target_project_id='', labels='', milestone_id='',
remove_source_branch=''): remove_source_branch=''):
url = "projects/{}/merge_requests?" url = "projects/{}/merge_requests?"
url += "&".join(['source_branch={}', 'target_branch={}', 'title={}', url += "&".join(['source_branch={}', 'target_branch={}', 'title={}',
'assignee_id={}', 'description={}', 'assignee_id={}', 'description={}',
'target_project_id={}', 'labels={}', 'target_project_id={}', 'labels={}',
'milestone_id={}', 'remove_source_branch={}']) 'milestone_id={}', 'remove_source_branch={}'])
url = url.format(project_id, source_branch, target_branch, title, url = url.format(project_id, source_branch, target_branch, title,
assignee_id, description, target_project_id, labels, assignee_id, description, target_project_id, labels,
milestone_id, remove_source_branch) milestone_id, remove_source_branch)
cmd = ["curl", "--request", "POST", "--header", cmd = ["curl", "--request", "POST", "--header",
"PRIVATE-TOKEN: {}".format(self.token), "PRIVATE-TOKEN: {}".format(self.token),
self.base_url + url] self.base_url + url]
pipeline = subprocess.check_output(cmd) pipeline = subprocess.check_output(cmd)
return json.loads(pipeline.decode()) return json.loads(pipeline.decode())
def main(package, direct_push=False): def update_meta(meta_path, package):
stable_version = get_version(package) stable_version = get_version(package)
print('latest stable version for {} is {}'.format(package, stable_version)) print('latest stable version for {} is {}'.format(package, stable_version))
url = 'https://pypi.io/packages/source/{0}/{1}/{1}-{2}.zip'.format( url = 'https://pypi.io/packages/source/{0}/{1}/{1}-{2}.zip'.format(
package[0], package, stable_version) package[0], package, stable_version)
try: md5 = get_remote_md5_sum(url)
md5 = get_remote_md5_sum(url) with open(meta_path) as f:
except Exception: doc = f.read()
raise 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() temp_dir = tempfile.mkdtemp()
try: try:
print("\nClonning bob.conda") print("\nClonning bob.conda")
root = os.path.join(temp_dir, '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: try:
run_commands( run_commands(
['git', 'clone', ['git', 'clone',
'git@gitlab.idiap.ch:bob/bob.conda.git', 'git@gitlab.idiap.ch:bob/bob.conda.git',
root]) root])
except ValueError: except ValueError:
print("\nFailed to clone `bob.conda`, Exiting ...") print("\nFailed to clone `bob.conda`, Exiting ...")
raise raise
branch_name = '{}-{}'.format(package, stable_version)
os.chdir(feedstock) os.chdir(feedstock)
if not direct_push:
run_commands(
['git', 'checkout', '-b', branch_name])
# update meta.yaml # update meta.yaml
meta_path = 'meta.yaml' meta_path = 'meta.yaml'
with open(meta_path) as f: stable_version = update_meta(meta_path, package)
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: branch_name = '{}-{}'.format(package, stable_version)
f.write(doc) if not direct_push:
run_commands(
['git', 'checkout', '-b', branch_name])
run_commands(['git', '--no-pager', 'diff'], run_commands(['git', '--no-pager', 'diff'],
['git', 'config', 'user.email', ['git', 'config', 'user.email',
...@@ -198,7 +202,8 @@ def main(package, direct_push=False): ...@@ -198,7 +202,8 @@ def main(package, direct_push=False):
if direct_push: if direct_push:
print(feedstock) print(feedstock)
try: 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: except Exception:
answer = input('Would you like to push directly to master?').lower() answer = input('Would you like to push directly to master?').lower()
if answer.startswith('y') or answer == '': if answer.startswith('y') or answer == '':
...@@ -223,5 +228,4 @@ def main(package, direct_push=False): ...@@ -223,5 +228,4 @@ def main(package, direct_push=False):
if __name__ == '__main__': if __name__ == '__main__':
import sys import sys
pkg = sys.argv[1] main(*sys.argv[1:])
main(pkg)
...@@ -243,3 +243,7 @@ text files to be placed along `conf.py` (on the same directory): ...@@ -243,3 +243,7 @@ text files to be placed along `conf.py` (on the same directory):
## 7. Update the logo on your project ## 7. Update the logo on your project
Please update the logo of your project (on the Settings), just set it to [this one](templates/bob-128x128.png). Please update the logo of your project (on the Settings), just set it to [this one](templates/bob-128x128.png).
## 8. Create a conda recipe for the package
Please create a conda build recipte for the new package and put it in bob.conda.
...@@ -28,10 +28,9 @@ Bob_. <SHORTINTRO> ...@@ -28,10 +28,9 @@ Bob_. <SHORTINTRO>
Installation Installation
------------ ------------
Follow our `installation`_ instructions. Then, using the Python interpreter Follow our `installation`_ instructions. Then, to install this pacakge, run::
provided by the distribution, build this package with::
$ buildout $ conda install <PACKAGE>
Contact Contact
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment