Skip to content

Commit

Permalink
Merge pull request #50 from Gadgetoid/master
Browse files Browse the repository at this point in the history
Added __version__ attribute to module for #41
  • Loading branch information
doceme authored Sep 2, 2016
2 parents 511db0d + 11adf8c commit fcd44e6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<bus>.<device>`

readbytes(n)

Expand Down
12 changes: 11 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand All @@ -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",
Expand Down
12 changes: 10 additions & 2 deletions spidev_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <sys/ioctl.h>
#include <linux/ioctl.h>

#define _VERSION_ "3.3"
#define SPIDEV_MAXPATH 4096


Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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<X>.<Y>\n");

static PyObject *
SpiDev_open(SpiDevObject *self, PyObject *args, PyObject *kwds)
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit fcd44e6

Please sign in to comment.