Skip to content

Commit

Permalink
Format and lint python (#1716)
Browse files Browse the repository at this point in the history
  • Loading branch information
externl authored Jan 23, 2024
1 parent 961bb1d commit f35941d
Show file tree
Hide file tree
Showing 170 changed files with 4,471 additions and 2,507 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 "python" --ignore E402
run: ruff check . --ignore E402
1 change: 1 addition & 0 deletions python/allTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), "..", "scripts"))

from Util import runTestsWithPath
Expand Down
13 changes: 10 additions & 3 deletions python/config/s2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@
if sys.platform == "win32":
platformName = "Win32" if "32bit" in platform.architecture() else "x64"
configurationName = os.getenv("CPP_CONFIGURATION", "Release")
sys.path.insert(1, os.path.join(basepath, "..", "python", platformName, configurationName))
os.putenv("PATH", os.path.join(basepath, "..", "..", "cpp", "bin", platformName, configurationName))
sys.path.insert(
1, os.path.join(basepath, "..", "python", platformName, configurationName)
)
os.putenv(
"PATH",
os.path.join(
basepath, "..", "..", "cpp", "bin", platformName, configurationName
),
)
else:
sys.path.insert(1, os.path.join(basepath, "..", "python"))

Expand All @@ -25,5 +32,5 @@ def main():
sys.exit(int(val))


if __name__ == '__main__':
if __name__ == "__main__":
main()
84 changes: 55 additions & 29 deletions python/python/Glacier2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
# Copyright (c) ZeroC, Inc. All rights reserved.
#

# ruff: noqa: F401, F821

"""
Glacier2 module
"""

import threading
import traceback
import copy

#
# Import the Python extension.
#
import Ice

Ice.updateModule("Glacier2")

import Glacier2.Router_ice
Expand All @@ -34,13 +36,11 @@ def __init__(self):


class Application(Ice.Application):

def __init__(self, signalPolicy=0): # HandleSignals=0
'''The constructor accepts an optional argument indicating
whether to handle signals. The value should be either
Application.HandleSignals (the default) or
Application.NoSignalHandling.
'''
"""The constructor accepts an optional argument indicating
whether to handle signals. The value should be either
Application.HandleSignals (the default) or
Application.NoSignalHandling."""

if type(self) == Application:
raise RuntimeError("Glacier2.Application is an abstract class")
Expand All @@ -53,50 +53,63 @@ def __init__(self, signalPolicy=0): # HandleSignals=0
Application._category = None

def run(self, args):
raise RuntimeError('run should not be called on Glacier2.Application - call runWithSession instead')
raise RuntimeError(
"run should not be called on Glacier2.Application - call runWithSession instead"
)

def createSession(self, args):
raise RuntimeError('createSession() not implemented')
raise RuntimeError("createSession() not implemented")

def runWithSession(self, args):
raise RuntimeError('runWithSession() not implemented')
raise RuntimeError("runWithSession() not implemented")

def sessionDestroyed(self):
pass

def restart(self):
raise RestartSessionException()

restart = classmethod(restart)

def router(self):
return Application._router

router = classmethod(router)

def session(self):
return Application._session

session = classmethod(session)

def categoryForClient(self):
if Application._router == None:
if Application._router is None:
raise SessionNotExistException()
return Application._category

categoryForClient = classmethod(categoryForClient)

def createCallbackIdentity(self, name):
return Ice.Identity(name, self.categoryForClient())

createCallbackIdentity = classmethod(createCallbackIdentity)

def addWithUUID(self, servant):
return self.objectAdapter().add(servant, self.createCallbackIdentity(Ice.generateUUID()))
return self.objectAdapter().add(
servant, self.createCallbackIdentity(Ice.generateUUID())
)

addWithUUID = classmethod(addWithUUID)

def objectAdapter(self):
if Application._router == None:
if Application._router is None:
raise SessionNotExistException()
if Application._adapter == None:
Application._adapter = self.communicator().createObjectAdapterWithRouter("", Application._router)
if Application._adapter is None:
Application._adapter = self.communicator().createObjectAdapterWithRouter(
"", Application._router
)
Application._adapter.activate()
return Application._adapter

objectAdapter = classmethod(objectAdapter)

def doMainInternal(self, args, initData):
Expand All @@ -112,8 +125,10 @@ def doMainInternal(self, args, initData):
try:
Ice.Application._communicator = Ice.initialize(args, initData)

