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

Support bitscrambler assembly files #17

Merged
merged 1 commit into from
Jan 9, 2025
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
4 changes: 2 additions & 2 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
name: Check copyright notices
entry: check-copyright --verbose --replace
language: python
files: \.(py|c|h|cpp|hpp|ld|s|S)$
require_serial: true
files: \.(py|c|h|cpp|hpp|ld|s|S|bsasm)$
require_serial: true
14 changes: 10 additions & 4 deletions check_copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,16 @@
MIME = {
'python': 'text/x-python',
'c': 'text/x-c',
'cpp': 'text/x-c++'
'cpp': 'text/x-c++',
'bsasm': 'text/x-bsasm',
}

# mime -> parser
MIME_PARSER = {
'text/x-c': c_parser,
'text/x-c++': c_parser,
'text/x-python': python_parser,
'text/x-bsasm': python_parser,
}

# terminal color output
Expand Down Expand Up @@ -205,6 +207,8 @@ def get_file_mime(fn: str) -> str:
return MIME['cpp']
if fn.endswith(('.c', '.h', '.ld', '.s', '.S')):
return MIME['c']
if fn.endswith('.bsasm'):
return MIME['bsasm']
raise UnsupportedFileType(fn)


Expand Down Expand Up @@ -283,7 +287,7 @@ def has_valid_copyright(file_name: str, mime: str, is_on_ignore: bool, is_new_fi
template = ' * SPDX-FileCopyrightText: ' + config_section['espressif_copyright']
if comment.is_first_in_multiline():
template = '/* SPDX-FileCopyrightText: ' + config_section['espressif_copyright']
if mime == MIME['python']:
if mime in (MIME['python'], MIME['bsasm']):
template = '# SPDX-FileCopyrightText: ' + config_section['espressif_copyright']
candidate_line = template.format(years=format_years(years[0], file_name))
no_time_update = template.format(years=format_years(years[0], file_name, years[1] or years[0]))
Expand All @@ -310,7 +314,7 @@ def has_valid_copyright(file_name: str, mime: str, is_on_ignore: bool, is_new_fi
template = ' * SPDX-FileContributor: ' + config_section['espressif_copyright']
if comment.is_first_in_multiline():
template = '/* SPDX-FileContributor: ' + config_section['espressif_copyright']
if mime == MIME['python']:
if mime in (MIME['python'], MIME['bsasm']):
template = '# SPDX-FileContributor: ' + config_section['espressif_copyright']
candidate_line = template.format(years=format_years(years[0], file_name))
no_time_update = template.format(years=format_years(years[0], file_name, years[1] or years[0]))
Expand Down Expand Up @@ -377,6 +381,8 @@ def insert_copyright(code_lines: list, file_name: str, mime: str, config_section
template = config_section['new_notice_c']
if mime == MIME['python']:
template = config_section['new_notice_python']
if mime == MIME['bsasm']:
template = config_section['new_notice_bsasm']
new_code_lines.extend(template.format(license=config_section['license_for_new_files'], years=format_years(0, file_name)).splitlines())
new_code_lines.extend(code_lines)
return new_code_lines
Expand Down Expand Up @@ -404,7 +410,7 @@ def replace_copyright(code_lines: list, year: int, line: int, mime: str, file_na
del code_lines[line - 1:end - 1]

template = NEW_APACHE_HEADER
if mime == MIME['python']:
if mime in (MIME['python'], MIME['bsasm']):
template = NEW_APACHE_HEADER_PYTHON
code_lines[line - 1:line - 1] = template.format(years=format_years(year, file_name)).splitlines()

Expand Down