Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AIRFLOW-4222] Add cli autocomplete for bash & zsh #5789

Merged
merged 5 commits into from
Aug 13, 2019

Conversation

kaxil
Copy link
Member

@kaxil kaxil commented Aug 12, 2019

Make sure you have checked all steps below.

Jira

Description

  • Here are some details about my PR, including screenshots of any UI changes:
    cli-completion

Tests

  • [] My PR adds the following unit tests OR does not need testing for this extremely good reason:

Commits

  • My commits all reference Jira issues in their subject lines, and I have squashed multiple commits if they address the same issue. In addition, my commits follow the guidelines from "How to write a good git commit message":
    1. Subject is separated from body by a blank line
    2. Subject is limited to 50 characters (not including Jira issue reference)
    3. Subject does not end with a period
    4. Subject uses the imperative mood ("add", not "adding")
    5. Body wraps at 72 characters
    6. Body explains "what" and "why", not "how"

Documentation

  • In case of new functionality, my PR adds documentation that describes how to use it.
    • All the public functions and the classes in the PR contain docstrings that explain what it does
    • If you implement backwards incompatible changes, please leave a note in the Updating.md so we can assign it to a appropriate release

Code Quality

  • Passes flake8

@kaxil kaxil requested review from ashb, Fokko and mik-laj August 12, 2019 23:40
docs/cli.rst Outdated Show resolved Hide resolved

.. code-block:: bash

eval "$(register-python-argcomplete airflow)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to have this as airflow autocompletions or something (which just tries to import that module etc.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure as it would have to find out current Shell (bash/zsh - which might be easy) and then export that command to .bash_rc or .bash_profile or .zshrc etc by running some bash commands?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the register-python-argcomplete airflow bit - not the eval etc.

So this line would be

Suggested change
eval "$(register-python-argcomplete airflow)"
eval "$(airflow autocompletions)"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aah ok. That should be plausible. Let me give it a go

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this isn't as trivial as I thought it would because just running airflow prints out the following:

/Users/kaxilnaik/Documents/GitHub/incubator-airflow/airflow/models/dagbag.py:21: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
[2019-08-13 22:30:04,803] {settings.py:173} INFO - settings.configure_orm(): Using pool settings. pool_size=5, max_overflow=10, pool_recycle=1800, pid=86597
/Users/kaxilnaik/.virtualenvs/airflow_cli_test/lib/python3.7/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
  """)
[2019-08-13 22:30:04,876] {__init__.py:51} INFO - Using executor LocalExecutor

Example implementation:
image

If we then run eval $(airflow autocomplete) it gives the following error:

/Users/kaxilnaik/Documents/GitHub/incubator-airflow/airflow/models/dagbag.py:21: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
/Users/kaxilnaik/.virtualenvs/airflow_cli_test/lib/python3.7/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
  """)
zsh: bad pattern: [2019-08-13

as it is trying to parse the log line [2019-08-13 22:29:39,045] {settings.py:173} INFO - settings.configure_orm(): Using pool settings. pool_size=5, max_overflow=10, pool_recycle=1800, pid=86465

Hence, not implementing this as part of this PR. Let's revisit this later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that damn logging whenever we import airflow :(

@mik-laj
Copy link
Member

mik-laj commented Aug 13, 2019

What do you think to add DAG/Task name suggestion? I think this library supports it.

@kaxil
Copy link
Member Author

kaxil commented Aug 13, 2019

@mik-laj It would have to access the DB to get task name and Dag Name.

Let's merge this one so we get a basic auto-completer. And then we can add functionalities to it.

Some of the things I will add this week would be around filename completions

@mik-laj
Copy link
Member

mik-laj commented Aug 13, 2019

Docs errors:

/opt/airflow/docs/howto/cli-completion.rst:43: WARNING: image file not readable: howto/img/cli_completion.gif

@kaxil kaxil merged commit 44eb89d into apache:master Aug 13, 2019
@kaxil kaxil deleted the cli-auto-completion branch August 13, 2019 21:34
ashb pushed a commit that referenced this pull request Oct 11, 2019
adityav pushed a commit to adityav/airflow that referenced this pull request Oct 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants