Skip to content

Commit 9abb0fc

Browse files
authored
Merge pull request #36 from vsoch/master
adding build specs to singularity python to close #35
2 parents a40b2be + 5a0a3bc commit 9abb0fc

22 files changed

+182
-233
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ install:
1414
- cd $TRAVIS_BUILD_DIR/
1515
- cd $TRAVIS_BUILD_DIR && pip install -r requirements.txt
1616
- cd $TRAVIS_BUILD_DIR && pip3 install -r requirements.txt
17+
- python setup.py sdist
18+
- python setup.py install
1719
- pylint --version
18-
# - cd $TRAVIS_BUILD_DIR/libexec/python && pylint $PWD --errors-only --ignore tests --disable=E0401,E0611
1920

2021
script:
21-
- bash $TRAVIS_BUILD_DIR/singularity/testing/run_tests.sh $TRAVIS_BUILD_DIR/singularity/testing /tmp
22+
- python -m unittest discover -s $TRAVIS_BUILD_DIR/singularity/tests/ -p '[t|T]est*.py'
23+
#bash $TRAVIS_BUILD_DIR/singularity/tests/run_tests.sh $TRAVIS_BUILD_DIR/singularity/tests /tmp

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515

1616
# Packages
1717
packages=find_packages(),
18-
18+
1919
# Data files
2020
include_package_data=True,
21+
2122
zip_safe=False,
2223

2324
# Details

singularity/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def api_get(url,headers=None,token=None,data=None):
7373
:param headers: a dictionary with headers for the request
7474
:param putdata: additional data to add to the request
7575
'''
76-
bot.logger.debug("GET ",url)
76+
bot.logger.debug("GET %s",url)
7777

7878
if headers == None:
7979
headers = get_headers(token=token)
@@ -94,7 +94,7 @@ def api_put(url,headers=None,token=None,data=None):
9494
:param headers: a dictionary with headers for the request
9595
:param data: additional data to add to the request
9696
'''
97-
bot.logger.debug("PUT ",url)
97+
bot.logger.debug("PUT %s",url)
9898

9999
if headers == None:
100100
headers = get_headers(token=token)
@@ -115,7 +115,7 @@ def api_post(url,headers=None,data=None,token=None):
115115
:param headers: a dictionary with headers for the request
116116
:param data: additional data to add to the request
117117
'''
118-
bot.logger.debug("POST ",url)
118+
bot.logger.debug("POST %s",url)
119119

120120
if headers == None:
121121
headers = get_headers(token=token)
Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
#!/usr/bin/env python
22

33
'''
4-
build.py: functions for singularity hub builders
4+
build/google.py: build functions for singularity hub google compute engine
55
66
'''
77

8-
from singularity.api import api_get, api_put, api_post
9-
from singularity.package import build_from_spec, package
10-
from singularity.utils import get_installdir, read_file, write_file, download_repo
8+
from singularity.api import (
9+
api_get,
10+
api_put,
11+
api_post
12+
)
13+
14+
from singularity.package import (
15+
build_from_spec,
16+
package
17+
)
18+
19+
from singularity.utils import (
20+
get_installdir,
21+
read_file,
22+
write_file,
23+
download_repo
24+
)
1125

1226
from googleapiclient.discovery import build
1327
from oauth2client.client import GoogleCredentials
@@ -79,7 +93,7 @@ def upload_file(storage_service,bucket,bucket_path,file_name,verbose=True):
7993
return request.execute()
8094

8195

82-
def list_bucket(bucket):
96+
def list_bucket(bucket,storage_service):
8397
# Create a request to objects.list to retrieve a list of objects.
8498
request = storage_service.objects().list(bucket=bucket['id'],
8599
fields='nextPageToken,items(name,size,contentType)')
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
sudo apt-get update
3+
sudo apt-get -y install git
4+
sudo apt-get install -y build-essential libtool autotools-dev automake autoconf
5+
sudo apt-get install -y python3-pip
6+
cd /tmp && git clone http://www.github.com/singularityware/singularity
7+
cd singularity && ./autogen.sh && ./configure --prefix=/usr/local && make && sudo make install
8+
SINGULARITY_VERSION=$(singularity --version)
9+
sudo pip3 install --upgrade pip
10+
sudo pip3 install --upgrade google-api-python-client
11+
sudo pip3 install --upgrade google
12+
sudo pip3 install oauth2client==3.0.0
13+
sudo pip3 install gitpython
14+
cd /tmp && git clone https://github.com/singularityware/singularity-python
15+
cd singularity-python && python3 setup.py sdist && sudo python3 setup.py install
16+
python3 -c "from singularity.build.google import run_build; run_build()" > /tmp/.shub-log 2>&1
17+
command=$(echo "from singularity.build.google import finish_build; finish_build(logfile='/tmp/.shub-log',version='$SINGULARITY_VERSION')")
18+
python3 -c "$command"

singularity/build/utils.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python
2+
3+
'''
4+
build/utils.py: general building util functions
5+
6+
'''
7+
8+
import os
9+
import re
10+
11+
import shutil
12+
import simplejson
13+
from singularity.logman import bot
14+
15+
from singularity.utils import (
16+
get_installdir,
17+
read_file
18+
)
19+
20+
import sys
21+
22+
import subprocess
23+
24+
import tempfile
25+
import zipfile
26+
27+
28+
######################################################################################
29+
# Build Templates
30+
######################################################################################
31+
32+
def get_build_template(template_name,params=None,to_file=None):
33+
'''get_build template returns a string or file for a particular build template, which is
34+
intended to build a version of a Singularity image on a cloud resource.
35+
:param template_name: the name of the template to retrieve in build/scripts
36+
:param params: (if needed) a dictionary of parameters to substitute in the file
37+
:param to_file: if defined, will write to file. Default returns string.
38+
'''
39+
base = get_installdir()
40+
template_folder = "%s/build/scripts" %(base)
41+
template_file = "%s/%s" %(template_folder,template_name)
42+
if os.path.exists(template_file):
43+
bot.logger.debug("Found template %s",template_file)
44+
45+
# Implement when needed - substitute params here
46+
# Will need to read in file instead of copying below
47+
# if params != None:
48+
49+
if to_file != None:
50+
shutil.copyfile(template_file,to_file)
51+
bot.logger.debug("Template file saved to %s",to_file)
52+
return to_file
53+
54+
# If the user wants a string
55+
content = ''.join(read_file(template_file))
56+
return content
57+
58+
59+
else:
60+
bot.logger.warning("Template %s not found.",template_file)
61+
return None

singularity/runscript.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,9 @@ def get_runscript_parameters(runscript,name,version,description=None):
8585

8686
if language == 'python':
8787
params = get_parameters_python(runscript)
88+
# TODO: here we would write something like boutiqes spec
8889

89-
# Finally, make a boutiques json object with the parameters
90-
if params != None:
91-
json_spec = get_boutiques_json(name=name,
92-
version=version,
93-
inputs=params,
94-
command=name,
95-
description=description)
96-
97-
return json_spec
90+
return params
9891

9992

10093
def get_parameters_python(runscript):

singularity/scripts/docker2singularity.sh

Lines changed: 0 additions & 121 deletions
This file was deleted.

singularity/testing/data/debian.def

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)