Files
cibuildwheel/test/test_projects/base.py
T
Matthieu DarboisandJoe Rickerby a96545b729 feat: use python3.11+ for cibuildwheel driver (#1912)
* chore: use SPEC 0 schedule for cibuildwheel

* remove support for {python} and {pip} in commands

* Remove specific Python versions from the update-dependencies job

The requirements pinning is done by uv now, so we don't need to
run the versions of Python to do the pinning anymore.

---------

Co-authored-by: Joe Rickerby <joerick@mac.com>
2025-01-16 10:45:18 -05:00

45 lines
1.3 KiB
Python

from __future__ import annotations
from pathlib import Path
from typing import Any
import jinja2
FilesDict = dict[str, str | jinja2.Template]
TemplateContext = dict[str, Any]
class TestProject:
"""
An object that represents a project that can be built by cibuildwheel.
Can be manipulated in tests by changing `files` and `template_context`.
Write out to the filesystem using `generate`.
"""
__test__ = False # Have pytest ignore this class on `from .test_projects import TestProject`
files: FilesDict
template_context: TemplateContext
def __init__(self) -> None:
self.files = {}
self.template_context = {}
def generate(self, path: Path) -> None:
for filename, content in self.files.items():
file_path = path / filename
file_path.parent.mkdir(parents=True, exist_ok=True)
with file_path.open("w", encoding="utf8") as f:
if isinstance(content, jinja2.Template):
content = content.render(self.template_context) # noqa: PLW2901
f.write(content)
def copy(self) -> TestProject:
other = TestProject()
other.files = self.files.copy()
other.template_context = self.template_context.copy()
return other