chore: make sure all python files have the correct header

Signed-off-by: EstherLerouzic <esther.lerouzic@orange.com>
Change-Id: Ifdd6a566fda74c5b7d417f9d61c51d4d3da07bfd
This commit is contained in:
EstherLerouzic
2025-05-30 16:10:11 +02:00
parent 7bc9461547
commit 7a1b15a916
39 changed files with 306 additions and 56 deletions

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# gnpy.core.ansi_escapes: A random subset of ANSI terminal escape codes for colored messages
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
gnpy.core.ansi_escapes
======================

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# gnpy.core.elements: Standard network elements which propagate optical spectrum
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
gnpy.core.elements
==================

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# gnpy.core.equipment: functionality for specifying equipment
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
gnpy.core.equipment
===================

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# gnpy.core.exceptions: Exceptions thrown by other gnpy modules
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
gnpy.core.exceptions
====================

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# gnpy.core.info: classes for modelling Spectral Information
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
gnpy.core.info
==============

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# gnpy.core.network: Working with networks which consist of network elements
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
gnpy.core.network
=================

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# gnpy.core.parameters: parameters to configure standard network elements
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
gnpy.core.parameters
====================

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# gnpy.core.science_utils: Solver definitions to calculate the Raman effect and the nonlinear interference noise
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
gnpy.core.science_utils
=======================

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# gnpy.core.utils: utility functions that are used with gnpy
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
gnpy.core.utils
===============

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# Utility functions that creates an Eqpt sheet template
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
create_eqpt_sheet.py
====================

View File

@@ -1,5 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# update an existing json file with all the 96ch txt files for a given amplifier type
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
Created on Tue Jan 30 12:32:00 2018

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# Reads JSON path result file and writes results to a CSV file
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
write_path_jsontocsv.py
========================

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# gnpy.tools.cli_examples: Common code for CLI examples
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
gnpy.tools.cli_examples
=======================

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# gnpy.tools.convert: utilities for converting between XLS and JSON
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
gnpy.tools.convert
==================

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# gnpy.tools.json_io: Loading and saving data from JSON files in GNPy's internal data format
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
gnpy.tools.json_io
==================

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# gnpy.tools.plots: Graphs and plots usable from a CLI application
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
gnpy.tools.plots
================

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# gnpy.tools.service_sheet: XLS parser that can be called to create a JSON request file
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
gnpy.tools.service_sheet
========================

View File

