Skip to content

Commit

Permalink
Fix to pylint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gabcro committed Jan 31, 2025
1 parent 22150b9 commit b308448
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 45 deletions.
2 changes: 0 additions & 2 deletions config_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
]
DESTINATION_DIR = './temp'
MAIN_SCRIPT_PATH = '/eda/processor-ci/main.py'
UTILITIES_SCRIPT_PATH = '/eda/processor-ci/core/labeler_prototype.py'


def get_top_module_file(modules: list[dict[str, str]], top_module: str) -> str:
Expand Down Expand Up @@ -286,7 +285,6 @@ def generate_all_pipelines(config_file_path: str) -> None:
processor_data,
FPGAs,
MAIN_SCRIPT_PATH,
UTILITIES_SCRIPT_PATH,
processor_data['language_version'],
processor_data['extra_flags'],
)
Expand Down
3 changes: 1 addition & 2 deletions core/jenkins.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def generate_jenkinsfile(
config: dict,
fpgas: list,
main_script_path: str,
utilities_script_path: str,
lang_version: str,
extra_flags: list = None,
) -> None:
Expand Down Expand Up @@ -106,7 +105,7 @@ def generate_jenkinsfile(
extra_flags_str = ' '.join(extra_flags) if extra_flags else ''

# Command for extra utilities in the pipeline
utilities_command = f'sh "python3 {utilities_script_path} -d \$(pwd) \
utilities_command = f'sh "python3 /eda/processor-ci/core/labeler_prototype.py -d \$(pwd) \
-c /eda/processor-ci/config.json -o /jenkins/processor_ci_utils/labels.json"'

# Determine simulation command based on file types
Expand Down
93 changes: 52 additions & 41 deletions core/labeler_prototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,57 @@ def determine_cpu_bits(top_file):
return None


def generate_labels_file(processor_name, license_types, cpu_bits, output_file):
"""Generate a JSON file with labels for the processor cores.
Args:
directory (str): The directory to search for LICENSE files.
config_file (str): The configuration JSON file path.
output_file (str): The output JSON file path.
"""
# Load existing JSON data if the file exists
if os.path.exists(output_file):
try:
with open(output_file, 'r', encoding='utf-8') as json_file:
existing_data = json.load(json_file)
except (json.JSONDecodeError, OSError) as e:
print(f'Error reading existing JSON file: {e}')
existing_data = {}
else:
existing_data = {}

# Check if "cores" exists
if 'cores' not in existing_data:
# Overwrite the file completely if "cores" is missing
output_data = {
'cores': {
processor_name: {
'license_types': list(
set(license_types)
), # Deduplicate license types
'bits': cpu_bits,
}
}
}
else:
# Update only the cores section without overwriting other data
existing_data['cores'][processor_name] = {
'license_types': list(
set(license_types)
), # Deduplicate license types
'bits': cpu_bits,
}
output_data = existing_data

# Write updated results back to JSON file
try:
with open(output_file, 'w', encoding='utf-8') as json_file:
json.dump(output_data, json_file, indent=4)
print(f'Results saved to {output_file}')
except OSError as e:
print(f'Error writing to JSON file: {e}')


def main(directory, config_file, output_file):
"""Main function to find LICENSE files and identify their types.
Expand Down Expand Up @@ -222,47 +273,7 @@ def main(directory, config_file, output_file):
if cpu_bits is not None:
break

# Load existing JSON data if the file exists
if os.path.exists(output_file):
try:
with open(output_file, 'r', encoding='utf-8') as json_file:
existing_data = json.load(json_file)
except (json.JSONDecodeError, OSError) as e:
print(f'Error reading existing JSON file: {e}')
existing_data = {}
else:
existing_data = {}

# Check if "cores" exists
if 'cores' not in existing_data:
# Overwrite the file completely if "cores" is missing
output_data = {
'cores': {
processor_name: {
'license_types': list(
set(license_types)
), # Deduplicate license types
'bits': cpu_bits,
}
}
}
else:
# Update only the cores section without overwriting other data
existing_data['cores'][processor_name] = {
'license_types': list(
set(license_types)
), # Deduplicate license types
'bits': cpu_bits,
}
output_data = existing_data

# Write updated results back to JSON file
try:
with open(output_file, 'w', encoding='utf-8') as json_file:
json.dump(output_data, json_file, indent=4)
print(f'Results saved to {output_file}')
except OSError as e:
print(f'Error writing to JSON file: {e}')
generate_labels_file(processor_name, license_types, cpu_bits, output_file)


if __name__ == '__main__':
Expand Down

0 comments on commit b308448

Please sign in to comment.