X Tutup
Skip to content

Commit 9fd59a9

Browse files
committed
use optparse for option parsing
Also added a --version command line option.
1 parent 267c897 commit 9fd59a9

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

bpython/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
22+
23+
24+
__version__ = '0.9.1'

bpython/cli.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import pydoc
4747
import types
4848
from cStringIO import StringIO
49+
from optparse import OptionParser
4950
from urlparse import urljoin
5051
from xmlrpclib import ServerProxy, Error as XMLRPCError
5152
from ConfigParser import ConfigParser, NoSectionError, NoOptionError
@@ -65,6 +66,8 @@
6566
Group, OneOrMore, ZeroOrMore, Literal, Optional, Word, \
6667
alphas, alphanums, printables, ParseException
6768

69+
from bpython import __version__
70+
6871
def log(x):
6972
f = open('/home/bob/tmp/bpython.out', 'a')
7073
f.write('%s\n' % (x,))
@@ -1794,7 +1797,7 @@ def migrate_rc(path):
17941797

17951798

17961799

1797-
def loadini():
1800+
def loadini(configfile):
17981801
"""Loads .ini configuration file and stores its values in OPTS"""
17991802
class CP(ConfigParser):
18001803
def safeget(self, section, option, default):
@@ -1812,10 +1815,7 @@ def safeget(self, section, option, default):
18121815
except ValueError:
18131816
return v
18141817

1815-
if len(sys.argv) > 2:
1816-
configfile = sys.argv[2]
1817-
else:
1818-
configfile = os.path.expanduser('~/.bpython.ini')
1818+
configfile = os.path.expanduser(configfile)
18191819

18201820
config = CP()
18211821
config.read(configfile)
@@ -1887,7 +1887,24 @@ def main_curses(scr):
18871887
return repl.getstdout()
18881888

18891889

1890-
def main():
1890+
def main(args=None):
1891+
if args is None:
1892+
args = sys.argv
1893+
1894+
parser = OptionParser()
1895+
parser.add_option('--config', '-c', default='~/.bpython.ini',
1896+
help='use CONFIG instead of default config file')
1897+
parser.add_option('--version', '-V', action='store_true',
1898+
help='print version and exit')
1899+
1900+
options, args = parser.parse_args(args)
1901+
1902+
if options.version:
1903+
print 'bpython version', __version__,
1904+
print 'on top of Python', sys.version.split()[0]
1905+
print '(C) 2008-2009 Bob Farrell et al. See AUTHORS for detail.'
1906+
return
1907+
18911908
if not os.isatty(sys.stdin.fileno()):
18921909
interpreter = code.InteractiveInterpreter()
18931910
interpreter.runsource(sys.stdin.read())
@@ -1898,7 +1915,7 @@ def main():
18981915
path = os.path.expanduser('~/.bpythonrc') # migrating old configuration file
18991916
if os.path.isfile(path):
19001917
migrate_rc(path)
1901-
loadini()
1918+
loadini(options.config)
19021919

19031920
try:
19041921
o = curses.wrapper(main_curses)

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
import re
99
import sys
1010

11+
from bpython import __version__
12+
1113
if platform.system() == 'FreeBSD':
1214
man_dir = 'man'
1315
else:
1416
man_dir = 'share/man'
1517

1618
setup(
1719
name="bpython",
18-
version = "0.9.1",
20+
version = __version__,
1921
author = "Robert Anthony Farrell",
2022
author_email = "robertanthonyfarrell@gmail.com",
2123
description = "Fancy Interface to the Python Interpreter",

0 commit comments

Comments
 (0)
X Tutup