Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ click==8.1.7
codespell==2.2.6
colorama==0.4.6
coverage==7.5.1
craft-application==3.1.0
craft-application==3.2.0
craft-archives==1.1.3
craft-cli==2.6.0
craft-grammar==1.2.0
Expand Down
2 changes: 1 addition & 1 deletion requirements-doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cffi==1.16.0
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
craft-application==3.1.0
craft-application==3.2.0
craft-archives==1.1.3
craft-cli==2.6.0
craft-grammar==1.2.0
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
craft-application==3.1.0
craft-application==3.2.0
craft-archives==1.1.3
craft-cli==2.6.0
craft-grammar==1.2.0
Expand Down
2 changes: 1 addition & 1 deletion rockcraft/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
ProjectClass=project.Project,
BuildPlannerClass=project.BuildPlanner,
source_ignore_patterns=["*.rock"],
docs_url="https://documentation.ubuntu.com/rockcraft/en/stable",
docs_url="https://documentation.ubuntu.com/rockcraft/en/{version}",
)


Expand Down
17 changes: 10 additions & 7 deletions rockcraft/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class InitCommand(AppCommand):
rockcraft_yaml=textwrap.dedent(
"""\
name: {name}
# see https://documentation.ubuntu.com/rockcraft/en/stable/explanation/bases/
# see {versioned_url}/explanation/bases/
# for more information about bases and using 'bare' bases for chiselled rocks
base: ubuntu@22.04 # the base environment for this rock
version: '0.1' # just for humans. Semantic versioning is recommended
Expand All @@ -91,7 +91,7 @@ class InitCommand(AppCommand):
rockcraft_yaml=textwrap.dedent(
"""\
name: {name}
# see https://documentation.ubuntu.com/rockcraft/en/stable/explanation/bases/
# see {versioned_url}/explanation/bases/
# for more information about bases and using 'bare' bases for chiselled rocks
base: ubuntu@22.04 # the base environment for this Flask application
version: '0.1' # just for humans. Semantic versioning is recommended
Expand All @@ -107,7 +107,7 @@ class InitCommand(AppCommand):
# to ensure the flask-framework extension works properly, your Flask application
# should have an `app.py` file with an `app` object as the WSGI entrypoint.
# a `requirements.txt` file with at least the flask package should also exist.
# see https://documentation.ubuntu.com/rockcraft/en/stable/reference/extensions/flask-framework
# see {versioned_url}/reference/extensions/flask-framework
# for more information.
extensions:
- flask-framework
Expand Down Expand Up @@ -139,7 +139,7 @@ class InitCommand(AppCommand):
# you can add package slices or Debian packages to the image.
# package slices are subsets of Debian packages, which result
# in smaller and more secure images.
# see https://documentation.ubuntu.com/rockcraft/en/latest/explanation/chisel/
# see {versioned_url}/explanation/chisel/

# add this part if you want to add packages slices to your image.
# you can find a list of packages slices at https://github.com/canonical/chisel-releases
Expand All @@ -164,7 +164,7 @@ class InitCommand(AppCommand):
rockcraft_yaml=textwrap.dedent(
"""\
name: {name}
# see https://documentation.ubuntu.com/rockcraft/en/stable/explanation/bases/
# see {versioned_url}/explanation/bases/
# for more information about bases and using 'bare' bases for chiselled rocks
base: ubuntu@22.04 # the base environment for this Django application
version: '0.1' # just for humans. Semantic versioning is recommended
Expand Down Expand Up @@ -246,17 +246,20 @@ def run(self, parsed_args: "argparse.Namespace") -> None:
# Get the init profile
init_profile = self._PROFILES[parsed_args.profile]

versioned_docs_url = self._app.versioned_docs_url

# Setup the reference documentation link if available
profile_reference_docs: str | None = None
if self._app.docs_url and init_profile.doc_slug:
profile_reference_docs = self._app.docs_url + init_profile.doc_slug
if versioned_docs_url and init_profile.doc_slug:
profile_reference_docs = versioned_docs_url + init_profile.doc_slug

# Format the template, all templates should be tested to avoid risk of
# expecting documentation when there isn't any set
context = {
"name": name,
"snake_name": name.replace("-", "_").lower(),
"profile_reference_docs": profile_reference_docs,
"versioned_url": versioned_docs_url,
}
rockcraft_yaml_path = init(init_profile.rockcraft_yaml.format(**context))

Expand Down
4 changes: 2 additions & 2 deletions rockcraft/extensions/gunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def _app_prime(self):
raise ExtensionError(
"flask-framework extension requires the 'prime' entry in the "
"flask-framework/install-app part to start with flask/app",
docs_url="https://documentation.ubuntu.com/rockcraft/en/stable/reference/extensions/flask-framework",
doc_slug="/reference/extensions/flask-framework",
logpath_report=False,
)
if not user_prime:
Expand Down Expand Up @@ -301,7 +301,7 @@ def check_project(self):
if error_messages:
raise ExtensionError(
"\n".join("- " + message for message in error_messages),
docs_url="https://documentation.ubuntu.com/rockcraft/en/stable/reference/extensions/flask-framework",
doc_slug="/reference/extensions/flask-framework",
logpath_report=False,
)

Expand Down
16 changes: 9 additions & 7 deletions tests/unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import yaml
from craft_cli import emit
from rockcraft import cli, extensions, services
from rockcraft.application import Rockcraft
from rockcraft.application import Rockcraft, APP_METADATA
from rockcraft.models import project


Expand Down Expand Up @@ -130,15 +130,17 @@ def test_run_init_flask(mocker, emitter, monkeypatch, new_dir, tmp_path):

cli.run()

versioned_url = APP_METADATA.versioned_docs_url

rockcraft_yaml_path = Path("rockcraft.yaml")
rock_project_yaml = yaml.safe_load(rockcraft_yaml_path.read_text())

assert len(rock_project_yaml["summary"]) < 80
assert len(rock_project_yaml["description"].split()) < 100
assert rockcraft_yaml_path.read_text() == textwrap.dedent(
"""\
f"""\
name: test-name
# see https://documentation.ubuntu.com/rockcraft/en/stable/explanation/bases/
# see {versioned_url}/explanation/bases/
# for more information about bases and using 'bare' bases for chiselled rocks
base: ubuntu@22.04 # the base environment for this Flask application
version: '0.1' # just for humans. Semantic versioning is recommended
Expand All @@ -154,7 +156,7 @@ def test_run_init_flask(mocker, emitter, monkeypatch, new_dir, tmp_path):
# to ensure the flask-framework extension works properly, your Flask application
# should have an `app.py` file with an `app` object as the WSGI entrypoint.
# a `requirements.txt` file with at least the flask package should also exist.
# see https://documentation.ubuntu.com/rockcraft/en/stable/reference/extensions/flask-framework
# see {versioned_url}/reference/extensions/flask-framework
# for more information.
extensions:
- flask-framework
Expand Down Expand Up @@ -186,7 +188,7 @@ def test_run_init_flask(mocker, emitter, monkeypatch, new_dir, tmp_path):
# you can add package slices or Debian packages to the image.
# package slices are subsets of Debian packages, which result
# in smaller and more secure images.
# see https://documentation.ubuntu.com/rockcraft/en/latest/explanation/chisel/
# see {versioned_url}/explanation/chisel/

# add this part if you want to add packages slices to your image.
# you can find a list of packages slices at https://github.com/canonical/chisel-releases
Expand All @@ -207,9 +209,9 @@ def test_run_init_flask(mocker, emitter, monkeypatch, new_dir, tmp_path):
)
emitter.assert_message(
textwrap.dedent(
"""\
f"""\
Created 'rockcraft.yaml'.
Go to https://documentation.ubuntu.com/rockcraft/en/stable/reference/extensions/flask-framework to read more about the 'flask-framework' profile."""
Go to {versioned_url}/reference/extensions/flask-framework to read more about the 'flask-framework' profile."""
)
)
monkeypatch.setenv("ROCKCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS", "0")
Expand Down
1 change: 1 addition & 0 deletions tools/schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def generate_project_schema() -> str:
# Initialize the default template with a name
context = {
"name": "my-rock-name",
"versioned_url": "www.example.com",
}
# pylint: disable=W0212
init_template = cli.commands.InitCommand._PROFILES[
Expand Down