Skip to content

Commit

Permalink
Format and lint scripts dir (#1714)
Browse files Browse the repository at this point in the history
  • Loading branch information
externl authored Jan 22, 2024
1 parent d572a6c commit 961bb1d
Show file tree
Hide file tree
Showing 47 changed files with 695 additions and 334 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
run: pip install ruff

- name: Run Ruff
run: ruff check . --exclude "scripts" --exclude "python" --ignore E402
run: ruff check . --exclude "python" --ignore E402
114 changes: 63 additions & 51 deletions scripts/Component.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
#

import os
import re

from Util import *
# Import as modules to allow for circular imports
import Util
import IceGridUtil


class Ice(Component):
class Ice(Util.Component):
# Options for all transports (ran only with Ice client/server tests defined for cross testing)
transportOptions = {
"protocol": ["tcp", "ssl", "wss", "ws"],
Expand Down Expand Up @@ -36,19 +39,20 @@ class Ice(Component):
}

def useBinDist(self, mapping, current):
return Component._useBinDist(self, mapping, current, "ICE_BIN_DIST")
return Util.Component._useBinDist(self, mapping, current, "ICE_BIN_DIST")

def getInstallDir(self, mapping, current):
# On Windows, the Ice MSI installation can only be used for C++
envHomeName = (
None
if isinstance(platform, Windows) and not isinstance(mapping, CppMapping)
if isinstance(Util.platform, Util.Windows)
and not isinstance(mapping, Util.CppMapping)
else "ICE_HOME"
)
return Component._getInstallDir(self, mapping, current, envHomeName)
return Util.Component._getInstallDir(self, mapping, current, envHomeName)

def getPhpExtension(self, mapping, current):
if isinstance(platform, Windows):
if isinstance(Util.platform, Util.Windows):
return (
"php_ice.dll"
if current.driver.configs[mapping].buildConfig in ["Debug", "Release"]
Expand All @@ -58,14 +62,16 @@ def getPhpExtension(self, mapping, current):
return "ice.so"

def getNugetPackageVersionFile(self, mapping):
if isinstance(mapping, CSharpMapping):
return os.path.join(toplevel, "csharp", "msbuild", "zeroc.ice.net.nuspec")
if isinstance(mapping, Util.CSharpMapping):
return os.path.join(
Util.toplevel, "csharp", "msbuild", "zeroc.ice.net.nuspec"
)
else:
return os.path.join(
toplevel,
Util.toplevel,
"cpp",
"msbuild",
"zeroc.ice.{0}.nuspec".format(platform.getPlatformToolset()),
"zeroc.ice.{0}.nuspec".format(Util.platform.getPlatformToolset()),
)

def getFilters(self, mapping, config):
Expand Down Expand Up @@ -96,7 +102,7 @@ def getFilters(self, mapping, config):
],
["Ice/library", "Ice/plugin"],
)
elif isinstance(mapping, JavaMapping) and config.android:
elif isinstance(mapping, Util.JavaMapping) and config.android:
return (
["Ice/.*"],
[
Expand All @@ -110,9 +116,9 @@ def getFilters(self, mapping, config):
"Ice/properties",
],
)
elif isinstance(mapping, JavaScriptMapping):
elif isinstance(mapping, Util.JavaScriptMapping):
return ([], ["typescript/.*"])
elif isinstance(mapping, SwiftMapping) and config.buildPlatform in [
elif isinstance(mapping, Util.SwiftMapping) and config.buildPlatform in [
"iphonesimulator",
"iphoneos",
]:
Expand All @@ -124,9 +130,9 @@ def getFilters(self, mapping, config):

def canRun(self, testId, mapping, current):
parent = re.match(r"^([\w]*).*", testId).group(1)
if isinstance(platform, Linux):
if isinstance(Util.platform, Util.Linux):
if (
platform.getLinuxId() in ["centos", "rhel", "fedora"]
Util.platform.getLinuxId() in ["centos", "rhel", "fedora"]
and current.config.buildPlatform == "x86"
):
#
Expand All @@ -135,7 +141,7 @@ def canRun(self, testId, mapping, current):
#
if parent in ["Glacier2", "IceStorm", "IceGrid"]:
return False
elif isinstance(platform, Windows):
elif isinstance(Util.platform, Util.Windows):
#
# On Windows, if testing with a binary distribution, don't test Glacier2/IceBridge services
# with the Debug configurations since we don't provide binaries for them.
Expand All @@ -146,7 +152,7 @@ def canRun(self, testId, mapping, current):
and current.config.buildConfig.find("Debug") >= 0
):
return False
elif isinstance(platform, AIX):
elif isinstance(Util.platform, Util.AIX):
if current.config.buildPlatform == "ppc" and self.useBinDist(
mapping, current
):
Expand All @@ -161,7 +167,7 @@ def canRun(self, testId, mapping, current):

