Coverage for src/somesy/cli/sync.py: 32%
37 statements
« prev ^ index » next coverage.py v7.3.2, created at 2024-04-30 09:42 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2024-04-30 09:42 +0000
1"""Sync command for somesy."""
2import logging
3from pathlib import Path
5import typer
7from somesy.commands import sync as sync_command
8from somesy.core.models import SomesyInput
10from .util import (
11 existing_file_arg_config,
12 file_arg_config,
13 resolved_somesy_input,
14 wrap_exceptions,
15)
17logger = logging.getLogger("somesy")
19app = typer.Typer()
22@app.callback(invoke_without_command=True)
23@wrap_exceptions
24def sync(
25 input_file: Path = typer.Option(
26 None,
27 "--input-file",
28 "-i",
29 help="Somesy input file path (default: .somesy.toml)",
30 **file_arg_config,
31 ),
32 no_sync_pyproject: bool = typer.Option(
33 None,
34 "--no-sync-pyproject",
35 "-P",
36 help="Do not sync pyproject.toml file (default: False)",
37 ),
38 pyproject_file: Path = typer.Option(
39 None,
40 "--pyproject-file",
41 "-p",
42 help="Existing pyproject.toml file path (default: pyproject.toml)",
43 **existing_file_arg_config,
44 ),
45 no_sync_package_json: bool = typer.Option(
46 None,
47 "--no-sync-package-json",
48 "-J",
49 help="Do not sync package.json file (default: False)",
50 ),
51 package_json_file: Path = typer.Option(
52 None,
53 "--package-json-file",
54 "-j",
55 help="Existing package.json file path (default: package.json)",
56 **existing_file_arg_config,
57 ),
58 no_sync_julia: bool = typer.Option(
59 None,
60 "--no-sync-julia",
61 "-L",
62 help="Do not sync Project.toml (Julia) file (default: False)",
63 ),
64 julia_file: Path = typer.Option(
65 None,
66 "--julia-file",
67 "-l",
68 help="Custom Project.toml (Julia) file path (default: Project.toml)",
69 **existing_file_arg_config,
70 ),
71 no_sync_fortran: bool = typer.Option(
72 None,
73 "--no-sync-fortran",
74 "-F",
75 help="Do not sync fpm.toml (Fortran) file (default: False)",
76 **existing_file_arg_config,
77 ),
78 fortran_file: Path = typer.Option(
79 None,
80 "--fortran-file",
81 "-f",
82 help="Custom fpm.toml (Fortran) file path (default: fpm.toml)",
83 ),
84 no_sync_pom_xml: bool = typer.Option(
85 None,
86 "--no-sync-pomxml",
87 "-X",
88 help="Do not sync pom.xml (Java Maven) file (default: False)",
89 ),
90 pom_xml_file: Path = typer.Option(
91 None,
92 "--pomxml-file",
93 "-x",
94 help="Custom pom.xml (Java Maven) file path (default: pom.xml)",
95 **existing_file_arg_config,
96 ),
97 no_sync_mkdocs: bool = typer.Option(
98 None,
99 "--no-sync-mkdocs",
100 "-D",
101 help="Do not sync mkdocs.yml file (default: False)",
102 ),
103 mkdocs_file: Path = typer.Option(
104 None,
105 "--mkdocs-file",
106 "-d",
107 help="Custom mkdocs.yml file path (default: mkdocs.yml)",
108 **existing_file_arg_config,
109 ),
110 no_sync_rust: bool = typer.Option(
111 None,
112 "--no-sync-rust",
113 "-R",
114 help="Do not sync Cargo.toml file (default: False)",
115 ),
116 rust_file: Path = typer.Option(
117 None,
118 "--rust-file",
119 "-r",
120 help="Custom Cargo.toml file path (default: Cargo.toml)",
121 **existing_file_arg_config,
122 ),
123 no_sync_cff: bool = typer.Option(
124 None,
125 "--no-sync-cff",
126 "-C",
127 help="Do not sync CITATION.cff file (default: False)",
128 ),
129 cff_file: Path = typer.Option(
130 None,
131 "--cff-file",
132 "-c",
133 help="CITATION.cff file path (default: CITATION.cff)",
134 **file_arg_config,
135 ),
136 no_sync_codemeta: bool = typer.Option(
137 None,
138 "--no-sync-codemeta",
139 "-M",
140 help="Do not sync codemeta.json file (default: False)",
141 ),
142 codemeta_file: Path = typer.Option(
143 None,
144 "--codemeta-file",
145 "-m",
146 help="Custom codemeta.json file path (default: codemeta.json)",
147 **file_arg_config,
148 ),
149):
150 """Sync project metadata input with metadata files."""
151 somesy_input = resolved_somesy_input(
152 input_file=input_file,
153 no_sync_cff=no_sync_cff,
154 cff_file=cff_file,
155 no_sync_pyproject=no_sync_pyproject,
156 pyproject_file=pyproject_file,
157 no_sync_package_json=no_sync_package_json,
158 package_json_file=package_json_file,
159 no_sync_codemeta=no_sync_codemeta,
160 codemeta_file=codemeta_file,
161 no_sync_julia=no_sync_julia,
162 julia_file=julia_file,
163 no_sync_fortran=no_sync_fortran,
164 fortran_file=fortran_file,
165 no_sync_pom_xml=no_sync_pom_xml,
166 pom_xml_file=pom_xml_file,
167 no_sync_mkdocs=no_sync_mkdocs,
168 mkdocs_file=mkdocs_file,
169 no_sync_rust=no_sync_rust,
170 rust_file=rust_file,
171 )
172 run_sync(somesy_input)
175def run_sync(somesy_input: SomesyInput):
176 """Write log messages and run synchronization based on passed config."""
177 conf = somesy_input.config
178 logger.info("[bold green]Synchronizing project metadata...[/bold green]")
179 logger.info("Files to sync:")
180 if not conf.no_sync_pyproject:
181 logger.info(
182 f" - [italic]pyproject.toml[/italic]:\t[grey]{conf.pyproject_file}[/grey]"
183 )
184 if not conf.no_sync_package_json:
185 logger.info(
186 f" - [italic]package.json[/italic]:\t[grey]{conf.package_json_file}[/grey]"
187 )
188 if not conf.no_sync_julia:
189 logger.info(
190 f" - [italic]Project.toml[/italic]:\t[grey]{conf.julia_file}[/grey]\n"
191 )
192 if not conf.no_sync_fortran:
193 logger.info(
194 f" - [italic]fpm.toml(fortran)[/italic]:\t[grey]{conf.fortran_file}[/grey]"
195 )
196 if not conf.no_sync_pom_xml:
197 logger.info(
198 f" - [italic]pom.xml[/italic]:\t[grey]{conf.pom_xml_file}[/grey]\n"
199 )
200 if not conf.no_sync_mkdocs:
201 logger.info(
202 f" - [italic]mkdocs.yml[/italic]:\t[grey]{conf.mkdocs_file}[/grey]"
203 )
204 if not conf.no_sync_rust:
205 logger.info(f" - [italic]Cargo.toml[/italic]:\t[grey]{conf.rust_file}[/grey]")
207 if not conf.no_sync_cff:
208 logger.info(f" - [italic]CITATION.cff[/italic]:\t[grey]{conf.cff_file}[/grey]")
209 if not conf.no_sync_codemeta:
210 logger.info(
211 f" - [italic]codemeta.json[/italic]:\t[grey]{conf.codemeta_file}[/grey]\n"
212 )
213 # ----
214 sync_command(somesy_input)
215 # ----
216 logger.info("[bold green]Metadata synchronization completed.[/bold green]")