-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python instead of shell for updating citation
- Loading branch information
1 parent
472f067
commit 053f1e4
Showing
3 changed files
with
39 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'''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) | ||
try: | ||
VERSION = package_json.get('version') | ||
except KeyError: | ||
print('No version found in root package.json') | ||
VERSION = '0.0.0' | ||
|
||
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) |