mirror of
https://github.com/kennethreitz-archive/bpython-gist.git
synced 2026-06-05 23:50:18 +00:00
Whoosh, I've switched over to an installable package.
Pascal Bleser was kind enough to package bpython for OpenSUSE and sent me a patch to have it working with distutils, which is always nice, so thanks a lot for that, here's the new dir structure.
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
v0.2.4
|
||||
======
|
||||
Thanks a lot to Angus Gibson for submitting a patch to fix a problem
|
||||
I was having with initialising the keyboard stuff in curses properly.
|
||||
|
||||
Also a big thanks to John Beisley for providing the patch that shows
|
||||
a class __init__ method's argspec on class instantiation.
|
||||
|
||||
I've fixed up the argspec display so it handles really long argspecs
|
||||
(e.g. subprocess.Popen()) and doesn't crash if something horrible
|
||||
happens (rather, it avoids letting something horrible happen).
|
||||
|
||||
I decided to add a key that will get rid of the autocomplete window,
|
||||
since it can get in the way. C-l seemed like a good choice, since
|
||||
it would work well as a side-effect of redrawing the screen (at
|
||||
least that makes sense to me). In so doing I also cleaned up a lot
|
||||
of the reevaluating and resizing code so that a lot of the strange
|
||||
output seen on Rewind/resize seems to be gone.
|
||||
|
||||
v0.2.3
|
||||
======
|
||||
The fix for the last bug broke the positioning of the autocomplete
|
||||
box, whoops.
|
||||
|
||||
v0.2.2
|
||||
======
|
||||
That pesky bug keeps coming up. I think it's finally nailed but
|
||||
it's just a matter of testing and hoping. I hate numbers.
|
||||
|
||||
v0.2.1
|
||||
======
|
||||
I'm having a bit of trouble with some integer division that's
|
||||
causing trouble when a certain set of circumstances arise,
|
||||
and I think I've taken care of that little bug, since it's
|
||||
a real pain in the ass and only creeps up when I'm actually
|
||||
doing something useful, so I'll test it for a bit and release
|
||||
it as hopefully a bug fixed version.
|
||||
|
||||
v0.2.0
|
||||
======
|
||||
A little late in the day to start a changelog, but here goes...
|
||||
This version fixed another annoying little bug that was causing
|
||||
crashes given certain exact circumstances. I always find it's the
|
||||
way with curses and sizing of windows and things...
|
||||
|
||||
I've also got bpython to try looking into pydoc if no matches
|
||||
are found for the argspec, which means the builtins have argspecs
|
||||
too now, hooray.
|
||||
@@ -0,0 +1,22 @@
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2008 Bob Farrell
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
bpython - A fancy curses interface to the Python interactive interpreter
|
||||
=======
|
||||
|
||||
Dependencies
|
||||
============
|
||||
Pygments
|
||||
pyparsing
|
||||
(apt-get install python-pyparsing python-pygments)
|
||||
|
||||
Introduction
|
||||
============
|
||||
A few people asked for stuff like syntax highlighting
|
||||
and autocomplete for the Python interactive interpreter.
|
||||
IPython seems to offer this (plus you can get readline
|
||||
behaviour in the vanilla interpreter) but I tried
|
||||
IPython a couple of times. Perhaps I didn't really get
|
||||
it, but I get the feeling that the ideas behind IPython
|
||||
are pretty different to bpython. I didn't want to create
|
||||
a whole development environment; I simply wanted to
|
||||
provide a couple of neat features that already exist
|
||||
and turn them into something a little more interactive.
|
||||
|
||||
The idea is to provide the user with all the features
|
||||
in-line, much like modern IDEs, but in a simple,
|
||||
lightweight package that can be run in a terminal
|
||||
window, so curses seemed like the best choice.
|
||||
Sorry if you use Windows.
|
||||
|
||||
bpython doesn't attempt to create anything new or
|
||||
groundbreaking, it simply brings together a few neat
|
||||
ideas and focuses on practicality and usefulness.
|
||||
For this reason, the "Rewind" function should be
|
||||
taken with a pinch of salt, but personally I have
|
||||
found it to be very useful. I use bpython now
|
||||
whenever I would normally use the vanilla interpreter,
|
||||
e.g. for testing out solutions to people's problems
|
||||
on IRC, quickly testing a method of doing something
|
||||
without creating a temporary file, etc..
|
||||
|
||||
I hope you find it useful and please feel free to
|
||||
submit any bugs/patches (yeah right)/suggestions
|
||||
to:
|
||||
robertanthonyfarrell@gmail.com
|
||||
|
||||
Features
|
||||
========
|
||||
|
||||
* In-line syntax highlighting.
|
||||
This uses Pygments for lexing the code as you type,
|
||||
and colours appropriately. Pygments does a great job
|
||||
of doing all of the tricky stuff and really leaving
|
||||
me with very little to do except format the tokens
|
||||
in all my favourite colours.
|
||||
|
||||
* Readline-like autocomplete with suggestions displayed
|
||||
as you type.
|
||||
Thanks to Python's readline interface to libreadline
|
||||
and a ready-made class for using a Python interpreter's
|
||||
scope as the dataset, the only work here was displaying
|
||||
the readline matches as you type in a separate curses
|
||||
window below/above the cursor.
|
||||
|
||||
* Expected parameter list.
|
||||
As in a lot of modern IDEs, bpython will attempt to
|
||||
display a list of parameters for any function you
|
||||
call. The inspect module is tried first, which works
|
||||
with any Python function, and then pydoc if that fails,
|
||||
which seems to be pretty adequate, but obviously
|
||||
in some cases it's simply not possible. I used pyparsing
|
||||
to cure my nested parentheses woes; again, it was
|
||||
nice and easy.
|
||||
|
||||
* Rewind.
|
||||
I didn't call this "Undo" because I thought that would
|
||||
be misleading, but "Rewind" is probably as bad. The
|
||||
idea is that the code entered is kept in memory and
|
||||
when the Rewind function is called, the last line is
|
||||
popped and the entire code is re-evaluated. As you can
|
||||
imagine, this has a lot of potential problems, but for
|
||||
defining classes and functions, I've found it to be
|
||||
nothing but useful.
|
||||
|
||||
* Pastebin code/write to file.
|
||||
I don't really use the save thing much, but the pastebin
|
||||
thing's great. Hit a key and what you see on the screen
|
||||
will be sent to a pastebin and a URL is returned for you
|
||||
to do what you like with. I've hardcoded rafb.net/paste
|
||||
in for now, that needs to be fixed so it's configurable.
|
||||
Next release, I promise.
|
||||
|
||||
* Flush curses screen to stdout.
|
||||
A featurette, perhaps, but I thought it was worth noting.
|
||||
I can't personally recall a curses app that does this,
|
||||
perhaps it's often not useful, but when you quit bpython,
|
||||
the screen data will be flushed to stdout, so it basically
|
||||
looks the same as if you had quit the vanilla interpreter.
|
||||
|
||||
Known Bugs
|
||||
==========
|
||||
|
||||
* There's some weirdness when you use rewind sometimes with how
|
||||
it displays the text afterwards, I haven't had enough time to
|
||||
sit down and look at exactly what's causing it, as it doesn't
|
||||
seem to happen a lot, and it fixes itself pretty quickly anyway.
|
||||
|
||||
* Triple quoted strings over multiple lines work, but they're
|
||||
not highlighted properly.
|
||||
|
||||
* There is no way to configure the keys or the pastebin options,
|
||||
this is a definite for the next release.
|
||||
+1281
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,21 @@
|
||||
# The MIT License
|
||||
#
|
||||
# Copyright (c) 2008 Bob Farrell
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
@@ -0,0 +1,99 @@
|
||||
# The MIT License
|
||||
#
|
||||
# Copyright (c) 2008 Bob Farrell
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
# A simple formatter for bpython to work with Pygments.
|
||||
# Pygments really kicks ass, it made it really easy to
|
||||
# get the exact behaviour I wanted, thanks Pygments. :)
|
||||
|
||||
from pygments.formatter import Formatter
|
||||
from pygments.token import Keyword, Name, Comment, String, Error, \
|
||||
Number, Operator, Generic, Token, Whitespace, Literal, Punctuation
|
||||
|
||||
"""These format strings are pretty ugly.
|
||||
\x01 represents a colour marker, which
|
||||
can be proceded by one or two of
|
||||
the following letters:
|
||||
k, r, g, y, b, m, c, w, d
|
||||
Which represent:
|
||||
blacK, Red, Green, Yellow, Blue, Magenta,
|
||||
Cyan, White, Default
|
||||
e.g. \x01y for yellow,
|
||||
\x01gb for green on blue background
|
||||
|
||||
\x02 represents the bold attribute
|
||||
|
||||
\x03 represents the start of the actual
|
||||
text that is output (in this case it's
|
||||
a %s for substitution)
|
||||
|
||||
\x04 represents the end of the string; this is
|
||||
necessary because the strings are all joined
|
||||
together at the end so the parser needs them
|
||||
as delimeters
|
||||
|
||||
"""
|
||||
|
||||
f_strings = {
|
||||
Keyword : "\x01y\x03%s\x04",
|
||||
Name : "\x01w\x02\x03%s\x04",
|
||||
Comment : "\x01b\x03%s\x04",
|
||||
String : "\x01m\x03%s\x04",
|
||||
Error : "\x01r\x03%s\x04",
|
||||
Literal : "\x01r\x03%s\x04",
|
||||
Literal.String : "\x01m\x03%s\x04",
|
||||
Token.Literal.Number.Float : "\x01g\x02\x03%s\x04",
|
||||
Number : "\x01g\x03%s\x04",
|
||||
Operator : "\x01c\x02\x03%s\x04",
|
||||
Operator.Word : "\x01c\x02\x03%s\x04",
|
||||
Punctuation : "\x01c\x02\x03%s\x04",
|
||||
Generic : "\x01d\x03%s\x04",
|
||||
Token : "\x01g\x03%s\x04",
|
||||
Whitespace : "\x02d\x03%s\x04"
|
||||
}
|
||||
|
||||
class BPythonFormatter( Formatter ):
|
||||
"""This is the custom formatter for bpython.
|
||||
Its format() method receives the tokensource
|
||||
and outfile params passed to it from the
|
||||
Pygments highlight() method and slops
|
||||
them into the appropriate format string
|
||||
as defined above, then writes to the outfile
|
||||
object the final formatted string.
|
||||
|
||||
See the Pygments source for more info; it's pretty
|
||||
straightforward."""
|
||||
|
||||
def __init__(self, **options):
|
||||
Formatter.__init__(self, **options)
|
||||
|
||||
def format( self, tokensource, outfile ):
|
||||
o = ''
|
||||
for token, text in tokensource:
|
||||
if text == '\n':
|
||||
continue
|
||||
|
||||
if token in f_strings:
|
||||
o += f_strings[ token ] % text
|
||||
else:
|
||||
o += f_strings[ Token ] % text
|
||||
outfile.write( o.rstrip() )
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# The MIT License
|
||||
#
|
||||
# Copyright (c) 2008 Bob Farrell
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
@@ -0,0 +1,99 @@
|
||||
# The MIT License
|
||||
#
|
||||
# Copyright (c) 2008 Bob Farrell
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
# A simple formatter for bpython to work with Pygments.
|
||||
# Pygments really kicks ass, it made it really easy to
|
||||
# get the exact behaviour I wanted, thanks Pygments. :)
|
||||
|
||||
from pygments.formatter import Formatter
|
||||
from pygments.token import Keyword, Name, Comment, String, Error, \
|
||||
Number, Operator, Generic, Token, Whitespace, Literal, Punctuation
|
||||
|
||||
"""These format strings are pretty ugly.
|
||||
\x01 represents a colour marker, which
|
||||
can be proceded by one or two of
|
||||
the following letters:
|
||||
k, r, g, y, b, m, c, w, d
|
||||
Which represent:
|
||||
blacK, Red, Green, Yellow, Blue, Magenta,
|
||||
Cyan, White, Default
|
||||
e.g. \x01y for yellow,
|
||||
\x01gb for green on blue background
|
||||
|
||||
\x02 represents the bold attribute
|
||||
|
||||
\x03 represents the start of the actual
|
||||
text that is output (in this case it's
|
||||
a %s for substitution)
|
||||
|
||||
\x04 represents the end of the string; this is
|
||||
necessary because the strings are all joined
|
||||
together at the end so the parser needs them
|
||||
as delimeters
|
||||
|
||||
"""
|
||||
|
||||
f_strings = {
|
||||
Keyword : "\x01y\x03%s\x04",
|
||||
Name : "\x01w\x02\x03%s\x04",
|
||||
Comment : "\x01b\x03%s\x04",
|
||||
String : "\x01m\x03%s\x04",
|
||||
Error : "\x01r\x03%s\x04",
|
||||
Literal : "\x01r\x03%s\x04",
|
||||
Literal.String : "\x01m\x03%s\x04",
|
||||
Token.Literal.Number.Float : "\x01g\x02\x03%s\x04",
|
||||
Number : "\x01g\x03%s\x04",
|
||||
Operator : "\x01c\x02\x03%s\x04",
|
||||
Operator.Word : "\x01c\x02\x03%s\x04",
|
||||
Punctuation : "\x01c\x02\x03%s\x04",
|
||||
Generic : "\x01d\x03%s\x04",
|
||||
Token : "\x01g\x03%s\x04",
|
||||
Whitespace : "\x02d\x03%s\x04"
|
||||
}
|
||||
|
||||
class BPythonFormatter( Formatter ):
|
||||
"""This is the custom formatter for bpython.
|
||||
Its format() method receives the tokensource
|
||||
and outfile params passed to it from the
|
||||
Pygments highlight() method and slops
|
||||
them into the appropriate format string
|
||||
as defined above, then writes to the outfile
|
||||
object the final formatted string.
|
||||
|
||||
See the Pygments source for more info; it's pretty
|
||||
straightforward."""
|
||||
|
||||
def __init__(self, **options):
|
||||
Formatter.__init__(self, **options)
|
||||
|
||||
def format( self, tokensource, outfile ):
|
||||
o = ''
|
||||
for token, text in tokensource:
|
||||
if text == '\n':
|
||||
continue
|
||||
|
||||
if token in f_strings:
|
||||
o += f_strings[ token ] % text
|
||||
else:
|
||||
o += f_strings[ Token ] % text
|
||||
outfile.write( o.rstrip() )
|
||||
|
||||
Executable
+1281
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python
|
||||
from distutils.command.install_data import install_data
|
||||
from distutils.sysconfig import get_python_lib
|
||||
from distutils.core import setup, Extension
|
||||
from distutils.dep_util import newer
|
||||
from distutils.log import info
|
||||
from distutils import sysconfig
|
||||
import distutils.file_util
|
||||
import distutils.dir_util
|
||||
import sys, os
|
||||
import glob
|
||||
import re
|
||||
|
||||
# Make distutils copy bpython.py to bpython
|
||||
copy_file_orig = distutils.file_util.copy_file
|
||||
copy_tree_orig = distutils.dir_util.copy_tree
|
||||
def copy_file(src, dst, *args, **kwargs):
|
||||
if dst.endswith("bin/bpython.py"):
|
||||
dst = dst[:-3]
|
||||
return copy_file_orig(src, dst, *args, **kwargs)
|
||||
def copy_tree(*args, **kwargs):
|
||||
outputs = copy_tree_orig(*args, **kwargs)
|
||||
for i in range(len(outputs)):
|
||||
if outputs[i].endswith("bin/bpython.py"):
|
||||
outputs[i] = outputs[i][:-3]
|
||||
return outputs
|
||||
distutils.file_util.copy_file = copy_file
|
||||
distutils.dir_util.copy_tree = copy_tree
|
||||
|
||||
PYTHONLIB = os.path.join(get_python_lib(standard_lib=1, prefix=""),
|
||||
"site-packages")
|
||||
|
||||
setup(name="bpython",
|
||||
version = "0.2.4",
|
||||
description = "Fancy Interface to the Python Interpreter",
|
||||
author = "Robert Anthony Farrell",
|
||||
author_email = "robertanthonyfarrell@gmail.com",
|
||||
license = "MIT/X",
|
||||
url = "http://www.noiseforfree.com/bpython/",
|
||||
long_description =
|
||||
"""\
|
||||
bpython is a fancy interface to the Python interpreter for Unix-like operating systems.
|
||||
""",
|
||||
packages = ["bpython"],
|
||||
scripts = ["bpython.py"],
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user