style: apply style changes in preparation for black and isort

This commit is contained in:
Gabriel Ferreira
2023-11-19 19:47:44 -03:00
parent e7f998b4aa
commit af98671fbe
8 changed files with 83 additions and 82 deletions

View File

@@ -35,11 +35,11 @@ def find_ns3_lock() -> str:
SYSTEM_LIBRARY_DIRECTORIES = (DEFAULT_LIB_DIR,
os.path.dirname(DEFAULT_LIB_DIR),
"/usr/lib64",
"/usr/lib"
"/usr/lib",
)
DYNAMIC_LIBRARY_EXTENSIONS = {"linux": "so",
"win32": "dll",
"darwin": "dylib"
"darwin": "dylib",
}
LIBRARY_EXTENSION = DYNAMIC_LIBRARY_EXTENSIONS[sys.platform]
@@ -158,8 +158,7 @@ def extract_linked_libraries(library_name: str, prefix: str) -> tuple:
with open(os.path.abspath(library_path), "rb") as f:
linked_libs = re.findall(b"\x00(lib.*?.%b)" % LIBRARY_EXTENSION.encode("utf-8"), f.read())
except Exception as e:
print("Failed to extract libraries used by {library} with exception:{exception}"
.format(library=library_path, exception=e))
print(f"Failed to extract libraries used by {library_path} with exception:{e}")
exit(-1)
return library_path, lib, list(map(lambda x: x.decode("utf-8"), linked_libs))
@@ -182,8 +181,7 @@ def extract_library_include_dirs(library_name: str, prefix: str) -> tuple:
# Raise error in case the library can't be found
if len(linked_library_path) == 0:
raise Exception(
"Failed to find {library}. Make sure its library directory is in LD_LIBRARY_PATH.".format(
library=linked_library))
f"Failed to find {linked_library}. Make sure its library directory is in LD_LIBRARY_PATH.")
# Get path with the shortest length
linked_library_path = sorted(linked_library_path, key=lambda x: len(x))[0]
@@ -239,7 +237,7 @@ def find_ns3_from_lock_file(lock_file: str) -> (str, list, str):
def filter_in_matching_ns3_libraries(libraries_to_filter: dict,
modules_to_filter: list,
version: str,
suffix: str) -> dict:
suffix: str,) -> dict:
suffix = [suffix[1:]] if len(suffix) > 1 else []
filtered_in_modules = []
for module in modules_to_filter:
@@ -255,13 +253,9 @@ def find_ns3_from_lock_file(lock_file: str) -> (str, list, str):
# When we have the lock file, we assemble the correct library names
libraries_to_load = []
for module in modules:
library_name = "libns{version}-{module}{suffix}".format(
version=version,
module=module,
suffix=suffix
)
library_name = f"libns{version}-{module}{suffix}"
if library_name not in libraries:
raise Exception("Missing library %s\n" % library_name,
raise Exception(f"Missing library {library_name}\n",
"Build all modules with './ns3 build'"
)
libraries_to_load.append(libraries[library_name])
@@ -351,8 +345,7 @@ def find_ns3_from_search() -> (str, list, str):
else:
newest_version_found = get_newest_version([newest_version, newest_version_found])
if newest_version != newest_version_found:
raise Exception("Incompatible versions of the ns-3 module '%s' were found: %s != %s."
% (module, newest_version, newest_version_found))
raise Exception(f"Incompatible versions of the ns-3 module '{module}' were found: {newest_version} != {newest_version_found}.")
for conflicting_library in list(conflicting_libraries):
if "-".join([newest_version, module]) not in conflicting_library:
@@ -360,8 +353,7 @@ def find_ns3_from_search() -> (str, list, str):
conflicting_libraries.remove(conflicting_library)
if len(conflicting_libraries) > 1:
raise Exception("There are multiple build profiles for module '%s'.\nDelete one to continue: %s"
% (module, ", ".join(conflicting_libraries)))
raise Exception(f"There are multiple build profiles for module '{module}'.\nDelete one to continue: {', '.join(conflicting_libraries)}")
return libraries_to_filter, newest_version_found

View File

@@ -1,17 +1,17 @@
# /*
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License version 2 as
# * published by the Free Software Foundation;
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with this program; if not, write to the Free Software
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# */
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation;
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
try:
from ns import ns

View File

@@ -1,20 +1,19 @@
# -*- Mode: Python; -*-
# /*
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License version 2 as
# * published by the Free Software Foundation;
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with this program; if not, write to the Free Software
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# *
# * Ported to Python by Mohit P. Tahiliani
# */
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation;
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Ported to Python by Mohit P. Tahiliani
#
try:
from ns import ns

View File

@@ -1,20 +1,19 @@
# -*- Mode: Python; -*-
# /*
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License version 2 as
# * published by the Free Software Foundation;
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with this program; if not, write to the Free Software
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# *
# * Ported to Python by Mohit P. Tahiliani
# */
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation;
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Ported to Python by Mohit P. Tahiliani
#
try:
from ns import ns

View File

@@ -89,15 +89,16 @@ class Axes(object):
dx_over_ndiv = dx / ndiv
for n in range(5): # iterate 5 times to find optimum division size
#/* div: length of each division */
#/* looking for approx. 'ndiv' divisions in a length 'dx' */
# div: length of each division
# looking for approx. 'ndiv' divisions in a length 'dx'
tbe = math.log10(dx_over_ndiv)
#/* div: power of 10 closest to dx/ndiv */
# div: power of 10 closest to dx/ndiv
div = pow(10, rint(tbe))
if math.fabs(div/2 - dx_over_ndiv) < math.fabs(div - dx_over_ndiv): #/* test if div/2 is closer to dx/ndiv */
# test if div/2 is closer to dx/ndiv
if math.fabs(div/2 - dx_over_ndiv) < math.fabs(div - dx_over_ndiv):
div /= 2
elif math.fabs(div*2 - dx_over_ndiv) < math.fabs(div - dx_over_ndiv):
div *= 2 # /* test if div*2 is closer to dx/ndiv */
div *= 2 # test if div*2 is closer to dx/ndiv
x0 = div*math.ceil(xi / div) - div
if n > 1:
ndiv = rint(size / text_width)

View File

@@ -63,11 +63,11 @@ class IterableIPShell:
# colors
## @var raw_input
# raw input
## Constructor
def __init__(self, argv=[], user_ns=None, user_global_ns=None,
cin=None, cout=None, cerr=None, input_func=None):
"""! Initializer
"""!
Constructor for the IterableIPShell class
@param self: this object
@param argv: Command line options for IPython
@param user_ns: User namespace.

View File

@@ -15,12 +15,22 @@ class ShowIpv4RoutingTable(InformationWindow):
# node index
## @var table_model
# table model
## @var COLUMN_DESTINATION
# column destination
## @var COLUMN_NEXT_HOP
# column hop
## @var COLUMN_INTERFACE
# column interface
## @var COLUMN_TYPE
# column type
## @var COLUMN_PRIO
# column priority
(
COLUMN_DESTINATION,
COLUMN_NEXT_HOP,
COLUMN_INTERFACE,
COLUMN_TYPE,
COLUMN_PRIO
COLUMN_PRIO,
) = range(5)
def __init__(self, visualizer, node_index):

View File

@@ -677,28 +677,28 @@ if __name__ == '__main__':
'non-zero code. When used in "fix mode", this script automatically fixes the files.')
parser.add_argument('paths', action='store', type=str, nargs='+',
help='List of paths to the files to check')
help='List of paths to the files to check',)
parser.add_argument('--no-include-prefixes', action='store_true',
help='Do not check / fix #include headers from the same module with the "ns3/" prefix')
help='Do not check / fix #include headers from the same module with the "ns3/" prefix',)
parser.add_argument('--no-formatting', action='store_true',
help='Do not check / fix code formatting')
help='Do not check / fix code formatting',)
parser.add_argument('--no-whitespace', action='store_true',
help='Do not check / fix trailing whitespace')
help='Do not check / fix trailing whitespace',)
parser.add_argument('--no-tabs', action='store_true',
help='Do not check / fix tabs')
help='Do not check / fix tabs',)
parser.add_argument('--fix', action='store_true',
help='Fix coding style issues detected in the files')
help='Fix coding style issues detected in the files',)
parser.add_argument('-v', '--verbose', action='store_true',
help='Show the lines that are not well-formatted')
help='Show the lines that are not well-formatted',)
parser.add_argument('-j', '--jobs', type=int, default=max(1, os.cpu_count() - 1),
help='Number of parallel jobs')
help='Number of parallel jobs',)
args = parser.parse_args()