1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""Utility script to work with the codemeta.json file."""
import json
import logging
from configparser import ConfigParser
import tomllib
import click
from datetime import date
log = logging.getLogger(__name__)
def update_codemeta(maintainer, filename, setup_file=None):
log.info(f"Updating {filename}")
# add potentially missing content
with open(filename, "r") as f:
data = json.load(f)
for author in data["author"]:
if "familyName" in author.keys() and author["familyName"] == maintainer:
log.info(f"Setting maintainer to {maintainer}")
data["maintainer"] = author
data["readme"] = "https://gammapy.org"
data["issueTracker"] = "https://github.com/gammapy/gammapy/issues"
data["developmentStatus"] = ("active",)
data["email"] = "GAMMAPY-COORDINATION-L@IN2P3.FR"
modified_date = str(date.today())
data["dateModified"] = modified_date
if setup_file:
# complete with software requirements from pyproject.toml
with open(setup_file, "rb") as fp:
conf = tomllib.load(fp)
requirements = conf["project"]["dependencies"]
if "" in requirements:
requirements.remove("")
data["softwareRequirements"] = requirements
with open(filename, "w") as f:
json.dump(data, f, indent=4)
# replace bad labelled attributes
with open(filename, "r") as f:
content = f.read()
content = content.replace("legalName", "name")
content = content.replace("version", "softwareVersion")
with open(filename, "w") as f:
f.write(content)
@click.command()
@click.option("--maintainer", default="Donath", type=str, help="Maintainer name")
@click.option(
"--filename", default="../codemeta.json", type=str, help="codemeta filename"
)
@click.option("--setup_file", default="../pyproject.toml", type=str, help="setup filename")
@click.option(
"--log_level",
default="INFO",
type=click.Choice(["DEBUG", "INFO", "WARNING"]),
help="log level",
)
def cli(maintainer, filename, log_level, setup_file):
logging.basicConfig(level=log_level)
log.setLevel(level=log_level)
update_codemeta(maintainer=maintainer, filename=filename, setup_file=setup_file)
if __name__ == "__main__":
cli()
|