diff --git a/hf_gen/README.md b/hf_gen/README.md index e954ab5..eb7f834 100644 --- a/hf_gen/README.md +++ b/hf_gen/README.md @@ -18,4 +18,4 @@ # Disclaimer -This repository has been automatically created using the [sb2hf](https://github.com/felixhultin/sb2hf/tree/main) tool. \ No newline at end of file +This repository has been automatically created using the [sb2hf](https://github.com/felixhultin/sb2hf/tree/main) tool, version {{ sb2hf_version }}. \ No newline at end of file diff --git a/hf_gen/create_docs.py b/hf_gen/create_docs.py index 0e6c692..fe48685 100644 --- a/hf_gen/create_docs.py +++ b/hf_gen/create_docs.py @@ -4,10 +4,13 @@ """ import codecs +import importlib import logging +import pkg_resources import requests import yaml + from jinja2 import Template from helpers import get_value @@ -19,11 +22,16 @@ def write_readme(url_reader: URLReader, metadata : dict, fp : str): bibtex_query = f"{TEMP_LINK}/bibtex?resource={url_reader.resource_name}&type={metadata['type']}" logging.info(f"Fetching bibtex from {bibtex_query}") bibtex = requests.get(bibtex_query).json()['bibtex'] + try: + sb2hf_version = pkg_resources.get_distribution('sb2hf').version + except importlib.metadata.PackageNotFoundError: + sb2hf_version = "Unknown" template_variables = { 'description': get_value(metadata, 'description'), 'title' : get_value(metadata, 'name'), 'bibtex': bibtex, - 'url': url_reader.url + 'url': url_reader.url, + 'sb2hf_version': sb2hf_version } with open('hf_gen/README.md', 'r') as file: template = Template(file.read(),trim_blocks=True)