diff options
author | Amjith Ramanujam <amjith.r@gmail.com> | 2018-11-17 11:25:20 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-17 11:25:20 -0800 |
commit | ec18ff014160f2ac5a7d98d567d8701311594c2f (patch) | |
tree | 0d6657b75830573246b43a4e7421079cb9a6281d | |
parent | b92743368bfc357f72a4046e899faef899ee9972 (diff) | |
parent | 462443a2d1d34d686eb11dd1b9b490c062e688a4 (diff) |
Merge branch 'master' into bugfix/named-queries-from-config
-rw-r--r-- | DEVELOP.rst | 50 | ||||
-rw-r--r-- | changelog.rst | 3 | ||||
-rw-r--r-- | pgcli/main.py | 37 | ||||
-rw-r--r-- | setup.py | 2 |
4 files changed, 58 insertions, 34 deletions
diff --git a/DEVELOP.rst b/DEVELOP.rst index 601c3f30..005c9f3f 100644 --- a/DEVELOP.rst +++ b/DEVELOP.rst @@ -6,7 +6,7 @@ GitHub Workflow --------------- If you're interested in contributing to pgcli, first of all my heart felt -thanks. `Fork the project <https://github.com/dbcli/pgcli>`_ in github. Then +thanks. `Fork the project <https://github.com/dbcli/pgcli>`_ on github. Then clone your fork into your computer (``git clone <url-for-your-fork>``). Make the changes and create the commits in your local machine. Then push those changes to your fork. Then click on the pull request icon on github and create @@ -26,16 +26,20 @@ Once the 'upstream' end point is added you can then periodically do a ``git pull upstream master`` to update your local copy and then do a ``git push origin master`` to keep your own fork up to date. +Check Github's `Understanding the GitHub flow guide +<https://guides.github.com/introduction/flow/>`_ for a more detailed +explanation of this process. + Local Setup ----------- The installation instructions in the README file are intended for users of pgcli. If you're developing pgcli, you'll need to install it in a slightly different way so you can see the effects of your changes right away without -having to go through the install cycle everytime you change the code. +having to go through the install cycle every time you change the code. It is highly recommended to use virtualenv for development. If you don't know -what a virtualenv is, this `guide <http://docs.python-guide.org/en/latest/dev/virtualenvs/#virtual-environments>`_ +what a virtualenv is, `this guide <http://docs.python-guide.org/en/latest/dev/virtualenvs/#virtual-environments>`_ will help you get started. Create a virtualenv (let's call it pgcli-dev). Activate it: @@ -57,10 +61,10 @@ and install pgcli using pip as follows: This will install the necessary dependencies as well as install pgcli from the working folder into the virtualenv. By installing it using `pip install -e` -we've linked the pgcli installation with the working copy. So any changes made -to the code is immediately available in the installed version of pgcli. This +we've linked the pgcli installation with the working copy. Any changes made +to the code are immediately available in the installed version of pgcli. This makes it easy to change something in the code, launch pgcli and check the -effects of your change. +effects of your changes. Adding PostgreSQL Special (Meta) Commands ----------------------------------------- @@ -123,22 +127,35 @@ in the ``tests`` directory. An example:: pg_test_host = db.example.com pg_test_port = 30000 -The database user has to have -permissions to create and drop test databases. Default user is ``postgres`` -at ``localhost``, without the password (authentication mode trust). - First, install the requirements for testing: :: $ pip install -r requirements-dev.txt -After that, tests can be run with: +Ensure that the database user has permissions to create and drop test databases +by checking your ``pg_hba.conf`` file. The default user should be ``postgres`` +at ``localhost``. Make sure the authentication method is set to ``trust``. If +you made any changes to your ``pg_hba.conf`` make sure to restart the postgres +service for the changes to take effect. + +:: + + # ONLY IF YOU MADE CHANGES TO YOUR pg_hba.conf FILE + $ sudo service postgresql restart + +After that, tests in the ``/pgcli/tests`` directory can be run with: :: - $ cd tests + # on directory /pgcli/tests $ behave + +And on the ``/pgcli`` directory: + +:: + + # on directory /pgcli $ py.test To see stdout/stderr, use the following command: @@ -147,9 +164,16 @@ To see stdout/stderr, use the following command: $ behave --no-capture +Troubleshooting the integration tests +------------------------------------- + +- Make sure postgres instance on localhost is running +- Check your ``pg_hba.conf`` file to verify local connections are enabled +- Check `this issue <https://github.com/dbcli/pgcli/issues/945>`_ for relevant information. +- Contact us on `gitter <https://gitter.im/dbcli/pgcli/>`_ or `file an issue <https://github.com/dbcli/pgcli/issues/new>`_. PEP8 checks (lint) ------------------_ +------------------ When you submit a PR, the changeset is checked for pep8 compliance using `pep8radius <https://github.com/hayd/pep8radius>`_. If you see a build failing because diff --git a/changelog.rst b/changelog.rst index 2a7505dc..bc2a6797 100644 --- a/changelog.rst +++ b/changelog.rst @@ -12,6 +12,8 @@ Internal: --------- * Clean up and add behave logging. (Thanks: `Dick Marinus`_) +* Require prompt_toolkit>=2.0.6. (Thanks: `Dick Marinus`_) +* Improve development guide (Thanks: `Ignacio Campabadal`_) 2.0.0: @@ -899,3 +901,4 @@ Improvements: .. _`Kenny Do`: https://github.com/kennydo .. _`Max Rothman`: https://github.com/maxrothman .. _`Daniel Egger`: https://github.com/DanEEStar +.. _`Ignacio Campabadal`: https://github.com/igncampa diff --git a/pgcli/main.py b/pgcli/main.py index 446470e3..86a86b1e 100644 --- a/pgcli/main.py +++ b/pgcli/main.py @@ -534,13 +534,10 @@ class PGCli(object): raise RuntimeError(message) while True: try: - text = self.prompt_app.prompt( - default=sql, - vi_mode=self.vi_mode - ) + text = self.prompt_app.prompt(default=sql) break except KeyboardInterrupt: - sql = None + sql = "" editor_command = special.editor_command(text) return text @@ -638,7 +635,7 @@ class PGCli(object): try: while True: try: - text = self.prompt_app.prompt(vi_mode=self.vi_mode) + text = self.prompt_app.prompt() except KeyboardInterrupt: continue @@ -943,20 +940,17 @@ class PGCli(object): help='Host address of the postgres database.') @click.option('-p', '--port', default=5432, help='Port number at which the ' 'postgres instance is listening.', envvar='PGPORT', type=click.INT) -@click.option('-U', '--username', 'username_opt', envvar='PGUSER', - help='Username to connect to the postgres database.') -@click.option('--user', 'username_opt', envvar='PGUSER', - help='Username to connect to the postgres database.') +@click.option('-U', '--username', 'username_opt', help='Username to connect to the postgres database.') +@click.option('--user', 'username_opt', help='Username to connect to the postgres database.') @click.option('-W', '--password', 'prompt_passwd', is_flag=True, default=False, - help='Force password prompt.') + help='Force password prompt.') @click.option('-w', '--no-password', 'never_prompt', is_flag=True, - default=False, help='Never prompt for password.') + default=False, help='Never prompt for password.') @click.option('--single-connection', 'single_connection', is_flag=True, - default=False, - help='Do not use a separate connection for completions.') + default=False, + help='Do not use a separate connection for completions.') @click.option('-v', '--version', is_flag=True, help='Version of pgcli.') -@click.option('-d', '--dbname', default='', envvar='PGDATABASE', - help='database name to connect to.') +@click.option('-d', '--dbname', 'dbname_opt', help='database name to connect to.') @click.option('--pgclirc', default=config_location() + 'config', envvar='PGCLIRC', help='Location of pgclirc file.', type=click.Path(dir_okay=False)) @click.option('-D', '--dsn', default='', envvar='DSN', @@ -976,10 +970,10 @@ class PGCli(object): help='Automatically switch to vertical output mode if the result is wider than the terminal width.') @click.option('--warn/--no-warn', default=None, help='Warn before running a destructive query.') -@click.argument('database', default=lambda: None, envvar='PGDATABASE', nargs=1) +@click.argument('dbname', default=lambda: None, envvar='PGDATABASE', nargs=1) @click.argument('username', default=lambda: None, envvar='PGUSER', nargs=1) -def cli(database, username_opt, host, port, prompt_passwd, never_prompt, - single_connection, dbname, username, version, pgclirc, dsn, row_limit, +def cli(dbname, username_opt, host, port, prompt_passwd, never_prompt, + single_connection, dbname_opt, username, version, pgclirc, dsn, row_limit, less_chatty, prompt, prompt_dsn, list_databases, auto_vertical_output, list_dsn, warn): @@ -1020,7 +1014,10 @@ def cli(database, username_opt, host, port, prompt_passwd, never_prompt, auto_vertical_output=auto_vertical_output, warn=warn) # Choose which ever one has a valid value. - database = database or dbname + if dbname_opt and dbname: + # work as psql: when database is given as option and argument use the argument as user + username = dbname + database = dbname_opt or dbname or '' user = username_opt or username # because option --list or -l are not supposed to have a db name @@ -15,7 +15,7 @@ install_requirements = [ 'pgspecial>=1.11.2', 'click >= 4.1', 'Pygments >= 2.0', # Pygments has to be Capitalcased. WTF? - 'prompt_toolkit>=2.0.0,<2.1.0', + 'prompt_toolkit>=2.0.6,<2.1.0', 'psycopg2 >= 2.7.4,<2.8', 'sqlparse >=0.2.2,<0.3.0', 'configobj >= 5.0.6', |