Skip to content
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

Set input encoding to UTF-8 to fix parsing issues. #1470

Merged
merged 3 commits into from
Oct 1, 2024
Merged
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
2 changes: 1 addition & 1 deletion modules/python/generator/visp_python_bindgen/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def generate_module(generate_path: Path, config_path: Path) -> None:

# Step 3: write to main.cpp the call to the submodule binding implementations.
main_path = generate_path / 'main.cpp'
with open(main_path, 'w') as main_file:
with open(main_path, 'w', encoding='utf-8') as main_file:
submodule_fn_declarations = []
submodule_fn_calls = []
for submodule in submodules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def to_pcpp_args_list(self) -> List[str]:
args += ['-I', v]
args += self.other_args
args.extend(['--passthru-includes', self.passthrough_includes_regex])
args.extend(['--output-encoding', 'utf-8'])
if self.line_directive is not None:
args.extend(['--line-directive', self.line_directive])
else:
Expand Down
6 changes: 3 additions & 3 deletions modules/python/generator/visp_python_bindgen/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def run_preprocessor(self):
tmp_file_content.append(f'#include <{include}>\n')

# Remove all includes: we only include configuration headers, defined above
with open(self.path.absolute(), 'r') as input_header_file:
with open(self.path.absolute(), 'r', encoding='utf-8') as input_header_file:
include_regex = '#include\s*<(.*)>'
for line in input_header_file.readlines():
matches = re.search(include_regex, line)
Expand All @@ -153,7 +153,7 @@ def run_preprocessor(self):
# if 'visp3' in matches.group() or 'opencv' in matches.group():
# tmp_file_content.append(line)

with open(tmp_file_path.absolute(), 'w') as tmp_file:
with open(tmp_file_path.absolute(), 'w', encoding='utf-8') as tmp_file:
tmp_file.write(''.join(tmp_file_content))
tmp_file.flush()

Expand All @@ -167,7 +167,7 @@ def run_preprocessor(self):
preprocessed_header_content = None

# Remove all #defines that could have been left by the preprocessor
with open(preprocessor_output_path, 'r') as header_file:
with open(preprocessor_output_path, 'r', encoding='utf-8') as header_file:
preprocessed_header_lines = []
for line in header_file.readlines():
if not line.startswith('#define'):
Expand Down
8 changes: 4 additions & 4 deletions modules/python/generator/visp_python_bindgen/submodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ def _get_config_file_or_create_default(self, path: Path) -> Dict:
'enums': {},
'config_includes': []
}
with open(path, 'w') as config_file:
with open(path, 'w', encoding='utf-8') as config_file:
json.dump(default_config, config_file)
return default_config
else:
with open(path, 'r') as config_file:
with open(path, 'r', encoding='utf-8') as config_file:
config = json.load(config_file)
for included_config_filename in config.get('config_includes', []):
included_config_path: Path = path.parent / included_config_filename
if not included_config_path.exists():
raise RuntimeError(f'Sub config file {included_config_path} does not exist')
logging.info(f'Trying to load subconfig file: {included_config_path}')
with open(included_config_path, 'r') as additional_config_file:
with open(included_config_path, 'r', encoding='utf-8') as additional_config_file:
additional_config = json.load(additional_config_file)
self.add_subconfig_file(config, additional_config)

Expand Down Expand Up @@ -195,7 +195,7 @@ def generate(self) -> None:
{bindings}
}}
'''
with open(self.submodule_file_path, 'w') as submodule_file:
with open(self.submodule_file_path, 'w', encoding='utf-8') as submodule_file:
submodule_file.write(format_str)

logs_path = self.submodule_file_path.parent.parent / 'logs'
Expand Down
Loading