dycw-actions 0.7.7__py3-none-any.whl → 0.8.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
actions/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.7.7"
3
+ __version__ = "0.8.4"
actions/constants.py CHANGED
@@ -1,14 +1,73 @@
1
1
  from __future__ import annotations
2
2
 
3
+ from pathlib import Path
4
+
3
5
  from ruamel.yaml import YAML
4
6
  from utilities.importlib import files
5
7
  from utilities.pathlib import get_repo_root
6
8
  from xdg_base_dirs import xdg_cache_home
7
9
 
10
+ ACTIONS_URL = "https://github.com/dycw/actions"
11
+
12
+
13
+ BUMPVERSION_TOML = Path(".bumpversion.toml")
14
+ COVERAGERC_TOML = Path(".coveragerc.toml")
15
+ ENVRC = Path(".envrc")
16
+ GITEA = Path(".gitea")
17
+ GITHUB = Path(".github")
18
+ GITIGNORE = Path(".gitignore")
19
+ PRE_COMMIT_CONFIG_YAML = Path(".pre-commit-config.yaml")
20
+ PYPROJECT_TOML = Path("pyproject.toml")
21
+ PYRIGHTCONFIG_JSON = Path("pyrightconfig.json")
22
+ PYTEST_TOML = Path("pytest.toml")
23
+ README_MD = Path("README.md")
24
+ REPO_ROOT = get_repo_root()
25
+ RUFF_TOML = Path("ruff.toml")
26
+
27
+
28
+ GITHUB_WORKFLOWS, GITEA_WORKFLOWS = [g / "workflows" for g in [GITHUB, GITEA]]
29
+ GITHUB_PULL_REQUEST_YAML, GITEA_PULL_REQUEST_YAML = [
30
+ w / "pull-request.yaml" for w in [GITHUB_WORKFLOWS, GITEA_WORKFLOWS]
31
+ ]
32
+ GITHUB_PUSH_YAML, GITEA_PUSH_YAML = [
33
+ w / "push.yaml" for w in [GITHUB_WORKFLOWS, GITEA_WORKFLOWS]
34
+ ]
35
+
36
+
37
+ MAX_PYTHON_VERSION = "3.14"
38
+
39
+
8
40
  PATH_ACTIONS = files(anchor="actions")
9
41
  PATH_CACHE = xdg_cache_home() / "actions"
10
42
  PATH_THROTTLE_CACHE = PATH_CACHE / "throttle" / get_repo_root().name
43
+
44
+
11
45
  YAML_INSTANCE = YAML()
12
46
 
13
47
 
