diff options
author | Jürg Billeter <j@bitron.ch> | 2017-10-23 11:17:21 +0200 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2018-02-08 14:04:04 +0100 |
commit | 1d331b9b7db812e3f18c3eed33af92739c2ffb7b (patch) | |
tree | d40c49423bb7aa804f0993495330c632d46fa9ba | |
parent | b5f101a2ac19ff4e64de17a18230e351137c1884 (diff) | |
download | buildstream-1d331b9b7db812e3f18c3eed33af92739c2ffb7b.tar.gz |
Move cli_options from Context to Project
cli_options are project-specific.
-rw-r--r-- | buildstream/_context.py | 3 | ||||
-rw-r--r-- | buildstream/_frontend/main.py | 8 | ||||
-rw-r--r-- | buildstream/_project.py | 6 | ||||
-rw-r--r-- | tests/artifactcache/config.py | 2 | ||||
-rw-r--r-- | tests/context/context.py | 2 | ||||
-rw-r--r-- | tests/plugins/pipeline.py | 2 | ||||
-rw-r--r-- | tests/project/plugins.py | 2 | ||||
-rw-r--r-- | tests/project/project.py | 12 | ||||
-rw-r--r-- | tests/variables/variables.py | 2 |
9 files changed, 20 insertions, 19 deletions
diff --git a/buildstream/_context.py b/buildstream/_context.py index b86ce2ad1..317621f0a 100644 --- a/buildstream/_context.py +++ b/buildstream/_context.py @@ -45,7 +45,7 @@ from ._artifactcache import artifact_cache_specs_from_config_node # class Context(): - def __init__(self, cli_options): + def __init__(self): # Filename indicating which configuration file was used, or None for the defaults self.config_origin = None @@ -110,7 +110,6 @@ class Context(): self._message_depth = deque() self._platform = None self._project_overrides = {} - self._cli_options = cli_options # load() # diff --git a/buildstream/_frontend/main.py b/buildstream/_frontend/main.py index 1abbd3592..cc92e6412 100644 --- a/buildstream/_frontend/main.py +++ b/buildstream/_frontend/main.py @@ -704,14 +704,14 @@ def workspace_list(app): config = app.main_options['config'] try: - context = Context(app.main_options['option']) + context = Context() context.load(config) except BstError as e: click.echo("Error loading user configuration: {}".format(e), err=True) sys.exit(-1) try: - project = Project(directory, context) + project = Project(directory, context, cli_options=app.main_options['option']) except BstError as e: click.echo("Error loading project: {}".format(e), err=True) sys.exit(-1) @@ -800,7 +800,7 @@ class App(): config = self.main_options['config'] try: - self.context = Context(self.main_options['option']) + self.context = Context() self.context.load(config) except BstError as e: click.echo("Error loading user configuration: {}".format(e), err=True) @@ -859,7 +859,7 @@ class App(): self.context._set_message_handler(self.message_handler) try: - self.project = Project(directory, self.context) + self.project = Project(directory, self.context, cli_options=self.main_options['option']) except BstError as e: click.echo("Error loading project: {}".format(e), err=True) sys.exit(-1) diff --git a/buildstream/_project.py b/buildstream/_project.py index 92efce926..d44a891bd 100644 --- a/buildstream/_project.py +++ b/buildstream/_project.py @@ -57,7 +57,7 @@ _ALIAS_SEPARATOR = ':' # class Project(): - def __init__(self, directory, context): + def __init__(self, directory, context, *, cli_options=None): # The project name self.name = None @@ -77,6 +77,7 @@ class Project(): self._plugin_source_origins = [] # Origins of custom sources self._plugin_element_origins = [] # Origins of custom elements self._options = None # Project options, the OptionPool + self._cli_options = cli_options self._cache_key = None self._source_format_versions = {} self._element_format_versions = {} @@ -157,7 +158,8 @@ class Project(): overrides = self._context._get_overrides(self.name) override_options = _yaml.node_get(overrides, Mapping, 'options', default_value={}) self._options.load_yaml_values(override_options) - self._options.load_cli_values(self._context._cli_options) + if self._cli_options: + self._options.load_cli_values(self._cli_options) # We're done modifying options, now we can use them for substitutions self._options.resolve() diff --git a/tests/artifactcache/config.py b/tests/artifactcache/config.py index e734c2dbe..690e354f5 100644 --- a/tests/artifactcache/config.py +++ b/tests/artifactcache/config.py @@ -94,7 +94,7 @@ def test_artifact_cache_precedence(tmpdir, override_caches, project_caches, user project_config_file = str(project_dir.join('project.conf')) _yaml.dump(_yaml.node_sanitize(project_config), filename=project_config_file) - context = Context([]) + context = Context() context.load(config=user_config_file) project = Project(str(project_dir), context) diff --git a/tests/context/context.py b/tests/context/context.py index 442069bf6..a153d7f6d 100644 --- a/tests/context/context.py +++ b/tests/context/context.py @@ -20,7 +20,7 @@ def context_fixture(): return { 'xdg-cache': cache_home, - 'context': Context([]) + 'context': Context() } diff --git a/tests/plugins/pipeline.py b/tests/plugins/pipeline.py index a77dcd1d2..805155731 100644 --- a/tests/plugins/pipeline.py +++ b/tests/plugins/pipeline.py @@ -13,7 +13,7 @@ DATA_DIR = os.path.join( def create_pipeline(tmpdir, basedir, target): - context = Context([]) + context = Context() project = Project(basedir, context) context.deploydir = os.path.join(str(tmpdir), 'deploy') context.artifactdir = os.path.join(str(tmpdir), 'artifact') diff --git a/tests/project/plugins.py b/tests/project/plugins.py index 4040137c1..8907c7eaf 100644 --- a/tests/project/plugins.py +++ b/tests/project/plugins.py @@ -12,7 +12,7 @@ DATA_DIR = os.path.join( def create_pipeline(tmpdir, basedir, target): - context = Context([]) + context = Context() project = Project(basedir, context) context.artifactdir = os.path.join(str(tmpdir), 'artifact') diff --git a/tests/project/project.py b/tests/project/project.py index 3a1484309..2505431d8 100644 --- a/tests/project/project.py +++ b/tests/project/project.py @@ -16,7 +16,7 @@ def test_missing_project_conf(datafiles): directory = os.path.join(datafiles.dirname, datafiles.basename) with pytest.raises(LoadError) as exc: - project = Project(directory, Context([])) + project = Project(directory, Context()) assert (exc.value.reason == LoadErrorReason.MISSING_FILE) @@ -26,7 +26,7 @@ def test_missing_project_name(datafiles): directory = os.path.join(datafiles.dirname, datafiles.basename, "missingname") with pytest.raises(LoadError) as exc: - project = Project(directory, Context([])) + project = Project(directory, Context()) assert (exc.value.reason == LoadErrorReason.INVALID_DATA) @@ -35,7 +35,7 @@ def test_missing_project_name(datafiles): def test_load_basic_project(datafiles): directory = os.path.join(datafiles.dirname, datafiles.basename, "basic") - project = Project(directory, Context([])) + project = Project(directory, Context()) # User provided assert (project.name == "pony") @@ -50,7 +50,7 @@ def test_load_basic_project(datafiles): def test_override_project_path(datafiles): directory = os.path.join(datafiles.dirname, datafiles.basename, "overridepath") - project = Project(directory, Context([])) + project = Project(directory, Context()) # Test the override assert (project._environment['PATH'] == "/bin:/sbin") @@ -60,7 +60,7 @@ def test_override_project_path(datafiles): def test_project_alias(datafiles): directory = os.path.join(datafiles.dirname, datafiles.basename, "alias") - project = Project(directory, Context([])) + project = Project(directory, Context()) # Test the override assert (project.translate_url('baserock:foo') == 'git://git.baserock.org/baserock/foo') @@ -72,6 +72,6 @@ def test_project_unsupported(datafiles): directory = os.path.join(datafiles.dirname, datafiles.basename, "unsupported") with pytest.raises(LoadError) as exc: - project = Project(directory, Context([])) + project = Project(directory, Context()) assert (exc.value.reason == LoadErrorReason.UNSUPPORTED_PROJECT) diff --git a/tests/variables/variables.py b/tests/variables/variables.py index 24f323c69..b16511ad6 100644 --- a/tests/variables/variables.py +++ b/tests/variables/variables.py @@ -12,7 +12,7 @@ DATA_DIR = os.path.join( def create_pipeline(tmpdir, basedir, target): - context = Context([]) + context = Context() project = Project(basedir, context) context.artifactdir = os.path.join(str(tmpdir), 'artifact') |