From ab88c6ba048db2434aa686400202aa711524e331 Mon Sep 17 00:00:00 2001 From: Maarten Huijsmans Date: Sat, 30 Nov 2024 11:46:18 +0000 Subject: [PATCH] Add gitlab workflow extension to VSCode --- template/.devcontainer/devcontainer.json.jinja | 5 +++-- testing/tests/test_package.py | 4 ++-- testing/tests/utils.py | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/template/.devcontainer/devcontainer.json.jinja b/template/.devcontainer/devcontainer.json.jinja index f89d313..27ddec5 100644 --- a/template/.devcontainer/devcontainer.json.jinja +++ b/template/.devcontainer/devcontainer.json.jinja @@ -19,9 +19,10 @@ "extensions": [ "charliermarsh.ruff", "eamodio.gitlens", - "github.copilot", + "github.copilot",{% if ci =='github' %} "GitHub.vscode-github-actions", - "GitHub.vscode-pull-request-github", + "GitHub.vscode-pull-request-github",{% elif ci == 'gitlab' %} + "GitLab.gitlab-workflow",{% endif %} "ms-azuretools.vscode-docker", "ms-python.mypy-type-checker", "ms-python.python", diff --git a/testing/tests/test_package.py b/testing/tests/test_package.py index c55e6ca..004cbf5 100644 --- a/testing/tests/test_package.py +++ b/testing/tests/test_package.py @@ -28,7 +28,7 @@ def test_github_generation(answers: dict[str, str | bool], expected_paths: set[s ".github/dependabot.yml", } assert_paths(tmpdir, expected) - assert_devcontainer(Path(tmpdir) / ".devcontainer/devcontainer.json") + assert_devcontainer(Path(tmpdir) / ".devcontainer/devcontainer.json", github=True) assert_toml(Path(tmpdir) / "pyproject.toml") assert_yaml(Path(tmpdir) / ".pre-commit-config.yaml") assert_yaml(Path(tmpdir) / "docker-compose.yml") @@ -47,7 +47,7 @@ def test_gitlab_generation(answers: dict[str, str | bool], expected_paths: set[s copier.run_copy(str(_path.absolute()), tmpdir, data=answers_, cleanup_on_error=True) expected = expected_paths | {".gitlab-ci.yml"} assert_paths(tmpdir, expected) - assert_devcontainer(Path(tmpdir) / ".devcontainer/devcontainer.json") + assert_devcontainer(Path(tmpdir) / ".devcontainer/devcontainer.json", gitlab=True) assert_toml(Path(tmpdir) / "pyproject.toml") assert_yaml(Path(tmpdir) / ".pre-commit-config.yaml") assert_yaml(Path(tmpdir) / "docker-compose.yml") diff --git a/testing/tests/utils.py b/testing/tests/utils.py index c9817f0..e424977 100644 --- a/testing/tests/utils.py +++ b/testing/tests/utils.py @@ -25,6 +25,7 @@ def assert_paths(directory: str, paths: set[str]) -> None: ------ AssertionError If any of the paths in the set are not found in the directory. + """ tree = set() for root, _, files in os.walk(directory): @@ -57,8 +58,17 @@ def assert_yaml(path: Path) -> dict[str, Any]: raise AssertionError(f"Could not load: {path}") from e -def assert_devcontainer(path: Path) -> None: +def assert_devcontainer(path: Path, /, github: bool = False, gitlab: bool = False) -> None: """Check if the given path is a valid devcontainer definition.""" + if github: + extensions = [ + "GitHub.vscode-github-actions", + "GitHub.vscode-pull-request-github", + ] + elif gitlab: + extensions = ["GitLab.gitlab-workflow"] + else: + extensions = [] try: with path.open("r") as fh: data = json.load(fh) @@ -80,8 +90,7 @@ def assert_devcontainer(path: Path) -> None: "charliermarsh.ruff", "eamodio.gitlens", "github.copilot", - "GitHub.vscode-github-actions", - "GitHub.vscode-pull-request-github", + *extensions, "ms-azuretools.vscode-docker", "ms-python.mypy-type-checker", "ms-python.python",