Skip to content

Commit c26131c

Browse files
committed
add fortran options to commands and cli
1 parent 2eea9cf commit c26131c

5 files changed

Lines changed: 74 additions & 8 deletions

File tree

src/somesy/cli/init.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ def config():
6363
if julia_file is not None or julia_file != "":
6464
options["julia_file"] = julia_file
6565

66+
options["no_sync_fortran"] = not typer.confirm(
67+
"Do you want to sync to a fpm.toml(fortran) file?", default=True
68+
)
69+
fortran_file = typer.prompt("fpm.toml(fortran) file path", default="fpm.toml")
70+
if fortran_file is not None or fortran_file != "":
71+
options["fortran_file"] = fortran_file
72+
6673
options["show_info"] = typer.confirm(
6774
"Do you want to show info about the sync process?"
6875
)

src/somesy/cli/sync.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ def sync(
104104
no_sync_julia: bool = typer.Option(
105105
None,
106106
"--no-sync-julia",
107-
"-M",
108-
help="Do not sync Project.toml(Julia) file",
107+
"-K",
108+
help="Do not sync Project.toml(Julia) file (default: False)",
109109
),
110110
julia_file: Path = typer.Option(
111111
None,
112112
"--julia-file",
113-
"-m",
113+
"-k",
114114
exists=True,
115115
file_okay=True,
116116
dir_okay=False,
@@ -119,6 +119,24 @@ def sync(
119119
resolve_path=True,
120120
help="Custom Project.toml(Julia) file path",
121121
),
122+
no_sync_fortran: bool = typer.Option(
123+
None,
124+
"--no-sync-fortran",
125+
"-F",
126+
help="Do not sync fpm.toml(fortran) file (default: False)",
127+
),
128+
fortran_file: Path = typer.Option(
129+
None,
130+
"--fortran-file",
131+
"-f",
132+
exists=True,
133+
file_okay=True,
134+
dir_okay=False,
135+
writable=True,
136+
readable=True,
137+
resolve_path=True,
138+
help="Custom fpm.toml(fortran) file path",
139+
),
122140
):
123141
"""Sync project metadata input with metadata files."""
124142
somesy_input = resolved_somesy_input(
@@ -133,6 +151,8 @@ def sync(
133151
codemeta_file=codemeta_file,
134152
no_sync_julia=no_sync_julia,
135153
julia_file=julia_file,
154+
no_sync_fortran=no_sync_fortran,
155+
fortran_file=fortran_file,
136156
)
137157
run_sync(somesy_input)
138158

@@ -156,6 +176,14 @@ def run_sync(somesy_input: SomesyInput):
156176
logger.info(
157177
f" - [italic]codemeta.json[/italic]:\t[grey]{conf.codemeta_file}[/grey]\n"
158178
)
179+
if not conf.no_sync_julia:
180+
logger.info(
181+
f" - [italic]Project.toml(Julia)[/italic]:\t[grey]{conf.julia_file}[/grey]"
182+
)
183+
if not conf.no_sync_fortran:
184+
logger.info(
185+
f" - [italic]fpm.toml(fortran)[/italic]:\t[grey]{conf.fortran_file}[/grey]"
186+
)
159187
# ----
160188
sync_command(somesy_input)
161189
# ----

src/somesy/commands/sync.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from somesy.cff.writer import CFF
88
from somesy.codemeta import Codemeta
99
from somesy.core.models import ProjectMetadata, SomesyInput
10+
from somesy.fortran.writer import Fortran
1011
from somesy.julia.writer import Julia
1112
from somesy.package_json.writer import PackageJSON
1213
from somesy.pyproject.writer import Pyproject
@@ -40,6 +41,9 @@ def sync(somesy_input: SomesyInput):
4041
if not conf.no_sync_julia:
4142
_sync_julia(metadata, conf.julia_file)
4243

44+
if not conf.no_sync_fortran:
45+
_sync_fortran(metadata, conf.fortran_file)
46+
4347

4448
def _sync_python(
4549
metadata: ProjectMetadata,
@@ -120,7 +124,7 @@ def _sync_julia(
120124
"""Sync Project.toml file using project metadata.
121125
122126
Args:
123-
metadata (ProjectMetadata): project metadata to sync pyproject.toml file.
127+
metadata (ProjectMetadata): project metadata to sync Project.toml file.
124128
julia_file (Path, optional): Project.toml file path if wanted to be synced. Defaults to None.
125129
"""
126130
logger.verbose("Loading Project.toml file.")
@@ -129,3 +133,21 @@ def _sync_julia(
129133
cm.sync(metadata)
130134
cm.save()
131135
logger.verbose(f"Saved synced Project.toml file to {julia_file}.")
136+
137+
138+
def _sync_fortran(
139+
metadata: ProjectMetadata,
140+
fortran_file: Path,
141+
):
142+
"""Sync fpm.toml file using project metadata.
143+
144+
Args:
145+
metadata (ProjectMetadata): project metadata to sync fpm.toml file.
146+
fortran_file (Path, optional): fpm.toml file path if wanted to be synced. Defaults to None.
147+
"""
148+
logger.verbose("Loading fpm.toml file.")
149+
cm = Fortran(fortran_file)
150+
logger.verbose("Syncing fpm.toml file.")
151+
cm.sync(metadata)
152+
cm.save()
153+
logger.verbose(f"Saved synced fpm.toml file to {fortran_file}.")

src/somesy/core/core.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"pyproject.toml",
1515
"package.json",
1616
"Project.toml",
17+
"fpm.toml",
1718
]
1819
"""Input files ordered by priority for discovery."""
1920

@@ -78,9 +79,10 @@ def get_input_content(path: Path, *, no_unwrap: bool = False) -> Dict[str, Any]:
7879
return ret if no_unwrap else ret.unwrap()
7980

8081
# pyproject.toml
81-
if (
82-
path.suffix == ".toml" and "pyproject" in path.name
83-
) or path.name == "Project.toml":
82+
if (path.suffix == ".toml" and "pyproject" in path.name) or path.name in [
83+
"Project.toml",
84+
"fpm.toml",
85+
]:
8486
with open(path, "r") as f:
8587
input_content = tomlkit.load(f)
8688
if "tool" in input_content and "somesy" in input_content["tool"]:

src/somesy/core/models.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def model_dump_json(self, *args, **kwargs):
119119
return json.dumps(ret, ensure_ascii=False)
120120

121121

122-
_SOMESY_TARGETS = ["cff", "pyproject", "package_json", "codemeta", "julia"]
122+
_SOMESY_TARGETS = ["cff", "pyproject", "package_json", "codemeta", "julia", "fortran"]
123123

124124

125125
class SomesyConfig(SomesyBaseModel):
@@ -190,6 +190,13 @@ def at_least_one_target(cls, values):
190190
"Project.toml"
191191
)
192192

193+
no_sync_fortran: Annotated[
194+
bool, Field(description="Do not sync with fpm.toml.")
195+
] = False
196+
fortran_file: Annotated[Path, Field(description="fpm.toml file path.")] = Path(
197+
"fpm.toml"
198+
)
199+
193200
def log_level(self) -> SomesyLogLevel:
194201
"""Return log level derived from this configuration."""
195202
return SomesyLogLevel.from_flags(

0 commit comments

Comments
 (0)