Skip to content
Merged
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
52 changes: 31 additions & 21 deletions messenger/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ 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))
subprocess.check_output(shlex.split(make_cmd), shell=True)

messenger_loc = os.path.join(messenger_dir, messenger_exe)

Expand All @@ -67,36 +67,46 @@ def build_octave():
do_build(make_cmd, 'messenger.mex')


def build_matlab():
def build_matlab(static=False):
"""build the messenger mex for MATLAB

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()
matlab_bin = cfg['matlab_bin']
# To deal with spaces, remove quotes now, and add
# to the full commands themselves.
matlab_bin = cfg['matlab_bin'].strip('"')
# Get the extension
if sys.platform == 'win32':
extcmd = '"%s\\mexext.bat"' % matlab_bin
else:
extcmd = matlab_bin + "/mexext"

check_extension = subprocess.Popen(extcmd, stdout=subprocess.PIPE)
extension = check_extension.stdout.read()
extcmd = '"' + os.path.join(matlab_bin, "mexext") + '"'
extension = subprocess.check_output(extcmd, shell=True)
extension = extension.decode('utf-8').rstrip('\r\n')

# Build the mex file
if sys.platform == 'win32':
mex = matlab_bin + "\\mex.bat"
else:
mex = matlab_bin + "/mex"
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)
if static:
make_cmd += ' -DZMQ_STATIC'
do_build(make_cmd, 'messenger.%s' % extension)


if __name__ == '__main__':
usage = 'Please specify a valid make target (Matlab or Octave)'
if len(sys.argv) < 2:
print(usage)
elif sys.argv[1].lower() == 'matlab':
build_matlab()
elif sys.argv[1].lower() == 'octave':
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()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it might be confusing. If someone enters a typo, it will try to build the octave thing and emit a confusing error. How about:

elif args.target == 'octave':
    build_octave
else: 
    e_s = "'%s' is not a valid target for building the messenger."%args.target
    e_s = e_s + " Use 'matlab' or 'octave'" 
    raise ValueError(e_s)

Or something to that effect. Also, could you please rebase on master? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't let you choose another one because argparse limits the choices.

for example, running ./make.py foo will give:
usage: make.py [-h] [--static] {matlab,octave}
make.py: error: argument target: invalid choice: 'foo' (choose from
'matlab', 'octave')

On Mon, Mar 9, 2015 at 7:54 PM, Ariel Rokem notifications@github.com
wrote:

In messenger/make.py
#161 (comment)
:

 else:
  •    print(usage)
    
  •    build_octave()
    

This seems like it might be confusing. If someone enters a typo, it will
try to build the octave thing and emit a confusing error. How about:

elif args.target == 'octave':
build_octave
else:
e_s = "'%s' is not a valid target for building the messenger."%args.target
e_s = e_s + " Use 'matlab' or 'octave'"
raise ValueError(e_s)

Or something to that effect. Also, could you please rebase on master?
Thanks!


Reply to this email directly or view it on GitHub
https://github.com/arokem/python-matlab-bridge/pull/161/files#r26095797.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll still change it though... it is your repo after all :)

On Mon, Mar 9, 2015 at 8:01 PM, Ali Ebrahim aebrahim@ucsd.edu wrote:

It won't let you choose another one because argparse limits the choices.

for example, running ./make.py foo will give:
usage: make.py [-h] [--static] {matlab,octave}
make.py: error: argument target: invalid choice: 'foo' (choose from
'matlab', 'octave')

On Mon, Mar 9, 2015 at 7:54 PM, Ariel Rokem notifications@github.com
wrote:

In messenger/make.py
#161 (comment)
:

 else:
  •    print(usage)
    
  •    build_octave()
    

This seems like it might be confusing. If someone enters a typo, it will
try to build the octave thing and emit a confusing error. How about:

elif args.target == 'octave':
build_octave
else:
e_s = "'%s' is not a valid target for building the messenger."%args.target
e_s = e_s + " Use 'matlab' or 'octave'"
raise ValueError(e_s)

Or something to that effect. Also, could you please rebase on master?
Thanks!


Reply to this email directly or view it on GitHub
https://github.com/arokem/python-matlab-bridge/pull/161/files#r26095797
.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. No need to change - I just really didn't know how that works. I see the whole thing above now. Cool. Thanks for doing this - much cleaner.

else:
print(usage)
raise ValueError()
4 changes: 2 additions & 2 deletions messenger/mexw64/local.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MATLAB_BIN=/Applications/MATLAB_R2012a.app/bin
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\src\.libs"
ZMQ_LIB="C:\zeromq-4.0.5\lib"
Binary file modified messenger/mexw64/messenger.mexw64
Binary file not shown.