From 8e1dece507fa4fbac5efaa23b2f2cbafd64bb590 Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Wed, 18 Sep 2024 11:56:23 +0200 Subject: [PATCH] format fix --- .dockerignore | 2 + .gitignore | 3 + BUILD.bazel | 13 + deps.bzl | 13 + go.mod | 4 +- or-tools.code-workspace | 90 +++---- .../linear_solver/csharp/LinearSolverTests.cs | 2 +- ortools/sat/csharp/SatSolverTests.cs | 2 +- tools/check_python_deps.py | 242 +++++++++++------- 9 files changed, 232 insertions(+), 139 deletions(-) diff --git a/.dockerignore b/.dockerignore index c74eaf1093..87ec80e5e9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -58,6 +58,8 @@ build_cross/ build_make/ install_make/ temp_*/ +export/ +export_meta/ # Editor directories and files *.user diff --git a/.gitignore b/.gitignore index 54694e398c..ab345f00c3 100644 --- a/.gitignore +++ b/.gitignore @@ -41,8 +41,10 @@ temp_cpp/ temp_cpp_test/ temp_dotnet/ temp_dotnet_test/ +temp_meta_dotnet/ temp_java/ temp_java_test/ +temp_meta_java/ temp_python* temp_python*_test/ temp_archive/ @@ -57,6 +59,7 @@ or-tools.snk private-key.gpg settings.xml export +export_meta ortools/bazel-* examples/bazel-* diff --git a/BUILD.bazel b/BUILD.bazel index 78bd668ed7..645593a0e7 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,3 +1,16 @@ +# Copyright 2010-2024 Google LLC +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + load("@bazel_gazelle//:def.bzl", "gazelle") # gazelle:build_file_name BUILD,BUILD.bazel diff --git a/deps.bzl b/deps.bzl index cf0d11ad35..35e86433be 100644 --- a/deps.bzl +++ b/deps.bzl @@ -1,3 +1,16 @@ +# Copyright 2010-2024 Google LLC +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + load("@bazel_gazelle//:deps.bzl", "go_repository") def go_dependencies(): diff --git a/go.mod b/go.mod index 0e1efc1b27..f14759a0a2 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module github.com/google/or-tools go 1.22.2 require ( - github.com/golang/glog v1.2.2 - google.golang.org/protobuf v1.34.2 + github.com/golang/glog v1.2.2 + google.golang.org/protobuf v1.34.2 ) diff --git a/or-tools.code-workspace b/or-tools.code-workspace index c91d78c8ea..96c6145349 100644 --- a/or-tools.code-workspace +++ b/or-tools.code-workspace @@ -1,11 +1,11 @@ { - "folders": [ - { - "path": "." - } - ], - "settings": { - "files.associations": { + "folders": [ + { + "path": "." + } + ], + "settings": { + "files.associations": { "scoped_allocator": "cpp", "*.inc": "cpp", "vector": "cpp", @@ -96,49 +96,49 @@ "slist": "cpp", "regex": "cpp" }, - "C_Cpp.clang_format_fallbackStyle": "Google", - "C_Cpp.default.includePath": [ - "${workspaceRoot}", - "${workspaceRoot}/ortools/gen", - "${workspaceRoot}/dependencies/install/include", - ], - "C_Cpp.default.cppStandard": "c++20", - "C_Cpp.default.cStandard": "c11", - "C_Cpp.default.defines": [ - "USE_BOP", - "USE_GLOP", - "USE_CLP", - "USE_CBC", - "USE_PDLP", - "USE_SCIP" - ], - "C_Cpp.clang_format_style": "Google", - "python.formatting.provider": "yapf", - "python.pythonPath": "python3", - "python.autoComplete.extraPaths": [ - "${workspaceRoot}", - "${workspaceRoot}/ortools/gen", - "${workspaceRoot}/dependencies/sources/protobuf-3.6.1/python", - ], - "[cpp]": { - "editor.tabSize": 2, - }, - "[csharp]": { - "editor.tabSize": 2, - }, - "[java]": { - "editor.tabSize": 2, - }, - "[python]": { - "editor.tabSize": 4, + "C_Cpp.clang_format_fallbackStyle": "Google", + "C_Cpp.default.includePath": [ + "${workspaceRoot}", + "${workspaceRoot}/ortools/gen", + "${workspaceRoot}/dependencies/install/include", + ], + "C_Cpp.default.cppStandard": "c++20", + "C_Cpp.default.cStandard": "c11", + "C_Cpp.default.defines": [ + "USE_BOP", + "USE_GLOP", + "USE_CLP", + "USE_CBC", + "USE_PDLP", + "USE_SCIP" + ], + "C_Cpp.clang_format_style": "Google", + "python.formatting.provider": "yapf", + "python.pythonPath": "python3", + "python.autoComplete.extraPaths": [ + "${workspaceRoot}", + "${workspaceRoot}/ortools/gen", + "${workspaceRoot}/dependencies/sources/protobuf-3.6.1/python", + ], + "[cpp]": { + "editor.tabSize": 2, + }, + "[csharp]": { + "editor.tabSize": 2, + }, + "[java]": { + "editor.tabSize": 2, + }, + "[python]": { + "editor.tabSize": 4, }, "java.configuration.updateBuildConfiguration": "interactive", "maven.view": "hierarchical", "git.ignoreLimitWarning": true, "python.analysis.extraPaths": [ "${workspaceRoot}", - "${workspaceRoot}/ortools/gen", - "${workspaceRoot}/dependencies/sources/protobuf-3.6.1/python" + "${workspaceRoot}/ortools/gen", + "${workspaceRoot}/dependencies/sources/protobuf-3.6.1/python" ], - } + } } diff --git a/ortools/linear_solver/csharp/LinearSolverTests.cs b/ortools/linear_solver/csharp/LinearSolverTests.cs index 1244befa46..ac887a3908 100644 --- a/ortools/linear_solver/csharp/LinearSolverTests.cs +++ b/ortools/linear_solver/csharp/LinearSolverTests.cs @@ -307,7 +307,7 @@ public class LinearSolverTest foreach (Constraint ct in constraints) { output.WriteLine($"{ct.Name()}: dual value = {ct.DualValue()}", - $" activity = {activities[ct.Index()]}"); + $" activity = {activities[ct.Index()]}"); } } } diff --git a/ortools/sat/csharp/SatSolverTests.cs b/ortools/sat/csharp/SatSolverTests.cs index 73d74b40c5..7fa4d18666 100644 --- a/ortools/sat/csharp/SatSolverTests.cs +++ b/ortools/sat/csharp/SatSolverTests.cs @@ -771,6 +771,6 @@ public class SatSolverTest Assert.Equal(0, model.Model.SolutionHint.Values[1]); Assert.Equal(2, model.Model.SolutionHint.Vars[2]); Assert.Equal(1, model.Model.SolutionHint.Values[2]); - } + } } } // namespace Google.OrTools.Tests diff --git a/tools/check_python_deps.py b/tools/check_python_deps.py index cad564c038..08332e7e6b 100644 --- a/tools/check_python_deps.py +++ b/tools/check_python_deps.py @@ -20,127 +20,189 @@ import sys # try to import setuptools try: - from setuptools import setup # pylint: disable=g-import-not-at-top,unused-import - from setuptools import Extension # pylint: disable=g-import-not-at-top,unused-import - from setuptools.command import easy_install # pylint: disable=g-import-not-at-top,unused-import + from setuptools import setup # pylint: disable=g-import-not-at-top,unused-import + from setuptools import ( + Extension, + ) # pylint: disable=g-import-not-at-top,unused-import + from setuptools.command import ( + easy_install, + ) # pylint: disable=g-import-not-at-top,unused-import except ImportError: - raise ImportError("""setuptools is not installed for \"""" + sys.executable + - """\" + raise ImportError( + """setuptools is not installed for \"""" + + sys.executable + + """\" Follow this link for installing instructions : https://pypi.python.org/pypi/setuptools -make sure you use \"""" + sys.executable + """\" during the installation""") +make sure you use \"""" + + sys.executable + + """\" during the installation""" + ) -from pkg_resources import parse_version # pylint: disable=g-import-not-at-top,unused-import +from pkg_resources import ( + parse_version, +) # pylint: disable=g-import-not-at-top,unused-import required_ortools_version = "VVVV" required_protobuf_version = "PROTOBUF_TAG" def notinstalled(modulename): - return modulename + """ is not installed for \"""" + sys.executable + """\" -Run \"""" + sys.executable + """ setup.py install --user\" to install it""" + return ( + modulename + + """ is not installed for \"""" + + sys.executable + + """\" +Run \"""" + + sys.executable + + """ setup.py install --user\" to install it""" + ) def absent_version(module, modulename): - return """You are using a """ + modulename + """ module that doesn't have a __version__ attribute : """ + inspect.getfile( - module) + """\" -Run \"""" + sys.executable + """ setup.py install --user\" to upgrade. -If the problem persists, remove the site-package that contains \"""" + inspect.getfile( - module) + """\". You can do so either manually or by using pip.""" + return ( + """You are using a """ + + modulename + + """ module that doesn't have a __version__ attribute : """ + + inspect.getfile(module) + + """\" +Run \"""" + + sys.executable + + """ setup.py install --user\" to upgrade. +If the problem persists, remove the site-package that contains \"""" + + inspect.getfile(module) + + """\". You can do so either manually or by using pip.""" + ) def wrong_version(module, modulename, required_version, installed_version): - return """You are using """ + modulename + """-""" + installed_version + """ : """ + inspect.getfile( - module - ) + """, while the required version is : """ + required_version + """ -Run \"""" + sys.executable + """ setup.py install --user\" to upgrade. -If the problem persists, remove the site-package that contains \"""" + inspect.getfile( - module) + """\". You can do so either manually or by using pip.""" + return ( + """You are using """ + + modulename + + """-""" + + installed_version + + """ : """ + + inspect.getfile(module) + + """, while the required version is : """ + + required_version + + """ +Run \"""" + + sys.executable + + """ setup.py install --user\" to upgrade. +If the problem persists, remove the site-package that contains \"""" + + inspect.getfile(module) + + """\". You can do so either manually or by using pip.""" + ) def log_error_and_exit(error_message): - logging.error(error_message) - raise SystemExit + logging.error(error_message) + raise SystemExit def check_absent_version(module, modulename): - if not hasattr(module, "__version__"): - log_error_and_exit(absent_version(module, modulename)) + if not hasattr(module, "__version__"): + log_error_and_exit(absent_version(module, modulename)) if __name__ == "__main__": - parser = optparse.OptionParser("Log level") - parser.add_option( - "-l", - "--log", - type="string", - help="Available levels are CRITICAL (3), ERROR (2), WARNING (1), INFO (0), DEBUG (-1)", - default="INFO") - options, args = parser.parse_args() + parser = optparse.OptionParser("Log level") + parser.add_option( + "-l", + "--log", + type="string", + help="Available levels are CRITICAL (3), ERROR (2), WARNING (1), INFO (0), DEBUG (-1)", + default="INFO", + ) + options, args = parser.parse_args() - # Create the logger - try: - loglevel = getattr(logging, options.log.upper()) - except AttributeError: - loglevel = { - 3: logging.CRITICAL, - 2: logging.ERROR, - 1: logging.WARNING, - 0: logging.INFO, - -1: logging.DEBUG, - }[int(options.log)] + # Create the logger + try: + loglevel = getattr(logging, options.log.upper()) + except AttributeError: + loglevel = { + 3: logging.CRITICAL, + 2: logging.ERROR, + 1: logging.WARNING, + 0: logging.INFO, + -1: logging.DEBUG, + }[int(options.log)] - logging.basicConfig( - format="[%(levelname)s] %(message)s", stream=sys.stdout, level=loglevel) + logging.basicConfig( + format="[%(levelname)s] %(message)s", stream=sys.stdout, level=loglevel + ) - # Display Python Version and path - logging.info("Python path : %s", sys.executable) - logging.info("Python version : %s", sys.version) + # Display Python Version and path + logging.info("Python path : %s", sys.executable) + logging.info("Python version : %s", sys.version) - # Choose the pypi package - ortools_name = "ortools" + # Choose the pypi package + ortools_name = "ortools" - # try to import ortools - try: - import ortools # pylint: disable=g-import-not-at-top - except ImportError: - log_error_and_exit(notinstalled(ortools_name)) + # try to import ortools + try: + import ortools # pylint: disable=g-import-not-at-top + except ImportError: + log_error_and_exit(notinstalled(ortools_name)) - # try to import protobuf - try: - import google.protobuf # pylint: disable=g-import-not-at-top - except ImportError: - log_error_and_exit(notinstalled("protobuf")) + # try to import protobuf + try: + import google.protobuf # pylint: disable=g-import-not-at-top + except ImportError: + log_error_and_exit(notinstalled("protobuf")) - # check ortools version - try: - check_absent_version(ortools, "ortools") - if required_ortools_version != ortools.__version__: - raise Exception - logging.info("or-tools version : " + ortools.__version__ + "\n" + - inspect.getfile(ortools)) - except (AttributeError, Exception): # pylint: disable=broad-except - log_error_and_exit( - wrong_version(ortools, ortools_name, required_ortools_version, - ortools.__version__)) + # check ortools version + try: + check_absent_version(ortools, "ortools") + if required_ortools_version != ortools.__version__: + raise Exception + logging.info( + "or-tools version : " + + ortools.__version__ + + "\n" + + inspect.getfile(ortools) + ) + except (AttributeError, Exception): # pylint: disable=broad-except + log_error_and_exit( + wrong_version( + ortools, ortools_name, required_ortools_version, ortools.__version__ + ) + ) - # check protobuf version - try: - check_absent_version(google.protobuf, "protobuf") - if required_protobuf_version != google.protobuf.__version__: - raise Exception - logging.info("protobuf version : " + google.protobuf.__version__ + "\n" + - inspect.getfile(google.protobuf)) - except (AttributeError, Exception): # pylint: disable=broad-except - log_error_and_exit( - wrong_version(google.protobuf, "protobuf", required_protobuf_version, - google.protobuf.__version__)) + # check protobuf version + try: + check_absent_version(google.protobuf, "protobuf") + if required_protobuf_version != google.protobuf.__version__: + raise Exception + logging.info( + "protobuf version : " + + google.protobuf.__version__ + + "\n" + + inspect.getfile(google.protobuf) + ) + except (AttributeError, Exception): # pylint: disable=broad-except + log_error_and_exit( + wrong_version( + google.protobuf, + "protobuf", + required_protobuf_version, + google.protobuf.__version__, + ) + ) - # Check if python can load the libraries' modules - # this is useful when the library architecture is not compatible with the - # python executable, or when the library's dependencies are not available or - # not compatible. - from ortools.constraint_solver import _pywrapcp # pylint: disable=g-import-not-at-top,unused-import - from ortools.linear_solver import _pywraplp # pylint: disable=g-import-not-at-top,unused-import - from ortools.algorithms.python import knapsack_solver # pylint: disable=g-import-not-at-top,unused-import - from ortools.graph import _pywrapgraph # pylint: disable=g-import-not-at-top,unused-import + # Check if python can load the libraries' modules + # this is useful when the library architecture is not compatible with the + # python executable, or when the library's dependencies are not available or + # not compatible. + from ortools.constraint_solver import ( + _pywrapcp, + ) # pylint: disable=g-import-not-at-top,unused-import + from ortools.linear_solver import ( + _pywraplp, + ) # pylint: disable=g-import-not-at-top,unused-import + from ortools.algorithms.python import ( + knapsack_solver, + ) # pylint: disable=g-import-not-at-top,unused-import + from ortools.graph import ( + _pywrapgraph, + ) # pylint: disable=g-import-not-at-top,unused-import