Skip to content

docs: fix doc/scripts/sync_to_translation_status.er and update some actions #508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
run:
working-directory: doc
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- run: pip install tqdm
- uses: erg-lang/setup-erg@v2.1
- uses: erg-lang/setup-erg@v4.1
- run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
RUST_BACKTRACE: full
timeout-minutes: 20
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: Swatinem/rust-cache@v2
Expand All @@ -63,15 +63,15 @@ jobs:
os: [windows-latest, ubuntu-latest, macos-13, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- run: rustup update stable
- run: cargo build --all --all-targets --verbose

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- run: rustup update stable
- name: cargo clippy
Expand All @@ -84,7 +84,7 @@ jobs:
runs-on: ubuntu-latest
if: contains(github.event.head_commit.message, 'update version (nightly')
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- run: rustup update stable
- name: Check semver
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:
create-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: taiki-e/create-gh-release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}

cargo-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: publish
run: |
rustup update stable
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: update-rustup
run: rustup update stable
- uses: taiki-e/upload-rust-binary-action@v1
Expand Down
10 changes: 8 additions & 2 deletions doc/scripts/mylib.d.er
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Most of these are not the correct type

.get_file_dirname!: () => Str

.path_join: (__a: Str, path: Str) => Str
.path_join: (__a: Str, path: Str) -> Str

.path_relpath: (path: Str, start: Str) -> Str

.path_sep: Str

.str_slice: (str: Str, first_index: Nat) => Str
.str_slice: (str: Str, first_index: Nat) -> Str
5 changes: 4 additions & 1 deletion doc/scripts/mylib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import re


def get_file_dirname():
Expand All @@ -8,6 +7,10 @@ def get_file_dirname():

path_join = os.path.join

path_relpath = os.path.relpath

path_sep = os.path.sep


def str_slice(str: str, first_index: int):
return str[first_index:]
109 changes: 58 additions & 51 deletions doc/scripts/sync_to_translation_status.er
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,73 @@
os = pyimport "os"
re = pyimport "re"
mylib = pyimport "mylib" # TODO: Make it work without this
# tqdm = pyimport "tqdm"

LANGUAGES_KEBAB_CASE = ["JA", "zh-TW", "zh-CN"]
EN = "EN"

os.chdir! mylib.path_join(mylib.get_file_dirname!(), "..")

'''
path_to_erg/erg/doc
'''
cwd = os.getcwd!()
path_to_posix path: Str =
if mylib.path_sep == "/":
do path
do path.replace(mylib.path_sep, "/")

badge_pattern = re.compile("\\[!\\[badge\\]\\(([\\w.,@?^=%&:\\/~+#-]+)\\)\\]\\(([\\w.,@?^=%&:\\/~+#-]+)\\)")

get_badge! file_path =
if! os.path.exists!(file_path) and os.path.isfile!(file_path):
do!:
with! open!(file_path, encoding := "utf-8"), f =>
badge_match = badge_pattern.search(f.read!())
match badge_match:
(matched: re.Match) -> matched.group(0)
_ -> "Badge not found"
do!:
"File not found"
main!() =
'''
path_to_erg/erg/doc
'''
cwd = os.path.dirname! mylib.get_file_dirname!()
os.chdir! cwd

get_doc_en_file_paths! relative_dir_path, relative_file_paths_result := [] =
dir_path = mylib.path_join(cwd, relative_dir_path)
dir_list = sorted os.listdir! dir_path
relative_file_paths = ![]
relative_dir_paths = ![]
for! dir_list, d =>
d_path = mylib.path_join(dir_path, d)
if! os.path.isfile!(d_path):
do! relative_file_paths.push! mylib.path_join(relative_dir_path, d)
if! os.path.isdir!(d_path):
do! relative_dir_paths.push! mylib.path_join(relative_dir_path, d)
result = ![]
for! relative_file_paths_result, path =>
result.push! path
for! relative_file_paths, path =>
result.push! path
for! relative_dir_paths, path =>
result.extend! get_doc_en_file_paths! path, result
result
badge_pattern = re.compile("\\[!\\[badge\\]\\(([\\w.,@?^=%&:\\/~+#-]+)\\)\\]\\(([\\w.,@?^=%&:\\/~+#-]+)\\)")

doc_en_file_paths = get_doc_en_file_paths! "EN"
get_badge! absolute_file_path =
if! os.path.exists!(absolute_file_path) and os.path.isfile!(absolute_file_path):
do!:
with! open!(absolute_file_path, encoding := "utf-8"), f =>
badge_match = badge_pattern.search(f.read!())
match badge_match:
(matched: re.Match) -> matched.group(0)
_ -> "Badge not found"
do!:
"File not found"

