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

Remove airflow.bin package #7808

Merged
merged 6 commits into from
Mar 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ COPY setup.cfg ${AIRFLOW_SOURCES}/setup.cfg

COPY airflow/version.py ${AIRFLOW_SOURCES}/airflow/version.py
COPY airflow/__init__.py ${AIRFLOW_SOURCES}/airflow/__init__.py
COPY airflow/bin/airflow ${AIRFLOW_SOURCES}/airflow/bin/airflow

COPY requirements.txt ${AIRFLOW_SOURCES}/requirements.txt

Expand Down
12 changes: 9 additions & 3 deletions airflow/bin/airflow → airflow/__main__.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,28 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

"""Main executable module"""

import os

import argcomplete

from airflow.bin import cli
from airflow.cli import cli_parser
from airflow.configuration import conf

if __name__ == '__main__':

def main():
"""Main executable function"""
if conf.get("core", "security") == 'kerberos':
os.environ['KRB5CCNAME'] = conf.get('kerberos', 'ccache')
os.environ['KRB5_KTNAME'] = conf.get('kerberos', 'keytab')

parser = cli.get_parser()
parser = cli_parser.get_parser()
argcomplete.autocomplete(parser)
args = parser.parse_args()
args.func(args)


if __name__ == '__main__':
main()
17 changes: 0 additions & 17 deletions airflow/bin/__init__.py

This file was deleted.

6 changes: 2 additions & 4 deletions airflow/bin/cli.py → airflow/cli/cli_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@

from tabulate import tabulate_formats

from airflow import api, settings
from airflow import settings
from airflow.configuration import conf
from airflow.exceptions import AirflowException
from airflow.executors.executor_loader import ExecutorLoader
from airflow.utils.helpers import partition
from airflow.utils.module_loading import import_string
from airflow.utils.timezone import parse as parsedate

api.load_auth()
Copy link
Member

Choose a reason for hiding this comment

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

Nice!


DAGS_FOLDER = settings.DAGS_FOLDER

BUILD_DOCS = "BUILDING_AIRFLOW_DOCS" in os.environ
Expand Down Expand Up @@ -1150,7 +1148,7 @@ class DefaultHelpParser(argparse.ArgumentParser):
def error(self, message):
self.print_help()
self.exit(2, '\n{} command error: {}, see help above.\n'.format(self.prog, message))
parser = DefaultHelpParser()
parser = DefaultHelpParser(prog="airflow")
subparsers = parser.add_subparsers(
help='sub-command help', dest='subcommand')
subparsers.required = True
Expand Down
4 changes: 2 additions & 2 deletions airflow/models/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -1407,8 +1407,8 @@ def cli(self):
"""
Exposes a CLI specific to this DAG
"""
from airflow.bin import cli
parser = cli.get_parser(dag_parser=True)
from airflow.cli import cli_parser
parser = cli_parser.get_parser(dag_parser=True)
args = parser.parse_args()
args.func(args, self)

Expand Down
2 changes: 2 additions & 0 deletions airflow/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from sqlalchemy.pool import NullPool

# noinspection PyUnresolvedReferences
from airflow import api
from airflow.configuration import AIRFLOW_HOME, WEBSERVER_CONFIG, conf # NOQA F401
from airflow.logging_config import configure_logging
from airflow.utils.module_loading import import_string
Expand Down Expand Up @@ -304,6 +305,7 @@ def initialize():
# The webservers import this file from models.py with the default settings.
configure_orm()
configure_action_logging()
api.load_auth()

# Ensure we close DB connections at scheduler and gunicon worker terminations
atexit.register(dispose_orm)
Expand Down
2 changes: 1 addition & 1 deletion airflow/task/task_runner/standard_task_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _start_by_fork(self): # pylint: disable=inconsistent-return-statements
self.log.info("Started process %d to run task", pid)
return psutil.Process(pid)
else:
from airflow.bin.cli import get_parser
from airflow.cli.cli_parser import get_parser
import signal
import airflow.settings as settings

Expand Down
2 changes: 1 addition & 1 deletion docs/cli-ref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ development and testing.
:depth: 2

