diff --git a/pex/bin/pex.py b/pex/bin/pex.py index 3266f3193..a92392bb4 100755 --- a/pex/bin/pex.py +++ b/pex/bin/pex.py @@ -68,7 +68,7 @@ def increment_verbosity(option, opt_str, _, parser): def process_disable_cache(option, option_str, option_value, parser): - setattr(parser.values, option.dest, []) + setattr(parser.values, option.dest, None) def process_pypi_option(option, option_str, option_value, parser, builder): @@ -530,7 +530,9 @@ def main(args=None): else: options.pex_root = ENV.PEX_ROOT # If option not specified fallback to env variable. - options.cache_dir = make_relative_to_root(options.cache_dir) + # Don't alter cache if it is disabled. + if options.cache_dir: + options.cache_dir = make_relative_to_root(options.cache_dir) options.interpreter_cache_dir = make_relative_to_root(options.interpreter_cache_dir) with ENV.patch(PEX_VERBOSE=str(options.verbosity)): diff --git a/tests/test_integration.py b/tests/test_integration.py index 98b02a456..f68159711 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -40,6 +40,28 @@ def test_pex_root(): assert 'build' in os.listdir(td), 'Expected build directory in tmp pex root.' +def test_cache_disable(): + with temporary_dir() as tmp_home: + with environment_as(HOME=tmp_home): + with temporary_dir() as td: + with temporary_dir() as output_dir: + env = os.environ.copy() + env['PEX_INTERPRETER'] = '1' + + output_path = os.path.join(output_dir, 'pex.pex') + args = [ + 'pex', + '-o', output_path, + '--not-zip-safe', + '--disable-cache', + '--pex-root={0}'.format(td), + ] + results = run_pex_command(args=args, env=env) + results.assert_success() + assert ['pex.pex'] == os.listdir(output_dir), 'Expected built pex file.' + assert [] == os.listdir(tmp_home), 'Expected empty temp home dir.' + + def test_pex_interpreter(): with named_temporary_file() as fp: fp.write(b"print('Hello world')")