Skip to content
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

Merged
merged 9 commits into from Aug 2, 2018

Conversation

sergiusens
Copy link
Collaborator

@sergiusens sergiusens commented Jul 31, 2018

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

  • Have you followed the guidelines for contributing?
  • Have you signed the CLA?
  • If this is a bugfix. Have you checked that there is a bug report open for the issue you are trying to fix on bug reports?
  • If this is a new feature. Have you discussed the design on the forum?
  • Have you successfully run ./runtests.sh static?
  • Have you successfully run ./runtests.sh unit?

@sergiusens sergiusens force-pushed the global-state-dir branch 2 times, most recently from fa6f40c to 8f37e90 Compare July 31, 2018 02:41
@codecov-io
Copy link

codecov-io commented Jul 31, 2018

Codecov Report

Merging #2186 into master will increase coverage by <.01%.
The diff coverage is 93.65%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
snapcraft/internal/states/__init__.py 100% <ø> (ø) ⬆️
snapcraft/internal/states/_state.py 87.5% <ø> (-0.74%) ⬇️
snapcraft/internal/states/_global_state.py 100% <100%> (+18.18%) ⬆️
snapcraft/internal/meta/_manifest.py 100% <100%> (ø) ⬆️
snapcraft/internal/meta/_snap_packaging.py 90.77% <100%> (+0.02%) ⬆️
snapcraft/internal/lifecycle/_clean.py 85.08% <100%> (-0.13%) ⬇️
snapcraft/internal/lifecycle/_runner.py 92.09% <100%> (+0.04%) ⬆️
snapcraft/project/_project_options.py 87.87% <33.33%> (-1.36%) ⬇️
snapcraft/project/_project.py 85.71% <71.42%> (-14.29%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 49cf505...76d7ec9. Read the comment docs.

@@ -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")
Copy link
Collaborator Author

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

Copy link
Contributor

@kyrofa kyrofa Jul 31, 2018

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?

Copy link
Collaborator Author

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):
Copy link
Contributor

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:
Copy link
Contributor

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?

Copy link
Collaborator Author

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>
def _global_state_constructor(loader, node):
parameters = loader.construct_mapping(node)
return GlobalState(**parameters)
GlobalStateT = TypeVar("GlobalStateT", bound="GlobalState")
Copy link
Contributor

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?

Copy link
Collaborator Author

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)
Copy link
Contributor

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 😛 .

Copy link
Collaborator Author

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

Copy link
Contributor

@kyrofa kyrofa left a 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!

@sergiusens sergiusens merged commit b412242 into canonical:master Aug 2, 2018
@sergiusens sergiusens deleted the global-state-dir branch August 2, 2018 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants