-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_citation.py
35 lines (28 loc) · 1 KB
/
update_citation.py
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
'''Updates the CITATION.cff file:
- Sets the date-released to the current date
- Sets the version from toplevel package.json
'''
from datetime import datetime
import json
import re
CITATION_FILE = 'CITATION.cff'
PACKAGE_FILE = 'package.json'
VERSION_PATTERN = r'^version:\s+.*$'
DATE_RELEASED_PATTERN = r'^date-released:.*$'
VERSION = None
TODAY = datetime.today().strftime('%Y-%m-%d')
with open(PACKAGE_FILE, 'r') as package_file:
package_json = json.load(package_file)
VERSION = package_json.get('version')
with open(CITATION_FILE) as citation_file:
citation_in = citation_file.readlines()
citation_out = []
for line in citation_in:
if re.match(VERSION_PATTERN, line):
citation_out.append(f'version: {VERSION}\n')
elif re.match(DATE_RELEASED_PATTERN, line):
citation_out.append(f"date-released: '{TODAY}'\n")
else:
citation_out.append(line)
with open(CITATION_FILE, 'w') as citation_file:
citation_file.writelines(citation_out)