Skip to content

Commit e1e4568

Browse files
authored
Merge pull request #75 from Materials-Data-Science-and-Informatics/feature/add-rust-support
add rust support
2 parents bdd6cb2 + 21dfc9c commit e1e4568

15 files changed

Lines changed: 624 additions & 25 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Please consult the changelog to inform yourself about breaking changes and secur
1111
* added support for Fortran `fpm.toml` file
1212
* added support for Java `pom.xml` file
1313
* added support for MkDocs `mkdocs.yml` file
14+
* added support for Rust `Cargo.toml` file
1415

1516
## [v0.3.1](https://github.com/Materials-Data-Science-and-Informatics/somesy/tree/v0.3.1) <small>(2024-01-23)</small> { id="0.3.1" }
1617

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ If you happen to use
134134
* `fpm.toml` (in Fortran projects),
135135
* `pom.xml` (in Java projects),
136136
* `mkdocs.yml` (in projects using MkDocs),
137+
* `Cargo.toml` (in Rust projects)
137138

138139
then somesy would also update the respective information there.
139140

@@ -182,6 +183,7 @@ Here is an overview of all the currently supported files and formats.
182183
| Project.toml | ✓ | | Project.toml _(Julia)_ | ✓ |
183184
| fpm.toml | ✓ | | fpm.toml _(Fortran)_ | ✓(3.) |
184185
| | ✓ | | pom.toml _(Java)_ | ✓(4.) |
186+
| Cargo.toml | ✓ | | Cargo.toml _(Rust)_ | ✓ |
185187
| | | | mkdocs.yml | ✓(5.) |
186188
| | | | CITATION.cff | ✓ |
187189
| | | | codemeta.json | ✓(6.) |

docs/manual.md

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,33 +117,34 @@ some of the currently supported formats. Bold field names are mandatory, the oth
117117

118118
=== "Person Metadata"
119119

120-
| Somesy Field | Poetry Config | SetupTools Config | Java POM | Julia Config | Fortran Config | package.json | mkdocs.yml | CITATION.cff | CodeMeta |
121-
| ---------------- | ------------- | ----------------- | ------------ | ------------ | -------------- | ------------ | ---------- | --------------- | --------------- |
122-
| | | | | | | | | | |
123-
| **given-names** | name+email | name | name | name+email | name+email | name | name+email | given-names | givenName |
124-
| **family-names** | name+email | name | name | name+email | name+email | name | name+email | family-names | familyName |
125-
| **email** | name+email | email | email | name+email | name+email | email | name+email | email | email |
126-
| orcid | - | - | url | - | - | url | - | orcid | id |
127-
| *(many others)* | - | - | - | - | - | - | - | *(same)* | *(same)* |
120+
| Somesy Field | Poetry Config | SetupTools Config | Java POM | Julia Config | Fortran Config | package.json | mkdocs.yml | Rust Config | CITATION.cff | CodeMeta |
121+
| ---------------- | ------------- | ----------------- | ------------ | ------------ | -------------- | ------------ | ---------- | -------------- | --------------- | -------------- |
122+
| | | | | | | | | | | |
123+
| **given-names** | name+email | name | name | name+email | name+email | name | name+email | name+email | givenName | name+email |
124+
| **family-names** | name+email | name | name | name+email | name+email | name | name+email | name+email | familyName | name+email |
125+
| **email** | name+email | email | email | name+email | name+email | email | name+email | name+email | email | name+email |
126+
| orcid | - | - | url | - | - | url | - | - | id | - |
127+
| *(many others)* | - | - | - | - | - | - | - | - | *(same)* | - |
128128

129129
=== "Project Metadata"
130130

