Skip to content

Commit 67c2ea7

Browse files
committed
Fixing project.py -S printing problem
Printing too large of a string can fail in Windows, as detailed here: https://bugs.python.org/issue11395. This works around the problem by adding a print_large_string function that breaks up the string into smaller pieces before printing it.
1 parent 8a9a246 commit 67c2ea7

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

tools/project.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from tools.utils import argparse_filestring_type, argparse_many, args_error
1919
from tools.utils import argparse_force_lowercase_type
2020
from tools.utils import argparse_force_uppercase_type
21+
from tools.utils import print_large_string
2122
from tools.project_api import export_project, get_exporter_toolchain
2223
from tools.options import extract_profile
2324

@@ -189,7 +190,7 @@ def main():
189190

190191
# Only prints matrix of supported IDEs
191192
if options.supported_ides:
192-
print mcu_ide_matrix()
193+
print_large_string(mcu_ide_matrix())
193194
exit(0)
194195

195196
# Only prints matrix of supported IDEs

tools/utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from os.path import isdir, join, exists, split, relpath, splitext, abspath
2525
from os.path import commonprefix, normpath, dirname
2626
from subprocess import Popen, PIPE, STDOUT, call
27+
from math import ceil
2728
import json
2829
from collections import OrderedDict
2930
import logging
@@ -486,3 +487,23 @@ def parse_type(not_parent):
486487
else:
487488
return not_parent
488489
return parse_type
490+
491+
def print_large_string(large_string):
492+
""" Breaks a string up into smaller pieces before print them
493+
494+
This is a limitation within Windows, as detailed here:
495+
https://bugs.python.org/issue11395
496+
497+
Positional arguments:
498+
large_string - the large string to print
499+
"""
500+
string_limit = 1000
501+
large_string_len = len(large_string)
502+
num_parts = int(ceil(float(large_string_len) / float(string_limit)))
503+
for string_part in range(num_parts):
504+
start_index = string_part * string_limit
505+
if string_part == num_parts - 1:
506+
print large_string[start_index:]
507+
else:
508+
end_index = ((string_part + 1) * string_limit) - 1
509+
print large_string[start_index:end_index],

0 commit comments

Comments
 (0)