Skip to content

Commit

Permalink
feat: use ops.main() type hints (#1911)
Browse files Browse the repository at this point in the history
The `ops.main` entry point will be properly typed starting with the
upcoming release, ops==2.17.0

This PR updates the templates so that new charms use the fixed type
hints.

It is paired with #1883 where charmcraft analyse validates that ops.main
is called.

We'll be relying on charm repo static type checker to validate that
ops.main is called with correct arguments.

- [x] wait for ops 2.17.0 to be released
- [x] update ops version in the templates
- [x] update ops.main() call in the templates

https://warthogs.atlassian.net/browse/CHARMTECH-276
parent: https://warthogs.atlassian.net/browse/CHARMTECH-219

---------

Co-authored-by: Alex Lowe <alex.lowe@canonical.com>
  • Loading branch information
dimaqq and lengau authored Sep 26, 2024
1 parent 6cb16e2 commit 2fe5362
Show file tree
Hide file tree
Showing 14 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ops ~= 2.17
paas-app-charmer>=1.1,<2
2 changes: 1 addition & 1 deletion charmcraft/templates/init-django-framework/src/charm.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ class {{ class_name }}(paas_app_charmer.django.Charm):


if __name__ == "__main__":
ops.main.main({{ class_name }})
ops.main({{ class_name }})
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ops ~= 2.17
paas-app-charmer>=1.1,<2
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ class {{ class_name }}(paas_app_charmer.fastapi.Charm):


if __name__ == "__main__":
ops.main.main({{ class_name }})
ops.main({{ class_name }})
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ops ~= 2.17
paas-app-charmer>=1.1,<2
2 changes: 1 addition & 1 deletion charmcraft/templates/init-flask-framework/src/charm.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ class {{ class_name }}(paas_app_charmer.flask.Charm):


if __name__ == "__main__":
ops.main.main({{ class_name }})
ops.main({{ class_name }})
1 change: 1 addition & 0 deletions charmcraft/templates/init-go-framework/requirements.txt.j2
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ops ~= 2.17
paas-app-charmer>=1.1,<2
2 changes: 1 addition & 1 deletion charmcraft/templates/init-go-framework/src/charm.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ class {{ class_name }}(paas_app_charmer.go.Charm):


if __name__ == "__main__":
ops.main.main({{ class_name }})
ops.main({{ class_name }})
2 changes: 1 addition & 1 deletion charmcraft/templates/init-kubernetes/requirements.txt.j2
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ops ~= 2.8
ops ~= 2.17
2 changes: 1 addition & 1 deletion charmcraft/templates/init-kubernetes/src/charm.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ class {{ class_name }}(ops.CharmBase):


if __name__ == "__main__": # pragma: nocover
ops.main({{ class_name }}) # type: ignore
ops.main({{ class_name }})
2 changes: 1 addition & 1 deletion charmcraft/templates/init-machine/requirements.txt.j2
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ops ~= 2.8
ops ~= 2.17
2 changes: 1 addition & 1 deletion charmcraft/templates/init-machine/src/charm.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ class {{ class_name }}(ops.CharmBase):


if __name__ == "__main__": # pragma: nocover
ops.main({{ class_name }}) # type: ignore
ops.main({{ class_name }})
2 changes: 1 addition & 1 deletion charmcraft/templates/init-simple/requirements.txt.j2
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ops ~= 2.8
ops ~= 2.17
2 changes: 1 addition & 1 deletion charmcraft/templates/init-simple/src/charm.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ class {{ class_name }}(ops.CharmBase):


if __name__ == "__main__": # pragma: nocover
ops.main({{ class_name }}) # type: ignore
ops.main({{ class_name }})

0 comments on commit 2fe5362

Please sign in to comment.