From 741ff1b0132e849328dbf9cbfcc42bb3b964fe8b Mon Sep 17 00:00:00 2001 From: Sang Han Date: Wed, 25 Mar 2015 06:40:55 -0700 Subject: [PATCH 01/14] building messenger call now from root --- config.ini | 20 +++++++ messenger/__init__.py | 1 + messenger/__main__.py | 40 ++++++++++++++ messenger/make.py | 124 +++++++++++++++++++----------------------- messenger/settings.py | 51 +++++++++++++++++ 5 files changed, 168 insertions(+), 68 deletions(-) create mode 100644 config.ini create mode 100644 messenger/__main__.py mode change 100755 => 100644 messenger/make.py create mode 100644 messenger/settings.py diff --git a/config.ini b/config.ini new file mode 100644 index 0000000..9a1cdae --- /dev/null +++ b/config.ini @@ -0,0 +1,20 @@ +[Darwin] +; MATLAB_BIN=Applications/MATLAB_R2014a.app/bin +; OCTAVE_INC= +; OCTAVE_LIB= +ZMQ_INC=/usr/local/include +ZMQ_LIB=/usr/local/lib + +[Windows] +; MATLAB_BIN=C:\Program Files\MATLAB\R2014b\bin +; OCTAVE_INC=C:\Octave\Octave-3.8.2\include\octave-3.8.2\octave +; OCTAVE_LIB=C:\Octave\Octave-3.8.2\lib\octave\3.8.2 +ZMQ_INC=C:/Program Files/ZeroMQ 4.0.4/include +ZMQ_LIB=C:/Program Files/ZeroMQ 4.0.4/lib + +[Linux] +; MATLAB_BIN=/usr/local/bin +; OCTAVE_INC=/usr/include +; OCTAVE_LIB=/usr/lib/x86_64-linux-gnu/ +ZMQ_INC= +ZMQ_LIB= diff --git a/messenger/__init__.py b/messenger/__init__.py index e69de29..c70020d 100644 --- a/messenger/__init__.py +++ b/messenger/__init__.py @@ -0,0 +1 @@ +from .settings import * \ No newline at end of file diff --git a/messenger/__main__.py b/messenger/__main__.py new file mode 100644 index 0000000..ce3ef9c --- /dev/null +++ b/messenger/__main__.py @@ -0,0 +1,40 @@ +from argparse import ArgumentParser + +from .make import * + +def command_line(): + """ + Manages command line arguments. + + Returns + ======= + Namespace containing parsed arguments + """ + + parser = ArgumentParser() + parser.add_argument( + "target", + choices=["matlab", "octave"], + type=str.lower, + help="target to be built" + ) + parser.add_argument( + "--static", + action="store_true", + help="staticly link libzmq" + ) + return parser.parse_args() + + + +def main(): + args = command_line() + if args.target == "matlab": + build_matlab(static=args.static) + elif args.target == "octave": + build_octave() + else: + raise ValueError() + +if __name__ == '__main__': + main() diff --git a/messenger/make.py b/messenger/make.py old mode 100755 new mode 100644 index 7048aab..0a5f21d --- a/messenger/make.py +++ b/messenger/make.py @@ -1,62 +1,61 @@ -#!/usr/bin/python from __future__ import print_function + import os -import platform import sys import shlex import shutil import subprocess +import platform + +from glob import glob +try: + from ConfigParser import ConfigParser +except ImportError: + from configparser import ConfigParser + +from . import settings + +__all__ = [ + 'get_messenger_dir', + 'get_config', + 'do_build', + 'build_octave', + 'build_matlab' +] def get_messenger_dir(): - # Check the system platform first - splatform = sys.platform - - if splatform.startswith('linux'): - messenger_dir = 'mexa64' - elif splatform.startswith('darwin'): - messenger_dir = 'mexmaci64' - elif splatform.startswith('win32'): - if splatform == "win32": - # We have a win64 messenger, so we need to figure out if this is 32 - # or 64 bit Windows: - if not platform.machine().endswith('64'): - raise ValueError("pymatbridge does not work on win32") - - # We further need to differniate 32 from 64 bit: - maxint = sys.maxsize - if maxint == 9223372036854775807: - messenger_dir = 'mexw64' - elif maxint == 2147483647: - messenger_dir = 'mexw32' - return messenger_dir + host, is_64bit = platform.system(), sys.maxsize > 2**32 + ostype = { + 'Darwin': 'mexmaci64', + 'Linux': 'mexa64', + 'Windows': 'mexw64', + } + if not is_64bit and host == 'Windows': + raise ValueError("pymatbridge does not support 32-bit Windows") + + return ostype[host] if is_64bit else 'mexw32' def get_config(): - messenger_dir = get_messenger_dir() - with open(os.path.join(messenger_dir, 'local.cfg')) as fid: - lines = fid.readlines() - - cfg = {} - for line in lines: - if '=' not in line: - continue - name, path = line.split('=') - cfg[name.lower()] = path.strip() or '.' + config = os.path.join(os.path.realpath(__file__), 'config.ini') + print(config) + cfg = ConfigParser() + config.read(config) return cfg def do_build(make_cmd, messenger_exe): print('Building %s...' % messenger_exe) print(make_cmd) - messenger_dir = get_messenger_dir() - subprocess.check_output(shlex.split(make_cmd), shell=True) + messenger_dir = 'messenger' + '/' + get_messenger_dir() + subprocess.call(shlex.split(make_cmd), stderr=subprocess.STDOUT) messenger_loc = os.path.join(messenger_dir, messenger_exe) - shutil.move(messenger_exe, messenger_loc) + # shutil.move(messenger_exe, messenger_loc) - if os.path.exists('messenger.o'): + if os.path.isfile('messenger.o'): os.remove('messenger.o') @@ -68,45 +67,34 @@ def build_octave(): def build_matlab(static=False): - """build the messenger mex for MATLAB - + """ + Build the messenger mex for MATLAB + + Parameters + ============ static : bool Determines if the zmq library has been statically linked. If so, it will append the command line option -DZMQ_STATIC when compiling the mex so it matches libzmq. """ - cfg = get_config() - # To deal with spaces, remove quotes now, and add - # to the full commands themselves. - matlab_bin = cfg['matlab_bin'].strip('"') - # Get the extension - extcmd = '"' + os.path.join(matlab_bin, "mexext") + '"' - extension = subprocess.check_output(extcmd, shell=True) - extension = extension.decode('utf-8').rstrip('\r\n') + matlab_bin = settings.get_matlab_bin() + cfg, host = ConfigParser(), platform.system() + cfg.read('config.ini') + libzmq = { + 'zmq_lib': os.path.normpath(cfg.get(host, 'ZMQ_LIB')), + 'zmq_inc': os.path.normpath(cfg.get(host, 'ZMQ_INC')), + } + + extcmd = '%s' % os.path.join(matlab_bin, "mexext") + extension = subprocess.check_output(extcmd, shell=True) + extension = os.path.join('messenger', extension.decode('utf-8').rstrip()) # Build the mex file mex = '"' + os.path.join(matlab_bin, "mex") + '"' - paths = "-L%(zmq_lib)s -I%(zmq_inc)s" % cfg - make_cmd = '%s -O %s -lzmq ./src/messenger.c' % (mex, paths) + paths = "-L'%(zmq_lib)s' -I'%(zmq_inc)s'" % libzmq + make_cmd = '%s -O %s -lzmq messenger/src/messenger.c' % (mex, paths) + if static: make_cmd += ' -DZMQ_STATIC' - do_build(make_cmd, 'messenger.%s' % extension) - -if __name__ == '__main__': - import argparse - parser = argparse.ArgumentParser() - parser.add_argument( - "target", - choices=["matlab", "octave"], - type=str.lower, - help="target to be built") - parser.add_argument("--static", action="store_true", - help="staticly link libzmq") - args = parser.parse_args() - if args.target == "matlab": - build_matlab(static=args.static) - elif args.target == "octave": - build_octave() - else: - raise ValueError() + do_build(make_cmd, 'messenger.%s' % extension) diff --git a/messenger/settings.py b/messenger/settings.py new file mode 100644 index 0000000..c51e570 --- /dev/null +++ b/messenger/settings.py @@ -0,0 +1,51 @@ +import os +import platform + +from glob import glob + +try: + from configparser import ConfigParser +except ImportError: + from ConfigParser import ConfigParser + +__all__= ['get_matlab_bin'] + +def get_matlab_bin(config='config.ini'): + """ + Tries to find the MATLAB bin directory independent on host platform. + The operation of this function can be overridden by setting the MATLAB_BIN + variable within the configuration file specified. + + Parameters + -========= + config: + Relative path to configuration file + + Returns + ======= + matlab: + Absolute path to matlab bin directory + """ + cfg, host = ConfigParser(), platform.system() + cfg.read(os.path.join(__file__, config)) + + programs = { + 'Darwin' : r'/Applications', + 'Windows': r'C:/Program Files', + 'Linux' : r'/usr/local', + } + + if cfg.has_option(host, 'MATLAB_BIN'): + matlab = cfg.get(host, 'MATLAB_BIN') + else: + # Searches for Matlab bin if it's not set + _root = glob(r'%s/MATLAB*' % programs[host])[0] + _version = [p for p in os.listdir(_root) if p.startswith('R20')] + if any(_version): + _root = r'%s/%s' % (_root, _version.pop()) + matlab = r'%s/%s' % (_root, 'bin') + + assert os.path.isdir(matlab) + + return os.path.normpath(matlab) + From 0ab40340521e124a60f1a32eb4ba59cbec3ba1e6 Mon Sep 17 00:00:00 2001 From: Sang Han Date: Wed, 25 Mar 2015 06:55:45 -0700 Subject: [PATCH 02/14] deprecated local.cfg --- messenger/make.py | 6 +++--- messenger/mexa64/local.cfg | 6 ------ messenger/mexmaci64/local.cfg | 5 ----- messenger/mexmaci64/messenger.mexmaci64 | Bin 9792 -> 9768 bytes messenger/mexw32/local.cfg | 3 --- messenger/mexw64/local.cfg | 5 ----- 6 files changed, 3 insertions(+), 22 deletions(-) delete mode 100644 messenger/mexa64/local.cfg delete mode 100644 messenger/mexmaci64/local.cfg delete mode 100644 messenger/mexw32/local.cfg delete mode 100644 messenger/mexw64/local.cfg diff --git a/messenger/make.py b/messenger/make.py index 0a5f21d..e77105a 100644 --- a/messenger/make.py +++ b/messenger/make.py @@ -48,12 +48,12 @@ def get_config(): def do_build(make_cmd, messenger_exe): print('Building %s...' % messenger_exe) print(make_cmd) - messenger_dir = 'messenger' + '/' + get_messenger_dir() + messenger_dir = get_messenger_dir() subprocess.call(shlex.split(make_cmd), stderr=subprocess.STDOUT) messenger_loc = os.path.join(messenger_dir, messenger_exe) - # shutil.move(messenger_exe, messenger_loc) + shutil.move(messenger_exe, os.path.join('messenger', messenger_loc)) if os.path.isfile('messenger.o'): os.remove('messenger.o') @@ -87,7 +87,7 @@ def build_matlab(static=False): extcmd = '%s' % os.path.join(matlab_bin, "mexext") extension = subprocess.check_output(extcmd, shell=True) - extension = os.path.join('messenger', extension.decode('utf-8').rstrip()) + extension = extension.decode('utf-8').rstrip() # Build the mex file mex = '"' + os.path.join(matlab_bin, "mex") + '"' diff --git a/messenger/mexa64/local.cfg b/messenger/mexa64/local.cfg deleted file mode 100644 index 54ff2f8..0000000 --- a/messenger/mexa64/local.cfg +++ /dev/null @@ -1,6 +0,0 @@ -MATLAB_BIN=/home/silvester/matlab2014b/bin/ -OCTAVE_INC=/usr/include -OCTAVE_LIB=/usr/lib/x86_64-linux-gnu/ -ZMQ_INC= -ZMQ_LIB= - diff --git a/messenger/mexmaci64/local.cfg b/messenger/mexmaci64/local.cfg deleted file mode 100644 index 1de2d8b..0000000 --- a/messenger/mexmaci64/local.cfg +++ /dev/null @@ -1,5 +0,0 @@ -MATLAB_BIN=/Applications/MATLAB_R2012b.app/bin -ZMQ_INC=/usr/include -ZMQ_LIB=/usr/lib/x86_64-linux-gnu/ -OCTAVE_INC= -OCTAVE_LIB= diff --git a/messenger/mexmaci64/messenger.mexmaci64 b/messenger/mexmaci64/messenger.mexmaci64 index 3cc7b8da8bc4461123e832ea6b73474352cac894..71e946f4d2832908f43aa5680d20ba9ec0e2d9cc 100755 GIT binary patch delta 417 zcmX@$v%+Tq3!}zlMiy(u8H@}JI}{lhBp4VNn1C2WODHig$N}jUDhvz_lVe$|S$`-q zFz8Hv$S6E{0}F@1!eh_APpvWK-FTIApDB}^>gE$H5sZo#fTnN&b!h^z01)2*@SpJ1?YGN-b9#5Eurs0%Lo42}O4 zjn4yA3`A^TBY=bm8ea~=XPn%iEFowN<-im>OkSz1FPMNPnzi|-vJK;AdsRk8pfdo3 COibVa delta 441 zcmZ4CbHHZ-3!}qiMiy(u6^slFClnbNBp4VNn1C2WYbY@=$N}jcDhv!AlVe$|Svi0# zoyiXwg(q)d;Sf+&eD7=e&Z57^VVhOVhcxZYCs-mF6(0ai;Q;E=1Y!XoegWizfHn|= z`I{Zt-muxK0xf(Q_5c6>3@Z>T0L1bFvD`qc7!b<_#L5A&j6kd=5K9BZnz%WO_na_S zcxFk4e^ORza>-;1#YPs8C7ZV^3NjjY09ioA%pegEm zg9ktos0+^jfX4ri#uo!B1|l|~Fc`=|`I8%zB?OHi93Tk+wv$&X>np~giDsekOE$k$ OwqZo_=w?+_Mn(WPDOBVD diff --git a/messenger/mexw32/local.cfg b/messenger/mexw32/local.cfg deleted file mode 100644 index d8d9ff6..0000000 --- a/messenger/mexw32/local.cfg +++ /dev/null @@ -1,3 +0,0 @@ -MATLAB_BIN=/Applications/MATLAB_R2012a.app/bin -HEADER_PATH=/usr/include -LIB_PATH=/usr/local/lib diff --git a/messenger/mexw64/local.cfg b/messenger/mexw64/local.cfg deleted file mode 100644 index daf8ab6..0000000 --- a/messenger/mexw64/local.cfg +++ /dev/null @@ -1,5 +0,0 @@ -MATLAB_BIN="C:\Program Files\MATLAB\2014b\bin" -OCTAVE_INC="C:\Octave\Octave-3.8.2\include\octave-3.8.2\octave" -OCTAVE_LIB="C:\Octave\Octave-3.8.2\lib\octave\3.8.2" -ZMQ_INC="C:\zeromq-4.0.5\include" -ZMQ_LIB="C:\zeromq-4.0.5\lib" From b548443b3e1e18d55c04d727881cbdbaaf7c4502 Mon Sep 17 00:00:00 2001 From: Sang Han Date: Thu, 26 Mar 2015 01:56:14 -0700 Subject: [PATCH 03/14] added get_matlab_env function --- messenger/settings.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/messenger/settings.py b/messenger/settings.py index c51e570..9f4c396 100644 --- a/messenger/settings.py +++ b/messenger/settings.py @@ -1,5 +1,6 @@ import os import platform +import subprocess from glob import glob @@ -8,7 +9,7 @@ except ImportError: from ConfigParser import ConfigParser -__all__= ['get_matlab_bin'] +__all__= ['get_matlab_bin', 'matlab_env'] def get_matlab_bin(config='config.ini'): """ @@ -49,3 +50,25 @@ def get_matlab_bin(config='config.ini'): return os.path.normpath(matlab) +def get_matlab_env(matlab='matlab'): + """ + Get's the underlying enviornement variables set for a matlab installation. + + Parameters + ========== + matlab: string + Path to the matlab binary executable. + If matlab is in the users $PATH, just pass 'matlab' + + Returns + ======= + enviornment: dictionary + Mapping of enviornment variable[s] + """ + command = ' '.join([matlab, '-e']), + process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + + envs = (line.decode('utf-8').strip() for line in process.stdout) + mapping = (env.split('=', maxsplit=1) for env in envs) + + return {key:value for key, value in mapping} From ba6854a1fdcab4faa3389cd846380a2e6e6ce6c5 Mon Sep 17 00:00:00 2001 From: Sang Han Date: Thu, 26 Mar 2015 13:07:44 -0700 Subject: [PATCH 04/14] function for fetching zmq source --- messenger/settings.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/messenger/settings.py b/messenger/settings.py index 9f4c396..d43b1b6 100644 --- a/messenger/settings.py +++ b/messenger/settings.py @@ -1,16 +1,22 @@ import os import platform import subprocess +import logging from glob import glob try: + from urllib.request import urlopen from configparser import ConfigParser except ImportError: + from urllib2 import urlopen from ConfigParser import ConfigParser __all__= ['get_matlab_bin', 'matlab_env'] +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + def get_matlab_bin(config='config.ini'): """ Tries to find the MATLAB bin directory independent on host platform. @@ -72,3 +78,27 @@ def get_matlab_env(matlab='matlab'): mapping = (env.split('=', maxsplit=1) for env in envs) return {key:value for key, value in mapping} + +def fetch_zmq(prefix, version=(4,0,5)): + """ + Download and extract libzmq + + Parameters + ========== + save: str + File Save Location + version: tuple + ZMQ Version Number + """ + logging.info('Downloading ZMQ Version %i.%i.%i' % version) + + url = "http://download.zeromq.org/zeromq-%i.%i.%i.tar.gz" % version + + name, msg = urlretrieve(url, url.rsplit('/')[-1]) + + logging.info('Extracting into prefix %s' % prefix) + with tarfile.open(name) as tar: + tar.extractall(prefix) + + os.remove(name) + logging.info('Download Complete') From 4dfaae107d74840dbdaa00e02e41be7e624dcf93 Mon Sep 17 00:00:00 2001 From: Sang Han Date: Thu, 26 Mar 2015 14:27:50 -0700 Subject: [PATCH 05/14] Fixed windows path --- .idea/scopes/scope_settings.xml | 5 +++++ messenger/settings.py | 25 ++++++++++++------------- setup.py | 10 +++++----- 3 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 .idea/scopes/scope_settings.xml diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000..922003b --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/messenger/settings.py b/messenger/settings.py index d43b1b6..9f473d8 100644 --- a/messenger/settings.py +++ b/messenger/settings.py @@ -2,17 +2,18 @@ import platform import subprocess import logging +import tarfile from glob import glob try: - from urllib.request import urlopen + from urllib.request import urlretrieve from configparser import ConfigParser except ImportError: - from urllib2 import urlopen + from urllib2 import urlretrieve from ConfigParser import ConfigParser -__all__= ['get_matlab_bin', 'matlab_env'] +__all__= ['get_matlab_bin', 'get_matlab_env', 'fetch_zmq'] logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) @@ -58,7 +59,7 @@ def get_matlab_bin(config='config.ini'): def get_matlab_env(matlab='matlab'): """ - Get's the underlying enviornement variables set for a matlab installation. + Get the underlying environment variables set for a matlab installation. Parameters ========== @@ -68,8 +69,8 @@ def get_matlab_env(matlab='matlab'): Returns ======= - enviornment: dictionary - Mapping of enviornment variable[s] + environment: dictionary + Mapping of environment variable[s] """ command = ' '.join([matlab, '-e']), process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) @@ -90,15 +91,13 @@ def fetch_zmq(prefix, version=(4,0,5)): version: tuple ZMQ Version Number """ - logging.info('Downloading ZMQ Version %i.%i.%i' % version) + logger.info('Downloading ZMQ Source Version %i.%i.%i' % version) + url = ("http://download.zeromq.org/zeromq-%i.%i.%i.tar.gz" % version) + name = urlretrieve(url, url.rsplit('/')[-1])[0] - url = "http://download.zeromq.org/zeromq-%i.%i.%i.tar.gz" % version - - name, msg = urlretrieve(url, url.rsplit('/')[-1]) - - logging.info('Extracting into prefix %s' % prefix) + logger.info('Extracting into prefix %s' % prefix) with tarfile.open(name) as tar: tar.extractall(prefix) - os.remove(name) logging.info('Download Complete') + os.remove(name) \ No newline at end of file diff --git a/setup.py b/setup.py index ae9622a..62048cf 100755 --- a/setup.py +++ b/setup.py @@ -2,18 +2,18 @@ """Setup file for python-matlab-bridge""" import os -import sys import shutil import glob # BEFORE importing distutils, remove MANIFEST. distutils doesn't properly # update it when the contents of directories change. -if os.path.exists('MANIFEST'): - os.remove('MANIFEST') +if os.path.exists('MANIFEST'): os.remove('MANIFEST') - -from distutils.core import setup +try: + from setuptools import setup +except ImportError: + from distutils.core import setup # Find the messenger binary file(s) and copy it to /matlab folder. From cc4bfef54581833e745b760d8c41200f86efdd30 Mon Sep 17 00:00:00 2001 From: Sang Han Date: Thu, 26 Mar 2015 14:32:27 -0700 Subject: [PATCH 06/14] Fixed windows path --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 5bd58c1..4c79558 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,5 @@ rebuildTags.sh # caused py setup.py develop pymatbridge.egg-info + +.idea/scopes/scope_settings.xml \ No newline at end of file From df419712ca111c84dcd18a2dedf37a675463d6a3 Mon Sep 17 00:00:00 2001 From: Sang Han Date: Thu, 26 Mar 2015 15:41:27 -0700 Subject: [PATCH 07/14] commit --- messenger/settings.py | 25 ++++++++++++------------- setup.py | 10 +++++----- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/messenger/settings.py b/messenger/settings.py index d43b1b6..9f473d8 100644 --- a/messenger/settings.py +++ b/messenger/settings.py @@ -2,17 +2,18 @@ import platform import subprocess import logging +import tarfile from glob import glob try: - from urllib.request import urlopen + from urllib.request import urlretrieve from configparser import ConfigParser except ImportError: - from urllib2 import urlopen + from urllib2 import urlretrieve from ConfigParser import ConfigParser -__all__= ['get_matlab_bin', 'matlab_env'] +__all__= ['get_matlab_bin', 'get_matlab_env', 'fetch_zmq'] logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) @@ -58,7 +59,7 @@ def get_matlab_bin(config='config.ini'): def get_matlab_env(matlab='matlab'): """ - Get's the underlying enviornement variables set for a matlab installation. + Get the underlying environment variables set for a matlab installation. Parameters ========== @@ -68,8 +69,8 @@ def get_matlab_env(matlab='matlab'): Returns ======= - enviornment: dictionary - Mapping of enviornment variable[s] + environment: dictionary + Mapping of environment variable[s] """ command = ' '.join([matlab, '-e']), process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) @@ -90,15 +91,13 @@ def fetch_zmq(prefix, version=(4,0,5)): version: tuple ZMQ Version Number """ - logging.info('Downloading ZMQ Version %i.%i.%i' % version) + logger.info('Downloading ZMQ Source Version %i.%i.%i' % version) + url = ("http://download.zeromq.org/zeromq-%i.%i.%i.tar.gz" % version) + name = urlretrieve(url, url.rsplit('/')[-1])[0] - url = "http://download.zeromq.org/zeromq-%i.%i.%i.tar.gz" % version - - name, msg = urlretrieve(url, url.rsplit('/')[-1]) - - logging.info('Extracting into prefix %s' % prefix) + logger.info('Extracting into prefix %s' % prefix) with tarfile.open(name) as tar: tar.extractall(prefix) - os.remove(name) logging.info('Download Complete') + os.remove(name) \ No newline at end of file diff --git a/setup.py b/setup.py index ae9622a..62048cf 100755 --- a/setup.py +++ b/setup.py @@ -2,18 +2,18 @@ """Setup file for python-matlab-bridge""" import os -import sys import shutil import glob # BEFORE importing distutils, remove MANIFEST. distutils doesn't properly # update it when the contents of directories change. -if os.path.exists('MANIFEST'): - os.remove('MANIFEST') +if os.path.exists('MANIFEST'): os.remove('MANIFEST') - -from distutils.core import setup +try: + from setuptools import setup +except ImportError: + from distutils.core import setup # Find the messenger binary file(s) and copy it to /matlab folder. From 0266b48480f021a909c239cec36553a0a198119b Mon Sep 17 00:00:00 2001 From: Sang Han Date: Thu, 26 Mar 2015 19:34:31 -0700 Subject: [PATCH 08/14] fixed bug with zip-safe --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 62048cf..8e7c896 100755 --- a/setup.py +++ b/setup.py @@ -43,6 +43,7 @@ version=VERSION, packages=PACKAGES, package_data=PACKAGE_DATA, + zip_safe=False, requires=REQUIRES, #extras_require=EXTRAS_REQUIRE, scripts=BIN From d7797ee31318f87081cf89499411bbdc6767647a Mon Sep 17 00:00:00 2001 From: Sang Han Date: Thu, 26 Mar 2015 19:40:01 -0700 Subject: [PATCH 09/14] cleanup --- .gitignore | 2 +- .idea/scopes/scope_settings.xml | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 .idea/scopes/scope_settings.xml diff --git a/.gitignore b/.gitignore index 4c79558..6f374ea 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,4 @@ rebuildTags.sh # caused py setup.py develop pymatbridge.egg-info -.idea/scopes/scope_settings.xml \ No newline at end of file +.idea/** diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml deleted file mode 100644 index 922003b..0000000 --- a/.idea/scopes/scope_settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file From d4476c73b9e6ac5c6bed3e1d029e1ca0c5ac3da1 Mon Sep 17 00:00:00 2001 From: Sang Han Date: Thu, 26 Mar 2015 19:54:01 -0700 Subject: [PATCH 10/14] urllib can go die --- messenger/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/messenger/settings.py b/messenger/settings.py index 9f473d8..0639f21 100644 --- a/messenger/settings.py +++ b/messenger/settings.py @@ -10,7 +10,7 @@ from urllib.request import urlretrieve from configparser import ConfigParser except ImportError: - from urllib2 import urlretrieve + from urllib import urlretrieve from ConfigParser import ConfigParser __all__= ['get_matlab_bin', 'get_matlab_env', 'fetch_zmq'] @@ -100,4 +100,4 @@ def fetch_zmq(prefix, version=(4,0,5)): tar.extractall(prefix) logging.info('Download Complete') - os.remove(name) \ No newline at end of file + os.remove(name) From 436ae0d0c0c8edf939199079643310c4949f0043 Mon Sep 17 00:00:00 2001 From: Sang Han Date: Thu, 26 Mar 2015 22:46:19 -0700 Subject: [PATCH 11/14] get_config() now actually returns a dict for the host platform --- messenger/__init__.py | 3 +- messenger/__main__.py | 25 ++++++++-------- messenger/make.py | 67 ++++++++++++++++++++++++++++++++----------- messenger/settings.py | 58 ++++--------------------------------- 4 files changed, 70 insertions(+), 83 deletions(-) diff --git a/messenger/__init__.py b/messenger/__init__.py index c70020d..da40056 100644 --- a/messenger/__init__.py +++ b/messenger/__init__.py @@ -1 +1,2 @@ -from .settings import * \ No newline at end of file +from .settings import * +from .make import * \ No newline at end of file diff --git a/messenger/__main__.py b/messenger/__main__.py index ce3ef9c..456f855 100644 --- a/messenger/__main__.py +++ b/messenger/__main__.py @@ -1,3 +1,5 @@ +import sys + from argparse import ArgumentParser from .make import * @@ -10,8 +12,8 @@ def command_line(): ======= Namespace containing parsed arguments """ + parser = ArgumentParser(prog='messenger') - parser = ArgumentParser() parser.add_argument( "target", choices=["matlab", "octave"], @@ -21,20 +23,19 @@ def command_line(): parser.add_argument( "--static", action="store_true", - help="staticly link libzmq" + help="statically link libzmq" ) return parser.parse_args() - - def main(): - args = command_line() - if args.target == "matlab": - build_matlab(static=args.static) - elif args.target == "octave": - build_octave() - else: - raise ValueError() + args = command_line() + build = { + 'matlab': build_matlab, + 'octave': build_octave, + } + target = build[args.target] + + return target(static=args.static) if __name__ == '__main__': - main() + sys.exit(main()) diff --git a/messenger/make.py b/messenger/make.py index e77105a..a430e1e 100644 --- a/messenger/make.py +++ b/messenger/make.py @@ -6,8 +6,7 @@ import shutil import subprocess import platform - -from glob import glob +import glob try: from ConfigParser import ConfigParser @@ -18,6 +17,7 @@ __all__ = [ 'get_messenger_dir', + 'get_matlab_bin' 'get_config', 'do_build', 'build_octave', @@ -37,12 +37,12 @@ def get_messenger_dir(): return ostype[host] if is_64bit else 'mexw32' -def get_config(): - config = os.path.join(os.path.realpath(__file__), 'config.ini') - print(config) +def get_config(host, config='config.ini'): + cfg = ConfigParser() - config.read(config) - return cfg + cfg.read(config) + + return dict(cfg.items(host)) def do_build(make_cmd, messenger_exe): @@ -59,9 +59,9 @@ def do_build(make_cmd, messenger_exe): os.remove('messenger.o') -def build_octave(): +def build_octave(static=False): paths = "-L%(octave_lib)s -I%(octave_inc)s -L%(zmq_lib)s -I%(zmq_inc)s" - paths = paths % get_config() + paths = paths % get_config(platform.system()) make_cmd = "mkoctfile --mex %s -lzmq ./src/messenger.c" % paths do_build(make_cmd, 'messenger.mex') @@ -77,13 +77,7 @@ def build_matlab(static=False): If so, it will append the command line option -DZMQ_STATIC when compiling the mex so it matches libzmq. """ - matlab_bin = settings.get_matlab_bin() - cfg, host = ConfigParser(), platform.system() - cfg.read('config.ini') - libzmq = { - 'zmq_lib': os.path.normpath(cfg.get(host, 'ZMQ_LIB')), - 'zmq_inc': os.path.normpath(cfg.get(host, 'ZMQ_INC')), - } + matlab_bin, cfg = settings.get_matlab_bin(), get_config(platform.system()) extcmd = '%s' % os.path.join(matlab_bin, "mexext") extension = subprocess.check_output(extcmd, shell=True) @@ -91,10 +85,49 @@ def build_matlab(static=False): # Build the mex file mex = '"' + os.path.join(matlab_bin, "mex") + '"' - paths = "-L'%(zmq_lib)s' -I'%(zmq_inc)s'" % libzmq + paths = "-L'%(zmq_lib)s' -I'%(zmq_inc)s'" % cfg make_cmd = '%s -O %s -lzmq messenger/src/messenger.c' % (mex, paths) if static: make_cmd += ' -DZMQ_STATIC' do_build(make_cmd, 'messenger.%s' % extension) + + +def get_matlab_bin(config='config.ini'): + """ + Tries to find the MATLAB bin directory independent on host platform. + The operation of this function can be overridden by setting the MATLAB_BIN + variable within the configuration file specified. + + Parameters + -========= + config: + Relative path to configuration file + + Returns + ======= + matlab: + Absolute path to matlab bin directory + """ + host = platform.system() + cfg = get_config(host) + programs = { + 'Darwin' : r'/Applications', + 'Windows': r'C:/Program Files', + 'Linux' : r'/usr/local', + } + + if cfg.get('MATLAB_BIN', None): + matlab = cfg['MATLAB_BIN'] + else: + # Searches for Matlab bin if it's not set + _root = glob.glob(r'%s/MATLAB*' % programs[host])[0] + _version = [p for p in os.listdir(_root) if p.startswith('R20')] + if _version: + _root = r'%s/%s' % (_root, _version.pop()) + matlab = r'%s/%s' % (_root, 'bin') + + assert os.path.isdir(matlab) + + return os.path.normpath(matlab) diff --git a/messenger/settings.py b/messenger/settings.py index 0639f21..a650350 100644 --- a/messenger/settings.py +++ b/messenger/settings.py @@ -1,61 +1,14 @@ import os -import platform import subprocess import logging import tarfile -from glob import glob - try: from urllib.request import urlretrieve - from configparser import ConfigParser except ImportError: from urllib import urlretrieve - from ConfigParser import ConfigParser - -__all__= ['get_matlab_bin', 'get_matlab_env', 'fetch_zmq'] - -logging.basicConfig(level=logging.INFO) -logger = logging.getLogger(__name__) - -def get_matlab_bin(config='config.ini'): - """ - Tries to find the MATLAB bin directory independent on host platform. - The operation of this function can be overridden by setting the MATLAB_BIN - variable within the configuration file specified. - - Parameters - -========= - config: - Relative path to configuration file - - Returns - ======= - matlab: - Absolute path to matlab bin directory - """ - cfg, host = ConfigParser(), platform.system() - cfg.read(os.path.join(__file__, config)) - - programs = { - 'Darwin' : r'/Applications', - 'Windows': r'C:/Program Files', - 'Linux' : r'/usr/local', - } - - if cfg.has_option(host, 'MATLAB_BIN'): - matlab = cfg.get(host, 'MATLAB_BIN') - else: - # Searches for Matlab bin if it's not set - _root = glob(r'%s/MATLAB*' % programs[host])[0] - _version = [p for p in os.listdir(_root) if p.startswith('R20')] - if any(_version): - _root = r'%s/%s' % (_root, _version.pop()) - matlab = r'%s/%s' % (_root, 'bin') - - assert os.path.isdir(matlab) - return os.path.normpath(matlab) +__all__= ['get_matlab_env', 'fetch_zmq'] def get_matlab_env(matlab='matlab'): """ @@ -76,9 +29,8 @@ def get_matlab_env(matlab='matlab'): process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) envs = (line.decode('utf-8').strip() for line in process.stdout) - mapping = (env.split('=', maxsplit=1) for env in envs) - return {key:value for key, value in mapping} + return dict(env.split('=', maxsplit=1) for env in envs) def fetch_zmq(prefix, version=(4,0,5)): """ @@ -91,13 +43,13 @@ def fetch_zmq(prefix, version=(4,0,5)): version: tuple ZMQ Version Number """ - logger.info('Downloading ZMQ Source Version %i.%i.%i' % version) + print('Downloading ZMQ Source Version %i.%i.%i' % version) url = ("http://download.zeromq.org/zeromq-%i.%i.%i.tar.gz" % version) name = urlretrieve(url, url.rsplit('/')[-1])[0] - logger.info('Extracting into prefix %s' % prefix) + print('Extracting into prefix %s' % prefix) with tarfile.open(name) as tar: tar.extractall(prefix) - logging.info('Download Complete') + print('Download Complete') os.remove(name) From 7eb892aa00b4828b4544cbbbd9f8a04d138ef8a1 Mon Sep 17 00:00:00 2001 From: Sang Han Date: Thu, 26 Mar 2015 22:52:47 -0700 Subject: [PATCH 12/14] oops forgot a comma --- messenger/make.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messenger/make.py b/messenger/make.py index a430e1e..eab158c 100644 --- a/messenger/make.py +++ b/messenger/make.py @@ -17,7 +17,7 @@ __all__ = [ 'get_messenger_dir', - 'get_matlab_bin' + 'get_matlab_bin', 'get_config', 'do_build', 'build_octave', From 4a61fae375b6c768895b8c35d1ad04277904d153 Mon Sep 17 00:00:00 2001 From: Sang Han Date: Fri, 27 Mar 2015 05:50:54 -0700 Subject: [PATCH 13/14] Spring cleaning. All relevant setup information is inside setup.py --- .gitignore | 1 + LICENSE | 30 +++++++++++++ pymatbridge/__init__.py | 4 +- pymatbridge/__version__.py | 3 ++ pymatbridge/version.py | 90 -------------------------------------- setup.py | 80 +++++++++++++++++++-------------- version.py | 1 + 7 files changed, 84 insertions(+), 125 deletions(-) create mode 100644 pymatbridge/__version__.py delete mode 100644 pymatbridge/version.py create mode 120000 version.py diff --git a/.gitignore b/.gitignore index 6f374ea..ed1fd60 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,4 @@ rebuildTags.sh pymatbridge.egg-info .idea/** +dist/** diff --git a/LICENSE b/LICENSE index d3632fc..2759572 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,33 @@ +Pymatbridge +=========== + +A python interface to call out to Matlab(R). + + +License information +=================== + +Copyright (c) 2012 -- , Max Jaderberg, Ariel Rokem, Haoxing Zhao +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +Neither the name of the Oxford University, Stanford University nor the names of +its contributors may be used to endorse or promote products derived from this +software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + Copyright (c) 2013. See "Contributors". MATLAB (R) is copyright of the Mathworks. All rights reserved. diff --git a/pymatbridge/__init__.py b/pymatbridge/__init__.py index 45d2145..bc6b244 100644 --- a/pymatbridge/__init__.py +++ b/pymatbridge/__init__.py @@ -1,5 +1,6 @@ from .pymatbridge import * -from .version import __version__ +from .__version__ import __version__ +from .__version__ import __build__ try: from .publish import * @@ -10,3 +11,4 @@ from .matlab_magic import * except ImportError: pass + diff --git a/pymatbridge/__version__.py b/pymatbridge/__version__.py new file mode 100644 index 0000000..ec2406a --- /dev/null +++ b/pymatbridge/__version__.py @@ -0,0 +1,3 @@ +__version__ = '0.5.0' +__build__ = 'dev' + diff --git a/pymatbridge/version.py b/pymatbridge/version.py deleted file mode 100644 index 0b9ef31..0000000 --- a/pymatbridge/version.py +++ /dev/null @@ -1,90 +0,0 @@ -"""pymatbridge version/release information""" - -# Format expected by setup.py and doc/source/conf.py: string of form "X.Y.Z" -_version_major = 0 -_version_minor = 5 -_version_micro = 0 #'' # use '' for first of series, number for 1 and above -_version_extra = 'dev' -#_version_extra = '' # Uncomment this for full releases - -# Construct full version string from these. -_ver = [_version_major, _version_minor] -if _version_micro: - _ver.append(_version_micro) -if _version_extra: - _ver.append(_version_extra) - -__version__ = '.'.join(map(str, _ver)) - -CLASSIFIERS = ["Development Status :: 3 - Alpha", - "Environment :: Console", - "Intended Audience :: Science/Research", - "License :: OSI Approved :: BSD License", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Topic :: Scientific/Engineering"] - -description = "pymatbridge is a set of python and matlab functions to allow these two systems to talk to each other" - -long_description = """ - -Pymatbridge -=========== - -A python interface to call out to Matlab(R). - - -License information -=================== - -Copyright (c) 2012 -- , Max Jaderberg, Ariel Rokem, Haoxing Zhao -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -Redistributions of source code must retain the above copyright notice, this -list of conditions and the following disclaimer. - -Redistributions in binary form must reproduce the above copyright notice, this -list of conditions and the following disclaimer in the documentation and/or -other materials provided with the distribution. - -Neither the name of the Oxford University, Stanford University nor the names of -its contributors may be used to endorse or promote products derived from this -software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -""" - -NAME = "pymatbridge" -MAINTAINER = "Ariel Rokem" -MAINTAINER_EMAIL = "arokem@gmail.com" -DESCRIPTION = description -LONG_DESCRIPTION = long_description -URL = "https://github.com/arokem/python-matlab-bridge" -DOWNLOAD_URL = "https://github.com/arokem/python-matlab-bridge/archive/master.tar.gz" -LICENSE = "BSD" -AUTHOR = "https://github.com/arokem/python-matlab-bridge/contributors" -AUTHOR_EMAIL = "arokem@gmail.com" -PLATFORMS = "OS Independent" -MAJOR = _version_major -MINOR = _version_minor -MICRO = _version_micro -VERSION = __version__ -PACKAGES = ['pymatbridge'] -PACKAGE_DATA = {"pymatbridge": ["matlab/matlabserver.m", "matlab/messenger.*", - "matlab/usrprog/*", "matlab/util/*.m", - "matlab/util/json_v0.2.2/LICENSE", - "matlab/util/json_v0.2.2/README.md", - "matlab/util/json_v0.2.2/test/*", - "matlab/util/json_v0.2.2/json/*.m", - "matlab/util/json_v0.2.2/json/java/*", - "tests/*.py", "examples/*.ipynb"]} - -REQUIRES = ['pyzmq'] -#EXTRAS_REQUIRE = ['numpy', 'scipy', 'ipython'] - -BIN=['scripts/publish-notebook'] diff --git a/setup.py b/setup.py index 8e7c896..7dda5ab 100755 --- a/setup.py +++ b/setup.py @@ -1,11 +1,12 @@ -#!/usr/bin/env python -"""Setup file for python-matlab-bridge""" +# -*- coding: utf-8 -*- +""" +Pymatbridge: A python interface to call out to Matlab(R) +""" import os import shutil import glob - # BEFORE importing distutils, remove MANIFEST. distutils doesn't properly # update it when the contents of directories change. if os.path.exists('MANIFEST'): os.remove('MANIFEST') @@ -15,41 +16,52 @@ except ImportError: from distutils.core import setup - # Find the messenger binary file(s) and copy it to /matlab folder. from messenger.make import get_messenger_dir -messenger_dir = get_messenger_dir() +from version import __version__, __build__ -for f in glob.glob("./messenger/%s/messenger.*" % messenger_dir): +for f in glob.glob("./messenger/%s/messenger.*" % get_messenger_dir()): shutil.copy(f, "./pymatbridge/matlab") - -# Get version and release info, which is all stored in pymatbridge/version.py -ver_file = os.path.join('pymatbridge', 'version.py') -exec(open(ver_file).read()) - -opts = dict(name=NAME, - maintainer=MAINTAINER, - maintainer_email=MAINTAINER_EMAIL, - description=DESCRIPTION, - long_description=LONG_DESCRIPTION, - url=URL, - download_url=DOWNLOAD_URL, - license=LICENSE, - classifiers=CLASSIFIERS, - author=AUTHOR, - author_email=AUTHOR_EMAIL, - platforms=PLATFORMS, - version=VERSION, - packages=PACKAGES, - package_data=PACKAGE_DATA, - zip_safe=False, - requires=REQUIRES, - #extras_require=EXTRAS_REQUIRE, - scripts=BIN - ) - - # Now call the actual setup function if __name__ == '__main__': - setup(**opts) + setup( + name="pymatbridge", + maintainer="Ariel Rokem", + maintainer_email="arokem@gmail.com", + description=__doc__, + long_description=open('LICENSE').read(), + url="https://github.com/arokem/python-matlab-bridge", + download_url="https://github.com/arokem/python-matlab-bridge/archive/master.tar.gz", + license='BSD', + author="https://github.com/arokem/python-matlab-bridge/contributors", + author_email="arokem@gmail.com", + platforms="OS Independent", + version='.'.join([__version__, __build__]), + packages=['pymatbridge'], + package_data={ + "pymatbridge": [ + "matlab/matlabserver.m", "matlab/messenger.*", + "matlab/usrprog/*", "matlab/util/*.m", + "matlab/util/json_v0.2.2/LICENSE", + "matlab/util/json_v0.2.2/README.md", + "matlab/util/json_v0.2.2/test/*", + "matlab/util/json_v0.2.2/json/*.m", + "matlab/util/json_v0.2.2/json/java/*", + "tests/*.py", "examples/*.ipynb" + ] + }, + zip_safe=False, + requires=['pyzmq'], + scripts=['scripts/publish-notebook'], + classifiers=[ + "Development Status :: 3 - Alpha", + "Environment :: Console", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: BSD License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Topic :: Scientific/Engineering", + ], + #extras_require=['numpy', 'scipy', 'ipython'] + ) diff --git a/version.py b/version.py new file mode 120000 index 0000000..c3709ac --- /dev/null +++ b/version.py @@ -0,0 +1 @@ +pymatbridge/__version__.py \ No newline at end of file From d940de3173560e72e72e3a6ecfa99c7ab4efc795 Mon Sep 17 00:00:00 2001 From: Sang Han Date: Fri, 27 Mar 2015 09:21:18 -0700 Subject: [PATCH 14/14] import only bare minimum through exec --- setup.py | 14 +++++++++----- version.py | 1 - 2 files changed, 9 insertions(+), 6 deletions(-) delete mode 120000 version.py diff --git a/setup.py b/setup.py index 7dda5ab..37785e8 100755 --- a/setup.py +++ b/setup.py @@ -2,7 +2,6 @@ """ Pymatbridge: A python interface to call out to Matlab(R) """ - import os import shutil import glob @@ -11,6 +10,9 @@ # update it when the contents of directories change. if os.path.exists('MANIFEST'): os.remove('MANIFEST') +# Set Version Info +exec(open('pymatbridge/__version__.py').read()) + try: from setuptools import setup except ImportError: @@ -18,10 +20,9 @@ # Find the messenger binary file(s) and copy it to /matlab folder. from messenger.make import get_messenger_dir -from version import __version__, __build__ -for f in glob.glob("./messenger/%s/messenger.*" % get_messenger_dir()): - shutil.copy(f, "./pymatbridge/matlab") +for f in glob.glob("messenger/%s/messenger.*" % get_messenger_dir()): + shutil.copy(f, 'pymatbridge/matlab/') # Now call the actual setup function if __name__ == '__main__': @@ -38,7 +39,10 @@ author_email="arokem@gmail.com", platforms="OS Independent", version='.'.join([__version__, __build__]), - packages=['pymatbridge'], + packages=['pymatbridge', 'messenger'], + data_files=[ + ('pymatbridge/matlab', ['messenger/mexmaci64/messenger.mex']) + ], package_data={ "pymatbridge": [ "matlab/matlabserver.m", "matlab/messenger.*", diff --git a/version.py b/version.py deleted file mode 120000 index c3709ac..0000000 --- a/version.py +++ /dev/null @@ -1 +0,0 @@ -pymatbridge/__version__.py \ No newline at end of file