for! LANGUAGES_KEBAB_CASE, lang =>
result_text = !"# \{lang} translation status\n\n"
result_text.push! "This file is generated automatically. If you want to edit this, edit [`doc/scripts/sync_to_translation_status.er`](../scripts/sync_to_translation_status.er)\n\n"
add_table_row_text! left: Str, right: Str =
result_text.push! "| \{left} | \{right} |\n"
doc_en_relative_file_paths =
result = ![]
absolute_dir_stack = ![mylib.path_join(cwd, EN)]
while! do! len(absolute_dir_stack) > 0, do!:
top_absolute_dir = absolute_dir_stack.pop!()
basenames = sorted os.listdir! top_absolute_dir # TODO: use `os.scandir!`
absolute_dirs = ![]
for! basenames, basename =>
absolute_path = mylib.path_join(top_absolute_dir, basename)
if! os.path.isfile!(absolute_path):
do! result.push! mylib.path_relpath(absolute_path, cwd)
# do! os.path.isdir!(absolute_path)
do! absolute_dirs.push! absolute_path
absolute_dir_stack.extend! reversed absolute_dirs
result

add_table_row_text! "EN file name", "edit icon and badge"
add_table_row_text! "---", "---"
add_table_row_text! "[README.md](../../README.md)", "[📝](../../README_\{lang}.md) \{get_badge!(mylib.path_join(cwd, "../README_\{lang}.md"))}"
add_table_row_text! "[CODE_OF_CONDUCT.md](../../CODE_OF_CONDUCT.md)", "[📝](../CODE_OF_CONDUCT/CODE_OF_CONDUCT_\{lang}.md) \{get_badge!(mylib.path_join(cwd, "./CODE_OF_CONDUCT/CODE_OF_CONDUCT_\{lang}.md"))}"
add_table_row_text! "[CONTRIBUTING.md](../../CONTRIBUTING.md)", "[📝](../CONTRIBUTING/CONTRIBUTING_\{lang}.md) \{get_badge!(mylib.path_join(cwd, "./CONTRIBUTING/CONTRIBUTING_\{lang}.md"))}"
for! LANGUAGES_KEBAB_CASE, lang =>
result_text = !"# \{lang} translation status\n\n"
result_text.push! "This file is generated automatically. If you want to edit this, edit [`doc/scripts/sync_to_translation_status.er`](../scripts/sync_to_translation_status.er)\n\n"
add_table_row_text! left: Str, right: Str =
result_text.push! "| \{left} | \{right} |\n"

for! doc_en_file_paths, en_path =>
relative_file_path = "\{lang.replace "-", "_"}\{mylib.str_slice en_path, 2}"
add_table_row_text! "[\{mylib.str_slice en_path, 3}](../\{en_path})", "[📝](../\{relative_file_path}) \{get_badge!(mylib.path_join(cwd, relative_file_path))}"
add_table_row_text! "EN file name", "edit icon and badge"
add_table_row_text! "---", "---"
add_table_row_text! "[README.md](../../README.md)", "[📝 Edit](../../README_\{lang}.md) \{get_badge!(mylib.path_join(cwd, "../README_\{lang}.md"))}"
add_table_row_text! "[CODE_OF_CONDUCT.md](../../CODE_OF_CONDUCT.md)", "[📝 Edit](../CODE_OF_CONDUCT/CODE_OF_CONDUCT_\{lang}.md) \{get_badge!(mylib.path_join(cwd, "./CODE_OF_CONDUCT/CODE_OF_CONDUCT_\{lang}.md"))}"
add_table_row_text! "[CONTRIBUTING.md](../../CONTRIBUTING.md)", "[📝 Edit](../CONTRIBUTING/CONTRIBUTING_\{lang}.md) \{get_badge!(mylib.path_join(cwd, "./CONTRIBUTING/CONTRIBUTING_\{lang}.md"))}"

with! open!(mylib.path_join(cwd, mylib.path_join("translation_status", "translation_status_\{lang}.md")), encoding := "utf-8", mode := "w"), f =>
discard f.write! str(result_text)
# for! tqdm.Tqdm!(doc_en_relative_file_paths), en_path =>
for! doc_en_relative_file_paths, en_path =>
relative_file_path = "\{lang.replace "-", "_"}\{mylib.str_slice en_path, len(EN)}"
add_table_row_text! "[\{path_to_posix mylib.str_slice(en_path, len(EN) + 1)}](../\{en_path})", "[📝 Edit](../\{path_to_posix relative_file_path}) \{get_badge!(mylib.path_join(cwd, relative_file_path))}"

with! open!(mylib.path_join(cwd, mylib.path_join("translation_status", "translation_status_\{lang}.md")), encoding := "utf-8", mode := "w"), f =>
discard f.write! str(result_text)

if! __name__ == "__main__", do!:
main!()