-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathconfig.py
More file actions
63 lines (42 loc) · 1.6 KB
/
config.py
File metadata and controls
63 lines (42 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from __future__ import annotations
import tomllib
from pathlib import Path
from typing import Any
from pydantic import BaseModel, ConfigDict
def _find_pyproject_toml(input_path: Path) -> Path | None:
"""Find a `pyproject.toml` in any of the parent dirs"""
if not input_path.is_dir():
input_path = input_path.parent
if (pyproject_path := input_path / "pyproject.toml").exists():
return pyproject_path
if input_path == input_path.parent:
# Reached root dir
return None
return _find_pyproject_toml(input_path.parent)
def _get_config_section(path: Path) -> dict[str, Any] | None:
"""Get the pyodide pack config section from a pyproject.toml"""
config = tomllib.loads(path.read_text())
tools_config = config.get("tool")
if not isinstance(tools_config, dict):
return None
output = tools_config.get("pyodide_pack")
if output and isinstance(output, dict):
return output
return None
class PyPackConfig(BaseModel):
"""Configuration for handling Python files"""
model_config = ConfigDict(extra="forbid")
strip_module_docstrings: bool = True
strip_docstrings: bool = True
py_compile: bool = False
class SoPackConfig(BaseModel):
"""Configuration for handling shared libraries"""
model_config = ConfigDict(extra="forbid")
drop_unused_so: bool = True
class PackConfig(BaseModel):
"""pyodide-pack configuration"""
model_config = ConfigDict(extra="forbid")
requires: list[str] = []
include_paths: list[str] = []
py: PyPackConfig = PyPackConfig()
so: SoPackConfig = SoPackConfig()