-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec.py
106 lines (79 loc) · 3.33 KB
/
spec.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import pathlib
from typing import List, Literal, Optional, Union
from pydantic import BaseModel, Field
from pydantic_yaml import YamlModelMixin
from typing_extensions import Annotated
# TODO: Add classmethods to convert these to their a
# TODO: Move models to the associated unit class
class AnacondaUnitModelMixin(BaseModel):
"""The definition for running an Anaconda-compatible Unit."""
name: str
"""The name of the environment."""
requirements: Union[pathlib.Path, List[str]] = []
"""Either a path to a requirements.txt file or a list of requirements to install."""
command: List[str]
"""A list of strings representing the command to be run."""
working_dir: Optional[str] = None
"""The optional working directory for the script being run."""
class CondaUnitModel(AnacondaUnitModelMixin):
"""The definition for running a conda Unit."""
unit_type: Literal["conda"]
"""Definition that this is a conda model."""
class MambaUnitModel(AnacondaUnitModelMixin):
"""The definition for running a mamba Unit."""
unit_type: Literal["mamba"]
"""Definition that this is a mamba model."""
class PoetryUnitModel(BaseModel):
"""The definition for running a poetry Unit."""
unit_type: Literal["poetry"]
"""Definition that this is a poetry model."""
source_dir: str
"""Path to the top level directory for the module using poetry."""
script_path: pathlib.Path
"""The path to a Python script to run relative to source dir."""
script_args: List[str]
"""Arguments to pass to script_path."""
class PyenvVirtualenvUnitModel(BaseModel):
"""The definition for running a pyenv Unit."""
unit_type: Literal["pyenv-virtualenv"]
"""Definition that this is a pyenv model."""
name: str
"""The name of the virtual environment."""
py_version: str
"""The base Python version to run e.g. 3.10"""
requirements: Union[pathlib.Path, List[str]] = []
"""Either a path to a requirements.txt file or a list of requirements to install."""
script_path: pathlib.Path
"""The path to a Python script to run."""
script_args: List[str]
"""Arguments to pass to script_path."""
class VenvUnitModel(BaseModel):
"""The definition for running a venv Unit."""
unit_type: Literal["venv"]
"""Definition that this is a venv model."""
name: str
"""The name of the virtual environment."""
env_dir: pathlib.Path
"""Location to create and save the virtual environment."""
requirements: Union[pathlib.Path, List[str]] = []
"""Either a path to a requirements.txt file or a list of requirements to install."""
script_path: pathlib.Path
"""The path to a Python script to run."""
script_args: List[str]
"""Arguments to pass to script_path."""
Unit = Annotated[
Union[
CondaUnitModel, MambaUnitModel, PoetryUnitModel, PyenvVirtualenvUnitModel, VenvUnitModel
],
Field(discriminator="unit_type"),
]
"""The collection of Unit models that we will be able to deserialize."""
# We have this class be separate from the yaml model so we can support
# toml, json, etc.
class Spec(BaseModel):
"""The definition of the Python Compose file specification."""
units: List[Unit]
"""A list of units that will be ran through Python Compose"""
class YamlSpec(YamlModelMixin, Spec):
"""A wrapper around Spec for YAML support."""
pass