# No C++98 tests for Glacier2, IceGrid, IceStorm, IceBridge
if (
isinstance(mapping, CppMapping)
isinstance(mapping, Util.CppMapping)
and not current.config.cpp11
and parent in ["Glacier2", "IceBridge", "IceGrid", "IceStorm"]
):
Expand All @@ -174,12 +180,12 @@ def isMainThreadOnly(self, testId):

def getDefaultProcesses(self, mapping, processType, testId):
if testId.startswith("IceUtil") or testId.startswith("Slice"):
return [SimpleClient()]
return [Util.SimpleClient()]
elif testId.startswith("IceGrid"):
if processType in ["client", "collocated"]:
return [IceGridClient()]
return [IceGridUtil.IceGridClient()]
if processType in ["server", "serveramd"]:
return [IceGridServer()]
return [IceGridUtil.IceGridServer()]

def getOptions(self, testcase, current):
parent = re.match(r"^([\w]*).*", testcase.getTestSuite().getId()).group(1)
Expand All @@ -194,7 +200,7 @@ def getOptions(self, testcase, current):
]:
return None

if isinstance(testcase, CollocatedTestCase):
if isinstance(testcase, Util.CollocatedTestCase):
return None

# Define here Ice tests which are slow to execute and for which it's not useful to test different options
Expand All @@ -206,7 +212,7 @@ def getOptions(self, testcase, current):
return self.serviceOptions

