Skip to content

Commit 1151201

Browse files
committed
updating setup to be more robust with versioning, etc.
1 parent d0b5737 commit 1151201

File tree

7 files changed

+159
-181
lines changed

7 files changed

+159
-181
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ flask
22
flask-restful
33
pandas
44
requests
5+
retrying
56
selenium
67
simplejson
78
scikit-learn

setup.py

Lines changed: 85 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,96 @@
22
import codecs
33
import os
44

5-
setup(
6-
# Application name:
7-
name="singularity",
5+
##########################################################################################
6+
# HELPER FUNCTIONS #######################################################################
7+
##########################################################################################
88

9-
# Version number:
10-
version="0.91",
9+
def get_lookup():
10+
'''get version by way of singularity.version, returns a
11+
lookup dictionary with several global variables without
12+
needing to import singularity
13+
'''
14+
lookup = dict()
15+
version_file = os.path.join('singularity', 'version.py')
16+
with open(version_file) as filey:
17+
exec(filey.read(), lookup)
18+
return lookup
1119

12-
# Application author details:
13-
author="Vanessa Sochat",
14-
author_email="[email protected]",
20+
# Read in requirements
21+
def get_requirements(lookup=None):
22+
'''get_requirements reads in requirements and versions from
23+
the lookup obtained with get_lookup'''
1524

16-
# Packages
17-
packages=find_packages(),
18-
19-
# Data files
20-
include_package_data=True,
21-
zip_safe=False,
25+
if lookup == None:
26+
lookup = get_lookup()
2227

23-
# Details
24-
url="http://www.github.com/singularityware/singularity-python",
28+
install_requires = []
29+
for module in lookup['INSTALL_REQUIRES']:
30+
module_name = module[0]
31+
module_meta = module[1]
32+
if "exact_version" in module_meta:
33+
dependency = "%s==%s" %(module_name,module_meta['exact_version'])
34+
elif "min_version" in module_meta:
35+
if module_meta['min_version'] == None:
36+
dependency = module_name
37+
else:
38+
dependency = "%s>=%s" %(module_name,module_meta['min_version'])
39+
install_requires.append(dependency)
40+
return install_requires
2541

26-
license="LICENSE",
27-
description="Command line tool for working with singularity-hub and packaging singularity containers.",
28-
keywords='singularity containers hub reproducibility package science',
2942

30-
install_requires = ['Flask','flask-restful','selenium','simplejson','scikit-learn','pygments',
31-
'requests','oauth2client','google-api-python-client','pandas'],
3243

33-
entry_points = {
34-
'console_scripts': [
35-
'shub=singularity.scripts:main',
36-
],
37-
},
44+
# Make sure everything is relative to setup.py
45+
install_path = os.path.dirname(os.path.abspath(__file__))
46+
os.chdir(install_path)
3847

39-
)
48+
# Get version information from the lookup
49+
lookup = get_lookup()
50+
VERSION = lookup['__version__']
51+
NAME = lookup['NAME']
52+
AUTHOR = lookup['AUTHOR']
53+
AUTHOR_EMAIL = lookup['AUTHOR_EMAIL']
54+
PACKAGE_URL = lookup['PACKAGE_URL']
55+
KEYWORDS = lookup['KEYWORDS']
56+
DESCRIPTION = lookup['DESCRIPTION']
57+
LICENSE = lookup['LICENSE']
58+
with open('README.md') as filey:
59+
LONG_DESCRIPTION = filey.read()
60+
61+
##########################################################################################
62+
# MAIN ###################################################################################
63+
##########################################################################################
64+
65+
66+
if __name__ == "__main__":
67+
68+
INSTALL_REQUIRES = get_requirements(lookup)
69+
70+
setup(name=NAME,
71+
version=VERSION,
72+
author=AUTHOR,
73+
author_email=AUTHOR_EMAIL,
74+
maintainer=AUTHOR,
75+
maintainer_email=AUTHOR_EMAIL,
76+
packages=find_packages(),
77+
include_package_data=True,
78+
zip_safe=False,
79+
url=PACKAGE_URL,
80+
license=LICENSE,
81+
description=DESCRIPTION,
82+
long_description=LONG_DESCRIPTION,
83+
keywords=KEYWORDS,
84+
install_requires = INSTALL_REQUIRES,
85+
classifiers=[
86+
'Intended Audience :: Science/Research',
87+
'Intended Audience :: Developers',
88+
'License :: OSI Approved :: MIT License',
89+
'Programming Language :: C',
90+
'Programming Language :: Python',
91+
'Topic :: Software Development',
92+
'Topic :: Scientific/Engineering',
93+
'Operating System :: Unix',
94+
'Programming Language :: Python :: 2.7',
95+
'Programming Language :: Python :: 3',
96+
],
97+
entry_points = {'console_scripts': [ 'shub=singularity.scripts:main' ] })

