Skip to content

Commit

Permalink
Merge branch 'master' of github.com:RNAer/burrito
Browse files Browse the repository at this point in the history
  • Loading branch information
RNAer committed Oct 13, 2015
2 parents e49b322 + aa40fd4 commit 640dd6e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ python:
- "3.3"
- "3.4"
install:
- pip install nose pep8 flake8 coveralls
- pip install nose flake8 coveralls
- pip install .
script:
- nosetests --with-coverage
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# burrito changelog

## Version 0.9.0-dev (changes since 0.9.0 release go here)
## Version 0.9.1-dev (changes since 0.9.1 go here)

## Version 0.9.1 (2015-05-22)

* Updated default temporary directory from ``/tmp`` to python's ``tempfile.gettempdir()``. This should address many of the issues with temporary files being written to ``/tmp``, which sometimes doesn't exist, doesn't provide a lot of storage, or is not shared across cluster nodes. It is still possible that individual burrito fillings (i.e., ``CommandLineApplication`` derived classes) can hard code ``/tmp``, so care should be taken when writing those derived classes to avoid that.

## Version 0.9.0 (2014-08-04)

Expand Down
2 changes: 1 addition & 1 deletion burrito/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

__version__ = "0.9.0-dev"
__version__ = "0.9.1-dev"
41 changes: 21 additions & 20 deletions burrito/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,11 @@ def test_base_command(self):
# because parameters are printed in arbitrary order
app.Parameters['-F'].on('junk.txt')
app.Parameters['--duh'].on()
self.assertTrue(app.BaseCommand ==
'cd "/tmp/"; /tmp/CLAppTester.py -F "junk.txt" --duh'
or app.BaseCommand ==
'cd "/tmp/"; /tmp/CLAppTester.py --duh -F "junk.txt"')
self.assertTrue(
app.BaseCommand ==
'cd "/tmp/"; /tmp/CLAppTester.py -F "junk.txt" --duh' or
app.BaseCommand ==
'cd "/tmp/"; /tmp/CLAppTester.py --duh -F "junk.txt"')
# Space in _command
app = CLAppTester_space_in_command()
self.assertEqual(app.BaseCommand,
Expand Down Expand Up @@ -760,7 +761,7 @@ def test_TmpDir(self):
self.assertEqual(app.InputHandler, '_input_as_string')
assert not app.SuppressStderr
# TmpDir is what we expect
self.assertEqual(app.TmpDir, '/tmp/tmp2')
self.assertEqual(app.TmpDir, '/tmp/tmp2/')
# test_command
self.assertEqual(app.BaseCommand,
'cd "/tmp/"; /tmp/CLAppTester.py -F "p_file.txt"')
Expand Down Expand Up @@ -788,7 +789,7 @@ def test_TmpDir_w_space(self):
self.assertEqual(app.InputHandler, '_input_as_string')
assert not app.SuppressStderr
# TmpDir is what we expect
self.assertEqual(app.TmpDir, '/tmp/tmp space')
self.assertEqual(app.TmpDir, '/tmp/tmp space/')
# test_command
self.assertEqual(app.BaseCommand,
'cd "/tmp/"; /tmp/CLAppTester.py -F "p_file.txt"')
Expand Down Expand Up @@ -893,7 +894,7 @@ def test_getTmpFilename_non_default(self):
"""TmpFilename handles alt tmp_dir, prefix and suffix properly"""
app = CLAppTester()
obs = app.getTmpFilename(include_class_id=False)
self.assertTrue(obs.startswith('/tmp/tmp'))
self.assertTrue(obs.startswith(app.TmpDir + 'tmp'))
self.assertTrue(obs.endswith('.txt'))

obs = app.getTmpFilename(tmp_dir="/tmp/blah", prefix="app_ctl_test",
Expand All @@ -908,9 +909,9 @@ def test_getTmpFilename_defaults_to_no_class_id(self):
# set the default to False if they change it for testing purposes
app = CLAppTester()
self.assertFalse(app.getTmpFilename().
startswith('/tmp/tmpCLAppTester'))
startswith(app.TmpDir + 'tmpCLAppTester'))
self.assertTrue(app.getTmpFilename(include_class_id=True).
startswith('/tmp/tmpCLAppTester'))
startswith(app.TmpDir + 'tmpCLAppTester'))

def test_input_as_path(self):
"""CLAppTester: _input_as_path casts data to FilePath"""
Expand Down Expand Up @@ -991,33 +992,33 @@ def test_getTmpFilename(self):
obs = app.getTmpFilename(include_class_id=True)
# leaving the strings in this statement so it's clear where the
# expected length comes from
self.assertEqual(len(obs), len(app.TmpDir) + len('/') + app.TmpNameLen
+ len('tmp') + len('CLAppTester') + len('.txt'))
self.assertEqual(len(obs), len(app.TmpDir) + app.TmpNameLen +
len('tmp') + len('CLAppTester') + len('.txt'))
assert obs.startswith(app.TmpDir)
chars = set(obs[18:])
assert len(chars) > 1

obs = app.getTmpFilename(include_class_id=False)
# leaving the strings in this statement so it's clear where the
# expected length comes from
self.assertEqual(len(obs), len(app.TmpDir) + len('/') + app.TmpNameLen
+ len('tmp') + len('.txt'))
self.assertEqual(len(obs), len(app.TmpDir) + app.TmpNameLen +
len('tmp') + len('.txt'))
assert obs.startswith(app.TmpDir)

