Permalink
Browse files

Add --defaultsettings option

  • Loading branch information...
jakelever committed Nov 2, 2017
1 parent 34a637e commit 70aeffb503984e54f0617c60a378df010bdde3d3
Showing with 25 additions and 14 deletions.
  1. +1 −0 MANIFEST.in
  2. +20 −14 pubrunner/__init__.py
  3. +4 −0 pubrunner/command_line.py
@@ -2,3 +2,4 @@ include README.rst
include requirements.txt
include pubrunner/resources/*.yml
include pubrunner/Snakefiles/*.py
include pubrunner/pubrunner.settings.default.yml
@@ -38,8 +38,13 @@ def promptuser(prompt='> ', accepted=None):
print("Input not allowed. Must be one of %s" % str(accepted))
return userinput

def setupDefaultGlobalSettingsFile(globalSettingsPath):
def getDefaultGlobalSettingsPath():
defaultPath = os.path.join(pubrunner.__path__[0],'pubrunner.settings.default.yml')
assert os.path.isfile(defaultPath), "Unable to find default settings file"
return defaultPath

def setupDefaultGlobalSettingsFile(globalSettingsPath):
defaultPath = getDefaultGlobalSettingsPath()
with codecs.open(defaultPath,'r','utf-8') as f:
defaultSettings = f.read()

@@ -48,7 +53,7 @@ def setupDefaultGlobalSettingsFile(globalSettingsPath):

userinput = promptuser(prompt='(Y/N): ',accepted=['Y','N','y','n'])
if userinput.lower() == 'y':
assert os.path.isfile(defaultPath), "Unable to find default settings file"

shutil.copy(defaultPath,globalSettingsPath)

print("Default settings installed. Do you want to continue with this run?")
@@ -57,20 +62,20 @@ def setupDefaultGlobalSettingsFile(globalSettingsPath):
print("Exiting...")
sys.exit(0)

def findGlobalSettingsFile():
homeDirectory = os.path.expanduser("~")
globalSettingsPath = os.path.join(homeDirectory,'.pubrunner.settings.yml')
if not os.path.isfile(globalSettingsPath):
setupDefaultGlobalSettingsFile(globalSettingsPath)
assert os.path.isfile(globalSettingsPath), "Unable to find ~/.pubrunner.settings.yml file."
return globalSettingsPath

globalSettings = None
def getGlobalSettings():
def getGlobalSettings(useDefault=False):
global globalSettings
if globalSettings is None:
settingsYamlFile = findGlobalSettingsFile()
globalSettings = loadYAML(settingsYamlFile)
if useDefault:
globalSettingsPath = getDefaultGlobalSettingsPath()
else:
homeDirectory = os.path.expanduser("~")
globalSettingsPath = os.path.join(homeDirectory,'.pubrunner.settings.yml')
if not os.path.isfile(globalSettingsPath):
setupDefaultGlobalSettingsFile(globalSettingsPath)
assert os.path.isfile(globalSettingsPath), "Unable to find ~/.pubrunner.settings.yml file."

globalSettings = loadYAML(globalSettingsPath)

return globalSettings

@@ -92,11 +97,12 @@ def launchSnakemake(snakeFilePath,useCluster=True,parameters={}):
else:
raise RuntimeError("Cluster must either have drmaa = true or provide options (e.g. using qsub)")

makecommand = "snakemake %s -s %s" % (clusterFlags,snakeFilePath)
makecommand = "snakemake %s --nolock -s %s" % (clusterFlags,snakeFilePath)

env = os.environ.copy()
env.update(parameters)

retval = subprocess.call(shlex.split(makecommand),env=env)
if retval != 0:
raise RuntimeError("Snake make call FAILED (file:%s)" % snakeFilePath)

@@ -32,6 +32,7 @@ def cloneGithubRepoToTempDir(githubRepo):
def main():
parser = argparse.ArgumentParser(description='PubRunner will manage the download of needed resources for a text mining tool, build and execute it and then share the results publicly')
parser.add_argument('codebase',nargs='?',type=str,help='Code base containing the text mining tool to execute. Code base should contain a pubrunner.yml file. The code base can be a directory, Github repo or archive')
parser.add_argument('--defaultsettings',action='store_true',help='Use default .pubrunner.settings.xml. Ignore ~/.pubrunner.settings.yml if it exists.')
parser.add_argument('--ignorecluster',action='store_true',help='Ignore any cluster settings and run everything locally')
parser.add_argument('--cleanonly',action='store_true',help='Remove the existing working directory')
parser.add_argument('--test',action='store_true',help='Run the test functionality instead of the full run')
@@ -56,6 +57,9 @@ def main():
parser.print_help()
sys.exit(1)

if args.defaultsettings:
globalSettings = pubrunner.getGlobalSettings(useDefault=True)

if args.ignorecluster:
globalSettings = pubrunner.getGlobalSettings()
if "cluster" in globalSettings:

0 comments on commit 70aeffb

Please sign in to comment.