Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita67273b

Browse files
Update to Python 3.11
1 parent4dac60f commita67273b

10 files changed

+93
-121
lines changed

‎.github/scripts/generate_tx_config.py

Lines changed: 55 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,67 @@
1-
#!/usr/bin/env python3
2-
importglob
3-
importjson
4-
importos
1+
"""Please note that this script requires a Transifex API token to run."""
2+
importsubprocess
3+
fromfunctoolsimportpartial
4+
frompathlibimportPath
55
importre
6-
importsys
7-
importurllib.request
86

7+
run=partial(subprocess.run,check=True)
98

10-
deflist_resources(token,project):
11-
auth_handler=urllib.request.HTTPBasicAuthHandler()
12-
auth_handler.add_password(
13-
realm="api",uri="https://api.transifex.com/",user="api",passwd=token
9+
10+
definit_project():
11+
run(["tx","init"])
12+
13+
14+
defadd_files(version:str):
15+
run(
16+
[
17+
"tx",
18+
"add",
19+
"remote",
20+
"--file-filter",
21+
"trans/<lang>/<resource_slug>.<ext>",
22+
f"https://www.transifex.com/python-doc/{version}/dashboard/",
23+
]
1424
)
15-
opener=urllib.request.build_opener(auth_handler)
16-
urllib.request.install_opener(opener)
17-
next_= (
18-
"https://api.transifex.com/organizations/python-doc/projects/"
19-
+project
20-
+"/resources/"
25+
26+
27+
FILTER_PATTERN=re.compile(
28+
r"^(?P<prefix>file_filter( *)=( *))(?P<resource>.+)$",re.MULTILINE
29+
)
30+
31+
32+
defname_replacer(match:re.Match[str]):
33+
prefix,resource=match.group("prefix","resource")
34+
override_prefix=prefix.replace("file_filter","trans.zh_CN")
35+
override_resource= (
36+
resource.replace("trans/<lang>/","")
37+
.replace("--","/")
38+
.replace("glossary_","glossary")
39+
.replace("_",".")
2140
)
22-
resources= []
23-
whileTrue:
24-
resp=urllib.request.urlopen(next_)
25-
result=json.loads(resp.read().decode("utf-8"))
26-
resources.extend([i["slug"]foriinresult])
27-
link=re.findall('<([^<]*)>; rel="next"',resp.getheader("Link")or"")
28-
ifnotlink:
29-
break
30-
next_=link[0]
31-
returnresources
32-
33-
34-
defrender_config(doc_dir,project,resources):
35-
os.chdir(doc_dir)
36-
tpl="""
37-
38-
[{project}.{resource}]
39-
trans.zh_CN = {filename}
40-
source_lang = en
41-
type = PO"""
42-
conf="""[main]
43-
host = https://www.transifex.com"""
44-
forresourceinsorted(resources):
45-
ifresource=="glossary_":
46-
filename="glossary.po"
47-
elifresource=="sphinx":
48-
filename="sphinx.po"
49-
else:
50-
pattern=resource.replace("--","/").replace("_","?")
51-
matches=glob.glob(pattern+".rst")
52-
iflen(matches)==0:
53-
print("missing",resource,file=sys.stderr)
54-
continue
55-
eliflen(matches)==1:
56-
filename=matches[0].replace(".rst",".po")
57-
else:
58-
print("multi match",resource,pattern,matches,file=sys.stderr)
59-
conf+=tpl.format(project=project,resource=resource,filename=filename)
60-
returnconf
41+
returnf"{prefix}{resource}\n{override_prefix}{override_resource}"
42+
43+
44+
defpatch_config():
45+
tx_config_path=Path(".tx","config")
46+
47+
config_content=tx_config_path.read_text("utf-8")
48+
config_content=FILTER_PATTERN.sub(name_replacer,config_content)
49+
tx_config_path.write_text(config_content,"utf-8")
6150

6251

6352
if__name__=="__main__":
64-
importargparse
53+
fromargparseimportArgumentParser
54+
importos
55+
56+
parser=ArgumentParser()
6557

66-
parser=argparse.ArgumentParser()
6758
parser.add_argument("--token")
68-
parser.add_argument("--project")
69-
parser.add_argument("--doc-dir")
70-
args=parser.parse_args()
59+
parser.add_argument("--version")
60+
61+
params=parser.parse_args()
7162

72-
resources=list_resources(args.token,args.project)
73-
conf=render_config(args.doc_dir,args.project,resources)
74-
print(conf)
63+
os.environ["TX_TOKEN"]=params.token
7564

76-
# vim: set et ts=4 sw=4 sts=4:
65+
init_project()
66+
add_files(params.version)
67+
patch_config()

‎.github/scripts/prepare.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ git clone --depth=1 --branch="$VERSION" https://github.com/python/cpython cpytho
66
git clone --branch="$VERSION" https://github.com/"$GITHUB_REPOSITORY" docs
77

88
pip3 install --user setuptools
9-
pip3 install --usertransifex-client
9+
curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh| bash
1010
sudo apt-get update
1111
sudo apt-get install -y python3-venv

‎.github/scripts/transifex_pull.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

‎.github/scripts/update.sh

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
#!/bin/bash
22

3-
set -ex
4-
5-
script_dir="$(dirname"$(realpath"$0")")"
6-
7-
if [[-n"$TRANSIFEX_APIKEY" ]];then
8-
cat>~/.transifexrc<<EOF
9-
[https://www.transifex.com]
10-
api_hostname = https://api.transifex.com
11-
hostname = https://www.transifex.com
12-
password =$TRANSIFEX_APIKEY
13-
username = api
14-
EOF
15-
fi
163

174
cd docs||exit 1
18-
"$script_dir"/transifex_pull.py
5+
tx pull --languages"$LOCALE"

‎.github/workflows/python-310.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
-name:update
2121
run:.github/scripts/update.sh
2222
env:
23-
TRANSIFEX_APIKEY:${{ secrets.TRANSIFEX_APIKEY }}
23+
TX_TOKEN:${{ secrets.TRANSIFEX_APIKEY }}
2424
-name:build
2525
run:.github/scripts/build.sh
2626
-name:commit

‎.github/workflows/python-311.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name:python-310
2+
3+
on:
4+
push:
5+
branches:
6+
-master
7+
schedule:
8+
-cron:"8 * * * *"
9+
10+
jobs:
11+
sync:
12+
runs-on:ubuntu-latest
13+
env:
14+
LOCALE:zh_CN
15+
VERSION:"3.11"
16+
steps:
17+
-uses:actions/checkout@v2
18+
-name:prepare
19+
run:.github/scripts/prepare.sh
20+
-name:update
21+
run:.github/scripts/update.sh
22+
env:
23+
TX_TOKEN:${{ secrets.TRANSIFEX_APIKEY }}
24+
-name:build
25+
run:.github/scripts/build.sh
26+
-name:commit
27+
run:.github/scripts/commit.sh
28+
env:
29+
GITHUB_TOKEN:${{ secrets.GITHUB_TOKEN }}

‎.github/workflows/python-37.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
-name:update
2121
run:.github/scripts/update.sh
2222
env:
23-
TRANSIFEX_APIKEY:${{ secrets.TRANSIFEX_APIKEY }}
23+
TX_TOKEN:${{ secrets.TRANSIFEX_APIKEY }}
2424
-name:build
2525
run:.github/scripts/build.sh
2626
-name:commit

‎.github/workflows/python-38.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
-name:update
2121
run:.github/scripts/update.sh
2222
env:
23-
TRANSIFEX_APIKEY:${{ secrets.TRANSIFEX_APIKEY }}
23+
TX_TOKEN:${{ secrets.TRANSIFEX_APIKEY }}
2424
-name:build
2525
run:.github/scripts/build.sh
2626
-name:commit

‎.github/workflows/python-39.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
-name:update
2121
run:.github/scripts/update.sh
2222
env:
23-
TRANSIFEX_APIKEY:${{ secrets.TRANSIFEX_APIKEY }}
23+
TX_TOKEN:${{ secrets.TRANSIFEX_APIKEY }}
2424
-name:build
2525
run:.github/scripts/build.sh
2626
-name:commit

‎README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Maintained versions:
1212
* - Version
1313
- Sync status
1414
- Translation progress
15+
* - `3.11<https://github.com/python/python-docs-zh-cn/tree/3.10>`_
16+
- .. image:: https://github.com/python/python-docs-zh-cn/workflows/python-311/badge.svg
17+
:target: https://github.com/python/python-docs-zh-cn/actions?workflow=python-311
1518
* - `3.10<https://github.com/python/python-docs-zh-cn/tree/3.10>`_
1619
- .. image:: https://github.com/python/python-docs-zh-cn/workflows/python-310/badge.svg
1720
:target: https://github.com/python/python-docs-zh-cn/actions?workflow=python-310

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp