direct: Use warnings module for more verbose deprecation prints

Closes #1067
Fixes #669
This commit is contained in:
Timothy Paustian 2021-03-09 18:32:36 +01:00 committed by rdb
parent ff80adc680
commit 2493c0689f
14 changed files with 476 additions and 394 deletions

View File

@ -11,7 +11,7 @@ from panda3d.core import Loader as PandaLoader
from direct.showbase.DirectObject import DirectObject from direct.showbase.DirectObject import DirectObject
from direct.showbase.Loader import Loader from direct.showbase.Loader import Loader
from direct.directnotify import DirectNotifyGlobal from direct.directnotify import DirectNotifyGlobal
import warnings
class Actor(DirectObject, NodePath): class Actor(DirectObject, NodePath):
""" """
@ -1652,6 +1652,8 @@ class Actor(DirectObject, NodePath):
This method is deprecated. You should use setBlend() instead. This method is deprecated. You should use setBlend() instead.
""" """
if __debug__:
warnings.warn("This method is deprecated. You should use setBlend() instead.", DeprecationWarning, stacklevel=2)
self.setBlend(animBlend = True, blendType = blendType, partName = partName) self.setBlend(animBlend = True, blendType = blendType, partName = partName)
def disableBlend(self, partName = None): def disableBlend(self, partName = None):
@ -1661,6 +1663,8 @@ class Actor(DirectObject, NodePath):
This method is deprecated. You should use setBlend() instead. This method is deprecated. You should use setBlend() instead.
""" """
if __debug__:
warnings.warn("This method is deprecated. You should use setBlend() instead.", DeprecationWarning, stacklevel=2)
self.setBlend(animBlend = False, partName = partName) self.setBlend(animBlend = False, partName = partName)
def setControlEffect(self, animName, effect, def setControlEffect(self, animName, effect,

View File

@ -12,6 +12,7 @@ import io
import distutils.sysconfig as sysconf import distutils.sysconfig as sysconf
import zipfile import zipfile
import importlib import importlib
import warnings
from . import pefile from . import pefile
@ -1985,7 +1986,7 @@ class Freezer:
if append_offset: if append_offset:
# This is for legacy deploy-stub. # This is for legacy deploy-stub.
print("WARNING: Could not find blob header. Is deploy-stub outdated?") warnings.warn("Could not find blob header. Is deploy-stub outdated?")
blob += struct.pack('<Q', blob_offset) blob += struct.pack('<Q', blob_offset)
with open(target, 'wb') as f: with open(target, 'wb') as f:

View File

@ -1,6 +1,7 @@
from panda3d.direct import CInterval from panda3d.direct import CInterval
from .extension_native_helpers import Dtool_funcToMethod from .extension_native_helpers import Dtool_funcToMethod
from direct.directnotify.DirectNotifyGlobal import directNotify from direct.directnotify.DirectNotifyGlobal import directNotify
import warnings
CInterval.DtoolClassDict["notify"] = directNotify.newCategory("Interval") CInterval.DtoolClassDict["notify"] = directNotify.newCategory("Interval")
@ -18,7 +19,8 @@ del setT
##################################################################### #####################################################################
def play(self, t0 = 0.0, duration = None, scale = 1.0): def play(self, t0 = 0.0, duration = None, scale = 1.0):
self.notify.error("CInterval.play() is deprecated, use start() instead") if __debug__:
warnings.warn("CInterval.play() is deprecated, use start() instead", DeprecationWarning, stacklevel=2)
if duration: # None or 0 implies full length if duration: # None or 0 implies full length
self.start(t0, t0 + duration, scale) self.start(t0, t0 + duration, scale)
else: else:
@ -29,7 +31,8 @@ del play
##################################################################### #####################################################################
def stop(self): def stop(self):
self.notify.error("CInterval.stop() is deprecated, use finish() instead") if __debug__:
warnings.warn("CInterval.stop() is deprecated, use finish() instead", DeprecationWarning, stacklevel=2)
self.finish() self.finish()
Dtool_funcToMethod(stop, CInterval) Dtool_funcToMethod(stop, CInterval)
@ -37,7 +40,8 @@ del stop
##################################################################### #####################################################################
def setFinalT(self): def setFinalT(self):
self.notify.error("CInterval.setFinalT() is deprecated, use finish() instead") if __debug__:
warnings.warn("CInterval.setFinalT() is deprecated, use finish() instead", DeprecationWarning, stacklevel=2)
self.finish() self.finish()
Dtool_funcToMethod(setFinalT, CInterval) Dtool_funcToMethod(setFinalT, CInterval)

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,7 @@ Methods to extend functionality of the VBase3 class
from panda3d.core import VBase3 from panda3d.core import VBase3
from .extension_native_helpers import Dtool_funcToMethod from .extension_native_helpers import Dtool_funcToMethod
import warnings
def pPrintValues(self): def pPrintValues(self):
""" """
@ -17,7 +18,8 @@ def asTuple(self):
""" """
Returns the vector as a tuple. Returns the vector as a tuple.
""" """
print("Warning: VBase3.asTuple() is no longer needed and deprecated. Use the vector directly instead.") if __debug__:
warnings.warn("VBase3.asTuple() is no longer needed and deprecated. Use the vector directly instead.", DeprecationWarning, stacklevel=2)
return tuple(self) return tuple(self)
Dtool_funcToMethod(asTuple, VBase3) Dtool_funcToMethod(asTuple, VBase3)
del asTuple del asTuple

View File

@ -4,6 +4,7 @@ Methods to extend functionality of the VBase4 class
from panda3d.core import VBase4 from panda3d.core import VBase4
from .extension_native_helpers import Dtool_funcToMethod from .extension_native_helpers import Dtool_funcToMethod
import warnings
def pPrintValues(self): def pPrintValues(self):
""" """
@ -17,7 +18,8 @@ def asTuple(self):
""" """
Returns the vector as a tuple. Returns the vector as a tuple.
""" """
print("Warning: VBase4.asTuple() is no longer needed and deprecated. Use the vector directly instead.") if __debug__:
warnings.warn("VBase4.asTuple() is no longer needed and deprecated. Use the vector directly instead.", DeprecationWarning, stacklevel=2)
return tuple(self) return tuple(self)
Dtool_funcToMethod(asTuple, VBase4) Dtool_funcToMethod(asTuple, VBase4)
del asTuple del asTuple

View File

@ -8,6 +8,7 @@ __all__ = ['OnscreenText', 'Plain', 'ScreenTitle', 'ScreenPrompt', 'NameConfirm'
from panda3d.core import * from panda3d.core import *
from . import DirectGuiGlobals as DGG from . import DirectGuiGlobals as DGG
import warnings
## These are the styles of text we might commonly see. They set the ## These are the styles of text we might commonly see. They set the
## overall appearance of the text according to one of a number of ## overall appearance of the text according to one of a number of
@ -304,6 +305,8 @@ class OnscreenText(NodePath):
.. deprecated:: 1.11.0 .. deprecated:: 1.11.0
Use `.setTextX()` method instead. Use `.setTextX()` method instead.
""" """
if __debug__:
warnings.warn("Use `.setTextX()` method instead.", DeprecationWarning, stacklevel=2)
self.setTextPos(x, self.__pos[1]) self.setTextPos(x, self.__pos[1])
def setTextY(self, y): def setTextY(self, y):
@ -317,6 +320,8 @@ class OnscreenText(NodePath):
.. deprecated:: 1.11.0 .. deprecated:: 1.11.0
Use `.setTextY()` method instead. Use `.setTextY()` method instead.
""" """
if __debug__:
warnings.warn("Use `.setTextY()` method instead.", DeprecationWarning, stacklevel=2)
self.setTextPos(self.__pos[0], y) self.setTextPos(self.__pos[0], y)
def setTextPos(self, x, y=None): def setTextPos(self, x, y=None):
@ -346,6 +351,8 @@ class OnscreenText(NodePath):
.. deprecated:: 1.11.0 .. deprecated:: 1.11.0
Use `.setTextPos()` method or `.text_pos` property instead. Use `.setTextPos()` method or `.text_pos` property instead.
""" """
if __debug__:
warnings.warn("Use `.setTextPos()` method or `.text_pos` property instead.", DeprecationWarning, stacklevel=2)
self.__pos = (x, y) self.__pos = (x, y)
self.updateTransformMat() self.updateTransformMat()
@ -354,6 +361,8 @@ class OnscreenText(NodePath):
.. deprecated:: 1.11.0 .. deprecated:: 1.11.0
Use `.getTextPos()` method or `.text_pos` property instead. Use `.getTextPos()` method or `.text_pos` property instead.
""" """
if __debug__:
warnings.warn("Use `.getTextPos()` method or `.text_pos` property instead.", DeprecationWarning, stacklevel=2)
return self.__pos return self.__pos
pos = property(getPos) pos = property(getPos)
@ -379,6 +388,8 @@ class OnscreenText(NodePath):
.. deprecated:: 1.11.0 .. deprecated:: 1.11.0
Use ``setTextR(-roll)`` instead (note the negated sign). Use ``setTextR(-roll)`` instead (note the negated sign).
""" """
if __debug__:
warnings.warn("Use ``setTextR(-roll)`` instead (note the negated sign).", DeprecationWarning, stacklevel=2)
self.__roll = roll self.__roll = roll
self.updateTransformMat() self.updateTransformMat()
@ -387,6 +398,8 @@ class OnscreenText(NodePath):
.. deprecated:: 1.11.0 .. deprecated:: 1.11.0
Use ``-getTextR()`` instead (note the negated sign). Use ``-getTextR()`` instead (note the negated sign).
""" """
if __debug__:
warnings.warn("Use ``-getTextR()`` instead (note the negated sign).", DeprecationWarning, stacklevel=2)
return self.__roll return self.__roll
roll = property(getRoll, setRoll) roll = property(getRoll, setRoll)
@ -424,7 +437,8 @@ class OnscreenText(NodePath):
.. deprecated:: 1.11.0 .. deprecated:: 1.11.0
Use `.setTextScale()` method or `.text_scale` property instead. Use `.setTextScale()` method or `.text_scale` property instead.
""" """
if __debug__:
warnings.warn("Use `.setTextScale()` method or `.text_scale` property instead.", DeprecationWarning, stacklevel=2)
if sy is None: if sy is None:
if isinstance(sx, tuple): if isinstance(sx, tuple):
self.__scale = sx self.__scale = sx
@ -439,6 +453,8 @@ class OnscreenText(NodePath):
.. deprecated:: 1.11.0 .. deprecated:: 1.11.0
Use `.getTextScale()` method or `.text_scale` property instead. Use `.getTextScale()` method or `.text_scale` property instead.
""" """
if __debug__:
warnings.warn("Use `.getTextScale()` method or `.text_scale` property instead.", DeprecationWarning, stacklevel=2)
return self.__scale return self.__scale
scale = property(getScale, setScale) scale = property(getScale, setScale)

View File

@ -4,6 +4,7 @@ from direct.task import Task
from direct.task.TaskManagerGlobal import taskMgr from direct.task.TaskManagerGlobal import taskMgr
from direct.showbase.DirectObject import DirectObject from direct.showbase.DirectObject import DirectObject
from direct.directnotify.DirectNotifyGlobal import directNotify from direct.directnotify.DirectNotifyGlobal import directNotify
import warnings
def remove_task(): def remove_task():
@ -11,7 +12,8 @@ def remove_task():
total_motion_trails = len(MotionTrail.motion_trail_list) total_motion_trails = len(MotionTrail.motion_trail_list)
if total_motion_trails > 0: if total_motion_trails > 0:
print("warning: %d motion trails still exist when motion trail task is removed" %(total_motion_trails)) if __debug__:
warnings.warn("%d motion trails still exist when motion trail task is removed" % (total_motion_trails), RuntimeWarning, stacklevel=2)
MotionTrail.motion_trail_list = [] MotionTrail.motion_trail_list = []

View File

@ -5,6 +5,7 @@ from direct.showbase.PhysicsManagerGlobal import *
from direct.directnotify import DirectNotifyGlobal from direct.directnotify import DirectNotifyGlobal
import sys import sys
import warnings
class ForceGroup(DirectObject): class ForceGroup(DirectObject):
@ -61,7 +62,7 @@ class ForceGroup(DirectObject):
# Get/set # Get/set
def getName(self): def getName(self):
"""Deprecated: access .name directly instead.""" warnings.warn("Deprecated: access .name directly instead.", DeprecationWarning, stacklevel=2)
return self.name return self.name
def getNode(self): def getNode(self):

View File

@ -12,7 +12,8 @@ the AppRunner at startup.
""" """
if __debug__: if __debug__:
print('AppRunner has been removed and AppRunnerGlobal has been deprecated') import warnings
warnings.warn("AppRunner has been removed and AppRunnerGlobal has been deprecated.", DeprecationWarning, stacklevel=2)
#: Contains the global :class:`~.AppRunner.AppRunner` instance, or None #: Contains the global :class:`~.AppRunner.AppRunner` instance, or None
#: if this application was not run from the runtime environment. #: if this application was not run from the runtime environment.

View File

@ -4,21 +4,30 @@ __all__ = []
from panda3d.core import (ConfigFlags, ConfigVariableBool, ConfigVariableInt, from panda3d.core import (ConfigFlags, ConfigVariableBool, ConfigVariableInt,
ConfigVariableDouble, ConfigVariableString) ConfigVariableDouble, ConfigVariableString)
import warnings
def GetBool(sym, default=False): def GetBool(sym, default=False):
if __debug__:
warnings.warn("This is deprecated. Use ConfigVariableBool instead", DeprecationWarning, stacklevel=2)
return ConfigVariableBool(sym, default, "DConfig", ConfigFlags.F_dconfig).value return ConfigVariableBool(sym, default, "DConfig", ConfigFlags.F_dconfig).value
def GetInt(sym, default=0): def GetInt(sym, default=0):
if __debug__:
warnings.warn("This is deprecated. Use ConfigVariableInt instead", DeprecationWarning, stacklevel=2)
return ConfigVariableInt(sym, default, "DConfig", ConfigFlags.F_dconfig).value return ConfigVariableInt(sym, default, "DConfig", ConfigFlags.F_dconfig).value
def GetDouble(sym, default=0.0): def GetDouble(sym, default=0.0):
if __debug__:
warnings.warn("This is deprecated. Use ConfigVariableDouble instead", DeprecationWarning, stacklevel=2)
return ConfigVariableDouble(sym, default, "DConfig", ConfigFlags.F_dconfig).value return ConfigVariableDouble(sym, default, "DConfig", ConfigFlags.F_dconfig).value
def GetString(sym, default=""): def GetString(sym, default=""):
if __debug__:
warnings.warn("This is deprecated. Use ConfigVariableString instead", DeprecationWarning, stacklevel=2)
return ConfigVariableString(sym, default, "DConfig", ConfigFlags.F_dconfig).value return ConfigVariableString(sym, default, "DConfig", ConfigFlags.F_dconfig).value

View File

@ -8,6 +8,7 @@ from panda3d.core import *
from panda3d.core import Loader as PandaLoader from panda3d.core import Loader as PandaLoader
from direct.directnotify.DirectNotifyGlobal import * from direct.directnotify.DirectNotifyGlobal import *
from direct.showbase.DirectObject import DirectObject from direct.showbase.DirectObject import DirectObject
import warnings
# You can specify a phaseChecker callback to check # You can specify a phaseChecker callback to check
# a modelPath to see if it is being loaded in the correct # a modelPath to see if it is being loaded in the correct
@ -295,7 +296,8 @@ class Loader(DirectObject):
called after cancelRequest() has been performed. called after cancelRequest() has been performed.
This is now deprecated: call cb.cancel() instead. """ This is now deprecated: call cb.cancel() instead. """
if __debug__:
warnings.warn("This is now deprecated: call cb.cancel() instead.", DeprecationWarning, stacklevel=2)
cb.cancel() cb.cancel()
def isRequestPending(self, cb): def isRequestPending(self, cb):
@ -304,7 +306,8 @@ class Loader(DirectObject):
been cancelled. been cancelled.
This is now deprecated: call cb.done() instead. """ This is now deprecated: call cb.done() instead. """
if __debug__:
warnings.warn("This is now deprecated: call cb.done() instead.", DeprecationWarning, stacklevel=2)
return bool(cb.requests) return bool(cb.requests)
def loadModelOnce(self, modelPath): def loadModelOnce(self, modelPath):
@ -315,7 +318,8 @@ class Loader(DirectObject):
then attempt to load it from disk. Return a nodepath to then attempt to load it from disk. Return a nodepath to
the model if successful or None otherwise the model if successful or None otherwise
""" """
Loader.notify.info("loader.loadModelOnce() is deprecated; use loader.loadModel() instead.") if __debug__:
warnings.warn("loader.loadModelOnce() is deprecated; use loader.loadModel() instead.", DeprecationWarning, stacklevel=2)
return self.loadModel(modelPath, noCache = False) return self.loadModel(modelPath, noCache = False)
@ -326,7 +330,8 @@ class Loader(DirectObject):
then attempt to load it from disk. Return a nodepath to then attempt to load it from disk. Return a nodepath to
a copy of the model if successful or None otherwise a copy of the model if successful or None otherwise
""" """
Loader.notify.info("loader.loadModelCopy() is deprecated; use loader.loadModel() instead.") if __debug__:
warnings.warn("loader.loadModelCopy() is deprecated; use loader.loadModel() instead.", DeprecationWarning, stacklevel=2)
return self.loadModel(modelPath, loaderOptions = loaderOptions, noCache = False) return self.loadModel(modelPath, loaderOptions = loaderOptions, noCache = False)
@ -344,7 +349,8 @@ class Loader(DirectObject):
However, if you're loading a font, see loadFont(), below. However, if you're loading a font, see loadFont(), below.
""" """
Loader.notify.info("loader.loadModelNode() is deprecated; use loader.loadModel() instead.") if __debug__:
warnings.warn("loader.loadModelNode() is deprecated; use loader.loadModel() instead.", DeprecationWarning, stacklevel=2)
model = self.loadModel(modelPath, noCache = False) model = self.loadModel(modelPath, noCache = False)
if model is not None: if model is not None:

View File

@ -72,6 +72,7 @@ if __debug__:
from direct.showbase import GarbageReport from direct.showbase import GarbageReport
from direct.directutil import DeltaProfiler from direct.directutil import DeltaProfiler
from . import OnScreenDebug from . import OnScreenDebug
import warnings
@atexit.register @atexit.register
def exitfunc(): def exitfunc():
@ -2034,7 +2035,8 @@ class ShowBase(DirectObject.DirectObject):
""" """
:deprecated: Use `.Loader.Loader.loadSfx()` instead. :deprecated: Use `.Loader.Loader.loadSfx()` instead.
""" """
assert self.notify.warning("base.loadSfx is deprecated, use base.loader.loadSfx instead.") if __debug__:
warnings.warn("base.loadSfx is deprecated, use base.loader.loadSfx instead.", DeprecationWarning, stacklevel=2)
return self.loader.loadSfx(name) return self.loader.loadSfx(name)
# This function should only be in the loader but is here for # This function should only be in the loader but is here for
@ -2044,7 +2046,8 @@ class ShowBase(DirectObject.DirectObject):
""" """
:deprecated: Use `.Loader.Loader.loadMusic()` instead. :deprecated: Use `.Loader.Loader.loadMusic()` instead.
""" """
assert self.notify.warning("base.loadMusic is deprecated, use base.loader.loadMusic instead.") if __debug__:
warnings.warn("base.loadMusic is deprecated, use base.loader.loadMusic instead.", DeprecationWarning, stacklevel=2)
return self.loader.loadMusic(name) return self.loader.loadMusic(name)
def playSfx( def playSfx(

View File

@ -19,6 +19,7 @@ from panda3d.core import VirtualFileSystem, Notify, ClockObject, PandaSystem
from panda3d.core import ConfigPageManager, ConfigVariableManager from panda3d.core import ConfigPageManager, ConfigVariableManager
from panda3d.core import NodePath, PGTop from panda3d.core import NodePath, PGTop
from . import DConfig as config from . import DConfig as config
import warnings
__dev__ = config.GetBool('want-dev', __debug__) __dev__ = config.GetBool('want-dev', __debug__)
@ -63,7 +64,8 @@ directNotify.setDconfigLevels()
def run(): def run():
"""Deprecated alias for :meth:`base.run() <.ShowBase.run>`.""" """Deprecated alias for :meth:`base.run() <.ShowBase.run>`."""
assert ShowBase.notify.warning("run() is deprecated, use base.run() instead") if __debug__:
warnings.warn("run() is deprecated, use base.run() instead", DeprecationWarning, stacklevel=2)
base.run() base.run()