-
Notifications
You must be signed in to change notification settings - Fork 2
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 dev container and tests #19
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
342ee9a
add devcontainer
john0isaac 98c7557
use requirements txt instead of pyproject
john0isaac a57be5c
fix github extension name
john0isaac c393f4c
automate site generation and testing
john0isaac b6240e9
fix ci
john0isaac 817b525
remove python3.9
john0isaac 000b0c8
test python3.13
john0isaac f29d701
add correct image for codespaces
john0isaac 25a0299
add correct image for codespaces
john0isaac 09afa2b
add correct image for codespaces
john0isaac 1055f1e
revert back to 3.12
john0isaac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ARG IMAGE="python:3.12" | ||
FROM --platform=amd64 mcr.microsoft.com/vscode/devcontainers/${IMAGE} | ||
RUN apt-get update \ | ||
&& export DEBIAN_FRONTEND=noninteractive \ | ||
&& apt-get -y install --no-install-recommends build-essential libssl-dev gdb cmake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
// README at: https://github.com/devcontainers/templates/tree/main/src/python | ||
{ | ||
"name": "Cookie Cutter - Render Engine", | ||
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile | ||
"build": { | ||
"dockerfile": "Dockerfile", | ||
"context": "..", | ||
"args": { | ||
"IMAGE": "python:3.12" | ||
} | ||
}, | ||
"postCreateCommand": ". .devcontainer/setup.sh", | ||
"customizations": { | ||
"vscode": { | ||
"settings": { | ||
"python.formatting.provider": "charliermarsh.ruff", | ||
"python.testing.pytestEnabled": true, | ||
"python.testing.pytestPath": "pytest", | ||
"python.testing.unittestEnabled": false, | ||
"python.editor.formatOnSave": true, | ||
"python.editor.codeActionsOnSave": {"source.fixAll": true}, | ||
"python.testing.pytestArgs": [ | ||
"tests" | ||
], | ||
".markdownlint-cli2.ignores": [".gitignore"] | ||
|
||
}, | ||
"extensions": [ | ||
"ms-python.python", | ||
"charliermarsh.ruff", | ||
"GitHub.vscode-github-actions", | ||
"yzhang.markdown-all-in-one", | ||
"DavidAnson.vscode-markdownlint", | ||
"ms-vscode.makefile-tools" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
python -m pip install --user --upgrade pip | ||
python -m venv .venv | ||
source .venv/bin/activate | ||
python -m pip install pip-tools | ||
python -m piptools compile --upgrade -o requirements.txt requirements.in | ||
python -m pip install -r requirements-dev.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Check Dev Container | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- ".devcontainer/**" | ||
- ".github/workflows/devcontainer-ci.yaml" | ||
pull_request: | ||
branches: [ main ] | ||
paths: | ||
- ".devcontainer/**" | ||
- ".github/workflows/devcontainer-ci.yaml" | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js 20.x | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20.x | ||
- run: npm install -g @devcontainers/cli | ||
- run: devcontainer build --config ./.devcontainer/devcontainer.json --workspace-folder "$(pwd)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: PyTest | ||
on: | ||
workflow_call: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.9", "3.10", "3.11", "3.12"] | ||
fail-fast: true | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: python -m pip install --upgrade pip -r requirements-dev.txt | ||
- name: Run tests | ||
run: python tests/test_template.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pip-tools | ||
pytest | ||
|
||
-r requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cookiecutter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# | ||
# This file is autogenerated by pip-compile with Python 3.12 | ||
# by the following command: | ||
# | ||
# pip-compile --output-file=requirements.txt requirements.in | ||
# | ||
arrow==1.3.0 | ||
# via cookiecutter | ||
binaryornot==0.4.4 | ||
# via cookiecutter | ||
certifi==2024.8.30 | ||
# via requests | ||
chardet==5.2.0 | ||
# via binaryornot | ||
charset-normalizer==3.4.0 | ||
# via requests | ||
click==8.1.7 | ||
# via cookiecutter | ||
cookiecutter==2.6.0 | ||
# via -r requirements.in | ||
idna==3.10 | ||
# via requests | ||
jinja2==3.1.4 | ||
# via cookiecutter | ||
markdown-it-py==3.0.0 | ||
# via rich | ||
markupsafe==3.0.2 | ||
# via jinja2 | ||
mdurl==0.1.2 | ||
# via markdown-it-py | ||
pygments==2.18.0 | ||
# via rich | ||
python-dateutil==2.9.0.post0 | ||
# via arrow | ||
python-slugify==8.0.4 | ||
# via cookiecutter | ||
pyyaml==6.0.2 | ||
# via cookiecutter | ||
requests==2.32.3 | ||
# via cookiecutter | ||
rich==13.9.4 | ||
# via cookiecutter | ||
six==1.17.0 | ||
# via python-dateutil | ||
text-unidecode==1.3 | ||
# via python-slugify | ||
types-python-dateutil==2.9.0.20241206 | ||
# via arrow | ||
urllib3==2.2.3 | ||
# via requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[pytest] | ||
python_files = test_*.py | ||
python_classes = [A-Z]*Test | ||
python_functions = test_* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
""" | ||
Test the Cookiecutter template. | ||
""" | ||
from cookiecutter.generate import generate_context | ||
from cookiecutter.main import cookiecutter | ||
from pathlib import Path | ||
from shlex import split | ||
from subprocess import run | ||
from venv import create | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def template() -> Path: | ||
""" The template under test. | ||
|
||
""" | ||
return Path(__file__).resolve().parents[1] | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def tmpdir(tmp_path_factory) -> Path: | ||
""" Test directory. | ||
|
||
""" | ||
return tmp_path_factory.mktemp("test_template") | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def context(template) -> dict: | ||
""" Template context for testing. | ||
|
||
""" | ||
context = generate_context(template.joinpath("cookiecutter.json")) | ||
context["cookiecutter"].update({ | ||
"project_slug": "slugify" | ||
}) | ||
return context["cookiecutter"] | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def project(tmpdir, template, context) -> Path: | ||
""" Create a test project from the Cookiecutter template. | ||
|
||
""" | ||
cookiecutter(str(template), no_input=True, output_dir=tmpdir, extra_context=context) | ||
return tmpdir / context["project_slug"] | ||
|
||
|
||
@pytest.fixture | ||
def python(tmp_path): | ||
""" Create a Python virtual environment for testing. | ||
|
||
""" | ||
venv = tmp_path / ".venv" | ||
create(venv, with_pip=True) | ||
return venv / "bin" / "python" | ||
|
||
|
||
def test_project(project): | ||
""" Verify that the project was created correctly. | ||
|
||
""" | ||
# Just a basic sanity test. | ||
assert len(list(project.iterdir())) == 4 | ||
return | ||
|
||
|
||
@pytest.fixture | ||
def install_render_engine_cli(python): | ||
install_cli = "pip install render_engine[cli]" | ||
install_args = split(f"{python} -m {install_cli}") | ||
install_process = run(install_args) | ||
assert install_process.returncode == 0 | ||
|
||
|
||
def test_site_generation(context, project, python, install_render_engine_cli): | ||
generate_site = "render_engine build app:app" | ||
generate_args = split(f"{python} -m {generate_site}") | ||
generate_process = run(generate_args, cwd=project) | ||
assert generate_process.returncode == 0 | ||
john0isaac marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
# Make the script executable. | ||
|
||
if __name__ == "__main__": | ||
raise SystemExit(pytest.main([__file__])) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason not 3.13?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we did discuss this before it was not available at the time of our discussion.
let me check if it's available now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's available now
https://github.com/devcontainers/images/tree/main/src/python
let me test it tonight.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they are lying the only available 3.13 is dev-3.13.
let's keep 3.12 until they release a stable 3.13
See:
https://mcr.microsoft.com/v2/vscode/devcontainers/python/tags/list