├── .gitignore ├── .travis.yml ├── AUTHORS.md ├── CONTRIBUTING.md ├── HISTORY.md ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.md ├── django_pgcli └── __init__.py ├── requirements.txt ├── setup.cfg ├── setup.py ├── tests ├── __init__.py └── test_django-pgcli.py └── tox.ini /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | 3 | # C extensions 4 | *.so 5 | 6 | # Packages 7 | *.egg 8 | *.egg-info 9 | dist 10 | build 11 | eggs 12 | parts 13 | bin 14 | var 15 | sdist 16 | develop-eggs 17 | .installed.cfg 18 | lib 19 | lib64 20 | 21 | # Installer logs 22 | pip-log.txt 23 | 24 | # Unit test / coverage reports 25 | .coverage 26 | .tox 27 | nosetests.xml 28 | htmlcov 29 | 30 | # Translations 31 | *.mo 32 | 33 | # Mr Developer 34 | .mr.developer.cfg 35 | .project 36 | .pydevproject 37 | 38 | # Complexity 39 | output/*.html 40 | output/*/index.html 41 | 42 | # Sphinx 43 | docs/_build 44 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Config file for automatic testing at travis-ci.org 2 | 3 | language: python 4 | 5 | matrix: 6 | include: 7 | - python: 3.6 8 | - python: 3.7 9 | - python: 3.8 10 | dist: xenial 11 | sudo: true 12 | 13 | # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors 14 | install: pip install -r requirements.txt 15 | 16 | # command to run tests, e.g. python setup.py test 17 | script: python setup.py test -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | ======= 2 | Credits 3 | ======= 4 | 5 | Development Lead 6 | ---------------- 7 | 8 | * Ash Christopher 9 | 10 | Contributors 11 | ------------ 12 | 13 | None yet. Why not be the first? 14 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ============ 2 | Contributing 3 | ============ 4 | 5 | Contributions are welcome, and they are greatly appreciated! Every 6 | little bit helps, and credit will always be given. 7 | 8 | You can contribute in many ways: 9 | 10 | Types of Contributions 11 | ---------------------- 12 | 13 | Report Bugs 14 | ~~~~~~~~~~~ 15 | 16 | Report bugs at https://github.com/ashchristopher/django-pgcli/issues. 17 | 18 | If you are reporting a bug, please include: 19 | 20 | * Your operating system name and version. 21 | * Any details about your local setup that might be helpful in troubleshooting. 22 | * Detailed steps to reproduce the bug. 23 | 24 | Fix Bugs 25 | ~~~~~~~~ 26 | 27 | Look through the GitHub issues for bugs. Anything tagged with "bug" 28 | is open to whoever wants to implement it. 29 | 30 | Implement Features 31 | ~~~~~~~~~~~~~~~~~~ 32 | 33 | Look through the GitHub issues for features. Anything tagged with "feature" 34 | is open to whoever wants to implement it. 35 | 36 | Write Documentation 37 | ~~~~~~~~~~~~~~~~~~~ 38 | 39 | django-pgcli could always use more documentation, whether as part of the 40 | official django-pgcli docs, in docstrings, or even on the web in blog posts, 41 | articles, and such. 42 | 43 | Submit Feedback 44 | ~~~~~~~~~~~~~~~ 45 | 46 | The best way to send feedback is to file an issue at https://github.com/ashchristopher/django-pgcli/issues. 47 | 48 | If you are proposing a feature: 49 | 50 | * Explain in detail how it would work. 51 | * Keep the scope as narrow as possible, to make it easier to implement. 52 | * Remember that this is a volunteer-driven project, and that contributions 53 | are welcome :) 54 | 55 | Get Started! 56 | ------------ 57 | 58 | Ready to contribute? Here's how to set up `django-pgcli` for local development. 59 | 60 | 1. Fork the `django-pgcli` repo on GitHub. 61 | 2. Clone your fork locally:: 62 | 63 | $ git clone git@github.com:your_name_here/django-pgcli.git 64 | 65 | 3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:: 66 | 67 | $ mkvirtualenv django-pgcli 68 | $ cd django-pgcli/ 69 | $ python setup.py develop 70 | 71 | 4. Create a branch for local development:: 72 | 73 | $ git checkout -b name-of-your-bugfix-or-feature 74 | 75 | Now you can make your changes locally. 76 | 77 | 5. When you're done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:: 78 | 79 | $ flake8 django-pgcli tests 80 | $ python setup.py test 81 | $ tox 82 | 83 | To get flake8 and tox, just pip install them into your virtualenv. 84 | 85 | 6. Commit your changes and push your branch to GitHub:: 86 | 87 | $ git add . 88 | $ git commit -m "Your detailed description of your changes." 89 | $ git push origin name-of-your-bugfix-or-feature 90 | 91 | 7. Submit a pull request through the GitHub website. 92 | 93 | Pull Request Guidelines 94 | ----------------------- 95 | 96 | Before you submit a pull request, check that it meets these guidelines: 97 | 98 | 1. The pull request should include tests. 99 | 2. If the pull request adds functionality, the docs should be updated. Put 100 | your new functionality into a function with a docstring, and add the 101 | feature to the list in README.rst. 102 | 3. The pull request should work for Python 2.6, 2.7, 3.3, and 3.4, and for PyPy. Check 103 | https://travis-ci.org/ashchristopher/django-pgcli/pull_requests 104 | and make sure that the tests pass for all supported Python versions. 105 | 106 | Tips 107 | ---- 108 | 109 | To run a subset of tests:: 110 | 111 | $ python -m unittest tests.test_django-pgcli 112 | -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | # History 2 | 3 | ## 1.0.1 (2020-06-21) 4 | 5 | * Rebuild wheel 6 | 7 | ## 1.0.0 (2020-06-20) 8 | 9 | * Upgrades to support Django LTS and above 10 | * Limits support to Python3 11 | 12 | ## 0.0.2 (2015-04-26) 13 | 14 | * Fixed typo in README.rst 15 | 16 | ## 0.0.1 (2015-04-25) 17 | 18 | * Initial release. 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Ash Christopher 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | * Neither the name of django-pgcli nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include AUTHORS.md 2 | include CONTRIBUTING.md 3 | include HISTORY.md 4 | include LICENSE 5 | include README.md 6 | 7 | recursive-include tests * 8 | recursive-exclude * __pycache__ 9 | recursive-exclude * *.py[co] 10 | 11 | recursive-include docs *.rst conf.py Makefile make.bat 12 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean-pyc clean-build docs clean 2 | 3 | help: 4 | @echo "clean - remove all build, test, coverage and Python artifacts" 5 | @echo "clean-build - remove build artifacts" 6 | @echo "clean-pyc - remove Python file artifacts" 7 | @echo "clean-test - remove test and coverage artifacts" 8 | @echo "lint - check style with flake8" 9 | @echo "test - run tests quickly with the default Python" 10 | @echo "test-all - run tests on every Python version with tox" 11 | @echo "coverage - check code coverage quickly with the default Python" 12 | @echo "docs - generate Sphinx HTML documentation, including API docs" 13 | @echo "release - package and upload a release" 14 | @echo "dist - package" 15 | @echo "install - install the package to the active Python's site-packages" 16 | 17 | clean: clean-build clean-pyc clean-test 18 | 19 | clean-build: 20 | rm -fr build/ 21 | rm -fr dist/ 22 | rm -fr .eggs/ 23 | find . -name '*.egg-info' -exec rm -fr {} + 24 | find . -name '*.egg' -exec rm -Rf {} + 25 | 26 | clean-pyc: 27 | find . -name '*.pyc' -exec rm -f {} + 28 | find . -name '*.pyo' -exec rm -f {} + 29 | find . -name '*~' -exec rm -f {} + 30 | find . -name '__pycache__' -exec rm -fr {} + 31 | 32 | clean-test: 33 | rm -fr .tox/ 34 | rm -f .coverage 35 | rm -fr htmlcov/ 36 | 37 | lint: 38 | flake8 django-pgcli tests 39 | 40 | test: 41 | python setup.py test 42 | 43 | test-all: 44 | tox 45 | 46 | coverage: 47 | coverage run --source django-pgcli setup.py test 48 | coverage report -m 49 | coverage html 50 | open htmlcov/index.html 51 | 52 | docs: 53 | rm -f docs/django-pgcli.rst 54 | rm -f docs/modules.rst 55 | sphinx-apidoc -o docs/ django-pgcli 56 | $(MAKE) -C docs clean 57 | $(MAKE) -C docs html 58 | open docs/_build/html/index.html 59 | 60 | release: dist 61 | python3 -m twine upload dist/* 62 | 63 | dist: clean 64 | python setup.py sdist bdist_wheel 65 | ls -l dist 66 | twine check dist/* 67 | 68 | install: clean 69 | python setup.py install 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # django-pgcli 2 | 3 | [![Build Status](https://travis-ci.org/ashchristopher/django-pgcli.svg?branch=master)](https://travis-ci.org/ashchristopher/django-pgcli) [![PyPI version](https://badge.fury.io/py/django-pgcli.svg)](https://badge.fury.io/py/django-pgcli) ![PyPI - License](https://img.shields.io/pypi/l/django-mycli) 4 | 5 | Replaces your existing *psql* cli for Postgres with *pgcli* which provides enhancements such as auto-completion and syntax highlighting. Visit the [pgcli website](https://www.pgcli.com/) to learn more about the **pgcli** client. 6 | 7 | ## Installation 8 | 9 | To install the package: 10 | 11 | `pip install django-pgcli` 12 | 13 | Add `django_pgcli` to your `INSTALLED_APPS` setting in your settings.py file. 14 | 15 | INSTALLED_APPS = [ 16 | ..., 17 | 'django_pgcli', 18 | 19 | ] 20 | 21 | ## Usage 22 | 23 | To use the `pgcli` command with your project, call the `dbshell` command. 24 | 25 | ./manage.py dbshell 26 | -------------------------------------------------------------------------------- /django_pgcli/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | __author__ = 'Ash Christopher' 4 | __email__ = 'ash.christopher@gmail.com' 5 | __version__ = '1.0.1' 6 | 7 | 8 | from django.db.backends.postgresql import base 9 | from django.db.backends.postgresql.client import DatabaseClient 10 | 11 | 12 | class PgCLIDatabaseClient(DatabaseClient): 13 | executable_name = 'pgcli' 14 | 15 | def runshell(self): 16 | PgCLIDatabaseClient.runshell_db(self.connection.get_connection_params()) 17 | 18 | base.DatabaseWrapper.__old_database_client_class = base.DatabaseClient 19 | base.DatabaseWrapper.client_class = PgCLIDatabaseClient 20 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | wheel==0.34.2 2 | psycopg2 3 | pgcli 4 | Django>=2.2.13 5 | twine 6 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [wheel] 2 | universal = 1 3 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | 5 | try: 6 | from setuptools import setup 7 | except ImportError: 8 | from distutils.core import setup 9 | 10 | 11 | with open('README.md') as readme_file: 12 | readme = readme_file.read() 13 | 14 | with open('HISTORY.md') as history_file: 15 | history = history_file.read() 16 | 17 | requirements = [ 18 | 'psycopg2', 19 | 'pgcli', 20 | 'Django>=2.2.13', 21 | ] 22 | 23 | test_requirements = [ 24 | 'psycopg2', 25 | 'pgcli', 26 | 'Django>=2.2.13', 27 | ] 28 | 29 | setup( 30 | name='django-pgcli', 31 | version='1.0.1', 32 | description="Database runtime for Django that replaces psql with pgcli.", 33 | long_description='\n' + readme + '\n\n' + history, 34 | long_description_content_type="text/markdown", 35 | author="Ash Christopher", 36 | author_email='ash.christopher@gmail.com', 37 | url='https://github.com/ashchristopher/django-pgcli', 38 | packages=[ 39 | 'django_pgcli', 40 | ], 41 | include_package_data=True, 42 | install_requires=requirements, 43 | license="BSD", 44 | zip_safe=False, 45 | keywords='django pgcli postgres database', 46 | classifiers=[ 47 | 'Development Status :: 5 - Production/Stable', 48 | 'Intended Audience :: Developers', 49 | 'License :: OSI Approved :: BSD License', 50 | 'Natural Language :: English', 51 | 'Programming Language :: Python :: 3.6', 52 | 'Programming Language :: Python :: 3.7', 53 | 'Programming Language :: Python :: 3.8', 54 | ], 55 | test_suite='tests', 56 | tests_require=test_requirements 57 | ) 58 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | -------------------------------------------------------------------------------- /tests/test_django-pgcli.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | import unittest 5 | import django_pgcli # noqa 6 | 7 | 8 | class RuntimeTestCase(unittest.TestCase): 9 | 10 | def test_database_client_subclassed(self): 11 | from django.db.backends.postgresql import base 12 | 13 | self.assertEqual(base.DatabaseWrapper.client_class, django_pgcli.PgCLIDatabaseClient) 14 | 15 | def test_database_client_calls_pgcli_executable(self): 16 | from django.db.backends.postgresql import base 17 | 18 | self.assertEqual(base.DatabaseWrapper.client_class.executable_name, 'pgcli') 19 | 20 | def test_old_database_client_set_on_base(self): 21 | from django.db.backends.postgresql import base 22 | from django.db.backends.postgresql.client import DatabaseClient 23 | 24 | self.assertEqual(getattr(base.DatabaseWrapper, '__old_database_client_class'), DatabaseClient) 25 | 26 | if __name__ == '__main__': 27 | unittest.main() 28 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = py27, py34, py35 3 | 4 | [testenv] 5 | setenv = 6 | PYTHONPATH = {toxinidir}:{toxinidir}/django-pgcli 7 | commands = python setup.py test 8 | deps = 9 | -r{toxinidir}/requirements.txt 10 | --------------------------------------------------------------------------------