From c9c16464d90d13e689ec06574cfa760fada51ff0 Mon Sep 17 00:00:00 2001 From: Greg Caporaso Date: Mon, 4 May 2015 09:32:29 -0700 Subject: [PATCH 1/9] MAINT: fixes #8 --- burrito/util.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/burrito/util.py b/burrito/util.py index 8d531d4..18c1e33 100644 --- a/burrito/util.py +++ b/burrito/util.py @@ -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 @@ -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. @@ -495,11 +494,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 @@ -745,14 +744,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 From 7df3e3321260f3672089363a2fd381d8ee8cc7e7 Mon Sep 17 00:00:00 2001 From: Greg Caporaso Date: Mon, 4 May 2015 09:49:51 -0700 Subject: [PATCH 2/9] MAINT: add trailing slash to temp dir --- burrito/util.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/burrito/util.py b/burrito/util.py index 18c1e33..1116ed3 100644 --- a/burrito/util.py +++ b/burrito/util.py @@ -218,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 From a1f78e124ce51d02795922336c88d16f3e819b60 Mon Sep 17 00:00:00 2001 From: Greg Caporaso Date: Mon, 4 May 2015 09:50:12 -0700 Subject: [PATCH 3/9] TST: updated tests --- burrito/tests/test_util.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/burrito/tests/test_util.py b/burrito/tests/test_util.py index 977599f..e7d664b 100644 --- a/burrito/tests/test_util.py +++ b/burrito/tests/test_util.py @@ -760,7 +760,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"') @@ -788,7 +788,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"') @@ -893,7 +893,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", @@ -908,9 +908,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""" @@ -991,7 +991,7 @@ 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 + self.assertEqual(len(obs), len(app.TmpDir) + app.TmpNameLen + len('tmp') + len('CLAppTester') + len('.txt')) assert obs.startswith(app.TmpDir) chars = set(obs[18:]) @@ -1000,7 +1000,7 @@ def test_getTmpFilename(self): 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 + self.assertEqual(len(obs), len(app.TmpDir) + app.TmpNameLen + len('tmp') + len('.txt')) assert obs.startswith(app.TmpDir) @@ -1008,16 +1008,17 @@ 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')) + print app.TmpDir, obs + 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 From af060942bfb74d97b31efb90f63baa84634d724b Mon Sep 17 00:00:00 2001 From: Greg Caporaso Date: Mon, 4 May 2015 10:19:37 -0700 Subject: [PATCH 4/9] MAINT: pep8 fixes --- burrito/tests/test_util.py | 25 +++++++++++++------------ setup.py | 4 ++-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/burrito/tests/test_util.py b/burrito/tests/test_util.py index e7d664b..09fbf8e 100644 --- a/burrito/tests/test_util.py +++ b/burrito/tests/test_util.py @@ -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, @@ -991,8 +992,8 @@ 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) + 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 @@ -1000,8 +1001,8 @@ def test_getTmpFilename(self): 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) + 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): @@ -1065,8 +1066,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 @@ -1076,8 +1077,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): diff --git a/setup.py b/setup.py index ff2961c..7bd0452 100644 --- a/setup.py +++ b/setup.py @@ -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.0-dev" + classes = """ Development Status :: 5 - Production/Stable Intended Audience :: Developers From f8988205ee526234338525bb662f053125a94202 Mon Sep 17 00:00:00 2001 From: Jai Ram Rideout Date: Mon, 4 May 2015 10:34:49 -0700 Subject: [PATCH 5/9] MAINT: remove pep8 install before flake8 This will hopefully resolve the version conflict issue when Travis runs. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 489a010..5734b2e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 From ba733d3f86f9131feed04358d7590dee52fa34e1 Mon Sep 17 00:00:00 2001 From: Greg Caporaso Date: Tue, 5 May 2015 19:44:03 -0700 Subject: [PATCH 6/9] MAINT: removed pep8 as flake is picky about which version it installs --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7bd0452..8953634 100644 --- a/setup.py +++ b/setup.py @@ -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) From 4d69f31a3b6a46fcc598649d1b3cbfdc0c7287dc Mon Sep 17 00:00:00 2001 From: Greg Caporaso Date: Tue, 5 May 2015 19:55:55 -0700 Subject: [PATCH 7/9] TST: cleaned up left over debugging statement --- burrito/tests/test_util.py | 1 - 1 file changed, 1 deletion(-) diff --git a/burrito/tests/test_util.py b/burrito/tests/test_util.py index 09fbf8e..d222e6e 100644 --- a/burrito/tests/test_util.py +++ b/burrito/tests/test_util.py @@ -1009,7 +1009,6 @@ 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) - print app.TmpDir, obs self.assertTrue(obs.startswith(app.TmpDir + 'blah')) obs = app.getTmpFilename(suffix='.blah', include_class_id=False) self.assertTrue(obs.endswith('.blah')) From 31407143735e7a154c4483fbbfe9337fb21fc7b6 Mon Sep 17 00:00:00 2001 From: Greg Caporaso Date: Fri, 22 May 2015 09:50:31 -0700 Subject: [PATCH 8/9] REL: updates for 0.9.1 release --- CHANGELOG.md | 4 +++- burrito/__init__.py | 2 +- setup.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1cd518..ff702c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # burrito changelog -## Version 0.9.0-dev (changes since 0.9.0 release 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) diff --git a/burrito/__init__.py b/burrito/__init__.py index b3b6038..7792d3a 100644 --- a/burrito/__init__.py +++ b/burrito/__init__.py @@ -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" diff --git a/setup.py b/setup.py index 8953634..8940668 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ from setuptools import find_packages, setup -__version__ = "0.9.0-dev" +__version__ = "0.9.1" classes = """ Development Status :: 5 - Production/Stable From 583391c08842ccfdba9a0199841049cc2c82a9d7 Mon Sep 17 00:00:00 2001 From: Greg Caporaso Date: Fri, 22 May 2015 10:15:52 -0700 Subject: [PATCH 9/9] REL: updated to 0.9.1-dev --- CHANGELOG.md | 2 ++ burrito/__init__.py | 2 +- setup.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff702c9..20dd4d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # burrito changelog +## 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. diff --git a/burrito/__init__.py b/burrito/__init__.py index 7792d3a..2ad87bb 100644 --- a/burrito/__init__.py +++ b/burrito/__init__.py @@ -6,4 +6,4 @@ # The full license is in the file LICENSE, distributed with this software. # ---------------------------------------------------------------------------- -__version__ = "0.9.1" +__version__ = "0.9.1-dev" diff --git a/setup.py b/setup.py index 8940668..f5eb209 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ from setuptools import find_packages, setup -__version__ = "0.9.1" +__version__ = "0.9.1-dev" classes = """ Development Status :: 5 - Production/Stable