-
Notifications
You must be signed in to change notification settings - Fork 122
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
refactor!: use ops._main._Manager in Scenario #1491
refactor!: use ops._main._Manager in Scenario #1491
Conversation
I had thought this might break #1445, but I seem to still get auto-completion for |
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!
@@ -1,4 +1,5 @@ | |||
import copy | |||
import typing |
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 a blocker.
- Should we use
from __future__ import annotations
instead? Withtype
andlist
. - If not, do we want
import typing
orfrom typing import List, Type
...?
I'm fine with leaving it as is for now
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.
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.
my 2c: incremental future annotations are great.
class MyCharm(CharmBase): | ||
on = _CharmEvents() | ||
class MyCharm(ops.CharmBase): | ||
on = _CharmEvents() # type: ignore |
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 a blocker. Is looking into making this type: ignore
unnecessary something we'd want to do in future? (I haven't looked at how on
is typed recently)
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.
Potentially, yes. It has an ignore in the main definition plus gets redefined when type checking. I'm sure we could do better.
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, thanks!
The ops._main._Manager class started out as the Ops class in Scenario, but went through significant modifications before it was added in ops. This PR merges those changes back into Scenario, so that it's also using the
_Manager
class. Other than generally simplifying the code, this also means that Scenario is even more consistent with using ops in production.This includes some small refactoring in ops to make this cleaner:
ops._main._emit_charm_event
is only used by_Manager
, so logically belongs inside that class. This also makes it much simpler to have a subclass override the behaviour.JujuContext
to_Manager
, so that it can be populated by something other thanos.environ
._Manager
subclasses to override how the charm metadata is loaded._Manager
subclasses to execute code after committing but before the framework is closed._
rather than-
in event names (Scenario consistently uses_
, even though this would always be-
from Juju - feel free to push back on this, requiring Scenario to undo the_
conversion when populating the context).The Scenario
runtime
andops_main_mock
modules are renamed to properly indicate that everything inside of them is an implementation detail and should be considered private by Scenario users. This is a breaking change but we're considering it a bug fix and not one that requires a major release, given that the documentation and top-level namespace were already clear on this. Note that the first commit does the rename and nothing else - but GitHub shows only one of the files as a rename (I think because too much content has then changed). It might be easier to read through the commits separately when reviewing.Significant Scenario refactoring:
runtime
toops_main_mock
, and it no longer (re) opens the SQLiteStorage - it instead takes a reference to the one that's in the framework, so that we're consistently using the same underlying storage, without relying on the filename being consistent (this eases moving to:memory:
in the future).runtime._OpsMainContext
is completely unused and missed being removed in previous refactoring, so it's entirely deleted.Ops
class survives, but is now a subclass of theops._main._Manager
class. A reasonable amount of functionality is now removed (because the parent handles it), and the remaining code is specifically for handling the testing framework.A few type hints are added in some tests where I was working on fixing the test and it helped to do that.
Fixes #1425