def test_getTmpFilename_prefix_suffix_result_constructor(self):
"""TmpFilename: result has correct prefix, suffix, type"""
app = CLAppTester()
obs = app.getTmpFilename(prefix='blah', include_class_id=False)
self.assertTrue(obs.startswith('/tmp/blah'))
self.assertTrue(obs.startswith(app.TmpDir + 'blah'))
obs = app.getTmpFilename(suffix='.blah', include_class_id=False)
self.assertTrue(obs.endswith('.blah'))
# Prefix defaults to not include the class name
obs = app.getTmpFilename(include_class_id=False)
self.assertFalse(obs.startswith('/tmp/tmpCLAppTester'))
self.assertFalse(obs.startswith(app.TmpDir + 'tmpCLAppTester'))
self.assertTrue(obs.endswith('.txt'))
# including class id functions correctly
obs = app.getTmpFilename(include_class_id=True)
self.assertTrue(obs.startswith('/tmp/tmpCLAppTester'))
self.assertTrue(obs.startswith(app.TmpDir + 'tmpCLAppTester'))
self.assertTrue(obs.endswith('.txt'))

# result as FilePath
Expand Down Expand Up @@ -1064,8 +1065,8 @@ def test_get_tmp_filename(self):
# leaving the strings in this statement so it's clear where the
# expected length comes from
self.assertEqual(len(obs),
len(self.tmp_dir) + len('/') + self.tmp_name_len
+ len('tmp') + len('.txt'))
len(self.tmp_dir) + len('/') + self.tmp_name_len +
len('tmp') + len('.txt'))
self.assertTrue(obs.startswith(self.tmp_dir))

# different results on different calls
Expand All @@ -1075,8 +1076,8 @@ def test_get_tmp_filename(self):
# leaving the strings in this statement so it's clear where the
# expected length comes from
self.assertEqual(len(obs),
len(self.tmp_dir) + len('/') + self.tmp_name_len
+ len('tmp') + len('.txt'))
len(self.tmp_dir) + len('/') + self.tmp_name_len +
len('tmp') + len('.txt'))
assert obs.startswith(self.tmp_dir)

def test_get_tmp_filename_prefix_suffix_constructor(self):
Expand Down
16 changes: 8 additions & 8 deletions burrito/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class CommandLineApplication(Application):
_working_dir = None

def __init__(self, params=None, InputHandler=None, SuppressStderr=None,
SuppressStdout=None, WorkingDir=None, TmpDir='/tmp',
SuppressStdout=None, WorkingDir=None, TmpDir=gettempdir(),
TmpNameLen=20, HALT_EXEC=False):
""" Initialize the CommandLineApplication object
Expand All @@ -192,8 +192,7 @@ def __init__(self, params=None, InputHandler=None, SuppressStderr=None,
running the script doesn't have write access to the current
working directory
WARNING: WorkingDir MUST be an absolute path!
TmpDir: the directory where temp files will be created, /tmp
by default
TmpDir: the directory where temp files will be created
TmpNameLen: the length of the temp file name
HALT_EXEC: if True, raises exception w/ command output just
before execution, doesn't clean up temp files. Default False.
Expand All @@ -219,6 +218,8 @@ def __init__(self, params=None, InputHandler=None, SuppressStderr=None,
else:
working_dir = self._working_dir or getcwd()
self.WorkingDir = FilePath(working_dir)
if not TmpDir.endswith("/"):
TmpDir += "/"
self.TmpDir = FilePath(TmpDir)
self.TmpNameLen = TmpNameLen
self.HaltExec = HALT_EXEC
Expand Down Expand Up @@ -496,11 +497,11 @@ def _get_result_paths(self, data):
"""
return {}

def getTmpFilename(self, tmp_dir="/tmp", prefix='tmp', suffix='.txt',
def getTmpFilename(self, tmp_dir=None, prefix='tmp', suffix='.txt',
include_class_id=False, result_constructor=FilePath):
""" Return a temp filename
tmp_dir: path for temp file
tmp_dir: directory where temporary files will be stored
prefix: text to append to start of file name
suffix: text to append to end of file name
include_class_id: if True, will append a class identifier (built
Expand Down Expand Up @@ -746,14 +747,13 @@ def get_tmp_filename(tmp_dir=gettempdir(), prefix="tmp", suffix=".txt",
result_constructor=FilePath):
""" Generate a temporary filename and return as a FilePath object
tmp_dir: the directory to house the tmp_filename (default: '/tmp')
prefix: string to append to beginning of filename (default: 'tmp')
tmp_dir: the directory to house the tmp_filename
prefix: string to append to beginning of filename
Note: It is very useful to have prefix be descriptive of the
process which is creating the temporary file. For example, if
your temp file will be used to build a temporary blast database,
you might pass prefix=TempBlastDB
suffix: the suffix to be appended to the temp filename
(default '.txt')
result_constructor: the constructor used to build the result filename
(default: cogent.app.parameters.FilePath). Note that joining
FilePath objects with one another or with strings, you must use
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

__version__ = "0.9.0-dev"

from setuptools import find_packages, setup

__version__ = "0.9.1-dev"

classes = """
Development Status :: 5 - Production/Stable
Intended Audience :: Developers
Expand Down Expand Up @@ -50,6 +50,6 @@
test_suite='nose.collector',
packages=find_packages(),
install_requires=['future'],
extras_require={'test': ["nose >= 0.10.1", "pep8", "flake8",
extras_require={'test': ["nose >= 0.10.1", "flake8",
"coveralls"]},
classifiers=classifiers)

0 comments on commit 640dd6e

Please sign in to comment.