diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b3700a45..98f8e54f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,16 +14,8 @@ Fixes: * Support for Python 3.6 has been dropped. -0.22.1 ------- - -Fixes: - -* #938: Fix missing dependency on typing_extensions. - Thanks to Dustin Rodrigues - -0.22 ----- +0.22.11 +-------- General information: @@ -50,6 +42,8 @@ Fixes: * #919: Replicate python behavior when running with -i and a non-existing file * #932: Fix handling of __signature__ for completion. Thanks to gpotter2 +* #938: Fix missing dependency on typing_extensions. + Thanks to Dustin Rodrigues Changes to dependencies: diff --git a/README.md b/README.md new file mode 100644 index 00000000..131771af --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# bpython-django + +This project is based on [bpython](https://github.com/bpython/bpython) REPL, I liked it very much but it missed some features for Django, like +* Autocomplete the constructor for the model, +* Autocomplete the attribute name on ModelManager functions like 'filter()' and 'get()' + +## Example + +[![asciicast](https://asciinema.org/a/443735.png)](https://asciinema.org/a/443735?speed=3&t=2) + +## Install + +`pip install bpython-django` + +## Usage + +`python manage shell` +or +`python manage shell -i bpython` diff --git a/README.rst b/README.rst deleted file mode 100644 index 6cfd5663..00000000 --- a/README.rst +++ /dev/null @@ -1,187 +0,0 @@ -.. image:: https://img.shields.io/pypi/v/bpython - :target: https://pypi.org/project/bpython - -.. image:: https://readthedocs.org/projects/bpython/badge/?version=latest - :target: https://docs.bpython-interpreter.org/en/latest/ - -.. image:: https://img.shields.io/badge/code%20style-black-000000.svg - :target: https://github.com/ambv/black - - -**************************************************************** -bpython: A fancy interface to the Python interactive interpreter -**************************************************************** - -`bpython`_ is a lightweight Python interpreter that adds several features common -to IDEs. These features include **syntax highlighting**, **expected parameter -list**, **auto-indentation**, and **autocompletion**. (See below for example -usage). - -.. image:: https://bpython-interpreter.org/images/math.gif - :alt: bpython - :width: 566 - :height: 348 - :align: center - -bpython does **not** aim to be a complete IDE - the focus is on implementing a -few ideas in a practical, useful, and lightweight manner. - -bpython is a great replacement to any occasion where you would normally use the -vanilla Python interpreter - testing out solutions to people's problems on IRC, -quickly testing a method of doing something without creating a temporary file, -etc. - -You can find more about bpython - including `full documentation`_ - at our -`homepage`_. - -========================== -Installation & Basic Usage -========================== - -Installation using Pip ----------------------- - -If you have `pip`_ installed, you can simply run: - -.. code-block:: bash - - $ pip install bpython - -Start bpython by typing ``bpython`` in your terminal. You can exit bpython by -using the ``exit()`` command or by pressing control-D like regular interactive -Python. - -=================== -Features & Examples -=================== -* Readline-like autocomplete, with suggestions displayed as you type. - -* In-line syntax highlighting. This uses Pygments for lexing the code as you - type, and colours appropriately. - -* 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 (which - works with any Python function) is tried first, and then pydoc if that fails. - -* Rewind. This isn't called "Undo" because it 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 - session is re-evaluated. Use to rewind. - -* Edit the current line or your entire session in an editor. F7 opens the current - session in a text editor, and if modifications are made, the session is rerun - with these changes. - -* Pastebin code/write to file. Use the key to upload the screen's contents - to pastebin, with a URL returned. - -* Reload imported Python modules. Use to clear sys.modules and rerun your - session to test changes to code in a module you're working on. - -============= -Configuration -============= -See the sample-config file for a list of available options. You should save -your config file as **~/.config/bpython/config** (i.e. -``$XDG_CONFIG_HOME/bpython/config``) or specify at the command line:: - - bpython --config /path/to/bpython/config - -============ -Dependencies -============ -* Pygments -* curtsies >= 0.3.5 -* greenlet -* pyxdg -* requests -* Sphinx >= 1.5 (optional, for the documentation) -* babel (optional, for internationalization) -* jedi (optional, for experimental multiline completion) -* watchdog (optional, for monitoring imported modules for changes) -* pyperclip (optional, for copying to the clipboard) - -bpython-urwid -------------- -``bpython-urwid`` requires the following additional packages: - -* urwid - - -=================================== -Installation via OS Package Manager -=================================== - -The majority of desktop computer operating systems come with package management -systems. If you use one of these OSes, you can install ``bpython`` using the -package manager. - -Ubuntu/Debian -------------- -Ubuntu/Debian family Linux users can install ``bpython`` using the ``apt`` -package manager, using the command with ``sudo`` privileges: - -.. code-block:: bash - - $ apt install bpython - -In case you are using an older version, run - -.. code-block:: bash - - $ apt-get install bpython - -Arch Linux ----------- -Arch Linux uses ``pacman`` as the default package manager; you can use it to install ``bpython``: - -.. code-block:: bash - - $ pacman -S bpython - -Fedora ------- -Fedora users can install ``bpython`` directly from the command line using ``dnf``. - -.. code-block:: bash - - $ dnf install bpython - -macOS ------ -macOS does not include a package manager by default. If you have installed any -third-party package manager like MacPorts, you can install it via - -.. code-block:: bash - - $ sudo port install py-bpython - - -========== -Known Bugs -========== -For known bugs please see bpython's `known issues and FAQ`_ page. - -====================== -Contact & Contributing -====================== -I hope you find it useful and please feel free to submit any bugs/patches -suggestions to `Robert`_ or place them on the GitHub -`issues tracker`_. - -For any other ways of communicating with bpython users and devs you can find us -at the community page on the `project homepage`_, or in the `community`_. - -Hope to see you there! - -.. _homepage: http://www.bpython-interpreter.org -.. _full documentation: http://docs.bpython-interpreter.org/ -.. _issues tracker: http://github.com/bpython/bpython/issues/ -.. _pip: https://pip.pypa.io/en/latest/index.html -.. _project homepage: http://bpython-interpreter.org -.. _community: http://docs.bpython-interpreter.org/community.html -.. _Robert: robertanthonyfarrell@gmail.com -.. _bpython: http://www.bpython-interpreter.org/ -.. _Curses: http://www.lfd.uci.edu/~gohlke/pythonlibs/ -.. _pyreadline: http://pypi.python.org/pypi/pyreadline/ -.. _known issues and FAQ: http://bpython-interpreter.org/known-issues-and-faq.html diff --git a/bpython/inspection.py b/bpython/inspection.py index e7ab0a15..afcc8b3a 100644 --- a/bpython/inspection.py +++ b/bpython/inspection.py @@ -35,6 +35,10 @@ from .lazyre import LazyReCompile +DJANGO_CONSTANTS=["check","DoesNotExist","MultipleObjectsReturned"," check","clean","clean_fields","date_error_message", + "delete","from_db","full_clean","get_deferred_fields","objects","prepare_database_save","refresh_from_db", + "save","save_base","serializable_value","unique_error_message","validate_unique"] + ArgSpec = namedtuple( "ArgSpec", [ @@ -56,8 +60,10 @@ class AttrCleaner: on attribute lookup.""" def __init__(self, obj: Any) -> None: - self.obj = obj - + if "ManagerDescriptor" in str(type(obj)): + self.obj = obj.manager + else: + self.obj = obj def __enter__(self): """Try to make an object not exhibit side-effects on attribute lookup.""" @@ -230,7 +236,7 @@ def getpydocspec(f, func): ) -def getfuncprops(func, f): +def getfuncprops(func, f,cls=None): # Check if it's a real bound method or if it's implicitly calling __init__ # (i.e. FooClass(...) and not FooClass.__init__(...) -- the former would # not take 'self', the latter would: @@ -251,7 +257,7 @@ def getfuncprops(func, f): # '__init__' throws xmlrpclib.Fault (see #202) return None try: - argspec = get_argspec_from_signature(f) + argspec = get_argspec_from_signature(f,cls) fixlongargs(f, argspec) if len(argspec) == 4: argspec = argspec + [list(), dict(), None] @@ -274,7 +280,7 @@ def is_eval_safe_name(string: str) -> bool: ) -def get_argspec_from_signature(f): +def get_argspec_from_signature(f,cls=None): """Get callable signature from inspect.signature in argspec format. inspect.signature is a Python 3 only function that returns the signature of @@ -308,7 +314,10 @@ def get_argspec_from_signature(f): kwonly_defaults[parameter.name] = parameter.default elif parameter.kind == inspect.Parameter.VAR_KEYWORD: varkwargs = parameter.name - + if cls: + members = inspect.getmembers(cls) + kwonly.extend([x[0] for x in members if not (x[0].startswith("_") or "get_pre" in x[0] + or "get_next" in x[0]) and x[0] not in DJANGO_CONSTANTS]) # inspect.getfullargspec returns None for 'defaults', 'kwonly_defaults' and # 'annotations' if there are no values for them. if not defaults: @@ -319,7 +328,6 @@ def get_argspec_from_signature(f): if not annotations: annotations = None - return [ args, varargs, diff --git a/bpython/repl.py b/bpython/repl.py index e1a5429d..5a1ff169 100644 --- a/bpython/repl.py +++ b/bpython/repl.py @@ -511,6 +511,8 @@ def get_object(self, name): obj = eval(attributes.pop(0), self.interp.locals) while attributes: with inspection.AttrCleaner(obj): + if "ManagerDescriptor" in str(type(obj)): + obj = obj.manager obj = getattr(obj, attributes.pop(0)) return obj @@ -582,7 +584,6 @@ def get_args(self): return True, otherwise set self.funcprops to None and return False""" self.current_func = None - if not self.config.arg_spec: return False @@ -601,22 +602,22 @@ def get_args(self): ) except simpleeval.EvaluationError: return False - if inspect.isclass(f): class_f = None if ( - (not class_f or not inspection.getfuncprops(func, class_f)) + (not class_f or not inspection.getfuncprops(func, class_f, f)) and hasattr(f, "__new__") and f.__new__ is not object.__new__ and # py3 f.__new__.__class__ is not object.__new__.__class__ ): - class_f = f.__new__ - + elif hasattr(f, "__init__") and f.__init__ is not object.__init__: + class_f = f.__init__ if class_f: + self.funcprops = inspection.getfuncprops(func, class_f, f) f = class_f except Exception: # another case of needing to catch every kind of error @@ -626,7 +627,11 @@ def get_args(self): return False self.current_func = f - self.funcprops = inspection.getfuncprops(func, f) + if "BaseManager._get_queryset_methods" in str(f): + cls = eval(func.split(".")[0],self.interp.locals) + self.funcprops = inspection.getfuncprops(func, f,cls) + if not self.funcprops: + self.funcprops = inspection.getfuncprops(func, f) if self.funcprops: self.arg_pos = arg_number return True diff --git a/example1.png b/example1.png new file mode 100644 index 00000000..6adc499d Binary files /dev/null and b/example1.png differ diff --git a/example2.png b/example2.png new file mode 100644 index 00000000..bca55049 Binary files /dev/null and b/example2.png differ diff --git a/setup.cfg b/setup.cfg index 96ef47be..8c4b0735 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,12 +1,6 @@ [metadata] -name = bpython -long_description = file: README.rst license = MIT license_file = LICENSE -url = https://www.bpython-interpreter.org/ -project_urls = - GitHub = https://github.com/bpython/bpython - Documentation = https://doc.bpython-interpreter.org classifiers = Programming Language :: Python :: 3 diff --git a/setup.py b/setup.py index 12d4eeec..6a1d4a59 100755 --- a/setup.py +++ b/setup.py @@ -178,10 +178,17 @@ def git_describe_to_python_version(version): mo_files.append(mo_subpath) setup( - version=version, - author=__author__, - author_email="robertanthonyfarrell@gmail.com", + name='bpython-django', + version="0.22.11", + author='Mohamed ElKalioby', + author_email="mkalioby@mkalioby.com", + description='Customized bpython for Django Projects', + long_description=open("README.md").read(), + long_description_content_type="text/markdown", data_files=data_files, + url = 'https://github.com/mkalioby/bpython-django/', + download_url='https://github.com/mkalioby/bpython-django/', + python_requires=">=3.7", package_data={ "bpython": ["sample-config"], "bpython.translations": mo_files, @@ -189,6 +196,25 @@ def git_describe_to_python_version(version): }, cmdclass=cmdclass, test_suite="bpython.test", + classifiers=[ + "Development Status :: 5 - Production/Stable", + "Environment :: Web Environment", + "Framework :: Django", + "Framework :: Django :: 2.0", + "Framework :: Django :: 2.1", + "Framework :: Django :: 2.2", + "Framework :: Django :: 3.0", + "Framework :: Django :: 3.1", + "Framework :: Django :: 3.2", + "Intended Audience :: Developers", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Topic :: Software Development :: Libraries :: Python Modules" + ] ) # vim: fileencoding=utf-8 sw=4 ts=4 sts=4 ai et sta