-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement somesy fill command with Jinja templating (closes #42)
- Loading branch information
a.pirogov
committed
Aug 17, 2023
1 parent
9acacdf
commit 5092b00
Showing
17 changed files
with
226 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
- id: somesy | ||
name: somesy | ||
description: Sync your metadata files with somesy | ||
entry: somesy sync | ||
entry: somesy | ||
args: ["sync"] | ||
language: python | ||
files: '^somesy\.toml|\.somesy\.toml|pyproject\.toml|package\.json$' | ||
pass_filenames: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,42 @@ | ||
# Authors and Contributors | ||
|
||
**Main authors** are persons whose contributions significantly shaped | ||
the state of the software at some point in time. | ||
**Authors** are people whose contributions significantly shaped | ||
the state of `somesy` at some point in time. | ||
|
||
**Additional contributors** are persons who are not main authors, | ||
but contributed non-trivially to this project, | ||
e.g. by providing smaller fixes and enhancements to the code and/or documentation. | ||
**Additional contributors** are people who contributed non-trivially to this project | ||
in different ways, e.g. by providing smaller fixes and enhancements to the code | ||
and/or documentation. | ||
|
||
Of course, this is just a rough overview and categorization. | ||
For a more complete overview of all contributors and contributions, | ||
please inspect the git history of this repository. | ||
|
||
## Main Authors | ||
## Authors | ||
|
||
- Mustafa Soylu ( | ||
[E-Mail](mailto:m.soylu@fz-juelich.de), | ||
[ORCID](https://orcid.org/0000-0003-2637-0432) | ||
): original author | ||
|
||
): Main developer, maintainer and tester. | ||
- Anton Pirogov ( | ||
[E-Mail](mailto:a.pirogov@fz-juelich.de), | ||
[ORCID](https://orcid.org/0000-0002-5077-7497) | ||
): documentation, review, and ideas | ||
): Concepts, tool development and enhancement, documentation. | ||
|
||
## Additional Contributors | ||
|
||
<!-- | ||
- Name (E-mail, ORCID): | ||
Summary of contribution | ||
--> | ||
## Additional Contributors | ||
|
||
- Jens Bröder ( | ||
[E-Mail](mailto:j.broeder@fz-juelich.de), | ||
[ORCID](https://orcid.org/0000-0001-7939-226X) | ||
): ideas | ||
|
||
... maybe **[you](https://materials-data-science-and-informatics.github.io/somesy/main/contributing)**? | ||
): Discussions and suggestions concerning metadata standards and usability. | ||
- Volker Hofmann ( | ||
[E-Mail](mailto:v.hofmann@fz-juelich.de), | ||
[ORCID](https://orcid.org/0000-0002-5149-603X) | ||
): Discussions and suggestions concerning tool scope and usability. | ||
- Stefan Sandfeld ( | ||
[E-Mail](mailto:s.sandfeld@fz-juelich.de), | ||
[ORCID](https://orcid.org/0000-0001-9560-4728) | ||
) | ||
|
||
|
||
... maybe **[you](https://materials-data-science-and-informatics.github.io/somesy/latest/contributing)**? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Authors and Contributors | ||
|
||
**Authors** are people whose contributions significantly shaped | ||
the state of `{{ project.name }}` at some point in time. | ||
|
||
**Additional contributors** are people who contributed non-trivially to this project | ||
in different ways, e.g. by providing smaller fixes and enhancements to the code | ||
and/or documentation. | ||
|
||
Of course, this is just a rough overview and categorization. | ||
For a more complete overview of all contributors and contributions, | ||
please inspect the git history of this repository. | ||
|
||
## Authors | ||
|
||
{% for p in project.authors() %} | ||
{%- set contr_desc = p.contribution or "" -%} | ||
- {{ p.full_name }} ( | ||
[E-Mail](mailto:{{ p.email }}), | ||
[ORCID]({{ p.orcid }}) | ||
){{ ": "+contr_desc if contr_desc else "" }} | ||
{% endfor %} | ||
|
||
## Additional Contributors | ||
|
||
{% for p in project.contributors() %} | ||
{%- set contr_desc = p.contribution or "" -%} | ||
- {{ p.full_name }} ( | ||
[E-Mail](mailto:{{ p.email }}), | ||
[ORCID]({{ p.orcid }}) | ||
){{ ": "+contr_desc if contr_desc else "" }} | ||
{% endfor %} | ||
|
||
... maybe **[you](https://materials-data-science-and-informatics.github.io/somesy/latest/contributing)**? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
"""Fill command of somesy.""" | ||
import logging | ||
from pathlib import Path | ||
from sys import stdin | ||
|
||
import typer | ||
from jinja2 import Environment, FileSystemLoader, FunctionLoader, select_autoescape | ||
|
||
from somesy.core.core import discover_input | ||
|
||
from ..core.models import SomesyInput | ||
from .util import wrap_exceptions | ||
|
||
logger = logging.getLogger("somesy") | ||
app = typer.Typer() | ||
|
||
|
||
@app.callback(invoke_without_command=True) | ||
@wrap_exceptions | ||
def fill( | ||
template_file: Path = typer.Option( | ||
None, | ||
"--template", | ||
"-t", | ||
exists=True, | ||
file_okay=True, | ||
dir_okay=False, | ||
writable=False, | ||
readable=True, | ||
resolve_path=False, | ||
help="Path to a Jinja2 template for somesy to fill (default: stdin).", | ||
), | ||
input_file: Path = typer.Option( | ||
None, | ||
"--input-file", | ||
"-i", | ||
exists=True, | ||
file_okay=True, | ||
dir_okay=False, | ||
writable=True, | ||
readable=True, | ||
resolve_path=True, | ||
help="Path of somesy input file (default: try to infer).", | ||
), | ||
output_file: Path = typer.Option( | ||
None, | ||
"--output-file", | ||
"-o", | ||
exists=False, | ||
file_okay=True, | ||
dir_okay=False, | ||
writable=True, | ||
readable=False, | ||
resolve_path=True, | ||
help="Path for target file (default: stdout).", | ||
), | ||
): | ||
"""Fill a Jinja2 template with somesy project metadata (e.g. list authors in project docs).""" | ||
somesy_input = SomesyInput.from_input_file(discover_input(input_file)) | ||
if template_file: | ||
env = Environment(loader=FileSystemLoader("."), autoescape=select_autoescape()) | ||
template = env.get_template(str(template_file)) | ||
else: | ||
env = Environment( | ||
loader=FunctionLoader(lambda _: stdin.read()), | ||
autoescape=select_autoescape(), | ||
) | ||
template = env.get_template("") | ||
result = template.render(project=somesy_input.project) | ||
if not output_file: | ||
print(result) | ||
else: | ||
with open(output_file, "w") as f: | ||
f.write(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.