quality-graph-cli 0.1.6__tar.gz → 0.1.8__tar.gz

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.
@@ -0,0 +1,45 @@
1
+ Metadata-Version: 2.4
2
+ Name: quality-graph-cli
3
+ Version: 0.1.8
4
+ Summary: Provider-driven Quality Graph command-line application
5
+ Project-URL: Homepage, https://alchemmist.github.io/quality-graph/
6
+ Project-URL: Documentation, https://alchemmist.github.io/quality-graph/
7
+ License-Expression: MIT
8
+ Requires-Python: >=3.12
9
+ Requires-Dist: quality-graph-core==0.1.8
10
+ Description-Content-Type: text/markdown
11
+
12
+ # qg
13
+
14
+ Provider-driven command-line application for Quality Graph projects.
15
+
16
+ The CLI discovers providers through the `qg.providers` entry-point group. Install it together
17
+ with the GitHub provider using
18
+ `uv tool install quality-graph-cli==0.1.2 --with quality-graph-github==0.1.2`.
19
+
20
+ Initialize a repository with its default branch, generate the provider-owned files, and list
21
+ those paths for repository tooling:
22
+
23
+ ```bash
24
+ qg init \
25
+ --default-branch main \
26
+ --runtime-action alchemmist/quality-graph@<release-commit-sha>
27
+ qg generate
28
+ qg generated-files
29
+ qg validate
30
+ ```
31
+
32
+ The graph declaration can select the generated workflow projections per node:
33
+
34
+ ```yaml
35
+ nodes:
36
+ lint:
37
+ events: [pull-request, push]
38
+ run: make lint
39
+ diff-check:
40
+ events: [pull-request]
41
+ run: make diff-check
42
+ ```
43
+
44
+ Nodes without `events` run for both supported events. See the
45
+ [configuration reference](../../docs/configuration.md) for dependency projection rules.
@@ -0,0 +1,34 @@
1
+ # qg
2
+
3
+ Provider-driven command-line application for Quality Graph projects.
4
+
5
+ The CLI discovers providers through the `qg.providers` entry-point group. Install it together
6
+ with the GitHub provider using
7
+ `uv tool install quality-graph-cli==0.1.2 --with quality-graph-github==0.1.2`.
8
+
9
+ Initialize a repository with its default branch, generate the provider-owned files, and list
10
+ those paths for repository tooling:
11
+
12
+ ```bash
13
+ qg init \
14
+ --default-branch main \
15
+ --runtime-action alchemmist/quality-graph@<release-commit-sha>
16
+ qg generate
17
+ qg generated-files
18
+ qg validate
19
+ ```
20
+
21
+ The graph declaration can select the generated workflow projections per node:
22
+
23
+ ```yaml
24
+ nodes:
25
+ lint:
26
+ events: [pull-request, push]
27
+ run: make lint
28
+ diff-check:
29
+ events: [pull-request]
30
+ run: make diff-check
31
+ ```
32
+
33
+ Nodes without `events` run for both supported events. See the
34
+ [configuration reference](../../docs/configuration.md) for dependency projection rules.
@@ -4,12 +4,12 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "quality-graph-cli"
7
- version = "0.1.6"
7
+ version = "0.1.8"
8
8
  description = "Provider-driven Quality Graph command-line application"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
11
11
  license = "MIT"
12
- dependencies = ["quality-graph-core==0.1.6"]
12
+ dependencies = ["quality-graph-core==0.1.8"]
13
13
 
14
14
  [project.urls]
15
15
  Homepage = "https://alchemmist.github.io/quality-graph/"
@@ -4,6 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  import argparse
6
6
  import sys
7
+ from importlib import import_module
7
8
  from pathlib import Path
8
9
  from typing import TYPE_CHECKING
9
10
 
@@ -24,6 +25,7 @@ def parser() -> argparse.ArgumentParser:
24
25
  initialize = commands.add_parser("init", help="Create a starter Quality Graph declaration")
25
26
  initialize.add_argument("--root", default=".")
26
27
  initialize.add_argument("--runtime-action", required=True)
