Skip to content

Added deprecation warning to bus.py and fixed notes #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion tmcl/bus.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,45 @@
import struct
from .motor import Motor
from .reply import Reply, TrinamicException
import functools
import inspect
import warnings

# NOTE(kgriffs): We don't want our deprecations to be ignored by default,
# so create our own type.
class DeprecatedWarning(UserWarning):
pass

def deprecated(instructions):
"""Flags a method as deprecated.
Args:
instructions: A human-friendly string of instructions, such
as: 'Please migrate to add_proxy() ASAP.'
By: Kurt Griffiths (kgriffs), https://gist.github.com/kgriffs/8202106
"""
def decorator(func):
'''This is a decorator which can be used to mark functions
as deprecated. It will result in a warning being emitted
when the function is used.'''
@functools.wraps(func)
def wrapper(*args, **kwargs):
message = 'Call to deprecated function {}. {}'.format(
func.__name__,
instructions)

frame = inspect.currentframe().f_back

warnings.warn_explicit(message,
category=DeprecatedWarning,
filename=inspect.getfile(frame.f_code),
lineno=frame.f_lineno)

return func(*args, **kwargs)

return wrapper

return decorator



# MSG_STRUCTURE = ">BBBBIB"
Expand All @@ -17,8 +56,9 @@
REPLY_LENGTH_IIC = 8


class Bus (object):

class Bus (object):

def __init__( self, serial, CAN = False ):
self.CAN = CAN
self.serial = serial
Expand Down Expand Up @@ -53,6 +93,17 @@ def _handle_reply (self, reply):
raise TrinamicException(reply)
return reply

@deprecated("Please use `get_module` in the future.")
def get_motor (self, address):
"""
Deprecated!
Although the name suggests otherwise, this function retuns a handle
for a driver module (rather than a motor).
Use `get_module` instead, which also allows to select the default motor
driver on the module.
"""
return Motor(self, address)

def get_module (self, module_address = 1, motor = 0):
"""
Returns object addressing motor number 'motor' on module 'module_address'.
Expand Down
4 changes: 0 additions & 4 deletions tmcl/info.txt

This file was deleted.