Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Remove global state attributes from snapcraft.common #434
Conversation
sergiusens
added some commits
Apr 8, 2016
|
same for |
sergiusens
added some commits
Apr 11, 2016
|
@elopio example tests fail straight out and for some reason I can't connect to the VPN |
|
retest this please |
sergiusens
added some commits
Apr 11, 2016
kyrofa
reviewed
Apr 11, 2016
| +def _find_machine(deb_arch): | ||
| + for machine in _ARCH_TRANSLATIONS: | ||
| + if _ARCH_TRANSLATIONS[machine].get('deb', '') == deb_arch: | ||
| + logger.info('Setting target machine to {!r}'.format(machine)) |
kyrofa
Apr 11, 2016
Member
This function isn't actually setting anything-- this logger.info() probably belongs in _set_machine(), no?
kyrofa
reviewed
Apr 11, 2016
| - | ||
| - return build_count | ||
| + raise EnvironmentError( | ||
| + "This plugin is outdated, use 'options.project.parallel_build_count'") |
kyrofa
reviewed
Apr 11, 2016
| + patcher = mock.patch('multiprocessing.cpu_count') | ||
| + self.cpu_count = patcher.start() | ||
| + self.cpu_count.return_value = 2 | ||
| + self.addCleanup(patcher.stop) |
kyrofa
reviewed
Apr 11, 2016
| - def set_target_machine(self, machine): | ||
| - self._target_arch = get_machine_info(machine) | ||
| + def set_target_machine(self): |
kyrofa
Apr 11, 2016
Member
A "set" function with no parameter seems odd. Is this something that can be done in the initializer now?
sergiusens
Apr 11, 2016
Collaborator
I thought about this, but if we make plugins take the charge on this I can add something to manage this. The problem is plugins that don't support cross compiling.
kyrofa
Apr 11, 2016
Member
The problem is plugins that don't support cross compiling.
You mean as of right now if one tries cross-compiling with plugins that don't support it you get a good error? That's an excellent point.
kyrofa
reviewed
Apr 11, 2016
| @@ -169,12 +169,15 @@ def _load_code(self, plugin_name, properties, part_schema): | ||
| plugin = _get_plugin(module) | ||
| options = _make_options(part_schema, properties, plugin.schema()) | ||
| + # For backwards compatibility we add the project options as an option | ||
| + setattr(options, 'project', self._project_options) |
kyrofa
Apr 11, 2016
Member
options currently have a pretty well-defined meaning: "options from the YAML." I like not breaking API in this way, but I also don't like diluting options. Particularly because: what happens when a local plugin declares project as a property in the schema?
Would it be better to actually set a __project attribute on the plugin instance and add a getter method on the base plugin (or something similar)? Or even just set a project attribute since people are used to using an options attribute.
sergiusens
Apr 11, 2016
Collaborator
This will need to go to the base plugin and it will break badly unless I add **kwargs, *args. What is your take?
|
Check the title, too |
sergiusens
added some commits
Apr 11, 2016
sergiusens
changed the title from
Bugfix/1551849/no state can be global forever
to
Remove global state attributes from snapcraft.common
Apr 11, 2016
kyrofa
reviewed
Apr 11, 2016
| @@ -288,8 +289,8 @@ def env(self, root): | ||
| """ | ||
| return [] | ||
| - def set_target_machine(self): | ||
| - """Set the target compilation architecture to machine.""" |
kyrofa
Apr 11, 2016
Member
Can we leave this function, continue taking the machine parameter, deprecate it, and simply have it call enable_cross_compilation()?
sergiusens
Apr 11, 2016
Collaborator
El 11/04/16 a las 14:27, Kyle Fazzari escribió:
In snapcraft/init.py
ubuntu-core#434 (comment):@@ -288,8 +289,8 @@ def env(self, root):
"""
return []
- def set_target_machine(self):
"""Set the target compilation architecture to machine."""Can we leave this function, continue taking the |machine| parameter,
deprecate it, and simply have it call |enable_cross_compilation()|?
While not hard, the target-arch thing was marked API unstable, so not really compelled to do it. Counter thoughts?
kyrofa
reviewed
Apr 11, 2016
| + # This is for plugins that inherit from BasePlugin but don't have | ||
| + # project in init. | ||
| + if not self.code.project: | ||
| + self.code.project = self._project_options |
kyrofa
Apr 11, 2016
Member
Thanks for the comments here, very clear. We can probably make that deprecation a little more helpful-- how about something like:
logger.warning(
'DEPRECATED: the plugin used by part {!r} needs to be updated '
'to accept project options in its initializer. See <link to plugins.md> '
'for more information'.format(self.name)And we can add that third param to the docs/plugins.md document.
|
Looks great! |
sergiusens commentedApr 11, 2016
No description provided.