New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
state: allow parametrization of the global state file #2186
Conversation
fa6f40c
to
8f37e90
Compare
Codecov Report
@@ Coverage Diff @@
## master #2186 +/- ##
==========================================
+ Coverage 91.23% 91.24% +<.01%
==========================================
Files 202 201 -1
Lines 12865 12899 +34
Branches 1907 1912 +5
==========================================
+ Hits 11738 11770 +32
Misses 767 767
- Partials 360 362 +2
Continue to review full report at Codecov.
|
@@ -231,6 +231,10 @@ def __init__( | |||
self._set_machine(target_deb_arch) | |||
self.__debug = debug | |||
|
|||
# These paths maintain backwards compatibility. | |||
self.internal_dir = os.path.join(self.__project_dir, "snap", ".snapcraft") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe these two need to be _ to indicate they should not be used from plugins
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Also note that _project_options is being phased out, do you want this in Project instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I can move it to project
@@ -31,6 +34,24 @@ class GlobalState(State): | |||
|
|||
yaml_tag = u"!GlobalState" | |||
|
|||
def __init__(self, build_packages, build_snaps): | |||
@classmethod | |||
def load(cls, *, filepath: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a return type check, here.
def get_build_snaps(self) -> List[str]: | ||
return self.assets.get("build-snaps", []) | ||
|
||
def __init__(self, *, build_packages: List[str], build_snaps: List[str]) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait... this should totally be broken right now. This should be trying to pass assets
as a kwarg, not build_packages
or build_snaps
. What's happening here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(snapcraft) ubuntu@snapcraft-xenial-dev:~/source/make-hello$ ipython
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from snapcraft.internal.states import GlobalState
In [2]: s = GlobalState.load(filepath="snap/.snapcraft/state")
In [3]: s
Out[3]: GlobalState(assets: OrderedDict([('build-packages', ['gcc']), ('build-snaps', ['go'])]))
In [4]: cat snap/.snapcraft/state
!GlobalState
assets:
build-packages: [gcc]
build-snaps: [go]
Refactor so that the global state file is not hard coded but part of the project instead. This allows for future relocations. LP: #1782783 Signed-off-by: Sergio Schvezov <sergio.schvezov@canonical.com>
Signed-off-by: Sergio Schvezov <sergio.schvezov@canonical.com>
d4e4efb
to
2c0b730
Compare
def _global_state_constructor(loader, node): | ||
parameters = loader.construct_mapping(node) | ||
return GlobalState(**parameters) | ||
GlobalStateT = TypeVar("GlobalStateT", bound="GlobalState") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this as opposed to just quoting the type within the class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure 🤷♂️, reverted
|
||
self.add_constructor(u"!GlobalState", type(self).construct_global_state) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yuck, they've made this awkward 😛 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it could be added after class declaration too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you!
Refactor so that the global state file is not hard coded but part
of the project instead. This allows for future relocations.
LP: #1782783
Signed-off-by: Sergio Schvezov sergio.schvezov@canonical.com
./runtests.sh static
?./runtests.sh unit
?