Application._router = RouterPrx.uncheckedCast(Ice.Application.communicator().getDefaultRouter())
if Application._router == None:
Application._router = RouterPrx.uncheckedCast(
Ice.Application.communicator().getDefaultRouter()
)
if Application._router is None:
Ice.getProcessLogger().error("no glacier2 router configured")
status = 1
else:
Expand All @@ -135,29 +150,38 @@ def doMainInternal(self, args, initData):
acmTimeout = 0
try:
acmTimeout = Application._router.getACMTimeout()
except (Ice.OperationNotExistException):
except Ice.OperationNotExistException:
pass
if acmTimeout <= 0:
acmTimeout = Application._router.getSessionTimeout()
if acmTimeout > 0:
connection = Application._router.ice_getCachedConnection()
assert (connection)
connection.setACM(acmTimeout, Ice.Unset, Ice.ACMHeartbeat.HeartbeatAlways)
connection.setCloseCallback(lambda conn: self.sessionDestroyed())
assert connection
connection.setACM(
acmTimeout, Ice.Unset, Ice.ACMHeartbeat.HeartbeatAlways
)
connection.setCloseCallback(
lambda conn: self.sessionDestroyed()
)
Application._category = Application._router.getCategoryForClient()
status = self.runWithSession(args)

# We want to restart on those exceptions which indicate a
# break down in communications, but not those exceptions that
# indicate a programming logic error (ie: marshal, protocol
# failure, etc).
except (RestartSessionException):
except RestartSessionException:
restart = True
except (Ice.ConnectionRefusedException, Ice.ConnectionLostException, Ice.UnknownLocalException,
Ice.RequestFailedException, Ice.TimeoutException):
except (
Ice.ConnectionRefusedException,
Ice.ConnectionLostException,
Ice.UnknownLocalException,
Ice.RequestFailedException,
Ice.TimeoutException,
):
Ice.getProcessLogger().error(traceback.format_exc())
restart = True
except:
except Exception:
Ice.getProcessLogger().error(traceback.format_exc())
status = 1

Expand Down Expand Up @@ -188,15 +212,17 @@ def doMainInternal(self, args, initData):
Application._router.destroySession()
except (Ice.ConnectionLostException, SessionNotExistException):
pass
except:
Ice.getProcessLogger().error("unexpected exception when destroying the session " +
traceback.format_exc())
except Exception:
Ice.getProcessLogger().error(
"unexpected exception when destroying the session "
+ traceback.format_exc()
)
Application._router = None

if Ice.Application._communicator:
try:
Ice.Application._communicator.destroy()
except:
except Exception:
getProcessLogger().error(traceback.format_exc())
status = 1

Expand Down
8 changes: 4 additions & 4 deletions python/python/Ice/CommunicatorF_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import IcePy

# Start of module Ice
_M_Ice = Ice.openModule('Ice')
__name__ = 'Ice'
_M_Ice = Ice.openModule("Ice")
__name__ = "Ice"

if 'Communicator' not in _M_Ice.__dict__:
_M_Ice._t_Communicator = IcePy.declareValue('::Ice::Communicator')
if "Communicator" not in _M_Ice.__dict__:
_M_Ice._t_Communicator = IcePy.declareValue("::Ice::Communicator")

# End of module Ice
71 changes: 42 additions & 29 deletions python/python/Ice/Communicator_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,59 +30,59 @@
import Ice.Connection_local

# Included module Ice
_M_Ice = Ice.openModule('Ice')
_M_Ice = Ice.openModule("Ice")

# Included module Ice.Instrumentation
_M_Ice.Instrumentation = Ice.openModule('Ice.Instrumentation')
_M_Ice.Instrumentation = Ice.openModule("Ice.Instrumentation")

# Start of module Ice
__name__ = 'Ice'
__name__ = "Ice"
_M_Ice.__doc__ = """
The Ice core library. Among many other features, the Ice core library manages all the communication tasks using an
efficient protocol (including protocol compression and support for both TCP and UDP), provides a thread pool for
multi-threaded servers, and additional functionality that supports high scalability.
"""

if 'Communicator' not in _M_Ice.__dict__:
if "Communicator" not in _M_Ice.__dict__:
_M_Ice.Communicator = Ice.createTempClass()

class Communicator(object):
"""
The central object in Ice. One or more communicators can be instantiated for an Ice application. Communicator
instantiation is language-specific, and not specified in Slice code.
The central object in Ice. One or more communicators can be instantiated for an Ice application. Communicator
instantiation is language-specific, and not specified in Slice code.
"""

def __init__(self):
if Ice.getType(self) == _M_Ice.Communicator:
raise RuntimeError('Ice.Communicator is an abstract class')
raise RuntimeError("Ice.Communicator is an abstract class")

def destroy(self):
"""
Destroy the communicator. This operation calls shutdown implicitly. Calling destroy cleans up
memory, and shuts down this communicator's client functionality and destroys all object adapters. Subsequent
calls to destroy are ignored.
Destroy the communicator. This operation calls shutdown implicitly. Calling destroy cleans up
memory, and shuts down this communicator's client functionality and destroys all object adapters. Subsequent
calls to destroy are ignored.
"""
raise NotImplementedError("method 'destroy' not implemented")

