-
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.
More regex rule for post-processing and skip citations (#69)
* Fix monkeypatch of no token raiser * Add tool to record the deepl api behavior changes * Bookkeeping * Post-processing regex for inline url link * Trigger apicall test on pull request
- Loading branch information
Showing
15 changed files
with
315 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: bookkeeping CI | ||
|
||
# run scheduled translation on given strings | ||
# make the record of the translation in the bookkeeping folder | ||
|
||
on: | ||
push: | ||
paths: | ||
- "src/**" | ||
branches: | ||
- main | ||
schedule: | ||
# every week on Monday at 00:00 UTC | ||
- cron: "0 0 * * 1" | ||
workflow_dispatch: | ||
|
||
jobs: | ||
|
||
bookkeeping: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Install Python 3.11 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.11" | ||
|
||
- name: Install aiida-core-i18n | ||
run: | | ||
pip install -e . | ||
- name: Run bookkeeping | ||
run: | | ||
python -m aiida_core_i18n.bookkeeping | ||
env: | ||
DEEPL_TOKEN: ${{ secrets.DEEPL_TOKEN }} | ||
|
||
- name: Make a PR for the bookkeeping | ||
uses: peter-evans/create-pull-request@v5 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
commit-message: Update bookkeeping | ||
title: Update bookkeeping | ||
body: | | ||
This pull request updates the bookkeeping file. | ||
branch: update-bookkeeping-${{ github.sha }} | ||
reviewers: unkcpz | ||
if: github.event_name != 'push' |
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 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 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 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,58 @@ | ||
"""Tool to translate raw en strings to every languages | ||
bookkeeping the Deepl API behavior by date. | ||
""" | ||
import pathlib | ||
from datetime import datetime | ||
|
||
from aiida_core_i18n import translate | ||
|
||
# list of original strings (English) | ||
inp_strs = [ | ||
r"Please visit the `Discourse forum <https://aiida.discourse.group>`__.", | ||
] | ||
|
||
rec_folder = pathlib.Path(__file__).parent / "_bookkeeping" | ||
|
||
def rec(inp_strs: list[str], lang: str, output_folder: pathlib.Path): | ||
"""Write raw strings to the file""" | ||
|
||
if not output_folder.is_dir(): | ||
output_folder.mkdir(parents=True) | ||
|
||
# Call translate to the inp_strs and record the result | ||
# by the date of running this script, and save to the _bookkeeping folder | ||
with open(output_folder / f"{lang}_{datetime.now().strftime('%Y-%m-%d')}.txt", "w") as fh: | ||
# write the metadata (date, lang) to the file | ||
fh.write(f"Date: {datetime.now().strftime('%Y-%m-%d')}\n") | ||
fh.write(f"Source: EN Target: {lang}\n\n") | ||
|
||
for inp_str in inp_strs: | ||
res = translate(inp_str, target_lang=f"{lang}", post_processing=False) | ||
|
||
fh.write(f"Input: \n\t{inp_str}\n") | ||
fh.write(f"Output: \n\t{res}\n\n") | ||
|
||
if __name__ == "__main__": | ||
# record the raw strings and the translated strings | ||
rec(inp_strs, "ZH", rec_folder) | ||
|
||
# compare the file with the previous one in date, if the same (exclude the first line for date) | ||
# means the API behavior is the same as before, remove the newly created file. | ||
|
||
# find the latest two files by date (2023-12-23) in filename (ZH_2023-12-23.txt) | ||
files = sorted(rec_folder.glob("ZH_*.txt"), key=lambda f: f.name.lstrip("ZH_").rstrip(".txt"), reverse=True)[:2] | ||
|
||
if len(files) < 2: | ||
print("No enough files to compare, exit") | ||
exit(1) | ||
|
||
# compare the two files if the same remove the one with the latest date | ||
with open(files[0], "r") as fh0, open(files[1], "r") as fh1: | ||
lines0 = fh0.readlines()[1:] | ||
lines1 = fh1.readlines()[1:] | ||
|
||
if lines0 == lines1: | ||
print("Same API behavior, remove the newly created file") | ||
files[0].unlink() | ||
|
||
|
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 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 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
Oops, something went wrong.