From 9bf0e6e871618520c284d00400efe51b2d8d7720 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 12 Jun 2013 08:40:16 -0400 Subject: [PATCH] Use relative imports (or absolute imports for cimport) The relative-import ticket is still open [1], but the Cython 0.15 release notes (2011-08-05) claim support for relative imports [2]. Relative cimports are not supported yet [3], but I've fixed them up to use the full absolute import path. [1]: http://trac.cython.org/cython_trac/ticket/542 [2]: http://wiki.cython.org/ReleaseNotes-0.15 [3]: http://thread.gmane.org/gmane.comp.python.cython.devel/14406 --- pycomedi/_comedilib_h.pxd | 2 +- pycomedi/_error.pyx | 8 +++--- pycomedi/calibration.pxd | 2 +- pycomedi/calibration.pyx | 10 ++++---- pycomedi/channel.pyx | 46 ++++++++++++++++++----------------- pycomedi/chanspec.pyx | 4 +-- pycomedi/command.pxd | 2 +- pycomedi/command.pyx | 12 ++++----- pycomedi/constant.pyx | 2 +- pycomedi/device.pxd | 10 ++++---- pycomedi/device.pyx | 38 ++++++++++++++--------------- pycomedi/device_holder.pxd | 2 +- pycomedi/instruction.pxd | 2 +- pycomedi/instruction.pyx | 12 ++++----- pycomedi/library.pyx | 4 +-- pycomedi/range.pxd | 6 ++--- pycomedi/range.pyx | 6 ++--- pycomedi/subdevice.pxd | 10 ++++---- pycomedi/subdevice.pyx | 31 ++++++++++++----------- pycomedi/subdevice_holder.pxd | 6 ++--- pycomedi/subdevice_holder.pyx | 2 +- 21 files changed, 108 insertions(+), 109 deletions(-) diff --git a/pycomedi/_comedilib_h.pxd b/pycomedi/_comedilib_h.pxd index 71563fa..f1e92aa 100644 --- a/pycomedi/_comedilib_h.pxd +++ b/pycomedi/_comedilib_h.pxd @@ -16,7 +16,7 @@ "Cython interface to comedilib.h" -from _comedi_h cimport * +from pycomedi._comedi_h cimport * cdef extern from 'comedilib.h': diff --git a/pycomedi/_error.pyx b/pycomedi/_error.pyx index 6e8e9a8..f222ffb 100644 --- a/pycomedi/_error.pyx +++ b/pycomedi/_error.pyx @@ -16,12 +16,10 @@ "Useful error checking wrappers around Comedilib function calls" -# No relative imports in Cython yet, see -# http://trac.cython.org/cython_trac/ticket/542 -from pycomedi import LOG as _LOG -from pycomedi import PyComediError as _PyComediError +from . import LOG as _LOG +from . import PyComediError as _PyComediError -cimport _comedilib_h +from pycomedi cimport _comedilib_h def raise_error(function_name=None, ret=None, error_msg=None): diff --git a/pycomedi/calibration.pxd b/pycomedi/calibration.pxd index 12a4e3f..6e98b53 100644 --- a/pycomedi/calibration.pxd +++ b/pycomedi/calibration.pxd @@ -16,7 +16,7 @@ "Expose `CalibratedConverter` internals at the C level for other Cython modules" -cimport _comedilib_h +from pycomedi cimport _comedilib_h cdef class CalibratedConverter (object): diff --git a/pycomedi/calibration.pyx b/pycomedi/calibration.pyx index 18b7768..cac765a 100644 --- a/pycomedi/calibration.pyx +++ b/pycomedi/calibration.pyx @@ -26,11 +26,11 @@ from libc cimport string as _string cimport numpy as _numpy import numpy as _numpy -cimport _comedi_h -cimport _comedilib_h -import _error -import constant as _constant -import utility as _utility +from pycomedi cimport _comedi_h +from pycomedi cimport _comedilib_h +from . import _error +from . import constant as _constant +from . import utility as _utility cdef void _python_to_charp( diff --git a/pycomedi/channel.pyx b/pycomedi/channel.pyx index b111da9..4b0a3c1 100644 --- a/pycomedi/channel.pyx +++ b/pycomedi/channel.pyx @@ -22,18 +22,17 @@ cimport cython cimport numpy as _numpy import numpy as _numpy -cimport _comedi_h -cimport _comedilib_h -from calibration cimport CalibratedConverter as _CalibratedConverter -from calibration cimport Calibration as _Calibration -from range cimport Range as _Range -from subdevice_holder cimport SubdeviceHolder as _SubdeviceHolder +from pycomedi cimport _comedi_h +from pycomedi cimport _comedilib_h +from pycomedi cimport calibration as _calibration +from pycomedi cimport range as _range +from pycomedi cimport subdevice_holder as _subdevice_holder -from pycomedi import LOG as _LOG -from chanspec import ChanSpec as _ChanSpec -from pycomedi import PyComediError as _PyComediError -import _error -import constant as _constant +from . import LOG as _LOG +from . import PyComediError as _PyComediError +from . import _error +from . import chanspec as _chanspec +from . import constant as _constant cdef class Channel (object): @@ -58,7 +57,7 @@ cdef class Channel (object): >>> d.close() """ - cdef public _SubdeviceHolder subdevice + cdef public _subdevice_holder.SubdeviceHolder subdevice cdef public int index def __cinit__(self): @@ -89,13 +88,13 @@ cdef class Channel (object): cdef _get_range(self, index): cdef _comedilib_h.comedi_range *rng - cdef _Range ret + cdef _range.Range ret # Memory pointed to by the return value is freed on Device.close(). rng = _comedilib_h.comedi_get_range( self._device(), self.subdevice.index, self.index, index) if rng is NULL: _error.raise_error(function_name='comedi_get_range') - ret = _Range(value=index) + ret = _range.Range(value=index) ret.set_comedi_range(rng[0]) # rng[0] is a sneaky way to dereference rng, since Cython # doesn't support *rng. @@ -280,7 +279,7 @@ cdef class AnalogChannel (Channel): >>> c.range """ - cdef public _Range range + cdef public _range.Range range cdef public object aref def __init__(self, range=None, aref=None, **kwargs): @@ -381,11 +380,12 @@ cdef class AnalogChannel (Channel): _error.raise_error(function_name='comedi_data_write', ret=ret) def chanspec(self): - return _ChanSpec(chan=self.index, range=self.range, aref=self.aref) + return _chanspec.ChanSpec( + chan=self.index, range=self.range, aref=self.aref) cdef _comedilib_h.comedi_polynomial_t get_softcal_converter( - self, direction, _Calibration calibration) except *: + self, direction, _calibration.Calibration calibration) except *: """Get a calibration polynomial for a software-calibrated channel `direction` should be a value from `constant.CONVERSION_DIRECTION`. @@ -417,9 +417,9 @@ cdef class AnalogChannel (Channel): ret=rc) return poly - cdef _get_converter(self, _Calibration calibration): + cdef _get_converter(self, _calibration.Calibration calibration): cdef _comedilib_h.comedi_polynomial_t to_physical, from_physical - cdef _CalibratedConverter ret + cdef _calibration.CalibratedConverter ret flags = self.subdevice.get_flags() from_physical_error = None if flags.soft_calibrated: @@ -439,7 +439,8 @@ cdef class AnalogChannel (Channel): _constant.CONVERSION_DIRECTION.to_physical) from_physical = self.get_hardcal_converter( _constant.CONVERSION_DIRECTION.from_physical) - ret = _CalibratedConverter(from_physical_error=from_physical_error) + ret = _calibration.CalibratedConverter( + from_physical_error=from_physical_error) ret._to_physical = to_physical if from_physical_error is None: ret._from_physical = from_physical @@ -463,7 +464,7 @@ cdef class AnalogChannel (Channel): function_name='comedi_apply_calibration', ret=ret) return ret - cdef _apply_parsed_calibration(self, _Calibration calibration): + cdef _apply_parsed_calibration(self, _calibration.Calibration calibration): ret = _comedilib_h.comedi_apply_parsed_calibration( self._device(), self.subdevice.index, self.index, _constant.bitwise_value(self.range), @@ -474,7 +475,8 @@ cdef class AnalogChannel (Channel): function_name='comedi_apply_parsed_calibration', ret=ret) return ret - def apply_calibration(self, _Calibration calibration=None, path=None): + def apply_calibration(self, _calibration.Calibration calibration=None, + path=None): """Apply a calibration to this channel configuration `calibration` may None or a `Calibration` instance. If it is diff --git a/pycomedi/chanspec.pyx b/pycomedi/chanspec.pyx index c0a3fbf..725d18d 100644 --- a/pycomedi/chanspec.pyx +++ b/pycomedi/chanspec.pyx @@ -16,8 +16,8 @@ "Replace Comedi's CR_PACK and related macros with a Python class" -cimport _comedi_h -import constant as _constant +from pycomedi cimport _comedi_h +from . import constant as _constant class ChanSpec (_constant.BitwiseOperator): diff --git a/pycomedi/command.pxd b/pycomedi/command.pxd index 3cd8c26..6aef3c7 100644 --- a/pycomedi/command.pxd +++ b/pycomedi/command.pxd @@ -16,7 +16,7 @@ "Expose `Command` internals at the C level for other Cython modules" -cimport _comedi_h +from pycomedi cimport _comedi_h cdef class Command (object): diff --git a/pycomedi/command.pyx b/pycomedi/command.pyx index 38d818d..7975c98 100644 --- a/pycomedi/command.pyx +++ b/pycomedi/command.pyx @@ -19,11 +19,11 @@ cimport libc.stdlib as _stdlib import numpy as _numpy -cimport _comedi_h -cimport _comedilib_h -from pycomedi import PyComediError as _PyComediError -from chanspec import ChanSpec as _ChanSpec -import constant as _constant +from pycomedi cimport _comedi_h +from pycomedi cimport _comedilib_h +from . import PyComediError as _PyComediError +from . import chanspec as _chanspec +from . import constant as _constant cdef class Command (object): @@ -230,7 +230,7 @@ cdef class Command (object): def _chanlist_get(self): ret = list() for i in range(self._cmd.chanlist_len): - c = _ChanSpec() + c = _chanspec.ChanSpec() c.value = self._cmd.chanlist[i] ret.append(c) return ret diff --git a/pycomedi/constant.pyx b/pycomedi/constant.pyx index 196650a..f99ddcf 100644 --- a/pycomedi/constant.pyx +++ b/pycomedi/constant.pyx @@ -117,7 +117,7 @@ import sys as _sys import numpy as _numpy import comedi as _comedi -from pycomedi import LOG as _LOG +from . import LOG as _LOG def bitwise_value(object): diff --git a/pycomedi/device.pxd b/pycomedi/device.pxd index 9897881..e6745c9 100644 --- a/pycomedi/device.pxd +++ b/pycomedi/device.pxd @@ -16,14 +16,14 @@ "Expose `Device` internals at the C level for other Cython modules" -cimport _comedilib_h -from device_holder cimport DeviceHolder as _DeviceHolder -from instruction cimport Insn as _Insn +from pycomedi cimport _comedilib_h +from pycomedi cimport device_holder as _device_holder +from pycomedi cimport instruction as _instruction -cdef class Device (_DeviceHolder): +cdef class Device (_device_holder.DeviceHolder): cdef public object file cdef public object filename cpdef do_insnlist(self, insnlist) - cpdef do_insn(self, _Insn insn) + cpdef do_insn(self, _instruction.Insn insn) diff --git a/pycomedi/device.pyx b/pycomedi/device.pyx index b0360eb..18b44be 100644 --- a/pycomedi/device.pyx +++ b/pycomedi/device.pyx @@ -21,20 +21,20 @@ import os as _os cimport libc.stdlib as _stdlib -from pycomedi import LOG as _LOG -from pycomedi import PyComediError as _PyComediError -cimport _comedi_h -cimport _comedilib_h -import _error -from calibration import Calibration as _Calibration -from device_holder cimport DeviceHolder as _DeviceHolder -from device_holder import DeviceHolder as _DeviceHolder -from instruction cimport Insn as _Insn -from instruction import Insn as _Insn -from subdevice import Subdevice as _Subdevice - - -cdef class Device (_DeviceHolder): +from . import LOG as _LOG +from . import PyComediError as _PyComediError +from pycomedi cimport _comedi_h +from pycomedi cimport _comedilib_h +from . import _error +from . import calibration as _calibration +from pycomedi cimport device_holder as _device_holder +from . import device_holder as _device_holder +from pycomedi cimport instruction as _instruction +from . import instruction as _instruction +from . import subdevice as _subdevice + + +cdef class Device (_device_holder.DeviceHolder): """A Comedi device >>> from . import constant @@ -229,7 +229,7 @@ cdef class Device (_DeviceHolder): Returns the number of successfully completed instructions. """ cdef _comedi_h.comedi_insnlist il - cdef _Insn i + cdef _instruction.Insn i il.n_insns = len(insnlist) if il.n_insns == 0: return @@ -251,7 +251,7 @@ cdef class Device (_DeviceHolder): _error.raise_error(function_name='comedi_do_insnlist', ret=ret) return ret - cpdef do_insn(self, _Insn insn): + cpdef do_insn(self, _instruction.Insn insn): """Preform a single instruction. Returns an instruction-specific integer. @@ -284,14 +284,14 @@ cdef class Device (_DeviceHolder): """ if path is None: path = self.get_default_calibration_path() - c = _Calibration(device=self) + c = _calibration.Calibration(device=self) c.from_file(path) return c # extensions to make a more idomatic Python interface def insn(self): - return _Insn() + return _instruction.Insn() def subdevices(self, **kwargs): "Iterate through all available subdevices." @@ -302,5 +302,5 @@ cdef class Device (_DeviceHolder): ret.append(self.subdevice(i, **kwargs)) return ret - def subdevice(self, index, factory=_Subdevice, **kwargs): + def subdevice(self, index, factory=_subdevice.Subdevice, **kwargs): return factory(device=self, index=index, **kwargs) diff --git a/pycomedi/device_holder.pxd b/pycomedi/device_holder.pxd index 9b49a57..5796b04 100644 --- a/pycomedi/device_holder.pxd +++ b/pycomedi/device_holder.pxd @@ -1,6 +1,6 @@ # Copyright -cimport _comedilib_h +from pycomedi cimport _comedilib_h cdef class DeviceHolder (object): diff --git a/pycomedi/instruction.pxd b/pycomedi/instruction.pxd index f99c04d..2297544 100644 --- a/pycomedi/instruction.pxd +++ b/pycomedi/instruction.pxd @@ -16,7 +16,7 @@ "Expose `Insn` internals at the C level for other Cython modules" -cimport _comedi_h +from pycomedi cimport _comedi_h cdef class Insn (object): diff --git a/pycomedi/instruction.pyx b/pycomedi/instruction.pyx index 28d370a..c25939f 100644 --- a/pycomedi/instruction.pyx +++ b/pycomedi/instruction.pyx @@ -19,11 +19,11 @@ cimport libc.stdlib as _stdlib import numpy as _numpy -cimport _comedi_h -cimport _comedilib_h -from pycomedi import PyComediError as _PyComediError -from chanspec import ChanSpec as _ChanSpec -import constant as _constant +from pycomedi cimport _comedi_h +from pycomedi cimport _comedilib_h +from . import PyComediError as _PyComediError +from . import chanspec as _chanspec +from . import constant as _constant cdef class Insn (object): @@ -125,7 +125,7 @@ cdef class Insn (object): subdev = property(fget=_subdev_get, fset=_subdev_set) def _chanspec_get(self): - c = _ChanSpec() + c = _chanspec.ChanSpec() c.value = self._insn.chanspec return c def _chanspec_set(self, value): diff --git a/pycomedi/library.pyx b/pycomedi/library.pyx index aadb336..2f5ccb6 100644 --- a/pycomedi/library.pyx +++ b/pycomedi/library.pyx @@ -18,8 +18,8 @@ import os as _os -cimport _comedilib_h -import constant as _constant +from pycomedi cimport _comedilib_h +from . import constant as _constant def set_loglevel(level): diff --git a/pycomedi/range.pxd b/pycomedi/range.pxd index ac74cee..0888ec1 100644 --- a/pycomedi/range.pxd +++ b/pycomedi/range.pxd @@ -16,11 +16,11 @@ "Expose `Range` internals at the C level for other Cython modules" -cimport _comedilib_h -from constant cimport BitwiseOperator as _BitwiseOperator +from pycomedi cimport _comedilib_h +from . import constant as _constant -cdef class Range (_BitwiseOperator): +cdef class Range (_constant.BitwiseOperator): cdef _comedilib_h.comedi_range range cdef set_comedi_range(self, _comedilib_h.comedi_range range) diff --git a/pycomedi/range.pyx b/pycomedi/range.pyx index 7ceb579..6171a83 100644 --- a/pycomedi/range.pyx +++ b/pycomedi/range.pyx @@ -16,11 +16,11 @@ "Wrap `comedi_range` in a Python class" -from constant cimport BitwiseOperator as _BitwiseOperator -import constant as _constant +from pycomedi import constant as _constant +from . import constant as _constant -cdef class Range (_BitwiseOperator): +cdef class Range (_constant.BitwiseOperator): """Stucture displaying a possible channel range Warning: You probably want to use `channel.Channel.get_range()` or diff --git a/pycomedi/subdevice.pxd b/pycomedi/subdevice.pxd index 1b85d28..31bfcf6 100644 --- a/pycomedi/subdevice.pxd +++ b/pycomedi/subdevice.pxd @@ -16,15 +16,15 @@ "Expose `Subdevice` internals at the C level for other Cython modules" -cimport _comedilib_h -from command cimport Command as _Command -from subdevice_holder cimport SubdeviceHolder as _SubdeviceHolder +from pycomedi cimport _comedilib_h +from pycomedi cimport command as _command +from pycomedi cimport subdevice_holder as _subdevice_holder -cdef class Subdevice (_SubdeviceHolder): +cdef class Subdevice (_subdevice_holder.SubdeviceHolder): cpdef dio_bitfield(self, unsigned int bits=*, write_mask=*, base_channel=*) cdef class StreamingSubdevice (Subdevice): - cdef public _Command cmd + cdef public _command.Command cmd cdef public list _command_test_errors diff --git a/pycomedi/subdevice.pyx b/pycomedi/subdevice.pyx index 6acb33a..a04def2 100644 --- a/pycomedi/subdevice.pyx +++ b/pycomedi/subdevice.pyx @@ -16,21 +16,20 @@ "Wrap subdevice-wide Comedi functions in `Subdevice` and related classes" -cimport _comedi_h -cimport _comedilib_h -cimport command as _command -from pycomedi import LOG as _LOG -import _error -from channel import Channel as _Channel -import chanspec as _chanspec -import constant as _constant -import command as _command -from subdevice_holder cimport SubdeviceHolder as _SubdeviceHolder -from subdevice_holder import SubdeviceHolder as _SubdeviceHolder -from utility import _subdevice_dtype, _subdevice_typecode - - -cdef class Subdevice (_SubdeviceHolder): +from pycomedi cimport _comedi_h +from pycomedi cimport _comedilib_h +from pycomedi cimport command as _command +from . import LOG as _LOG +from . import _error as _error +from . import channel as _channel +from . import constant as _constant +from . import command as _command +from pycomedi cimport subdevice_holder as _subdevice_holder +from . import subdevice_holder as _subdevice_holder +from .utility import _subdevice_dtype, _subdevice_typecode + + +cdef class Subdevice (_subdevice_holder.SubdeviceHolder): """Class bundling subdevice-related functions >>> from .device import Device @@ -158,7 +157,7 @@ cdef class Subdevice (_SubdeviceHolder): ret.append(self.channel(i, **kwargs)) return ret - def channel(self, index, factory=_Channel, **kwargs): + def channel(self, index, factory=_channel.Channel, **kwargs): "`Channel` instance for the `index`\ed channel." return factory(subdevice=self, index=index, **kwargs) diff --git a/pycomedi/subdevice_holder.pxd b/pycomedi/subdevice_holder.pxd index daa982c..0cf8b0f 100644 --- a/pycomedi/subdevice_holder.pxd +++ b/pycomedi/subdevice_holder.pxd @@ -1,11 +1,11 @@ # Copyright -cimport _comedilib_h -from device_holder cimport DeviceHolder as _DeviceHolder +from pycomedi cimport _comedilib_h +from pycomedi cimport device_holder as _device_holder cdef class SubdeviceHolder (object): - cdef public _DeviceHolder device + cdef public _device_holder.DeviceHolder device cdef public int index cdef _comedilib_h.comedi_t * _device(self) except * diff --git a/pycomedi/subdevice_holder.pyx b/pycomedi/subdevice_holder.pyx index 981ce22..81d8696 100644 --- a/pycomedi/subdevice_holder.pyx +++ b/pycomedi/subdevice_holder.pyx @@ -1,6 +1,6 @@ # Copyright -cimport _comedilib_h +from pycomedi cimport _comedilib_h cdef class SubdeviceHolder (object): -- 2.26.2