@@ -1,12 +1,17 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
# SPDX-License-Identifier: BSD-3-Clause
# gnpy.tools.worker_utils: Common code for CLI examples and API
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
gnpy.tools.worker_utils
=======================
Common code for CLI examples and API
'''
"""
import logging
from copy import deepcopy
from typing import Union, List, Tuple

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# gnpy.topology.request: path computation functionality
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
gnpy.topology.request
=====================

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# gnpy.topology.spectrum_assignment: spectrum assignment functionality
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
gnpy.topology.spectrum_assignment
=================================

View File

@@ -1,8 +1,10 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright (C) 2020 Telecom Infra Project and GNPy contributors
# see LICENSE.md for a list of contributors
#
# test_amplifier
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
import pytest
from gnpy.core.parameters import SimParams, NLIParams, RamanParams

View File

@@ -1,7 +1,10 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Author: Jean-Luc Auge
# @Date: 2018-02-02 14:06:55
# SPDX-License-Identifier: BSD-3-Clause
# test_amplifier
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
from numpy import zeros, array
from numpy.testing import assert_allclose

View File

@@ -1,11 +1,12 @@
#!/usr/bin/env python3
# Module name : test_automaticmodefeature.py
# Version :
# License : BSD 3-Clause Licence
# Copyright (c) 2018, Telecom Infra Project
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# test_automaticmodefeature
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
@author: esther.lerouzic
checks that empty info on mode, power, nbchannel in service file are supported
uses combination of [mode, pow, nb channel] filled or empty defined in meshTopologyToy_services.json
leading to feasible path or not, and check the propagate and propagate_and_optimize_mode

View File

@@ -1,11 +1,12 @@
#!/usr/bin/env python3
# Module name : test_disjunction.py
# Version:
# License: BSD 3-Clause Licence
# Copyright (c) 2018, Telecom Infra Project
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# test_disjunction
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
@author: esther.lerouzic
checks that computed paths are disjoint as specified in the json service file
that computed paths do not loop
that include node constraints are correctly taken into account

View File

@@ -1,9 +1,12 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Author: Esther Le Rouzic
# @Date: 2019-05-22
# SPDX-License-Identifier: BSD-3-Clause
# test_equalization
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
@author: esther.lerouzic
checks that new equalization option give the same output as old one:
"""

View File

@@ -1,9 +1,12 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Author: Esther Le Rouzic
# @Date: 2019-05-22
# SPDX-License-Identifier: BSD-3-Clause
# test_gain_mode
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
@author: esther.lerouzic
checks behaviour of gain mode
- if all amps have their gains set, check that these gains are used, even if power_dbm or req_power change
- check that saturation is correct in gain mode

View File

@@ -1,6 +1,15 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# test_info
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
Checks spectral information utilities
"""
import pytest
from numpy import array, zeros, ones
from numpy.testing import assert_array_equal

View File

@@ -1,5 +1,15 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# test_invocation
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
Checks that invocation of scripts give expected results
"""
from pathlib import Path
import os
from logging import INFO, Formatter

View File

@@ -1,8 +1,14 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright (C) 2020 Telecom Infra Project and GNPy contributors
# see LICENSE.md for a list of contributors
#
# test_logger
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
Checks that loggers works as expected
"""
from pathlib import Path
import re

View File

@@ -1,8 +1,14 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright (C) 2020 Telecom Infra Project and GNPy contributors
# see LICENSE.md for a list of contributors
#
# test_info
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
Checks autodesign functions
"""
from pathlib import Path
import pytest

View File

@@ -6,6 +6,11 @@
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
checks compliance to opensource rules:
- list of authors
- presence of headers
"""
import subprocess
import re
from pathlib import Path
@@ -50,3 +55,71 @@ def test_commit_authors_in_author_rst():
missing_emails = commit_emails - author_emails - allowed_missing
assert not missing_emails, f"The following commit author emails are missing in AUTHOR.rst: {missing_emails}"
def get_python_files(root_dir):
"""Get all Python files in the project."""
return list(root_dir.glob('**/*.py'))
def check_header(file_path):
"""Check if a file has the correct header."""
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read(500) # Read just the beginning of the file
# Check for shebang
has_shebang = content.startswith('#!/usr/bin/env python')
# Check for encoding
has_encoding = '# -*- coding: utf-8 -*-' in content[:100]
# Check for SPDX license
has_license = 'SPDX-License-Identifier: BSD-3-Clause' in content
# Check for copyright
has_copyright = re.search(r'Copyright \(C\) .*Telecom Infra Project', content) is not None
# Check for AUTHORS reference
has_authors_ref = 'see AUTHORS.rst' in content
return {
'file': file_path,
'has_shebang': has_shebang,
'has_encoding': has_encoding,
'has_license': has_license,
'has_copyright': has_copyright,
'has_authors_ref': has_authors_ref,
'is_compliant': has_shebang and has_encoding and has_license and has_copyright and has_authors_ref
}
def test_file_headers():
"""Test that all Python files have the correct header."""
# Get all Python files
python_files = get_python_files(SRC_DIR / 'gnpy') + get_python_files(SRC_DIR / 'tests')
# Files that can be excluded from header checks (e.g., third-party code, generated files)
excluded_files = [
SRC_DIR / 'gnpy' / 'topology' / '__init__.py',
SRC_DIR / 'gnpy' / 'tools' / '__init__.py',
SRC_DIR / 'gnpy' / 'core' / '__init__.py',
SRC_DIR / 'gnpy' / '__init__.py',
SRC_DIR / 'tests' / '__init__.py'
]
# Filter out excluded files
python_files = [f for f in python_files if f not in excluded_files]
# Check headers
results = [check_header(f) for f in python_files]
non_compliant = [r for r in results if not r['is_compliant']]
# Generate detailed error message
error_msg = ""
if non_compliant:
error_msg = "The following files have non-compliant headers:\n"
for result in non_compliant:
file_path = result['file'].relative_to(SRC_DIR)
error_msg += f"\n{file_path}:\n"
print(non_compliant)
assert len(non_compliant) == 0, error_msg

View File

@@ -1,6 +1,12 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# test_parameters
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
Checks that the class SimParams behaves as a mutable Singleton.
"""

View File

@@ -1,7 +1,10 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Author: Esther Le Rouzic
# @Date: 2018-06-15
# SPDX-License-Identifier: BSD-3-Clause
# test_parser
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""Adding tests to check the parser non regression

View File

@@ -1,11 +1,15 @@
#!/usr/bin/env python3
# Module name: test_path_computation_functions.py
# Version:
# License: BSD 3-Clause Licence
# Copyright (c) 2018, Telecom Infra Project
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# test_path_computation_functions
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
@author: esther.lerouzic
test path computation functions
"""

View File

@@ -1,7 +1,14 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Author: Jean-Luc Auge
# @Date: 2018-02-02 14:06:55
# SPDX-License-Identifier: BSD-3-Clause
# test_propagation
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
Check that propagation example give expected results
"""
import pytest

View File

@@ -1,9 +1,13 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Author: Esther Le Rouzic
# @Date: 2019-05-22
# SPDX-License-Identifier: BSD-3-Clause
# test_roadm_restrictions
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
@author: esther.lerouzic
checks that fused placed in amp type is correctly converted to a fused element instead of an edfa
and that no additional amp is added.
checks that restrictions in roadms are correctly applied during autodesign

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# test_science_utils
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
Checks that RamanFiber propagates properly the spectral information. In this way, also the RamanSolver and the NliSolver
are tested.

View File

@@ -1,12 +1,13 @@
#!/usr/bin/env python3
# Module name: test_spectrum_assignment.py
# Version:
# License: BSD 3-Clause Licence
# Copyright (c) 2018, Telecom Infra Project
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# test_spectrum_assignment
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
@author: esther.lerouzic
test spectrum assignment utilities
"""
from pathlib import Path

View File

@@ -1,11 +1,13 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Author: Esther Le Rouzic
# @Date: 2023-09-29
"""
@author: esther.lerouzic
checks all possibilities of this function
# SPDX-License-Identifier: BSD-3-Clause
# test_trx_mode_params
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
checks all possibilities of this function
"""
from pathlib import Path