14
- __all__ = ["PATH_ACTIONS", "PATH_CACHE", "PATH_THROTTLE_CACHE", "YAML_INSTANCE"]
48
+ __all__ = [
49
+ "ACTIONS_URL",
50
+ "BUMPVERSION_TOML",
51
+ "COVERAGERC_TOML",
52
+ "ENVRC",
53
+ "GITEA",
54
+ "GITEA_PUSH_YAML",
55
+ "GITEA_WORKFLOWS",
56
+ "GITHUB",
57
+ "GITHUB_PULL_REQUEST_YAML",
58
+ "GITHUB_PUSH_YAML",
59
+ "GITHUB_WORKFLOWS",
60
+ "GITHUB_WORKFLOWS",
61
+ "GITIGNORE",
62
+ "MAX_PYTHON_VERSION",
63
+ "PATH_ACTIONS",
64
+ "PATH_CACHE",
65
+ "PATH_THROTTLE_CACHE",
66
+ "PRE_COMMIT_CONFIG_YAML",
67
+ "PYPROJECT_TOML",
68
+ "PYRIGHTCONFIG_JSON",
69
+ "PYTEST_TOML",
70
+ "README_MD",
71
+ "RUFF_TOML",
72
+ "YAML_INSTANCE",
73
+ ]
@@ -0,0 +1,247 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Any
4
+
5
+ from ruamel.yaml.scalarstring import LiteralScalarString
6
+ from typed_settings import Secret
7
+
8
+ from actions.pre_commit.conformalize_repo.settings import SETTINGS
9
+ from actions.publish_package.constants import PUBLISH_PACKAGE_DOCSTRING
10
+ from actions.random_sleep.constants import RANDOM_SLEEP_DOCSTRING
11
+ from actions.run_hooks.constants import RUN_HOOKS_DOCSTRING
12
+ from actions.tag_commit.constants import TAG_COMMIT_DOCSTRING
13
+
14
+ if TYPE_CHECKING:
15
+ from utilities.types import StrDict
16
+
17
+
18
+ def action_publish_package_dict(
19
+ *,
20
+ token: str | None = SETTINGS.ci__token,
21
+ username: str | None = SETTINGS.ci__push__publish__username,
22
+ password: Secret[str] | None = SETTINGS.ci__push__publish__password,
23
+ publish_url: Secret[str] | None = SETTINGS.ci__push__publish__publish_url,
24
+ trusted_publishing: bool = False,
25
+ native_tls: bool = SETTINGS.uv__native_tls,
26
+ ) -> StrDict:
27
+ out: StrDict = {
28
+ "name": PUBLISH_PACKAGE_DOCSTRING,
29
+ "uses": "dycw/action-publish-package@latest",
30
+ }
31
+ with_: StrDict = {}
32
+ _add_token(with_, token=token)
33
+ _add_item(with_, "username", value=username)
34
+ _add_item(with_, "password", value=password)
35
+ _add_item(with_, "publish-url", value=publish_url)
36
+ _add_boolean(with_, "trusted-publishing", value=trusted_publishing)
37
+ _add_native_tls(with_, native_tls=native_tls)
38
+ _add_with_dict(out, with_)
39
+ return out
40
+
41
+
42
+ def action_pyright_dict(
43
+ *,
44
+ token: str | None = SETTINGS.ci__token,
45
+ python_version: str | None = None,
46
+ resolution: str | None = None,
47
+ prerelease: str | None = None,
48
+ native_tls: bool = SETTINGS.uv__native_tls,
49
+ with_requirements: str | None = None,
50
+ ) -> StrDict:
51
+ out: StrDict = {"name": "Run 'pyright'", "uses": "dycw/action-pyright@latest"}
52
+ with_: StrDict = {}
53
+ _add_token(with_, token=token)
54
+ _add_python_version(with_, python_version=python_version)
55
+ _add_resolution(with_, resolution=resolution)
56
+ _add_prerelease(with_, prerelease=prerelease)
57
+ _add_native_tls(with_, native_tls=native_tls)
58
+ _add_with_requirements(with_, with_requirements=with_requirements)
59
+ _add_with_dict(out, with_)
60
+ return out
61
+
62
+
63
+ def action_pytest_dict(
64
+ *,
65
+ token: str | None = SETTINGS.ci__token,
66
+ python_version: str | None = None,
67
+ sops_age_key: str | None = None,
68
+ resolution: str | None = None,
69
+ prerelease: str | None = None,
70
+ native_tls: bool = SETTINGS.uv__native_tls,
71
+ with_requirements: str | None = None,
72
+ ) -> StrDict:
73
+ out: StrDict = {"name": "Run 'pytest'", "uses": "dycw/action-pytest@latest"}
74
+ with_: StrDict = {}
75
+ _add_token(with_, token=token)
76
+ _add_python_version(with_, python_version=python_version)
77
+ _add_item(with_, "sops-age-key", value=sops_age_key)
78
+ _add_resolution(with_, resolution=resolution)
79
+ _add_prerelease(with_, prerelease=prerelease)
80
+ _add_native_tls(with_, native_tls=native_tls)
81
+ _add_with_requirements(with_, with_requirements=with_requirements)
82
+ _add_with_dict(out, with_)
83
+ return out
84
+
85
+
86
+ def action_random_sleep_dict(
87
+ *,
88
+ token: str | None = SETTINGS.ci__token,
89
+ min: int = 0, # noqa: A002
90
+ max: int = 3600, # noqa: A002
91
+ step: int = 1,
92
+ log_freq: int = 1,
93
+ ) -> StrDict:
94
+ out: StrDict = {
95
+ "name": RANDOM_SLEEP_DOCSTRING,
96
+ "uses": "dycw/action-random-sleep@latest",
97
+ }
98
+ with_: StrDict = {}
99
+ _add_token(with_, token=token)
100
+ with_["min"] = min
101
+ with_["max"] = max
102
+ with_["step"] = step
103
+ with_["log-freq"] = log_freq
104
+ _add_with_dict(out, with_)
105
+ return out
106
+
107
+
108
+ def action_ruff_dict(*, token: str | None = SETTINGS.ci__token) -> StrDict:
109
+ out: StrDict = {"name": "Run 'ruff'", "uses": "dycw/action-ruff@latest"}
110
+ with_: StrDict = {}
111
+ _add_token(with_, token=token)
112
+ _add_with_dict(out, with_)
113
+ return out
114
+
115
+
116
+ def action_run_hooks_dict(
117
+ *,
118
+ token: str | None = SETTINGS.ci__token,
119
+ submodules: str | None = None,
120
+ repos: list[str] | None = None,
121
+ hooks: list[str] | None = None,
122
+ hooks_exclude: list[str] | None = None,
123
+ sleep: int | None = None,
124
+ gitea: bool = SETTINGS.ci__gitea,
125
+ ) -> StrDict:
126
+ out: StrDict = {
127
+ "if": f"{_runner(gitea=gitea)}.event_name == 'pull_request'",
128
+ "name": RUN_HOOKS_DOCSTRING,
129
+ "uses": "dycw/action-run-hooks@latest",
130
+ }
131
+ with_: StrDict = {}
132
+ _add_token(with_, token=token)
133
+ _add_item(with_, "submodules", value=submodules)
134
+ _add_yaml_str(with_, "repos", values=repos)
135
+ _add_yaml_str(with_, "hooks", values=hooks)
136
+ _add_yaml_str(with_, "hooks-exclude", values=hooks_exclude)
137
+ _add_item(with_, "hooks", value=hooks)
138
+ _add_item(with_, "sleep", value=sleep)
139
+ _add_with_dict(out, with_)
140
+ return out
141
+
142
+
143
+ def action_tag_commit_dict(
144
+ *,
145
+ token: str | None = SETTINGS.ci__token,
146
+ user_name: str | None = None,
147
+ user_email: str | None = None,
148
+ major_minor: bool = False,
149
+ major: bool = False,
150
+ latest: bool = False,
151
+ ) -> StrDict:
152
+ out: StrDict = {
153
+ "name": TAG_COMMIT_DOCSTRING,
154
+ "uses": "dycw/action-tag-commit@latest",
155
+ }
156
+ with_: StrDict = {}
157
+ _add_token(with_, token=token)
158
+ _add_item(with_, "user-name", value=user_name)
159
+ _add_item(with_, "user-email", value=user_email)
160
+ _add_boolean(with_, "major-minor", value=major_minor)
161
+ _add_boolean(with_, "major", value=major)
162
+ _add_boolean(with_, "latest", value=latest)
163
+ _add_with_dict(out, with_)
164
+ return out
165
+
166
+
167
+ def update_ca_certificates_dict(desc: str, /) -> StrDict:
168
+ return {
169
+ "name": f"Update CA certificates ({desc})",
170
+ "run": "sudo update-ca-certificates",
171
+ }
172
+
173
+
174
+ ##
175
+
176
+
177
+ def _add_boolean(dict_: StrDict, key: str, /, *, value: bool = False) -> None:
178
+ if value:
179
+ dict_[key] = value
180
+
181
+
182
+ def _add_item(dict_: StrDict, key: str, /, *, value: Any | None = None) -> None:
183
+ match value:
184
+ case None:
185
+ ...
186
+ case Secret():
187
+ _add_item(dict_, key, value=value.get_secret_value())
188
+ case _:
189
+ dict_[key] = value
190
+
191
+
192
+ def _add_native_tls(
193
+ dict_: StrDict, /, *, native_tls: bool = SETTINGS.uv__native_tls
194
+ ) -> None:
195
+ _add_boolean(dict_, "native-tls", value=native_tls)
196
+
197
+
198
+ def _add_python_version(
199
+ dict_: StrDict, /, *, python_version: str | None = None
200
+ ) -> None:
201
+ _add_item(dict_, "python-version", value=python_version)
202
+
203
+
204
+ def _add_prerelease(dict_: StrDict, /, *, prerelease: str | None = None) -> None:
205
+ _add_item(dict_, "prerelease", value=prerelease)
206
+
207
+
208
+ def _add_resolution(dict_: StrDict, /, *, resolution: str | None = None) -> None:
209
+ _add_item(dict_, "resolution", value=resolution)
210
+
211
+
212
+ def _add_token(dict_: StrDict, /, *, token: str | None = SETTINGS.ci__token) -> None:
213
+ _add_item(dict_, "token", value=token)
214
+
215
+
216
+ def _add_with_dict(dict_: StrDict, with_: StrDict, /) -> None:
217
+ if len(with_) >= 1:
218
+ dict_["with"] = with_
219
+
220
+
221
+ def _add_with_requirements(
222
+ dict_: StrDict, /, *, with_requirements: str | None = None
223
+ ) -> None:
224
+ _add_item(dict_, "with-requirements", value=with_requirements)
225
+
226
+
227
+ def _add_yaml_str(
228
+ dict_: StrDict, key: str, /, *, values: list[str] | None = None
229
+ ) -> None:
230
+ if values is not None:
231
+ dict_[key] = LiteralScalarString("\n".join(values))
232
+
233
+
234
+ def _runner(*, gitea: bool = False) -> str:
235
+ return "gitea" if gitea else "github"
236
+
237
+
238
+ __all__ = [
239
+ "action_publish_package_dict",
240
+ "action_pyright_dict",
241
+ "action_pytest_dict",
242
+ "action_random_sleep_dict",
243
+ "action_ruff_dict",
244
+ "action_run_hooks_dict",
245
+ "action_tag_commit_dict",
246
+ "update_ca_certificates_dict",
247
+ ]
@@ -16,23 +16,23 @@ def conformalize_repo_sub_cmd(settings: Settings, /) -> None:
16
16
  return