# We only run the client/server tests defined for cross testing with all transports
if isinstance(testcase, ClientServerTestCase) and self.isCross(
if isinstance(testcase, Util.ClientServerTestCase) and self.isCross(
testcase.getTestSuite().getId()
):
return self.transportOptions
Expand Down Expand Up @@ -245,7 +251,7 @@ def isCross(self, testId):

def getSoVersion(self):
with open(
os.path.join(toplevel, "cpp", "include", "IceUtil", "Config.h"), "r"
os.path.join(Util.toplevel, "cpp", "include", "IceUtil", "Config.h"), "r"
) as config:
intVersion = int(
re.search("ICE_INT_VERSION ([0-9]*)", config.read()).group(1)
Expand All @@ -263,60 +269,66 @@ def getSoVersion(self):

component = Ice()

from Glacier2Util import *
from IceBoxUtil import *
from IceBridgeUtil import *
from IcePatch2Util import *
from IceGridUtil import *
from IceStormUtil import *

#
# Supported mappings
#
for m in filter(
lambda x: os.path.isdir(os.path.join(toplevel, x)), os.listdir(toplevel)
lambda x: os.path.isdir(os.path.join(Util.toplevel, x)), os.listdir(Util.toplevel)
):
if m == "cpp" or re.match("cpp-.*", m):
Mapping.add(m, CppMapping(), component)
Util.Mapping.add(m, Util.CppMapping(), component)
elif m == "java" or re.match("java-.*", m):
Mapping.add(m, JavaMapping(), component)
Util.Mapping.add(m, Util.JavaMapping(), component)
elif m == "python" or re.match("python-.*", m):
Mapping.add(m, PythonMapping(), component)
Util.Mapping.add(m, Util.PythonMapping(), component)
elif m == "ruby" or re.match("ruby-.*", m):
Mapping.add(
m, RubyMapping(), component, enable=not isinstance(platform, Windows)
Util.Mapping.add(
m,
Util.RubyMapping(),
component,
enable=not isinstance(Util.platform, Util.Windows),
)
elif m == "php" or re.match("php-.*", m):
Mapping.add(
m, PhpMapping(), component, enable=not isinstance(platform, Windows)
Util.Mapping.add(
m,
Util.PhpMapping(),
component,
enable=not isinstance(Util.platform, Util.Windows),
)
elif m == "js" or re.match("js-.*", m):
Mapping.add(m, JavaScriptMapping(), component, enable=platform.hasNodeJS())
Mapping.add(
Util.Mapping.add(
m, Util.JavaScriptMapping(), component, enable=Util.platform.hasNodeJS()
)
Util.Mapping.add(
"typescript",
TypeScriptMapping(),
Util.TypeScriptMapping(),
component,
"js",
enable=platform.hasNodeJS(),
enable=Util.platform.hasNodeJS(),
)
elif m == "swift" or re.match("swift-.*", m):
# Swift mapping requires Swift 5.0 or greater
Mapping.add(
"swift", SwiftMapping(), component, enable=platform.hasSwift((5, 0))
Util.Mapping.add(
"swift",
Util.SwiftMapping(),
component,
enable=Util.platform.hasSwift((5, 0)),
)
elif m == "csharp" or re.match("charp-.*", m):
Mapping.add(
Util.Mapping.add(
"csharp",
CSharpMapping(),
Util.CSharpMapping(),
component,
enable=isinstance(platform, Windows) or platform.hasDotNet(),
enable=isinstance(Util.platform, Util.Windows) or Util.platform.hasDotNet(),
)

#
# Check if Matlab is installed and eventually add the Matlab mapping
#
try:
run("where matlab" if isinstance(platform, Windows) else "which matlab")
Mapping.add("matlab", MatlabMapping(), component)
except:
Util.run(
"where matlab" if isinstance(Util.platform, Util.Windows) else "which matlab"
)
Util.Mapping.add("matlab", Util.MatlabMapping(), component)
except Exception:
pass
20 changes: 16 additions & 4 deletions scripts/Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@

import os
import sys
from Util import *

from Util import (
Darwin,
Driver,
IceProcess,
Mapping,
Result,
parseOptions,
toplevel,
platform,
runTests,
traceback,
)


class ControllerDriver(Driver):
Expand Down Expand Up @@ -109,7 +121,7 @@ def startServerSide(self, config, c):
try:
self.serverSideRunning = True
return self.current.serverTestCase._startServerSide(self.current)
except Exception as ex:
except Exception:
self.serverSideRunning = False
raise Test.Common.TestCaseFailedException(
self.current.result.getOutput() + "\n" + traceback.format_exc()
Expand Down Expand Up @@ -141,7 +153,7 @@ def destroy(self, c):
if self.serverSideRunning:
try:
self.current.serverTestCase._stopServerSide(self.current, False)
except:
except Exception:
pass
c.adapter.remove(c.id)

Expand Down Expand Up @@ -171,7 +183,7 @@ def runTestCase(self, mapping, testsuite, testcase, cross, c):
if self.testcase:
try:
self.testcase.destroy()
except:
except Exception:
pass
self.testcase = None

Expand Down
4 changes: 3 additions & 1 deletion scripts/Expect.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,11 +634,13 @@ def kill():
return
killProcess(self.p)
self.wait()
break
except KeyboardInterrupt as e:
ex = e
raise
except e:
except Exception as e:
ex = e

if ex:
print(ex)
raise ex
Expand Down
12 changes: 11 additions & 1 deletion scripts/Glacier2Util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@

import sys
import os
from Util import *

from Util import (
ClientServerTestCase,
Mapping,
ProcessFromBinDir,
ProcessIsReleaseOnly,
Server,
TestSuite,
run,
toplevel,
)


class Glacier2Router(ProcessFromBinDir, ProcessIsReleaseOnly, Server):
Expand Down
18 changes: 15 additions & 3 deletions scripts/IceBoxUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@
# Copyright (c) ZeroC, Inc. All rights reserved.
#

from Util import *
from Component import component
import Component
from Util import (
AIX,
CSharpMapping,
Client,
CppMapping,
JavaMapping,
Linux,
Mapping,
ProcessFromBinDir,
ProcessIsReleaseOnly,
Server,
platform,
)


class IceBox(ProcessFromBinDir, Server):
Expand Down Expand Up @@ -62,7 +74,7 @@ def getExe(self, current):
elif (
isinstance(platform, AIX)
and current.config.buildPlatform == "ppc"
and not component.useBinDist(mapping, current)
and not Component.component.useBinDist(mapping, current)
):
return "iceboxadmin_32"
else:
Expand Down
3 changes: 2 additions & 1 deletion scripts/IceBridgeUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Copyright (c) ZeroC, Inc. All rights reserved.
#

from Util import *

from Util import Mapping, ProcessFromBinDir, ProcessIsReleaseOnly, Server


class IceBridge(ProcessFromBinDir, ProcessIsReleaseOnly, Server):
Expand Down
Loading

0 comments on commit 961bb1d

Please sign in to comment.