def shutdown(self):
"""
Shuts down this communicator's server functionality, which includes the deactivation of all object adapters.
Attempts to use a deactivated object adapter raise ObjectAdapterDeactivatedException. Subsequent calls to
shutdown are ignored.
After shutdown returns, no new requests are processed. However, requests that have been started before shutdown
was called might still be active. You can use waitForShutdown to wait for the completion of all
requests.
Shuts down this communicator's server functionality, which includes the deactivation of all object adapters.
Attempts to use a deactivated object adapter raise ObjectAdapterDeactivatedException. Subsequent calls to
shutdown are ignored.
After shutdown returns, no new requests are processed. However, requests that have been started before shutdown
was called might still be active. You can use waitForShutdown to wait for the completion of all
requests.
"""
raise NotImplementedError("method 'shutdown' not implemented")

def waitForShutdown(self):
"""
Wait until the application has called shutdown (or destroy). On the server side, this
operation blocks the calling thread until all currently-executing operations have completed. On the client
side, the operation simply blocks until another thread has called shutdown or destroy.
A typical use of this operation is to call it from the main thread, which then waits until some other thread
calls shutdown. After shut-down is complete, the main thread returns and can do some cleanup work
before it finally calls destroy to shut down the client functionality, and then exits the application.
Wait until the application has called shutdown (or destroy). On the server side, this
operation blocks the calling thread until all currently-executing operations have completed. On the client
side, the operation simply blocks until another thread has called shutdown or destroy.
A typical use of this operation is to call it from the main thread, which then waits until some other thread
calls shutdown. After shut-down is complete, the main thread returns and can do some cleanup work
before it finally calls destroy to shut down the client functionality, and then exits the application.
"""
raise NotImplementedError("method 'waitForShutdown' not implemented")

Expand Down Expand Up @@ -172,7 +172,9 @@ def createObjectAdapterWithEndpoints(self, name, endpoints):
endpoints -- The endpoints for the object adapter.
Returns: The new object adapter.
"""
raise NotImplementedError("method 'createObjectAdapterWithEndpoints' not implemented")
raise NotImplementedError(
"method 'createObjectAdapterWithEndpoints' not implemented"
)

def createObjectAdapterWithRouter(self, name, rtr):
"""
Expand All @@ -183,7 +185,9 @@ def createObjectAdapterWithRouter(self, name, rtr):
rtr -- The router.
Returns: The new object adapter.
"""
raise NotImplementedError("method 'createObjectAdapterWithRouter' not implemented")
raise NotImplementedError(
"method 'createObjectAdapterWithRouter' not implemented"
)

def getImplicitContext(self):
"""
Expand Down Expand Up @@ -339,13 +343,15 @@ def __str__(self):

__repr__ = __str__

_M_Ice._t_Communicator = IcePy.defineValue('::Ice::Communicator', Communicator, -1, (), False, True, None, ())
_M_Ice._t_Communicator = IcePy.defineValue(
"::Ice::Communicator", Communicator, -1, (), False, True, None, ()
)
Communicator._ice_type = _M_Ice._t_Communicator

_M_Ice.Communicator = Communicator
del Communicator

if 'ToStringMode' not in _M_Ice.__dict__:
if "ToStringMode" not in _M_Ice.__dict__:
_M_Ice.ToStringMode = Ice.createTempClass()

class ToStringMode(Ice.EnumBase):
Expand All @@ -371,14 +377,21 @@ def valueOf(self, _n):
if _n in self._enumerators:
return self._enumerators[_n]
return None

valueOf = classmethod(valueOf)

ToStringMode.Unicode = ToStringMode("Unicode", 0)
ToStringMode.ASCII = ToStringMode("ASCII", 1)
ToStringMode.Compat = ToStringMode("Compat", 2)
ToStringMode._enumerators = {0: ToStringMode.Unicode, 1: ToStringMode.ASCII, 2: ToStringMode.Compat}

_M_Ice._t_ToStringMode = IcePy.defineEnum('::Ice::ToStringMode', ToStringMode, (), ToStringMode._enumerators)
ToStringMode._enumerators = {
0: ToStringMode.Unicode,
1: ToStringMode.ASCII,
2: ToStringMode.Compat,
}

_M_Ice._t_ToStringMode = IcePy.defineEnum(
"::Ice::ToStringMode", ToStringMode, (), ToStringMode._enumerators
)

_M_Ice.ToStringMode = ToStringMode
del ToStringMode
Expand Down
Loading

0 comments on commit f35941d

Please sign in to comment.