-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathsettings.py
More file actions
152 lines (119 loc) · 5.48 KB
/
settings.py
File metadata and controls
152 lines (119 loc) · 5.48 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import contextlib
from typing import Annotated
from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict
ENVIRONMENT_PREFIX = "CF_TICK_"
"""
All environment variables are expected to be prefixed with this.
"""
ENV_CONDA_FORGE_ORG = ENVIRONMENT_PREFIX + "CONDA_FORGE_ORG"
"""
The environment variable used to set the `conda_forge_org` setting.
Note: This must match the field name in the `BotSettings` class.
"""
ENV_GRAPH_GITHUB_BACKEND_REPO = ENVIRONMENT_PREFIX + "GRAPH_GITHUB_BACKEND_REPO"
"""
The environment variable used to set the `graph_github_backend_repo` setting.
Note: This must match the field name in the `BotSettings` class.
"""
Fraction = Annotated[float, Field(ge=0.0, le=1.0)]
class BotSettings(BaseSettings):
"""
The global settings for the bot.
To configure a settings value, set the corresponding environment variable with the prefix `CF_TICK_`.
For example, to set the `graph_github_backend_repo` setting, set the environment variable
`CF_TICK_GRAPH_GITHUB_BACKEND_REPO`.
To access the current settings object, please use the `settings()` function.
Note: There still exists a significant amount of settings that are not yet exposed here.
All new settings should go here, and the other ones should eventually be migrated.
"""
model_config = SettingsConfigDict(env_prefix=ENVIRONMENT_PREFIX)
conda_forge_org: str = Field("conda-forge", pattern=r"^[\w\.-]+$")
"""
The GitHub organization containing all feedstocks. Default: "conda-forge".
If you change the field name, you must also update the `ENV_CONDA_FORGE_ORG` constant.
"""
graph_github_backend_repo: str = Field(
"regro/cf-graph-countyfair", pattern=r"^[\w\.-]+/[\w\.-]+$"
)
"""
The GitHub repository to deploy to. Default: "regro/cf-graph-countyfair".
If you change the field name, you must also update the `ENV_GRAPH_GITHUB_BACKEND_REPO` constant.
"""
graph_repo_default_branch: str = "master"
"""
The default branch of the graph_github_backend_repo repository.
"""
@property
def graph_github_backend_raw_base_url(self) -> str:
"""
The base URL for the GitHub raw view of the graph_github_backend_repo repository.
Example: https://github.com/regro/cf-graph-countyfair/raw/master.
"""
return f"https://github.com/{self.graph_github_backend_repo}/raw/{self.graph_repo_default_branch}/"
github_runner_debug: bool = Field(False, alias="RUNNER_DEBUG")
"""
Whether we are executing within a GitHub Actions run with debug logging enabled. Default: False.
This is set automatically by GitHub Actions.
https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#default-environment-variables
"""
frac_update_upstream_versions: Fraction = 1.0
"""
The fraction of feedstocks (randomly selected) to update in the update-upstream-versions job.
This is currently only respected when running concurrently (via process pool), not in sequential mode.
Therefore, you don't need to set this when debugging locally.
"""
batch_size_update_upstream_versions_deploy: int = 10
"""The batch size used to push upstream version updates to the graph as they are found.
"""
frac_make_graph: Fraction = 0.1
"""
The fraction of feedstocks (randomly selected) to update in the make-graph job.
In tests or when debugging, you probably need to set this to 1.0 to update all feedstocks.
"""
frac_update_pr_json: Fraction = 0.25
"""
The fraction of feedstocks (randomly selected) to update in the prs job.
In tests or when debugging, you probably need to set this to 1.0 to update all feedstocks.
"""
pull_request_reopen_window: float = 15 * 60.0
"""
A pull request that is closed can be reopened if it is done so within this amount of time.
Specified in seconds.
"""
pr_refresh_age_days: float = 7.0
"""
Number of days after which to refresh PR cache for 'clean' PRs to detect potential conflicts.
Works around GitHub API bug #5150 where Last-Modified caching can hide merge conflicts.
Set to 0 to always refresh.
"""
_use_settings_override: BotSettings | None = None
"""
If not None, the application should use this settings object instead of generating a new one.
"""
def settings() -> BotSettings:
"""Get the current settings object."""
if _use_settings_override:
return _use_settings_override.model_copy() # prevent side-effects
return BotSettings()
@contextlib.contextmanager
def use_settings(s: BotSettings | None):
"""
Context manager that overrides the application settings with the values set in the provided settings object.
The new settings are used within the context of the `with` statement.
After exiting the context, the original settings are restored.
DO NOT call this function within multithreading contexts, as it will override the settings for all threads,
and lead to unpredictable behavior.
Parameters
----------
s
The settings object to use. None stands for the default settings behavior. The default settings
behavior reads the environment variables every time the settings are accessed.
"""
global _use_settings_override
old_settings = (
_use_settings_override.model_copy() if _use_settings_override else None
)
_use_settings_override = s.model_copy() if s else None
yield
_use_settings_override = old_settings