Skip to content

Commit

Permalink
fix(flask): don't enforce definition of base, build-base and platforms (
Browse files Browse the repository at this point in the history
#529)

---------

Co-authored-by: Tiago Nobrega <[email protected]>
  • Loading branch information
jdkandersson and tigarmo authored Apr 9, 2024
1 parent 31a6152 commit 1101844
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
7 changes: 0 additions & 7 deletions rockcraft/extensions/gunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,6 @@ def get_root_snippet(self) -> Dict[str, Any]:
},
},
}
if (
"build-base" not in self.yaml_data
and self.yaml_data.get("base", "bare") == "bare"
):
snippet["build-base"] = "[email protected]"
if "platforms" not in self.yaml_data:
snippet["platforms"] = {"amd64": {}}
snippet["parts"] = self._gen_parts()
return snippet

Expand Down
22 changes: 19 additions & 3 deletions tests/unit/extensions/test_gunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def flask_extension(mock_extensions, monkeypatch):

@pytest.fixture(name="flask_input_yaml")
def flask_input_yaml_fixture():
return {"base": "[email protected]", "extensions": ["flask-framework"]}
return {
"base": "[email protected]",
"platforms": {"amd64": {}},
"extensions": ["flask-framework"],
}


@pytest.fixture(name="django_input_yaml")
Expand Down Expand Up @@ -276,6 +280,8 @@ def test_flask_extension_bare(tmp_path):
flask_input_yaml = {
"extensions": ["flask-framework"],
"base": "bare",
"build-base": "[email protected]",
"platforms": {"amd64": {}},
"parts": {"flask/install-app": {"prime": ["-flask/app/.git"]}},
}
applied = extensions.apply_extensions(tmp_path, flask_input_yaml)
Expand All @@ -284,13 +290,17 @@ def test_flask_extension_bare(tmp_path):
"override-build": "mkdir -m 777 ${CRAFT_PART_INSTALL}/tmp",
"stage-packages": ["bash_bins", "coreutils_bins", "ca-certificates_data"],
}
assert applied["build-base"] == "[email protected]"


@pytest.mark.usefixtures("flask_extension")
def test_flask_extension_no_requirements_txt_error(tmp_path):
(tmp_path / "app.py").write_text("app = object()")
flask_input_yaml = {"extensions": ["flask-framework"], "base": "bare"}
flask_input_yaml = {
"extensions": ["flask-framework"],
"base": "bare",
"build-base": "[email protected]",
"platforms": {"amd64": {}},
}
with pytest.raises(ExtensionError) as exc:
extensions.apply_extensions(tmp_path, flask_input_yaml)
assert "requirements.txt" in str(exc)
Expand All @@ -303,6 +313,8 @@ def test_flask_extension_incorrect_prime_prefix_error(tmp_path):
flask_input_yaml = {
"extensions": ["flask-framework"],
"base": "bare",
"build-base": "[email protected]",
"platforms": {"amd64": {}},
"parts": {"flask-framework/install-app": {"prime": ["app.py"]}},
}
(tmp_path / "requirements.txt").write_text("flask")
Expand All @@ -317,6 +329,8 @@ def test_flask_extension_incorrect_wsgi_path_error(tmp_path):
flask_input_yaml = {
"extensions": ["flask-framework"],
"base": "bare",
"build-base": "[email protected]",
"platforms": {"amd64": {}},
"parts": {"flask/install-app": {"prime": ["flask/app/requirement.txt"]}},
}
(tmp_path / "requirements.txt").write_text("flask")
Expand All @@ -339,6 +353,8 @@ def test_flask_extension_flask_service_override_disable_wsgi_path_check(tmp_path
flask_input_yaml = {
"extensions": ["flask-framework"],
"base": "bare",
"build-base": "[email protected]",
"platforms": {"amd64": {}},
"services": {
"flask": {
"command": "/bin/python3 -m gunicorn -c /flask/gunicorn.conf.py webapp:app"
Expand Down

0 comments on commit 1101844

Please sign in to comment.