Skip to content

Commit 50262ab

Browse files
committed
deploy: b4420d4
1 parent 410f0c6 commit 50262ab

6 files changed

Lines changed: 207 additions & 225 deletions

File tree

bin/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Script development guidelines
2+
3+
## Testing your changes
4+
5+
Before pushing you changes, create a `test.sh` file in this folder with this content :
6+
7+
```sh
8+
#!/bin/bash
9+
10+
BODY="" # -> put there the content of the issue
11+
12+
python $SCRIPT_NAME -b "${BODY}"
13+
```
14+
15+
- from github, copy-paste the issue body using the "..." icon and `Copy Markdown`
16+
- replace $SCRIPT_NAME by the script you want to test, like `issue_to_bibtex.py`, `arxiv_to_publications_correct.py`, ...
17+
18+
Then, check that the modification of the `_bibliography/pint.bib` file is correct.
19+
You can commit the changes on the `pint.bib` file (done now, no need to do it again), or reset those and trigger the scripts on Github using the label manipulation on the issue (check if the whole pipeline works well).

bin/arxiv_to_publications_correct.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,7 @@
88
from bibtexparser.bwriter import BibTexWriter
99
from requests.exceptions import RequestException
1010

11-
12-
def normalize_month_fields(bib):
13-
def replace_month(match):
14-
prefix, value = match.groups()
15-
value = unescape(value).strip()
16-
if value.startswith("{") and value.endswith("}"):
17-
return match.group(0)
18-
if value.startswith('"') and value.endswith('"'):
19-
value = value[1:-1].strip()
20-
value = value.strip("'\"{}")
21-
value = re.sub(r"[^A-Za-z]", "", value)
22-
return f"{prefix}{{{value}}},"
23-
24-
return re.sub(
25-
r"(^\s*month\s*=\s*)([^,\n]+)\s*,",
26-
replace_month,
27-
bib,
28-
flags=re.MULTILINE | re.IGNORECASE,
29-
)
30-
11+
from utils import fixBadBibFormat
3112

3213
def fetch_doi_content(url, accept_header, description):
3314
try:
@@ -104,7 +85,7 @@ def fetch_doi_content(url, accept_header, description):
10485
if id != id_db:
10586
print(f'Note: ID updated from {id_db} to {id} to reflect the publication year.')
10687
bib = "{".join([bType] + [','.join([id]+rest2)] + rest1[1:])
107-
bib = normalize_month_fields(bib)
88+
bib = fixBadBibFormat(bib)
10889
bib_db = bibtexparser.loads(bib)
10990
new_entries = bib_db.get_entry_list()
11091
if not new_entries:

bin/issue_to_bibtex.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,7 @@
1111
from bibtexparser.bibdatabase import BibDatabase
1212
from bibtexparser.bwriter import BibTexWriter
1313

14-
15-
def fixBadBibFormat(bibString):
16-
bibString = bibString.strip()
17-
assert bibString.startswith("@") and bibString.endswith("}"), \
18-
"bib entry should start with '@' and finish with '}', got :\n{bibString}"
19-
content = bibString[1:-1]
20-
fields = content.split(",")
21-
for i, field in enumerate(fields[1:]):
22-
item = field.split("=")
23-
if len(item) == 2 and "{" not in item[1]:
24-
item[1] = "{"+item[1]+"}"
25-
fields[i+1] = "=".join(item)
26-
return "@"+",".join(fields)+"}"
14+
from utils import fixBadBibFormat
2715

2816
try:
2917

bin/request.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

bin/utils.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
def fixBadBibFormat(bibString:str)->str:
2+
"""
3+
Fixes the formatting of a BibTeX entry string by ensuring all field values are enclosed in braces.
4+
5+
Parameters
6+
----------
7+
bibString : str
8+
The BibTeX entry string to be fixed. Must start with '@' and end with '}'.
9+
10+
Returns
11+
-------
12+
str
13+
The corrected BibTeX entry string with all field values enclosed in braces.
14+
15+
Raises
16+
------
17+
AssertionError
18+
If the input string does not start with '@' or does not end with '}'.
19+
"""
20+
bibString = bibString.strip()
21+
assert bibString.startswith("@") and bibString.endswith("}"), \
22+
"bib entry should start with '@' and finish with '}', got :\n{bibString}"
23+
content = bibString[1:-1]
24+
fields = content.split(",")
25+
for i, field in enumerate(fields[1:]):
26+
item = field.split("=")
27+
if len(item) == 2 and "{" not in item[1]:
28+
item[1] = "{"+item[1]+"}"
29+
fields[i+1] = "=".join(item)
30+
return "@"+",".join(fields)+"}"

0 commit comments

Comments
 (0)