diff --git a/README.md b/README.md index 0ee6942..168fc47 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Methods open(bus, device) -Connects to the specified SPI device, opening /dev/spidev-bus.device +Connects to the specified SPI device, opening `/dev/spidev.` readbytes(n) diff --git a/setup.py b/setup.py index e69d442..34674d4 100755 --- a/setup.py +++ b/setup.py @@ -2,6 +2,16 @@ from distutils.core import setup, Extension +version = "0.0" + +lines = [x for x in open("spidev_module.c").read().split("\n") if "#define" in x and "_VERSION_" in x and "\"" in x] + +if len(lines) > 0: + version = lines[0].split("\"")[1] +else: + raise Exception("Unable to find _VERSION_ in spidev_module.c") + + classifiers = ['Development Status :: 5 - Production/Stable', 'Operating System :: POSIX :: Linux', 'License :: OSI Approved :: GNU General Public License v2 (GPLv2)', @@ -14,7 +24,7 @@ 'Topic :: System :: Hardware :: Hardware Drivers'] setup( name = "spidev", - version = "3.2", + version = version, description = "Python bindings for Linux SPI access through spidev", long_description= open('README.md').read() + "\n" + open('CHANGELOG.md').read(), author = "Volker Thoms", diff --git a/spidev_module.c b/spidev_module.c index a89c86d..c7b44b2 100644 --- a/spidev_module.c +++ b/spidev_module.c @@ -27,6 +27,7 @@ #include #include +#define _VERSION_ "3.3" #define SPIDEV_MAXPATH 4096 @@ -56,7 +57,7 @@ PyDoc_STRVAR(SpiDev_module_doc, typedef struct { PyObject_HEAD - int fd; /* open file descriptor: /dev/spi-X.Y */ + int fd; /* open file descriptor: /dev/spidevX.Y */ uint8_t mode; /* current SPI mode */ uint8_t bits_per_word; /* current SPI bits per word setting */ uint32_t max_speed_hz; /* current SPI max speed setting in Hz */ @@ -888,7 +889,7 @@ static PyGetSetDef SpiDev_getset[] = { PyDoc_STRVAR(SpiDev_open_doc, "open(bus, device)\n\n" "Connects the object to the specified SPI device.\n" - "open(X,Y) will open /dev/spidev-X.Y\n"); + "open(X,Y) will open /dev/spidev.\n"); static PyObject * SpiDev_open(SpiDevObject *self, PyObject *args, PyObject *kwds) @@ -1089,9 +1090,16 @@ void initspidev(void) #if PY_MAJOR_VERSION >= 3 m = PyModule_Create(&moduledef); + PyObject *version = PyUnicode_FromString(_VERSION_); #else m = Py_InitModule3("spidev", SpiDev_module_methods, SpiDev_module_doc); + PyObject *version = PyString_FromString(_VERSION_); #endif + + PyObject *dict = PyModule_GetDict(m); + PyDict_SetItemString(dict, "__version__", version); + Py_DECREF(version); + Py_INCREF(&SpiDevObjectType); PyModule_AddObject(m, "SpiDev", (PyObject *)&SpiDevObjectType);