quality-graph-cli 0.1.7__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.
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quality-graph-cli
3
- Version: 0.1.7
3
+ Version: 0.1.8
4
4
  Summary: Provider-driven Quality Graph command-line application
5
5
  Project-URL: Homepage, https://alchemmist.github.io/quality-graph/
6
6
  Project-URL: Documentation, https://alchemmist.github.io/quality-graph/
7
7
  License-Expression: MIT
8
8
  Requires-Python: >=3.12
9
- Requires-Dist: quality-graph-core==0.1.7
9
+ Requires-Dist: quality-graph-core==0.1.8
10
10
  Description-Content-Type: text/markdown
11
11
 
12
12
  # qg
@@ -4,12 +4,12 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "quality-graph-cli"
7
- version = "0.1.7"
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.7"]
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
 
@@ -35,6 +36,16 @@ def parser() -> argparse.ArgumentParser:
35
36
  "generated-files", help="List compiler-owned artifact paths"
36
37
  )
37
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=".")
38
49
  graph_schema = commands.add_parser("schema", help="Render the graph JSON Schema")
39
50
  graph_schema.add_argument("--output", default="-")
40
51
  result_command = commands.add_parser("result", help="Work with native result JSON")
@@ -69,12 +80,31 @@ def main(arguments: Sequence[str] | None = None) -> int:
69
80
  return _project_command(args)
70
81
  if args.command == "result":
71
82
  return _result_command(command_parser, args)
72
- 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:
73
86
  command_parser.error(str(error))
74
87
  command_parser.print_help()
75
88
  return 0
76
89
 
77
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
+
78
108
  def _project_command(args: argparse.Namespace) -> int:
79
109
  if args.command == "init":
80
110
  Project.initialize(
@@ -13,7 +13,8 @@ from quality_graph_core.graph import Graph
13
13
  if TYPE_CHECKING:
14
14
  from quality_graph_core.provider import GeneratedProject, Provider
15
15
 
16
- CONFIGURATION_PATH = Path("quality-graph.yml")
16
+ CONFIGURATION_PATH = Path("qg.yaml")
17
+ LEGACY_CONFIGURATION_PATH = Path("quality-graph.yml")
17
18
  PRETTIER_IGNORE_PATH = Path(".prettierignore")
18
19
  PRETTIER_BLOCK_START = "# Quality Graph generated files (managed by qg)"
19
20
  PRETTIER_BLOCK_END = "# End Quality Graph generated files"
@@ -42,7 +43,7 @@ class Project:
42
43
  @classmethod
43
44
  def open(cls, root: Path) -> Self:
44
45
  """Load a project from its committed declaration."""
45
- configuration = root / CONFIGURATION_PATH
46
+ configuration = _configuration_path(root)
46
47
  if not configuration.is_file():
47
48
  message = f"Quality Graph declaration does not exist: {configuration}"
48
49
  raise FileNotFoundError(message)
@@ -123,7 +124,7 @@ class Project:
123
124
  force: bool = False,
124
125
  ) -> Self:
125
126
  """Create one understandable starter declaration."""
126
- configuration = root / CONFIGURATION_PATH
127
+ configuration = _configuration_path(root)
127
128
  if configuration.exists() and not force:
128
129
  message = f"Refusing to replace existing declaration: {configuration}"
129
130
  raise FileExistsError(message)
@@ -136,6 +137,24 @@ class Project:
136
137
  return cls(root, graph, provider)
137
138
 
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
156
+
157
+
139
158
  def _starter_configuration(
140
159
  runtime_action: str,
141
160
  default_branch: str,