FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Examples/.github/scripts/unicode_conversion.py at master · granular-storage/Examples · GitHub
granular-storage
/
Examples
Public
forked from
tlaplus/Examples
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Examples
/
.github
/
scripts
/
unicode_conversion.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
71 lines (61 loc) · 2.75 KB
Breadcrumbs
Examples
/
.github
/
scripts
/
unicode_conversion.py
Copy path
File metadata and controls
71 lines (61 loc) · 2.75 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
Converts all TLA⁺ modules from ASCII to Unicode or vice-versa.
"""
from
argparse
import
ArgumentParser
from
concurrent
.
futures
import
ThreadPoolExecutor
import
logging
from
os
import
cpu_count
from
os
.
path
import
dirname
,
normpath
import
subprocess
from
subprocess
import
CompletedProcess
import
tla_utils
parser
=
ArgumentParser
(
description
=
'Converts all TLA+ modules from ASCII to Unicode or vice-versa.'
)
parser
.
add_argument
(
'--tlauc_path'
,
help
=
'Path to the TLAUC executable'
,
required
=
True
)
parser
.
add_argument
(
'--examples_root'
,
help
=
'Root directory of the tlaplus/examples repository'
,
required
=
True
)
parser
.
add_argument
(
'--to_ascii'
,
help
=
'Convert to ASCII instead of Unicode'
,
action
=
'store_true'
)
parser
.
add_argument
(
'--skip'
,
nargs
=
'+'
,
help
=
'Space-separated list of .tla modules to skip converting'
,
required
=
False
,
default
=
[])
parser
.
add_argument
(
'--only'
,
nargs
=
'+'
,
help
=
'If provided, only convert models in this space-separated list'
,
required
=
False
,
default
=
[])
parser
.
add_argument
(
'--verbose'
,
help
=
'Set logging output level to debug'
,
action
=
'store_true'
)
args
=
parser
.
parse_args
()
logging
.
basicConfig
(
level
=
logging
.
DEBUG
if
args
.
verbose
else
logging
.
INFO
)
tlauc_path
=
normpath
(
args
.
tlauc_path
)
to_ascii
=
args
.
to_ascii
examples_root
=
args
.
examples_root
skip_modules
=
args
.
skip
only_modules
=
args
.
only
manifest
=
tla_utils
.
load_all_manifests
(
examples_root
)
# List of all modules to convert
modules
=
[
tla_utils
.
from_cwd
(
examples_root
,
module
[
'path'
])
for
path
,
spec
in
manifest
for
module
in
spec
[
'modules'
]
if
module
[
'path'
]
not
in
skip_modules
and
(
only_modules
==
[]
or
module
[
'path'
]
in
only_modules
)
]
for
path
in
skip_modules
:
logging
.
info
(
f'Skipping
{
path
}
'
)
def
convert_module
(
module_path
):
logging
.
info
(
f'Converting
{
module_path
}
'
)
result
=
subprocess
.
run
(
[
tlauc_path
,
module_path
,
'--skip'
,
'numsets'
]
+
([
'--ascii'
]
if
to_ascii
else
[]),
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
,
text
=
True
)
match
result
:
case
CompletedProcess
():
if
result
.
returncode
==
0
:
logging
.
debug
(
result
.
stdout
)
return
True
else
:
logging
.
error
(
f'Module
{
module_path
}
conversion failed with return code
{
result
.
returncode
}
; output:
\n
{
result
.
stdout
}
'
)
return
False
case
_:
logging
.
error
(
f'Unhandled TLAUC result type
{
type
(
result
)
}
:
{
result
.
stdout
}
'
)
return
False
success
=
True
thread_count
=
cpu_count
()
if
not
args
.
verbose
else
1
logging
.
info
(
f'Converting specs to
{
"ASCII"
if
to_ascii
else
"Unicode"
}
using
{
thread_count
}
threads'
)
with
ThreadPoolExecutor
(
thread_count
)
as
executor
:
results
=
executor
.
map
(
convert_module
,
modules
)
exit
(
0
if
all
(
results
)
else
1
)
Back
|
FazBrowse Home
|
New Git URL