131-
| Somesy Field | Poetry Config | SetupTools Config | Java POM | Julia Config | Fortran Config | package.json | mkdocs.yml | CITATION.cff | CodeMeta |
132-
| ----------------- | ------------- | ------------------ | ------------------------------- | ------------ | -------------- | ------------ | ---------------- | --------------- | ----------------- |
133-
| | | | | | | | | | |
134-
| **name** | name | name | name | name | name | name | site_name | title | name |
135-
| **description** | description | description | description | - | description | description | site_description | abstract | description |
136-
| **license** | license | license | licenses.license | - | license | license | - | license | license |
137-
| **version** | version | version | version | version | version | version | - | version | version |
138-
| | | | | | | | | | |
139-
| ***author=true*** | authors | authors | developers | authors | author | author | site_author | authors | author |
140-
| *maintainer=true* | maintainers | maintainers | - | - | maintainer | maintainers | - | contact | maintainer |
141-
| *people* | - | - | - | - | - | contributors | - | - | contributor |
142-
| | | | | | | | | | |
143-
| keywords | keywords | keywords | - | - | keywords | keywords | - | keywords | keywords |
144-
| homepage | homepage | urls.homepage | urls | - | homepage | homepage | site_url | url | url |
145-
| repository | repository | urls.repository | scm.url | - | - | repository | repo_url | repository_code | codeRepository |
146-
| documentation | documentation | urls.documentation | distributionManagement.site.url | - | - | - | - | - | buildInstructions |
131+
| Somesy Field | Poetry Config | SetupTools Config | Java POM | Julia Config | Fortran Config | package.json | mkdocs.yml | Rust Config | CITATION.cff | CodeMeta |
132+
| ----------------- | ------------- | ------------------ | ------------------------------- | ------------ | -------------- | ------------ | ---------------- | --------------- | --------------- | ----------------- |
133+
| | | | | | | | | | | |
134+
| **name** | name | name | name | name | name | name | site_name | name | title | name |
135+
| **description** | description | description | description | - | description | description | site_description | description | abstract | description |
136+
| **license** | license | license | licenses.license | - | license | license | - | license | license | license |
137+
| **version** | version | version | version | version | version | version | - | version | version | version |
138+
| | | | | | | | | | | |
139+
| ***author=true*** | authors | authors | developers | authors | author | author | site_author | authors | authors | author |
140+
| *maintainer=true* | maintainers | maintainers | - | - | maintainer | maintainers | - | - | contact | maintainer |
141+
| *people* | - | - | - | - | - | contributors | - | - | - | contributor |
142+
| | | | | | | | | | | |
143+
| keywords | keywords | keywords | - | - | keywords | keywords | - | keywords | keywords | keywords |
144+
| homepage | homepage | urls.homepage | urls | - | homepage | homepage | site_url | homepage | url | url |
145+
| repository | repository | urls.repository | scm.url | - | - | repository | repo_url | repository | repository_code | codeRepository |
146+
| documentation | documentation | urls.documentation | distributionManagement.site.url | - | - | - | - | documentation | - | buildInstructions |
147+
147148

148149
Note that the mapping is often not 1-to-1. For example, CITATION.cff allows rich
149150
specification of author contact information and complex names. In contrast,
@@ -173,6 +174,7 @@ Without an input file specifically provided, somesy will check if it can find a
173174
* `Project.toml` (in `tool.somesy` section)
174175
* `fpm.toml` (in `tool.somesy` section)
175176
* `package.json` (in `somesy` section)
177+
* `Cargo.toml` (in `package.metadata.somesy` section)
176178

177179
which is located in the current working directory. If you want to provide
178180
the somesy input file from a different location, you can pass it with the `-i` option.

src/somesy/cli/init.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ def config():
8484
if mkdocs_file := typer.prompt("mkdocs.yml file path", default="mkdocs.yml"):
8585
options["mkdocs_file"] = mkdocs_file
8686

87+
options["no_sync_rust"] = not typer.confirm(
88+
"Do you want to sync to a Cargo.toml file?", default=True
89+
)
90+
if rust_file := typer.prompt("Cargo.toml file path", default="Cargo.toml"):
91+
options["rust_file"] = rust_file
92+
8793
# ----
8894

8995
options["show_info"] = typer.confirm(

src/somesy/cli/sync.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,19 @@ def sync(
107107
help="Custom mkdocs.yml file path (default: mkdocs.yml)",
108108
**existing_file_arg_config,
109109
),
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+
),
110123
no_sync_cff: bool = typer.Option(
111124
None,
112125
"--no-sync-cff",
@@ -153,6 +166,8 @@ def sync(
153166
pom_xml_file=pom_xml_file,
154167
no_sync_mkdocs=no_sync_mkdocs,
155168
mkdocs_file=mkdocs_file,
169+
no_sync_rust=no_sync_rust,
170+
rust_file=rust_file,
156171
)
157172
run_sync(somesy_input)
158173

@@ -186,6 +201,8 @@ def run_sync(somesy_input: SomesyInput):
186201
logger.info(
187202
f" - [italic]mkdocs.yml[/italic]:\t[grey]{conf.mkdocs_file}[/grey]"
188203
)
204+
if not conf.no_sync_rust:
205+
logger.info(f" - [italic]Cargo.toml[/italic]:\t[grey]{conf.rust_file}[/grey]")
189206

190207
if not conf.no_sync_cff:
191208
logger.info(f" - [italic]CITATION.cff[/italic]:\t[grey]{conf.cff_file}[/grey]")

src/somesy/commands/sync.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from somesy.package_json.writer import PackageJSON
1616
from somesy.pom_xml.writer import POM
1717
from somesy.pyproject.writer import Pyproject
18+
from somesy.rust import Rust
1819

1920
logger = logging.getLogger("somesy")
2021

@@ -58,6 +59,9 @@ def sync(somesy_input: SomesyInput):
5859
if conf.mkdocs_file.is_file() and not conf.no_sync_mkdocs:
5960
_sync_file(metadata, conf.mkdocs_file, MkDocs)
6061

62+
if conf.rust_file.is_file() and not conf.no_sync_rust:
63+
_sync_file(metadata, conf.rust_file, Rust)
64+
6165
# create these by default if they are missing:
6266
if not conf.no_sync_cff:
6367
_sync_file(metadata, conf.cff_file, CFF)

src/somesy/core/core.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"package.json",
1616
"Project.toml",
1717
"fpm.toml",
18+
"Cargo.toml",
1819
]
1920
"""Input files ordered by priority for discovery."""
2021

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

81-
# pyproject.toml
82+
# pyproject.toml or fpm.toml
8283
if (path.suffix == ".toml" and "pyproject" in path.name) or path.name in [
8384
"Project.toml",
8485
"fpm.toml",
@@ -92,6 +93,22 @@ def get_input_content(path: Path, *, no_unwrap: bool = False) -> Dict[str, Any]:
9293
"No tool.somesy section found in pyproject.toml file!"
9394
)
9495

96+
# Cargo.toml
97+
if path.name == "Cargo.toml":
98+
with open(path, "r") as f:
99+
input_content = tomlkit.load(f)
100+
if (
101+
"package" in input_content
102+
and "metadata" in input_content["package"]
103+
and "somesy" in input_content["package"]["metadata"]
104+
):
105+
return input_content["package"]["metadata"]["somesy"].unwrap()
106+
else:
107+
raise RuntimeError(
108+
"No package.somesy section found in Cargo.toml file!"
109+
)
110+
111+
# package.json
95112
if path.suffix == ".json" and "package" in path.name:
96113
with open(path, "r") as f:
97114
input_content = json.load(f)

src/somesy/core/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def model_dump_json(self, *args, **kwargs):
129129
"fortran",
130130
"pom_xml",
131131
"mkdocs",
132+
"rust",
132133
]
133134

134135

@@ -209,6 +210,13 @@ def at_least_one_target(cls, values):
209210
"mkdocs.yml"
210211
)
211212

213+
no_sync_rust: Annotated[
214+
bool, Field(description="Do not sync with Cargo.toml.")
215+
] = False
216+
rust_file: Annotated[Path, Field(description="Cargo.toml file path.")] = Path(
217+
"Cargo.toml"
218+
)
219+
212220
no_sync_cff: Annotated[bool, Field(description="Do not sync with CFF.")] = False
213221
cff_file: Annotated[Path, Field(description="CFF file path.")] = Path(
214222
"CITATION.cff"

src/somesy/rust/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""Rust module."""
2+
from .writer import Rust
3+
4+
__all__ = ["Rust"]

0 commit comments

Comments
 (0)