.. argparse::
:module: airflow.bin.cli
:module: airflow.cli.cli_parser
:func: get_parser
:prog: airflow
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,11 @@ def do_setup(pinned=False):
},
include_package_data=True,
zip_safe=False,
scripts=['airflow/bin/airflow'],
entry_points={
"console_scripts": [
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

"airflow = airflow.__main__:main",
],
},
install_requires=get_install_requires(pinned=pinned),
setup_requires=[
'bowler',
Expand Down
20 changes: 10 additions & 10 deletions tests/cli/commands/test_celery_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import sqlalchemy

import airflow
from airflow.bin import cli
from airflow.cli import cli_parser
from airflow.cli.commands import celery_command
from airflow.configuration import conf
from tests.test_utils.config import conf_vars
Expand Down Expand Up @@ -71,11 +71,11 @@ class TestWorkerServeLogs(unittest.TestCase):
@classmethod
@conf_vars({("core", "executor"): "CeleryExecutor"})
def setUpClass(cls):
importlib.reload(cli)
cls.parser = cli.get_parser()
importlib.reload(cli_parser)
cls.parser = cli_parser.get_parser()

def tearDown(self):
importlib.reload(cli)
importlib.reload(cli_parser)

@mock.patch('airflow.cli.commands.celery_command.worker_bin')
def test_serve_logs_on_worker_start(self, mock_worker):
Expand All @@ -102,11 +102,11 @@ class TestCeleryStopCommand(unittest.TestCase):
@classmethod
@conf_vars({("core", "executor"): "CeleryExecutor"})
def setUpClass(cls):
importlib.reload(cli)
cls.parser = cli.get_parser()
importlib.reload(cli_parser)
cls.parser = cli_parser.get_parser()

def tearDown(self):
importlib.reload(cli)
importlib.reload(cli_parser)

@mock.patch("airflow.cli.commands.celery_command.setup_locations")
@mock.patch("airflow.cli.commands.celery_command.psutil.Process")
Expand Down Expand Up @@ -158,11 +158,11 @@ class TestWorkerStart(unittest.TestCase):
@classmethod
@conf_vars({("core", "executor"): "CeleryExecutor"})
def setUpClass(cls):
importlib.reload(cli)
cls.parser = cli.get_parser()
importlib.reload(cli_parser)
cls.parser = cli_parser.get_parser()

def tearDown(self):
importlib.reload(cli)
importlib.reload(cli_parser)

@mock.patch("airflow.cli.commands.celery_command.setup_locations")
@mock.patch('airflow.cli.commands.celery_command.Process')
Expand Down
4 changes: 2 additions & 2 deletions tests/cli/commands/test_config_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
import unittest
from unittest import mock

from airflow.bin import cli
from airflow.cli import cli_parser
from airflow.cli.commands import config_command
from tests.test_utils.config import conf_vars


class TestCliConfig(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.parser = cli.get_parser()
cls.parser = cli_parser.get_parser()

@mock.patch("airflow.cli.commands.config_command.io.StringIO")
@mock.patch("airflow.cli.commands.config_command.conf")
Expand Down
8 changes: 4 additions & 4 deletions tests/cli/commands/test_connection_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from parameterized import parameterized

from airflow.bin import cli
from airflow.cli import cli_parser
from airflow.cli.commands import connection_command
from airflow.models import Connection
from airflow.utils.db import merge_conn
Expand All @@ -47,7 +47,7 @@ class TestCliListConnections(unittest.TestCase):
]

def setUp(self):
self.parser = cli.get_parser()
self.parser = cli_parser.get_parser()
clear_db_connections()

def tearDown(self):
Expand Down Expand Up @@ -80,7 +80,7 @@ def test_cli_connections_list_as_tsv(self):
class TestCliAddConnections(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.parser = cli.get_parser()
cls.parser = cli_parser.get_parser()
clear_db_connections()

@classmethod
Expand Down Expand Up @@ -255,7 +255,7 @@ def test_cli_connections_add_delete_with_missing_parameters(self):
class TestCliDeleteConnections(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.parser = cli.get_parser()
cls.parser = cli_parser.get_parser()
clear_db_connections()

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions tests/cli/commands/test_dag_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import mock
import pytz

import airflow.bin.cli as cli
from airflow import settings
from airflow.cli import cli_parser
from airflow.cli.commands import dag_command
from airflow.exceptions import AirflowException
from airflow.models import DagBag, DagModel, DagRun
Expand Down Expand Up @@ -58,7 +58,7 @@ class TestCliDags(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.dagbag = DagBag(include_examples=True)
cls.parser = cli.get_parser()
cls.parser = cli_parser.get_parser()

@mock.patch("airflow.cli.commands.dag_command.DAG.run")
def test_backfill(self, mock_run):
Expand Down
4 changes: 2 additions & 2 deletions tests/cli/commands/test_db_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@

from sqlalchemy.engine.url import make_url

from airflow.bin import cli
from airflow.cli import cli_parser
from airflow.cli.commands import db_command
from airflow.exceptions import AirflowException


class TestCliDb(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.parser = cli.get_parser()
cls.parser = cli_parser.get_parser()

@mock.patch("airflow.cli.commands.db_command.db.initdb")
def test_cli_initdb(self, mock_initdb):
Expand Down
4 changes: 2 additions & 2 deletions tests/cli/commands/test_pool_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from contextlib import redirect_stdout

from airflow import models, settings
from airflow.bin import cli
from airflow.cli import cli_parser
from airflow.cli.commands import pool_command
from airflow.models import Pool
from airflow.settings import Session
Expand All @@ -34,7 +34,7 @@ class TestCliPools(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.dagbag = models.DagBag(include_examples=True)
cls.parser = cli.get_parser()
cls.parser = cli_parser.get_parser()

def setUp(self):
super().setUp()
Expand Down
4 changes: 2 additions & 2 deletions tests/cli/commands/test_role_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from contextlib import redirect_stdout

from airflow import models
from airflow.bin import cli
from airflow.cli import cli_parser
from airflow.cli.commands import role_command
from airflow.settings import Session

Expand All @@ -33,7 +33,7 @@ class TestCliRoles(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.dagbag = models.DagBag(include_examples=True)
cls.parser = cli.get_parser()
cls.parser = cli_parser.get_parser()

def setUp(self):
from airflow.www import app as application
Expand Down
4 changes: 2 additions & 2 deletions tests/cli/commands/test_sync_perm_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import unittest
from unittest import mock

from airflow.bin import cli
from airflow.cli import cli_parser
from airflow.cli.commands import sync_perm_command
from airflow.models.dag import DAG
from airflow.models.dagbag import DagBag
Expand All @@ -30,7 +30,7 @@ class TestCliSyncPerm(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.dagbag = DagBag(include_examples=True)
cls.parser = cli.get_parser()
cls.parser = cli_parser.get_parser()

def setUp(self):
from airflow.www import app as application
Expand Down
6 changes: 3 additions & 3 deletions tests/cli/commands/test_task_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from parameterized import parameterized
from tabulate import tabulate

from airflow.bin import cli
from airflow.cli import cli_parser
from airflow.cli.commands import task_command
from airflow.exceptions import AirflowException
from airflow.models import DagBag, TaskInstance
Expand All @@ -50,7 +50,7 @@ class TestCliTasks(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.dagbag = DagBag(include_examples=True)
cls.parser = cli.get_parser()
cls.parser = cli_parser.get_parser()

def test_cli_list_tasks(self):
for dag_id in self.dagbag.dags:
Expand Down Expand Up @@ -251,7 +251,7 @@ def setUp(self):
clear_db_runs()
clear_db_pools()

self.parser = cli.get_parser()
self.parser = cli_parser.get_parser()

def test_run_ignores_all_dependencies(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/cli/commands/test_user_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from contextlib import redirect_stdout

from airflow import models
from airflow.bin import cli
from airflow.cli import cli_parser
from airflow.cli.commands import user_command
from airflow.settings import Session

Expand All @@ -44,7 +44,7 @@ class TestCliUsers(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.dagbag = models.DagBag(include_examples=True)
cls.parser = cli.get_parser()
cls.parser = cli_parser.get_parser()

def setUp(self):
from airflow.www import app as application
Expand Down
Loading