Skip to content

Commit

Permalink
feat: implement somesy fill command with Jinja templating (closes #42)
Browse files Browse the repository at this point in the history
  • Loading branch information
a.pirogov committed Aug 17, 2023
1 parent 9acacdf commit 5092b00
Show file tree
Hide file tree
Showing 17 changed files with 226 additions and 52 deletions.
11 changes: 9 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,16 @@ repos:
- repo: local
hooks:
# NOTE: copy from .pre-commit-hooks.yaml, for technical reasons
- id: somesy
name: somesy
- id: somesy-sync
name: Run somesy sync
entry: somesy sync
language: python
files: '^\.somesy\.toml|pyproject\.toml$'
pass_filenames: false

- id: somesy-fill
name: Update AUTHORS.md
entry: somesy fill -t docs/_template_authors.md -o AUTHORS.md
language: python
files: '^\.somesy\.toml|pyproject\.toml$'
pass_filenames: false
3 changes: 2 additions & 1 deletion .pre-commit-hooks.yaml
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
4 changes: 2 additions & 2 deletions .somesy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ given-names = "Mustafa"
email = "m.soylu@fz-juelich.de"
orcid = "https://orcid.org/0000-0003-2637-0432"

contribution = "The main developer, maintainer and tester."
contribution = "Main developer, maintainer and tester."
contribution_begin = "2023-03-01"
contribution_types = ["maintenance", "code", "test", "review", "doc"]

Expand All @@ -26,7 +26,7 @@ given-names = "Anton"
email = "a.pirogov@fz-juelich.de"
orcid = "https://orcid.org/0000-0002-5077-7497"

contribution = "Initial concepts, tool development and enhancement, documentation."
contribution = "Concepts, tool development and enhancement, documentation."
contribution_begin = "2023-03-01"
contribution_types = ["ideas", "code", "test", "review", "doc"]

Expand Down
38 changes: 21 additions & 17 deletions AUTHORS.md
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)**?
8 changes: 4 additions & 4 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ authors:
email: m.soylu@fz-juelich.de
given-names: Mustafa
family-names: Soylu
- orcid: https://orcid.org/0000-0002-5077-7497
email: a.pirogov@fz-juelich.de
given-names: Anton
family-names: Pirogov
- email: v.hofmann@fz-juelich.de
orcid: https://orcid.org/0000-0002-5149-603X
family-names: Hofmann
Expand All @@ -27,6 +23,10 @@ authors:
orcid: https://orcid.org/0000-0001-9560-4728
family-names: Sandfeld
given-names: Stefan
- email: a.pirogov@fz-juelich.de
orcid: https://orcid.org/0000-0002-5077-7497
family-names: Pirogov
given-names: Anton
contact:
- email: m.soylu@fz-juelich.de
family-names: Soylu
Expand Down
23 changes: 15 additions & 8 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@
"audience": [
{
"@type": "Audience",
"audienceType": "Developers"
"audienceType": "Science/Research"
},
{
"@type": "Audience",
"audienceType": "Science/Research"
"audienceType": "Developers"
}
],
"author": [
{
"@id": "https://orcid.org/0000-0003-2637-0432",
"@type": "Person",
"familyName": "Soylu",
"givenName": "Mustafa"
},
{
"@id": "https://orcid.org/0000-0002-5149-603X",
"@type": "Person",
Expand All @@ -31,12 +37,6 @@
"familyName": "Sandfeld",
"givenName": "Stefan"
},
{
"@id": "https://orcid.org/0000-0003-2637-0432",
"@type": "Person",
"familyName": "Soylu",
"givenName": "Mustafa"
},
{
"@id": "https://orcid.org/0000-0002-5077-7497",
"@type": "Person",
Expand Down Expand Up @@ -91,6 +91,13 @@
"runtimePlatform": "Python 3",
"version": "^4.11.0"
},
{
"@type": "SoftwareApplication",
"identifier": "jinja2",
"name": "jinja2",
"runtimePlatform": "Python 3",
"version": "^3.1.2"
},
{
"@type": "SoftwareApplication",
"identifier": "packaging",
Expand Down
35 changes: 35 additions & 0 deletions docs/_template_authors.md
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)**?

3 changes: 3 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ plugins:
enabled: !ENV [OFFLINE, false]
# to make multi-version docs work right
- mike
- exclude:
glob:
- "_*.md" # for internal purposes

hooks:
- docs/scripts/coverage_status.py
Expand Down
15 changes: 14 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ wrapt = "^1.15.0"
packaging = "^23.1"
rdflib = "^6.3.2"
codemetapy = "^2.5.0"
jinja2 = "^3.1.2"

[tool.poetry.group.dev.dependencies]
poethepoet = "^0.18.1"
Expand Down Expand Up @@ -76,6 +77,7 @@ mike = "^1.1.2"
anybadge = "^1.14.0"
interrogate = "^1.5.0"
black = "^23.3.0"
mkdocs-exclude = "^1.0.2"

[tool.poetry.scripts]
somesy = "somesy.main:app"
Expand All @@ -99,9 +101,10 @@ licensecheck = "licensecheck" # run this when you add new deps
pythonpath = ["src"]
addopts = "--cov-report=term-missing:skip-covered"
filterwarnings = [
"ignore::DeprecationWarning:pkg_resources.*"
"ignore::DeprecationWarning:pkg_resources.*",
"ignore::DeprecationWarning:pyshacl.*",
# Example:
# "ignore::DeprecationWarning:importlib_metadata.*"
# "ignore::DeprecationWarning:importlib_metadata.*",
]

[tool.coverage.run]
Expand Down
74 changes: 74 additions & 0 deletions src/somesy/cli/fill.py
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)
2 changes: 1 addition & 1 deletion src/somesy/cli/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def sync(
),
no_sync_package_json: bool = typer.Option(
None,
"--sync-package-json",
"--no-sync-package-json",
"-J",
help="Do not sync package.json file (default: False)",
),
Expand Down
Loading

0 comments on commit 5092b00

Please sign in to comment.