28
+ initialize.add_argument("--default-branch", default="main")
27
29
  initialize.add_argument("--preset", choices=("oss", "internal"), default="oss")
28
30
  initialize.add_argument("--force", action="store_true")
29
31
  generate = commands.add_parser("generate", help="Generate committed GitHub workflows")
@@ -34,6 +36,16 @@ def parser() -> argparse.ArgumentParser:
34
36
  "generated-files", help="List compiler-owned artifact paths"
35
37
  )
36
38
  generated_files.add_argument("--root", default=".")
39
+ github = commands.add_parser("github", help="Synchronize GitHub repository settings")
40
+ github_commands = github.add_subparsers(dest="github_command")
41
+ required_checks = github_commands.add_parser(
42
+ "required-checks", help="Manage required status checks"
43
+ )
44
+ required_checks_commands = required_checks.add_subparsers(dest="required_checks_command")
45
+ synchronize = required_checks_commands.add_parser(
46
+ "sync", help="Synchronize required checks from qg.yaml"
47
+ )
48
+ synchronize.add_argument("--root", default=".")
37
49
  graph_schema = commands.add_parser("schema", help="Render the graph JSON Schema")
38
50
  graph_schema.add_argument("--output", default="-")
39
51
  result_command = commands.add_parser("result", help="Work with native result JSON")
@@ -68,17 +80,37 @@ def main(arguments: Sequence[str] | None = None) -> int:
68
80
  return _project_command(args)
69
81
  if args.command == "result":
70
82
  return _result_command(command_parser, args)
71
- except (OSError, TypeError, ValueError) as error:
83
+ if args.command == "github":
84
+ return _github_command(command_parser, args)
85
+ except (ModuleNotFoundError, OSError, RuntimeError, TypeError, ValueError) as error:
72
86
  command_parser.error(str(error))
73
87
  command_parser.print_help()
74
88
  return 0
75
89
 
76
90
 
91
+ def _github_command(command_parser: argparse.ArgumentParser, args: argparse.Namespace) -> int:
92
+ if args.github_command != "required-checks" or args.required_checks_command != "sync":
93
+ command_parser.print_help()
94
+ return 0
95
+ project = Project.open(Path(args.root))
96
+ github = import_module("qg_github.github")
97
+ synchronization = import_module("qg_github.required_checks")
98
+ port = github.HttpGitHubPort.from_environment()
99
+ plan = synchronization.plan_required_checks(port, project.graph)
100
+ sys.stdout.write(plan.render())
101
+ sys.stdout.flush()
102
+ synchronization.apply_required_checks(port, plan)
103
+ result = "Applied required-check synchronization.\n" if plan.changed else "No changes.\n"
104
+ sys.stdout.write(result)
105
+ return 0
106
+
107
+
77
108
  def _project_command(args: argparse.Namespace) -> int:
78
109
  if args.command == "init":
79
110
  Project.initialize(
80
111
  Path(args.root),
81
112
  args.runtime_action,
113
+ default_branch=args.default_branch,
82
114
  preset=args.preset,
83
115
  force=args.force,
84
116
  )
@@ -2,6 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import json
5
6
  from dataclasses import dataclass
6
7
  from pathlib import Path, PurePosixPath
7
8
  from typing import TYPE_CHECKING, Literal, Self
@@ -12,7 +13,8 @@ from quality_graph_core.graph import Graph
12
13
  if TYPE_CHECKING:
13
14
  from quality_graph_core.provider import GeneratedProject, Provider
14
15
 
15
- CONFIGURATION_PATH = Path("quality-graph.yml")
16
+ CONFIGURATION_PATH = Path("qg.yaml")
17
+ LEGACY_CONFIGURATION_PATH = Path("quality-graph.yml")
16
18
  PRETTIER_IGNORE_PATH = Path(".prettierignore")
17
19
  PRETTIER_BLOCK_START = "# Quality Graph generated files (managed by qg)"
18
20
  PRETTIER_BLOCK_END = "# End Quality Graph generated files"
@@ -41,7 +43,7 @@ class Project:
41
43
  @classmethod
42
44
  def open(cls, root: Path) -> Self:
