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.Loader import Loader
from direct.directnotify import DirectNotifyGlobal
import warnings
class Actor(DirectObject, NodePath):
"""
@ -1652,6 +1652,8 @@ class Actor(DirectObject, NodePath):
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)
def disableBlend(self, partName = None):
@ -1661,6 +1663,8 @@ class Actor(DirectObject, NodePath):
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)
def setControlEffect(self, animName, effect,

View File

@ -12,6 +12,7 @@ import io
import distutils.sysconfig as sysconf
import zipfile
import importlib
import warnings
from . import pefile
@ -1985,7 +1986,7 @@ class Freezer:
if append_offset:
# 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)
with open(target, 'wb') as f:

View File

@ -1,6 +1,7 @@
from panda3d.direct import CInterval
from .extension_native_helpers import Dtool_funcToMethod
from direct.directnotify.DirectNotifyGlobal import directNotify
import warnings
CInterval.DtoolClassDict["notify"] = directNotify.newCategory("Interval")
@ -18,7 +19,8 @@ del setT
#####################################################################
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
self.start(t0, t0 + duration, scale)
else:
@ -29,7 +31,8 @@ del play
#####################################################################
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()
Dtool_funcToMethod(stop, CInterval)
@ -37,7 +40,8 @@ del stop
#####################################################################
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()
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 .extension_native_helpers import Dtool_funcToMethod
import warnings
def pPrintValues(self):
"""
@ -17,7 +18,8 @@ def asTuple(self):
"""
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)
Dtool_funcToMethod(asTuple, VBase3)
del asTuple

View File

@ -4,6 +4,7 @@ Methods to extend functionality of the VBase4 class
from panda3d.core import VBase4
from .extension_native_helpers import Dtool_funcToMethod
import warnings
def pPrintValues(self):
"""
@ -17,7 +18,8 @@ def asTuple(self):
"""
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)
Dtool_funcToMethod(asTuple, VBase4)
del asTuple

View File

@ -8,6 +8,7 @@ __all__ = ['OnscreenText', 'Plain', 'ScreenTitle', 'ScreenPrompt', 'NameConfirm'
from panda3d.core import *
from . import DirectGuiGlobals as DGG
import warnings
## 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
@ -304,6 +305,8 @@ class OnscreenText(NodePath):
.. deprecated:: 1.11.0
Use `.setTextX()` method instead.
"""
if __debug__:
warnings.warn("Use `.setTextX()` method instead.", DeprecationWarning, stacklevel=2)
self.setTextPos(x, self.__pos[1])
def setTextY(self, y):
@ -317,6 +320,8 @@ class OnscreenText(NodePath):
.. deprecated:: 1.11.0
Use `.setTextY()` method instead.
"""
if __debug__:
warnings.warn("Use `.setTextY()` method instead.", DeprecationWarning, stacklevel=2)
self.setTextPos(self.__pos[0], y)
def setTextPos(self, x, y=None):
@ -346,6 +351,8 @@ class OnscreenText(NodePath):
.. deprecated:: 1.11.0
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.updateTransformMat()
@ -354,6 +361,8 @@ class OnscreenText(NodePath):
.. deprecated:: 1.11.0
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
pos = property(getPos)
@ -379,6 +388,8 @@ class OnscreenText(NodePath):
.. deprecated:: 1.11.0
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.updateTransformMat()
@ -387,6 +398,8 @@ class OnscreenText(NodePath):
.. deprecated:: 1.11.0
Use ``-getTextR()`` instead (note the negated sign).
"""
if __debug__:
warnings.warn("Use ``-getTextR()`` instead (note the negated sign).", DeprecationWarning, stacklevel=2)
return self.__roll
roll = property(getRoll, setRoll)
@ -424,7 +437,8 @@ class OnscreenText(NodePath):
.. deprecated:: 1.11.0
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 isinstance(sx, tuple):
self.__scale = sx
@ -439,6 +453,8 @@ class OnscreenText(NodePath):
.. deprecated:: 1.11.0
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
scale = property(getScale, setScale)

View File

@ -4,6 +4,7 @@ from direct.task import Task
from direct.task.TaskManagerGlobal import taskMgr
from direct.showbase.DirectObject import DirectObject
from direct.directnotify.DirectNotifyGlobal import directNotify
import warnings
def remove_task():
@ -11,7 +12,8 @@ def remove_task():
total_motion_trails = len(MotionTrail.motion_trail_list)
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 = []

View File

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

View File

@ -12,7 +12,8 @@ the AppRunner at startup.
"""
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
#: if this application was not run from the runtime environment.

View File

@ -4,21 +4,30 @@ __all__ = []
from panda3d.core import (ConfigFlags, ConfigVariableBool, ConfigVariableInt,
ConfigVariableDouble, ConfigVariableString)
import warnings
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
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
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
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

View File

@ -8,6 +8,7 @@ from panda3d.core import *
from panda3d.core import Loader as PandaLoader
from direct.directnotify.DirectNotifyGlobal import *
from direct.showbase.DirectObject import DirectObject
import warnings
# You can specify a phaseChecker callback to check
# 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.
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()
def isRequestPending(self, cb):
@ -304,7 +306,8 @@ class Loader(DirectObject):
been cancelled.
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)
def loadModelOnce(self, modelPath):
@ -315,7 +318,8 @@ class Loader(DirectObject):
then attempt to load it from disk. Return a nodepath to
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)
@ -326,7 +330,8 @@ class Loader(DirectObject):
then attempt to load it from disk. Return a nodepath to
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)
@ -344,7 +349,8 @@ class Loader(DirectObject):
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)
if model is not None:

View File

@ -72,6 +72,7 @@ if __debug__:
from direct.showbase import GarbageReport
from direct.directutil import DeltaProfiler
from . import OnScreenDebug
import warnings
@atexit.register
def exitfunc():
@ -2034,7 +2035,8 @@ class ShowBase(DirectObject.DirectObject):
"""
: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)
# 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.
"""
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)
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 NodePath, PGTop
from . import DConfig as config
import warnings
__dev__ = config.GetBool('want-dev', __debug__)
@ -63,7 +64,8 @@ directNotify.setDconfigLevels()
def 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()