Skip to content

Commit

Permalink
Remove all direct config access in task.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjyw authored and Benjy committed Feb 25, 2015
1 parent b065ea8 commit 1da125c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
16 changes: 9 additions & 7 deletions src/python/pants/backend/core/tasks/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,23 @@ def __init__(self, *args, **kwargs):
"""
self.context = context
self._workdir = workdir
# TODO: It would be nice to use self.get_options().cache_key_gen_version here, because then
# we could have a separate value for each scope if we really wanted to. However we can't
# access per-task options in Task.__init__ because GroupTask.__init__ calls it with the
# group task's scope, which isn't currently in the known scopes we generate options for.
self._cache_key_generator = CacheKeyGenerator(
context.config.getdefault('cache_key_gen_version', default='200'))
self.context.options.for_global_scope().cache_key_gen_version)
self._read_artifact_cache_spec = None
self._write_artifact_cache_spec = None
self._artifact_cache = None
self._artifact_cache_setup_lock = threading.Lock()

self._cache_key_errors = set()

default_invalidator_root = os.path.join(
self.context.options.for_global_scope().pants_workdir, 'build_invalidator')
suffix_type = self.__class__.__name__
self._build_invalidator_dir = os.path.join(
context.config.get('tasks', 'build_invalidator', default=default_invalidator_root),
suffix_type)
self.context.options.for_global_scope().pants_workdir,
'build_invalidator',
self.__class__.__name__)

def get_options(self):
"""Returns the option values for this task's scope."""
Expand Down Expand Up @@ -198,7 +200,7 @@ def _setup_artifact_cache_from_specs(self, read_spec, write_spec):
def _create_artifact_cache(self, spec, action):
if len(spec) > 0:
pants_workdir = self.context.options.for_global_scope().pants_workdir
compression = self.context.config.getint('cache', 'compression', default=5)
compression = self.get_options().cache_compression
my_name = self.__class__.__name__
return create_artifact_cache(
log=self.context.log,
Expand Down
7 changes: 7 additions & 0 deletions src/python/pants/option/global_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def register_global_options(register):
register('--exclude-target-regexp', action='append', default=[], metavar='<regexp>',
help='Regex pattern to exclude from the target list (useful in conjunction with ::). '
'Multiple patterns may be specified by setting this flag multiple times.')
# TODO: When we have a model for 'subsystems', create one for artifact caching and move these
# options to there. When we do that, also drop the cumbersome word 'artifact' from these
# option names. There's only one cache concept that users care about.
register('--read-from-artifact-cache', action='store_true', default=True,
help='Read build artifacts from cache, if available.')
register('--read-artifact-caches', type=Options.list,
Expand All @@ -53,6 +56,10 @@ def register_global_options(register):
'choose from.')
register('--overwrite-cache-artifacts', action='store_true',
help='If writing to build artifacts to cache, overwrite (instead of skip) existing.')
register('--cache-key-gen-version', advanced=True, default='200',
help='The cache key generation. Bump this to invalidate every artifact.')
register('--cache-compression', advanced=True, type=int, default=5,
help='The gzip compression level for created artifacts.')
register('--print-exception-stacktrace', action='store_true',
help='Print to console the full exception stack trace if encountered.')
register('--fail-fast', action='store_true',
Expand Down
6 changes: 5 additions & 1 deletion src/python/pants/option/migrate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@
('ide', 'extra_jvm_source_paths'): ('idea', 'extra_jvm_source_paths'),
('ide', 'extra_jvm_test_paths'): ('idea', 'extra_jvm_test_paths'),
('ide', 'debug_port'): ('idea', 'debug_port'),

('cache', 'compression'): ('DEFAULT', 'cache_compression'),
}

notes = {
Expand Down Expand Up @@ -161,7 +163,9 @@
'idea and eclipse goals.',
('ide', 'debug_port'): 'debug_port now must be specified separately for idea and eclipse '
'goals. Also, IDE goals now use their own debug setting and do not '
'inherit from jvm configuration.'
'inherit from jvm configuration.',

('tasks', 'build_invalidator'): 'This is no longer configurable. The default will be used.',
}


Expand Down
3 changes: 2 additions & 1 deletion tests/python/pants_test/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def setUp(self):
self.options[''] = {
'pants_workdir': os.path.join(self.build_root, '.pants.d'),
'pants_supportdir': os.path.join(self.build_root, 'build-support'),
'pants_distdir': os.path.join(self.build_root, 'dist')
'pants_distdir': os.path.join(self.build_root, 'dist'),
'cache_key_gen_version': '0-test'
}
BuildRoot().path = self.build_root

Expand Down

0 comments on commit 1da125c

Please sign in to comment.