17
17
  basic_config(obj=LOGGER)
18
18
  conformalize_repo(
19
+ ci__ca_certificates=settings.ci__ca_certificates,
20
+ ci__gitea=settings.ci__gitea,
21
+ ci__token=settings.ci__token,
22
+ ci__pull_request__pre_commit=settings.ci__pull_request__pre_commit,
23
+ ci__pull_request__pyright=settings.ci__pull_request__pyright,
24
+ ci__pull_request__pytest__macos=settings.ci__pull_request__pytest__macos,
25
+ ci__pull_request__pytest__ubuntu=settings.ci__pull_request__pytest__ubuntu,
26
+ ci__pull_request__pytest__windows=settings.ci__pull_request__pytest__windows,
27
+ ci__pull_request__pytest__sops_age_key=settings.ci__pull_request__pytest__sops_age_key,
28
+ ci__pull_request__ruff=settings.ci__pull_request__ruff,
29
+ ci__push__publish=settings.ci__push__publish,
30
+ ci__push__tag=settings.ci__push__tag,
31
+ ci__push__tag__all=settings.ci__push__tag__all,
19
32
  coverage=settings.coverage,
20
33
  description=settings.description,
21
34
  envrc=settings.envrc,
22
35
  envrc__uv=settings.envrc__uv,
23
- envrc__uv__native_tls=settings.envrc__uv__native_tls,
24
- github__pull_request__pre_commit=settings.github__pull_request__pre_commit,
25
- github__pull_request__pre_commit__gitea=settings.github__pull_request__pre_commit__gitea,
26
- github__pull_request__pyright=settings.github__pull_request__pyright,
27
- github__pull_request__pytest__macos=settings.github__pull_request__pytest__macos,
28
- github__pull_request__pytest__ubuntu=settings.github__pull_request__pytest__ubuntu,
29
- github__pull_request__pytest__windows=settings.github__pull_request__pytest__windows,
30
- github__pull_request__ruff=settings.github__pull_request__ruff,
31
- github__push__publish=settings.github__push__publish,
32
- github__push__tag=settings.github__push__tag,
33
- github__push__tag__major=settings.github__push__tag__major,
34
- github__push__tag__major_minor=settings.github__push__tag__major_minor,
35
- github__push__tag__latest=settings.github__push__tag__latest,
36
36
  gitignore=settings.gitignore,
37
37
  package_name=settings.package_name,
38
38
  pre_commit__dockerfmt=settings.pre_commit__dockerfmt,
@@ -42,7 +42,6 @@ def conformalize_repo_sub_cmd(settings: Settings, /) -> None:
42
42
  pre_commit__shell=settings.pre_commit__shell,
43
43
  pre_commit__taplo=settings.pre_commit__taplo,
44
44
  pre_commit__uv=settings.pre_commit__uv,
45
- pre_commit__uv__script=settings.pre_commit__uv__script,
46
45
  pyproject=settings.pyproject,
47
46
  pyproject__project__optional_dependencies__scripts=settings.pyproject__project__optional_dependencies__scripts,
48
47
  pyproject__tool__uv__indexes=settings.pyproject__tool__uv__indexes,
@@ -58,6 +57,7 @@ def conformalize_repo_sub_cmd(settings: Settings, /) -> None:
58
57
  ruff=settings.ruff,
59
58
  run_version_bump=settings.run_version_bump,
60
59
  script=settings.script,
60
+ uv__native_tls=settings.uv__native_tls,
61
61
  )
