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

Add init template for flask-framework #1428

Merged
merged 7 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions charmcraft/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"simple": "init-simple",
"kubernetes": "init-kubernetes",
"machine": "init-machine",
"flask-framework": "init-flask-framework",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update _overview below to include a description of this template.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added an one sentence summary for now, but I will add a link to the document once we have published the document for the 12-factor project.

}
DEFAULT_PROFILE = "simple"

Expand Down
3 changes: 2 additions & 1 deletion charmcraft/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

from charmcraft import const
from charmcraft.bases import check_if_base_matches_host
from charmcraft.const import EXPERIMENTAL_EXTENSIONS_ENV_VAR
from charmcraft.env import (
get_managed_environment_log_path,
get_managed_environment_snap_channel,
Expand Down Expand Up @@ -130,7 +131,7 @@ def get_command_environment(base: Base) -> dict[str, str]:
env[const.MANAGED_MODE_ENV_VAR] = "1"

# Pass-through host environment that target may need.
for env_key in ["http_proxy", "https_proxy", "no_proxy"]:
for env_key in ["http_proxy", "https_proxy", "no_proxy", EXPERIMENTAL_EXTENSIONS_ENV_VAR]:
if env_key in os.environ:
env[env_key] = os.environ[env_key]

Expand Down
9 changes: 9 additions & 0 deletions charmcraft/templates/init-flask-framework/.gitignore.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
venv/
build/
*.charm
.tox/
.coverage
__pycache__/
*.py[cod]
.idea
.vscode/
31 changes: 31 additions & 0 deletions charmcraft/templates/init-flask-framework/charmcraft.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This file configures Charmcraft.
# See https://juju.is/docs/sdk/charmcraft-config for guidance.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the extension does fill in the type field, I'd prefer if we keep it in the template too, since a user might see from the documentation that it's required and be confused by it. This confusion will become more obvious when we make a jsonschema for charmcraft.yaml, since that will mark type as required (and thus IDEs will start complaining about its nonexistence).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, added, thanks!

name: {{ name }}

bases:
- build-on:
- name: ubuntu
channel: "22.04"
run-on:
- name: ubuntu
channel: "22.04"

# (Required)
summary: A very short one-line summary of the flask application.

# (Required)
description: |
A comprehensive overview of your Flask application.

extensions:
- flask-framework

# Uncomment the integrations used by your application
# requires:
# mysql:
# interface: mysql_client
# limit: 1
# postgresql:
# interface: postgresql_client
# limit: 1
Comment on lines +26 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this include all of the integrations we support? E.g., ingress seems to be missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ingress and other relations are default and static for now, so user can't change them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/canonical/xiilib/archive/v0.1.0.tar.gz
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of interest, what's the name? xiilib? Feels a bit cryptic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was originally going to be 12f, but names starting with a number caused some problems, so I substituted it with number XII.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any great ideas for better names are more than welcome 🙂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about twelve-f? Looks awkward at first glance but reads the same as 12f

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll throw my hat in the ring with zwolf. Advantages:

  • Is the German word for twelve
  • Isn't yet registered on pypi
  • Includes the substring "wolf" 🐺

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about ffffffffffff, and it's pronounced as /ɛfɛfɛfɛfɛfɛfɛfɛfɛfɛfɛfɛf/ 🤣

30 changes: 30 additions & 0 deletions charmcraft/templates/init-flask-framework/src/charm.py.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python3
# Copyright {{ year }} {{ author }}
# See LICENSE file for licensing details.

"""Flask Charm entrypoint."""

import logging
import typing

import ops

import xiilib.flask

logger = logging.getLogger(__name__)


class FlaskCharm(xiilib.flask.Charm):
"""Flask Charm service."""

def __init__(self, *args: typing.Any) -> None:
"""Initialize the instance.

Args:
args: passthrough to CharmBase.
"""
super().__init__(*args)


if __name__ == "__main__": # pragma: nocover
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove the pragma: nocover? It might not be relevant for all users

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, thanks!

ops.main.main(FlaskCharm)
23 changes: 23 additions & 0 deletions tests/spread/commands/init-flask-framework/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
summary: test charmcraft init with flask-framework profile

execute: |
mkdir -p test-init
cd test-init
charmcraft init --profile flask-framework
export CHARMCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS=true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be set in an environment keyword for the task. Here's an example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, thanks!

charmcraft fetch-lib charms.traefik_k8s.v2.ingress
charmcraft fetch-lib charms.observability_libs.v0.juju_topology
charmcraft fetch-lib charms.grafana_k8s.v0.grafana_dashboard
charmcraft fetch-lib charms.loki_k8s.v0.loki_push_api
charmcraft fetch-lib charms.data_platform_libs.v0.data_interfaces
charmcraft fetch-lib charms.prometheus_k8s.v0.prometheus_scrape
charmcraft pack --verbose
test -f *.charm

restore: |
export CHARMCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS=true
pushd test-init
charmcraft clean
popd

rm -rf test-init
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# limitations under the License.
#
# For further info, check https://github.com/canonical/charmcraft

"""Test charm library."""

PYDEPS = ["ops"]
LIBID = "my_lib"
LIBAPI = 0
Expand Down
Loading