singularity/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from singularity.version import __version__
2+
3+
__all__ = ['analysis', 'build', 'views', 'api',
4+
'app', 'cli', 'logman', 'scripts',
5+
'utils', '__version__']

singularity/build/google.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import pickle
3737
import re
3838
import requests
39+
from retrying import retry
3940
import sys
4041
import tempfile
4142
import time
@@ -47,24 +48,35 @@
4748
from singularity.logman import bot
4849

4950
##########################################################################################
50-
# GOOGLE STORAGE API #####################################################################
51+
# GOOGLE GENERAL API #####################################################################
5152
##########################################################################################
5253

53-
def get_storage_service():
54+
def get_google_service(service_type=None,version=None):
55+
'''
56+
get_url will use the requests library to get a url
57+
:param service_type: the service to get (default is storage)
58+
:param version: version to use (default is v1)
59+
'''
60+
if service_type == None:
61+
service_type = "storage"
62+
if version == None:
63+
version = "v1"
64+
5465
credentials = GoogleCredentials.get_application_default()
55-
return build('storage', 'v1', credentials=credentials)
66+
return build(service_type, version, credentials=credentials)
5667

5768

58-
def get_compute_service():
59-
credentials = GoogleCredentials.get_application_default()
60-
return build('compute', 'v1', credentials=credentials)
69+
##########################################################################################
70+
# GOOGLE STORAGE API #####################################################################
71+
##########################################################################################
6172

62-
73+
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000)
6374
def get_bucket(storage_service,bucket_name):
6475
req = storage_service.buckets().get(bucket=bucket_name)
6576
return req.execute()
6677

6778

79+
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000)
6880
def delete_object(storage_service,bucket_name,object_name):
6981
'''delete_file will delete a file from a bucket
7082
:param storage_service: the service obtained with get_storage_service
@@ -75,6 +87,7 @@ def delete_object(storage_service,bucket_name,object_name):
7587
object=object_name).execute()
7688

7789

90+
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000)
7891
def upload_file(storage_service,bucket,bucket_path,file_name,verbose=True):
7992
'''get_folder will return the folder with folder_name, and if create=True,
8093
will create it if not found. If folder is found or created, the metadata is
@@ -103,6 +116,7 @@ def upload_file(storage_service,bucket,bucket_path,file_name,verbose=True):
103116
return request.execute()
104117

105118

119+
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000)
106120
def list_bucket(bucket,storage_service):
107121
# Create a request to objects.list to retrieve a list of objects.
108122
request = storage_service.objects().list(bucket=bucket['id'],
@@ -209,7 +223,7 @@ def run_build(build_dir=None,spec_file=None,repo_url=None,token=None,size=None,b
209223
bot.logger.info("Sending build files %s to storage",'\n'.join(build_files))
210224

211225
# Start the storage service, retrieve the bucket
212-
storage_service = get_storage_service()
226+
storage_service = get_google_service() # default is "storage" "v1"
213227
bucket = get_bucket(storage_service,params["bucket_name"])
214228

215229
# For each file, upload to storage
@@ -275,7 +289,7 @@ def finish_build(verbose=True):
275289
params = pickle.load(open(passing_params,'rb'))
276290

277291
# Start the storage service, retrieve the bucket
278-
storage_service = get_storage_service()
292+
storage_service = get_google_service()
279293
bucket = get_bucket(storage_service,params['bucket_name'])
280294
image_path = "%s/%s" %(re.sub('^http.+//www[.]','',params['repo_url']),params['commit'])
281295

singularity/build/utils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@
2525
import tempfile
2626
import zipfile
2727

28+
######################################################################################
29+
# Retry Functions
30+
######################################################################################
31+
32+
def stop_if_result_none(result):
33+
'''stop if result none will return True if we should not retry
34+
when result is none, False otherwise using retrying python package
35+
'''
36+
do_retry = result is not None
37+
return do_retry
38+
2839

2940
######################################################################################
3041
# Build Templates
@@ -62,6 +73,11 @@ def get_build_template(template_name,params=None,to_file=None):
6273
return None
6374

6475

76+
######################################################################################
77+
# Software Versions
78+
######################################################################################
79+
80+
6581
def get_singularity_version(singularity_version=None):
6682
'''get_singularity_version will determine the singularity version for a build
6783
first, an environmental variable is looked at, followed by using the system
@@ -83,6 +99,12 @@ def get_singularity_version(singularity_version=None):
8399
return singularity_version
84100

85101

102+
103+
######################################################################################
104+
# Extensions and Files
105+
######################################################################################
106+
107+
86108
def sniff_extension(file_path,verbose=True):
87109
'''sniff_extension will attempt to determine the file type based on the extension,
88110
and return the proper mimetype

0 commit comments

Comments
 (0)