62
62
 
63
63
 
@@ -1,14 +1,12 @@
1
1
  from __future__ import annotations
2
2
 
3
- from pathlib import Path
4
3
  from re import search
5
4
 
6
- from utilities.pathlib import get_repo_root
7
5
  from utilities.pytest import IS_CI
8
6
 
7
+ from actions.constants import REPO_ROOT
9
8
  from actions.pre_commit.constants import PATH_PRE_COMMIT
10
9
 
11
- ACTIONS_URL = "https://github.com/dycw/actions"
12
10
  DOCKERFMT_URL = "https://github.com/reteps/dockerfmt"
13
11
  PRE_COMMIT_HOOKS_URL = "https://github.com/pre-commit/pre-commit-hooks"
14
12
  RUFF_URL = "https://github.com/astral-sh/ruff-pre-commit"
@@ -18,57 +16,23 @@ TAPLO_URL = "https://github.com/compwa/taplo-pre-commit"
18
16
  UV_URL = "https://github.com/astral-sh/uv-pre-commit"
19
17
 
20
18
 
21
- BUMPVERSION_TOML = Path(".bumpversion.toml")
22
- COVERAGERC_TOML = Path(".coveragerc.toml")
23
- ENVRC = Path(".envrc")
24
- GITIGNORE = Path(".gitignore")
25
- PRE_COMMIT_CONFIG_YAML = Path(".pre-commit-config.yaml")
26
- PYPROJECT_TOML = Path("pyproject.toml")
27
- PYRIGHTCONFIG_JSON = Path("pyrightconfig.json")
28
- PYTEST_TOML = Path("pytest.toml")
29
- README_MD = Path("README.md")
30
- REPO_ROOT = get_repo_root()
31
- RUFF_TOML = Path("ruff.toml")
32
-
33
-
34
19
  CONFORMALIZE_REPO_DOCSTRING = "Conformalize a repo"
35
20
  CONFORMALIZE_REPO_SUB_CMD = "conformalize-repo"
36
21
 
37
22
 
38
- MAX_PYTHON_VERSION = "3.14"
23
+ PATH_CONFIGS = PATH_PRE_COMMIT / "conformalize_repo/configs"
39
24
 
40
25
 
41
26
  RUN_VERSION_BUMP = (search("template", str(REPO_ROOT)) is None) and not IS_CI
42
27
 
43
28
 
44
- GITHUB_WORKFLOWS = Path(".github/workflows")
45
- GITHUB_PULL_REQUEST_YAML = GITHUB_WORKFLOWS / "pull-request.yaml"
46
- GITHUB_PUSH_YAML = GITHUB_WORKFLOWS / "push.yaml"
47
- PATH_CONFIGS = PATH_PRE_COMMIT / "conformalize_repo/configs"
48
-
49
-
50
29
  __all__ = [
51
- "ACTIONS_URL",
52
- "BUMPVERSION_TOML",
53
30
  "CONFORMALIZE_REPO_DOCSTRING",
54
31
  "CONFORMALIZE_REPO_SUB_CMD",
55
- "COVERAGERC_TOML",
56
32
  "DOCKERFMT_URL",
57
- "ENVRC",
58
- "GITHUB_PULL_REQUEST_YAML",
59
- "GITHUB_PUSH_YAML",
60
- "GITHUB_WORKFLOWS",
61
- "GITIGNORE",
62
- "MAX_PYTHON_VERSION",
63
33
  "PATH_CONFIGS",
64
- "PRE_COMMIT_CONFIG_YAML",
65
34
  "PRE_COMMIT_HOOKS_URL",
66
- "PYPROJECT_TOML",
67
- "PYRIGHTCONFIG_JSON",
68
- "PYTEST_TOML",
69
- "README_MD",
70
35
  "REPO_ROOT",
71
- "RUFF_TOML",
72
36
  "RUFF_URL",
73
37
  "RUN_VERSION_BUMP",
74
38
  "SHELLCHECK_URL",