43
45
  """Load a project from its committed declaration."""
44
- configuration = root / CONFIGURATION_PATH
46
+ configuration = _configuration_path(root)
45
47
  if not configuration.is_file():
46
48
  message = f"Quality Graph declaration does not exist: {configuration}"
47
49
  raise FileNotFoundError(message)
@@ -117,26 +119,53 @@ class Project:
117
119
  root: Path,
118
120
  runtime_action: str,
119
121
  *,
122
+ default_branch: str = "main",
120
123
  preset: Literal["oss", "internal"] = "oss",
121
124
  force: bool = False,
122
125
  ) -> Self:
123
126
  """Create one understandable starter declaration."""
124
- configuration = root / CONFIGURATION_PATH
127
+ configuration = _configuration_path(root)
125
128
  if configuration.exists() and not force:
126
129
  message = f"Refusing to replace existing declaration: {configuration}"
127
130
  raise FileExistsError(message)
128
131
  provider = load_provider("github")
132
+ source = _starter_configuration(runtime_action, default_branch, preset)
133
+ graph = Graph.from_yaml(source)
134
+ provider.generate(graph)
129
135
  root.mkdir(parents=True, exist_ok=True)
130
- configuration.write_text(_starter_configuration(runtime_action, preset))
131
- return cls(root, Graph.from_yaml(configuration.read_text()), provider)
136
+ configuration.write_text(source)
137
+ return cls(root, graph, provider)
138
+
139
+
140
+ def _configuration_path(root: Path) -> Path:
141
+ configuration = root / CONFIGURATION_PATH
142
+ legacy = root / LEGACY_CONFIGURATION_PATH
143
+ if legacy.exists() or legacy.is_symlink():
144
+ if configuration.exists():
145
+ message = (
146
+ f"Both {CONFIGURATION_PATH} and {LEGACY_CONFIGURATION_PATH} exist; "
147
+ f"remove {LEGACY_CONFIGURATION_PATH}"
148
+ )
149
+ raise FileExistsError(message)
150
+ message = (
151
+ f"{LEGACY_CONFIGURATION_PATH} is no longer supported; "
152
+ f"rename it with `git mv {LEGACY_CONFIGURATION_PATH} {CONFIGURATION_PATH}`"
153
+ )
154
+ raise FileNotFoundError(message)
155
+ return configuration
132
156
 
133
157
 
134
- def _starter_configuration(runtime_action: str, preset: Literal["oss", "internal"]) -> str:
158
+ def _starter_configuration(
159
+ runtime_action: str,
160
+ default_branch: str,
161
+ preset: Literal["oss", "internal"],
162
+ ) -> str:
135
163
  runner = "ubuntu-latest" if preset == "oss" else "self-hosted"
136
164
  return f"""version: 0
137
165
  provider:
138
166
  name: github
139
167
  configuration:
168
+ default-branch: {json.dumps(default_branch)}
140
169
  runtime:
141
170
  action: {runtime_action}
142
171
 
@@ -1,18 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: quality-graph-cli
3
- Version: 0.1.6
4
- Summary: Provider-driven Quality Graph command-line application
5
- Project-URL: Homepage, https://alchemmist.github.io/quality-graph/
6
- Project-URL: Documentation, https://alchemmist.github.io/quality-graph/
7
- License-Expression: MIT
8
- Requires-Python: >=3.12
9
- Requires-Dist: quality-graph-core==0.1.6
10
- Description-Content-Type: text/markdown
11
-
12
- # qg
13
-
14
- Provider-driven command-line application for Quality Graph projects.
15
-
16
- The CLI discovers providers through the `qg.providers` entry-point group. Install it together
17
- with the GitHub provider using
18
- `uv tool install quality-graph-cli==0.1.2 --with quality-graph-github==0.1.2`.
@@ -1,7 +0,0 @@
1
- # qg
2
-
3
- Provider-driven command-line application for Quality Graph projects.
4
-
5
- The CLI discovers providers through the `qg.providers` entry-point group. Install it together
6
- with the GitHub provider using
7
- `uv tool install quality-graph-cli==0.1.2 --with quality-graph-github==0.1.2`.