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