Skip to content

Workaround for Japanese Windows environment #108

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

Merged
merged 1 commit into from
Feb 2, 2023
Merged
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
20 changes: 14 additions & 6 deletions expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
Options:
-a --all import all modules
-h --help print help
-o file
--output file output file
'''
output_header = '//https://github.com/rust-lang-ja/ac-library-rs\n'
opt_list = ['help', 'all']
opt_list = ['help', 'all', 'output=']
output_list_all = ('convolution', 'dsu', 'fenwicktree', 'lazysegtree', 'math',
'maxflow', 'mincostflow', 'modint', 'scc', 'segtree',
'string', 'twosat',
Expand All @@ -44,13 +46,14 @@
'segtree': ('internal_bit', 'internal_type_traits',),
'twosat': ('internal_scc',), }
src_path = 'src/'
output_path = None


def output_file(filename):
global src_path

res = []
with open(src_path+filename+'.rs', 'r') as f:
with open(src_path+filename+'.rs', 'r', encoding='utf-8', newline='') as f:
res.append('pub mod {} {{'.format(filename))

for line in f:
Expand All @@ -61,7 +64,7 @@ def output_file(filename):


try:
opts, args = getopt.getopt(sys.argv[1:], 'ah', opt_list)
opts, args = getopt.getopt(sys.argv[1:], 'aho:', opt_list)
except getopt.GetoptError as e:
print(e)
print(usage)
Expand All @@ -77,6 +80,8 @@ def output_file(filename):
sys.exit(0)
elif o == '--all' or o == '-a':
args = list(output_list_all)
elif o == '--output' or o == '-o':
output_path = v

output_list = set()

Expand Down Expand Up @@ -108,11 +113,14 @@ def output_file(filename):
# rustfmt
with tempfile.TemporaryDirectory() as temp_dir:
temp_file = temp_dir + '/output.rs'
with open(temp_file, 'w') as f:
with open(temp_file, 'w', encoding='utf-8', newline='') as f:
print(output_header, file=f)
for i in output_data:
print(i, file=f)
output_data = subprocess.run(["rustfmt", temp_file], check=True)
with open(temp_file, 'r') as f:
with open(temp_file, 'r', encoding='utf-8', newline='') as f:
wf = open(output_path, 'w', encoding='utf-8', newline='') if output_path is not None else sys.stdout
for line in f:
print(line, end="")
print(line, end='', file=wf)
if output_path is not None:
wf.close()