Skip to content

refactor commands/scripts to expose only one named mne #866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 2, 2013
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ codespell:
manpages:
@echo "I: generating manpages"
set -e; mkdir -p build/manpages && \
cd bin && for f in *; do \
cd bin && for f in mne*; do \
descr=$$(grep -h -e "^ *'''" -e 'DESCRIP =' $$f -h | sed -e "s,.*' *\([^'][^']*\)'.*,\1,g" | head -n 1); \
PYTHONPATH=../ \
help2man -n "$$descr" --no-discard-stderr --no-info --version-string "$(uver)" ./$$f \
Expand Down
46 changes: 46 additions & 0 deletions bin/mne
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python

import sys
import glob
import subprocess
import os.path as op

import mne
Copy link
Member

Choose a reason for hiding this comment

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

we should think about optimizing import speed. it takes too long to wait for the help print


mne_bin_dir = op.dirname(mne.__file__)
valid_commands = sorted(glob.glob(op.join(mne_bin_dir, 'commands', 'mne_*.py')))
Copy link
Member

Choose a reason for hiding this comment

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

filtering is not needed here, os.listdir will be 50 % faster

valid_commands = [c.split(op.sep)[-1][4:-3] for c in valid_commands]

def print_help():
print "Usage : mne command options\n"
print "Accepted commands :\n"
for c in valid_commands:
print "\t- %s" % c
print "\nExample : mne browse_raw --raw sample_audvis_raw.fif"
print "\nGetting help example : mne compute_proj_eog -h"
sys.exit(0)

if len(sys.argv) == 1:
print_help()
elif ("help" in sys.argv[1] or "-h" in sys.argv[1]):
print_help()
elif sys.argv[1] == "--version":
print "MNE %s" % mne.__version__
elif sys.argv[1] not in valid_commands:
print 'Invalid command: "%s"\n' % sys.argv[1]
print_help()
sys.exit(0)
else:
cmd = sys.argv[1]
cmd_path = op.join(mne_bin_dir, 'commands', 'mne_%s.py' % cmd)
p = subprocess.Popen([cmd_path] + sys.argv[2:],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
if stdout.startswith('Usage'):
stdout = stdout.replace("mne_", "mne ")
stdout = stdout.replace(".py", "")
if p.returncode:
print stderr, stdout
else:
print stdout
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 5 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env python
#
# Copyright (C) 2011 Alexandre Gramfort <gramfort@nmr.mgh.harvard.edu>
# Copyright (C) 2011-2013 Alexandre Gramfort <gramfort@nmr.mgh.harvard.edu>

import os
import mne
Expand Down Expand Up @@ -67,14 +67,11 @@
'mne.tests',
'mne.stats', 'mne.stats.tests',
'mne.time_frequency', 'mne.time_frequency.tests',
'mne.realtime', 'mne.realtime.tests', 'mne.decoding',
'mne.decoding.tests'],
'mne.realtime', 'mne.realtime.tests',
'mne.decoding', 'mne.decoding.tests',
'mne.commands'],
package_data={'mne': ['data/*.sel',
'data/icos.fif.gz',
'data/coil_def.dat',
'layouts/*.lout']},
scripts=['bin/mne_clean_eog_ecg.py', 'bin/mne_flash_bem_model.py',
'bin/mne_surf2bem.py', 'bin/mne_compute_proj_ecg.py',
'bin/mne_compute_proj_eog.py', 'bin/mne_maxfilter.py',
'bin/mne_bti2fiff.py', 'bin/mne_kit2fiff.py',
'bin/mne_browse_raw.py', 'bin/mne_make_scalp_surfaces.py'])
scripts=['bin/mne'])
Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't original MNE have an 'mne' cmdline? or is it a proper 'MNE'? ;)

Copy link
Member

Choose a reason for hiding this comment

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

Not just mne, no -- they all are mne_*, e.g. mne_process_raw.

Copy link
Contributor

Choose a reason for hiding this comment

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

On Fri, 01 Nov 2013, Eric89GXL wrote:

In setup.py:

       package_data={'mne': ['data/*.sel',
                             'data/icos.fif.gz',
                             'data/coil_def.dat',
                             'layouts/*.lout']},
  •      scripts=['bin/mne_clean_eog_ecg.py', 'bin/mne_flash_bem_model.py',
    
  •               'bin/mne_surf2bem.py', 'bin/mne_compute_proj_ecg.py',
    
  •               'bin/mne_compute_proj_eog.py', 'bin/mne_maxfilter.py',
    
  •               'bin/mne_bti2fiff.py', 'bin/mne_kit2fiff.py',
    
  •               'bin/mne_browse_raw.py', 'bin/mne_make_scalp_surfaces.py'])
    
  •      scripts=['bin/mne'])
    

Not just mne, no -- they all are mne_*, e.g. mne_process_raw.

the idea is to have only 1 public level script (consider git) which
would proxy calls to the other mne_* scripts (e.g. mne_process_raw) so
instead of typing 'mne_process_raw' you would have 'mne process_raw'

Yaroslav O. Halchenko, Ph.D.
http://neuro.debian.net http://www.pymvpa.org http://www.fail2ban.org
Senior Research Associate, Psychological and Brain Sciences Dept.
Dartmouth College, 419 Moore Hall, Hinman Box 6207, Hanover, NH 03755
Phone: +1 (603) 646-9834 Fax: +1 (603) 646-1419
WWW: http://www.linkedin.com/in/yarik

Copy link
Member

Choose a reason for hiding this comment

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

I know -- I was responding to your comment asking if the original MNE had an mne command. I must have misunderstood.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah -- fault is mine + github. In the email I replied to it was just code and your answer without my question which I successfully forgotten to have placed at that point ;) so -- thanks!

happen stock MNE comes up with its cmdline single command, could we pursuade them to make it e.g. capitalcased? ;)

Copy link
Member

Choose a reason for hiding this comment

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

but still, will this -- as proposed -- resove the name space issue? Wasn't the initial proposal to have mne-python my_command and mne my_command