Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more metadata from redata to readme #277

Merged
merged 13 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ldcoolp/config/default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ report_url = https://bit.ly/ReDATA_CurationTemplate
# README template filename located in curation.inspection.readme
readme_template = README_template.md

# Macros for README located in curation.inspection.readme.template
macros_folder = macros
funders_macro = ***override***

# For logging
log_parent_dir = %(parent_dir)s
log_dir = logs
Expand Down
15 changes: 14 additions & 1 deletion ldcoolp/curation/inspection/readme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# Template engine
from jinja2 import Environment, FileSystemLoader
from jinja2.ext import loopcontrols
from html2text import html2text

# Logging
Expand Down Expand Up @@ -125,6 +126,7 @@ def __init__(self, dn: DepositorName, config_dict=config_default_dict,

self.curation_dict = self.config_dict['curation']
self.root_directory_main = self.curation_dict[self.curation_dict['parent_dir']]
self.funders_macro = join(self.curation_dict['macros_folder'], self.curation_dict['funders_macro'])

# Always obtain current data curation stage
self.mc = move.MoveClass(curation_dict=self.curation_dict)
Expand Down Expand Up @@ -260,6 +262,10 @@ def save_template(self):

dest_file = join(self.metadata_path, self.readme_template)

funders_macro_file_src = join(dirname(__file__), 'templates',
self.funders_macro)
funders_macro_file_dest = join(self.metadata_path, self.curation_dict['funders_macro'])

if not exists(dest_file):
self.log.info(f"Saving {self.readme_template} template in METADATA ...")

Expand All @@ -271,6 +277,7 @@ def save_template(self):

self.log.info(f"Source file name: {src_file}")
shutil.copy(src_file, dest_file)
shutil.copy(funders_macro_file_src, funders_macro_file_dest)
else:
self.log.info(f"{dest_file} exists. Not overwriting template!")

Expand All @@ -283,7 +290,7 @@ def import_template(self):
"""Returns a jinja2 template by importing README markdown template (README_template.md)"""

file_loader = FileSystemLoader(self.metadata_path)
env = Environment(loader=file_loader, lstrip_blocks=True, trim_blocks=True)
env = Environment(loader=file_loader, lstrip_blocks=True, trim_blocks=True, extensions=[loopcontrols])

jinja_template = env.get_template(self.default_readme_file)
return jinja_template
Expand Down Expand Up @@ -365,9 +372,15 @@ def retrieve_article_metadata(self):
self.log.info("No footer to strip")
readme_dict['description'] = description

# Retrieve funder details as a list of dicts
readme_dict['funders'] = self.article_dict['item']['funding_list']

# Retrieve references as list
readme_dict['references'] = self.article_dict['item']['references']

# Retrieve related materials as a list of dicts
readme_dict['related_materials'] = self.article_dict['item']['related_materials']

return readme_dict

def retrieve_qualtrics_readme(self):
Expand Down
24 changes: 20 additions & 4 deletions ldcoolp/curation/inspection/readme/templates/DVC.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ DOI:



{% endif %}
{% if figshare_dict.funders != [] %}
---------------------------------------------
## Funding Information

{% import 'funders_macro.jinja' as funds %}
{% for funder in figshare_dict.funders -%}
{% if funder.is_user_defined == 0 -%}
{{ funds.funders_(funder) }}
{% else %}
- {{ funder.title }}
{% endif %}
{%- endfor %}



{% endif %}
{% if qualtrics_dict.files != 'nan' %}
---------------------------------------------
Expand Down Expand Up @@ -87,9 +103,9 @@ The roles are defined by the CRediT taxonomy http://credit.niso.org/
This item is part of the University of Arizona Libraries 2021 Data Visualization Challenge, which is available here:
https://doi.org/10.25422/azu.data.c.5405493

{% if figshare_dict.references != [] %}
Links:
{% for reference in figshare_dict.references %}
- {{ reference }}
{% if figshare_dict.related_materials != [] %}
Related Materials:
{% for material in figshare_dict.related_materials %}
- {{ material.relation }}: {{ material.title }} ({{ material.link }})
{% endfor -%}
{% endif %}
26 changes: 21 additions & 5 deletions ldcoolp/curation/inspection/readme/templates/Main.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ DOI:



{% endif %}
{% if figshare_dict.funders != [] %}
---------------------------------------------
## Funding Information

{% import 'funders_macro.jinja' as funds %}
{% for funder in figshare_dict.funders -%}
{% if funder.is_user_defined == 0 -%}
{{ funds.funders_(funder) }}
{% else %}
- {{ funder.title }}
{% endif %}
{%- endfor %}



{% endif %}
{% if qualtrics_dict.files != 'nan' %}
---------------------------------------------
Expand Down Expand Up @@ -87,7 +103,7 @@ The roles are defined by the CRediT taxonomy http://credit.niso.org/

{% endif %}
{% endif %}
{% if qualtrics_dict.notes != 'nan' or figshare_dict.references != [] %}
{% if qualtrics_dict.notes != 'nan' or figshare_dict.related_materials != [] %}
---------------------------------------------
## Additional Notes

Expand All @@ -96,9 +112,9 @@ The roles are defined by the CRediT taxonomy http://credit.niso.org/
{{ qualtrics_dict.notes }}

{% endif %}
{% if figshare_dict.references != [] %}
Links:
{% for reference in figshare_dict.references %}
- {{ reference }}
{% if figshare_dict.related_materials != [] %}
Related Materials:
{% for material in figshare_dict.related_materials %}
- {{ material.relation }}: {{ material.title }} ({{ material.link }})
{% endfor -%}
{% endif %}
24 changes: 20 additions & 4 deletions ldcoolp/curation/inspection/readme/templates/Space_Grant.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ DOI:



{% endif %}
{% if figshare_dict.funders != [] %}
---------------------------------------------
## Funding Information

{% import 'funders_macro.jinja' as funds %}
{% for funder in figshare_dict.funders -%}
{% if funder.is_user_defined == 0 -%}
{{ funds.funders_(funder) }}
{% else %}
- {{ funder.title }}
{% endif %}
{%- endfor %}



{% endif %}
{% if qualtrics_dict.files != 'nan' %}
---------------------------------------------
Expand Down Expand Up @@ -96,10 +112,10 @@ The roles are defined by the CRediT taxonomy http://credit.niso.org/
{{ qualtrics_dict.notes }}

{% endif %}
{% if figshare_dict.references != [] %}
Links:
{% for reference in figshare_dict.references %}
- {{ reference }}
{% if figshare_dict.related_materials != [] %}
Related Materials:
{% for material in figshare_dict.related_materials %}
- {{ material.relation }}: {{ material.title }} ({{ material.link }})
{% endfor -%}
{% endif %}

Expand Down
24 changes: 20 additions & 4 deletions ldcoolp/curation/inspection/readme/templates/WCCFL.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ DOI:



{% endif %}
{% if figshare_dict.funders != [] %}
---------------------------------------------
## Funding Information

{% import 'funders_macro.jinja' as funds %}
{% for funder in figshare_dict.funders -%}
{% if funder.is_user_defined == 0 -%}
{{ funds.funders_(funder) }}
{% else %}
- {{ funder.title }}
{% endif %}
{%- endfor %}



{% endif %}
{% if qualtrics_dict.files != 'nan' %}
---------------------------------------------
Expand Down Expand Up @@ -96,10 +112,10 @@ The roles are defined by the CRediT taxonomy http://credit.niso.org/
{{ qualtrics_dict.notes }}

{% endif %}
{% if figshare_dict.references != [] %}
Links:
{% for reference in figshare_dict.references %}
- {{ reference }}
{% if figshare_dict.related_materials != [] %}
Related Materials:
{% for material in figshare_dict.related_materials %}
- {{ material.relation }}: {{ material.title }} ({{ material.link }})
{% endfor -%}
{% endif %}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% macro funders_(given_funder) -%}
{% set funders = {
'National Science Foundation': ['Directorate for Biological Sciences',
'Directorate for Computer and Information Science and Engineering',
'Directorate for Engineering',
'Directorate of Geosciences',
'Directorate for Mathematical and Physical Sciences',
'Directorate for Social, Behavioral and Economic Sciences',
'Directorate for STEM Education',
'Directorate for Technology, Innovation and Partnerships'
]
} %}
{% set ns = namespace(given_funder_found = false) %}
{% for funder, offices in funders.items() -%}
{% if given_funder.funder_name in offices -%}
{% set ns.given_funder_found = true %}
- {{ funder }} (Grant no: {{ given_funder.grant_code }})
{{ given_funder.url }}
{% break %}
{% else %}
{% set ns.given_funder_found = false %}
{%- endif %}
{%- endfor %}
{% if ns.given_funder_found == false -%}
- {{ given_funder.funder_name}} (Grant no: {{ given_funder.grant_code }})
{{ given_funder.url }}
{%- endif %}
{%- endmacro %}
Loading