Skip to content

Commit

Permalink
[cleanup] Remove Py2 related code
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshg999 committed Aug 28, 2024
1 parent 64dac7f commit 74332ff
Show file tree
Hide file tree
Showing 457 changed files with 8,342 additions and 9,528 deletions.
1 change: 0 additions & 1 deletion apps/about/src/about/templates/admin_wizard.mako
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ from metadata.conf import OPTIMIZER, has_optimizer
from desktop.auth.backend import is_admin
from desktop.conf import has_connectors
from desktop.lib.i18n import smart_unicode
from desktop.views import commonheader, commonfooter
if sys.version_info[0] > 2:
Expand Down
7 changes: 1 addition & 6 deletions apps/about/src/about/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
from django.urls import re_path

from about import views as about_views

if sys.version_info[0] > 2:
from django.urls import re_path
else:
from django.conf.urls import url as re_path

urlpatterns = [
re_path(r'^$', about_views.admin_wizard, name='index'),
re_path(r'^admin_wizard$', about_views.admin_wizard, name='admin_wizard'),
Expand Down
9 changes: 1 addition & 8 deletions apps/about/src/about/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from builtins import str
import logging
import sys
from django.utils.translation import gettext as _

from desktop import appmanager
from desktop.auth.backend import is_hue_admin
Expand All @@ -26,11 +24,6 @@
from desktop.models import Settings, hue_version
from desktop.views import collect_usage

if sys.version_info[0] > 2:
from django.utils.translation import gettext as _
else:
from django.utils.translation import ugettext as _


def admin_wizard(request):
if is_hue_admin(request.user):
Expand Down
1 change: 0 additions & 1 deletion apps/beeswax/src/beeswax/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# limitations under the License.

import re
import sys
import json
import logging
from builtins import zip
Expand Down
29 changes: 8 additions & 21 deletions apps/beeswax/src/beeswax/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import logging
import pytest
import sys
import logging
from unittest.mock import Mock, patch

import pytest
from django.test import TestCase
from requests.exceptions import ReadTimeout

from beeswax.api import _autocomplete, get_functions
from desktop.lib.django_test_util import make_logged_in_client
from desktop.lib.test_utils import add_to_group, grant_access
from useradmin.models import User

from beeswax.api import _autocomplete, get_functions


if sys.version_info[0] > 2:
from unittest.mock import patch, Mock
else:
from mock import patch, Mock


LOG = logging.getLogger()


Expand All @@ -47,9 +39,8 @@ def setup_method(self):
self.client = make_logged_in_client(username="test", groupname="default", recreate=True, is_superuser=False)
self.user = User.objects.get(username="test")


def test_autocomplete_time_out(self):
get_tables_meta=Mock(
get_tables_meta = Mock(
side_effect=ReadTimeout("HTTPSConnectionPool(host='gethue.com', port=10001): Read timed out. (read timeout=120)")
)
db = Mock(
Expand All @@ -65,7 +56,6 @@ def test_autocomplete_time_out(self):
'error': "HTTPSConnectionPool(host='gethue.com', port=10001): Read timed out. (read timeout=120)"
})


def test_get_functions(self):
db = Mock(
get_functions=Mock(
Expand All @@ -83,7 +73,6 @@ def test_get_functions(self):
resp ==
[{'name': 'f1'}, {'name': 'f2'}])


def test_get_functions(self):
with patch('beeswax.api._get_functions') as _get_functions:
db = Mock()
Expand All @@ -97,12 +86,11 @@ def test_get_functions(self):
resp['functions'] ==
[{'name': 'f1'}, {'name': 'f2'}, {'name': 'f3'}])


def test_get_function(self):
db = Mock()
db.client = Mock(query_server = {'dialect': 'hive'})
db.client = Mock(query_server={'dialect': 'hive'})
db.get_function = Mock(
return_value = [
return_value=[
['floor_month(param) - Returns the timestamp at a month granularity'],
['param needs to be a timestamp value'],
['Example:'],
Expand All @@ -123,8 +111,7 @@ def test_get_function(self):
'> SELECT floor_month(CAST(\'yyyy-MM-dd HH:mm:ss\' AS TIMESTAMP)) FROM src;\nyyyy-MM-01 00:00:00'
})


db.client = Mock(query_server = {'dialect': 'impala'})
db.client = Mock(query_server={'dialect': 'impala'})
data = _autocomplete(db, operation='function')

assert data['function'] == {}
51 changes: 33 additions & 18 deletions apps/beeswax/src/beeswax/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import division
from builtins import str
import logging
import math
import logging
import os.path
import sys

from desktop.conf import default_ssl_cacerts, default_ssl_validate, AUTH_PASSWORD as DEFAULT_AUTH_PASSWORD,\
AUTH_USERNAME as DEFAULT_AUTH_USERNAME
from desktop.lib.conf import ConfigSection, Config, coerce_bool, coerce_csv, coerce_password_from_script

if sys.version_info[0] > 2:
from django.utils.translation import gettext_lazy as _t, gettext as _
else:
from django.utils.translation import ugettext_lazy as _t, ugettext as _
from django.utils.translation import gettext as _, gettext_lazy as _t

from desktop.conf import (
AUTH_PASSWORD as DEFAULT_AUTH_PASSWORD,
AUTH_USERNAME as DEFAULT_AUTH_USERNAME,
default_ssl_cacerts,
default_ssl_validate,
)
from desktop.lib.conf import Config, ConfigSection, coerce_bool, coerce_csv, coerce_password_from_script

LOG = logging.getLogger()

Expand Down Expand Up @@ -103,21 +100,25 @@
"the fully-qualified domain name (FQDN) is required"),
default="localhost")


def get_hive_thrift_binary_port():
"""Devise port from core-site Thrift / execution mode & Http port"""
from beeswax.hive_site import hiveserver2_thrift_binary_port, get_hive_execution_mode # Cyclic dependency
from beeswax.hive_site import get_hive_execution_mode, hiveserver2_thrift_binary_port # Cyclic dependency
return hiveserver2_thrift_binary_port() or (10500 if (get_hive_execution_mode() or '').lower() == 'llap' else 10000)


HIVE_SERVER_PORT = Config(
key="hive_server_port",
help=_t("Configure the binary Thrift port for HiveServer2."),
dynamic_default=get_hive_thrift_binary_port,
type=int)


def get_hive_thrift_http_port():
"""Devise port from core-site Thrift / execution mode & Http port"""
from beeswax.hive_site import hiveserver2_thrift_http_port, get_hive_execution_mode # Cyclic dependency
return hiveserver2_thrift_http_port() or (10501 if (get_hive_execution_mode() or '').lower() == 'llap' else 10001)
from beeswax.hive_site import get_hive_execution_mode, hiveserver2_thrift_http_port # Cyclic dependency
return hiveserver2_thrift_http_port() or (10501 if (get_hive_execution_mode() or '').lower() == 'llap' else 10001)


HIVE_HTTP_THRIFT_PORT = Config(
key="hive_server_http_port",
Expand Down Expand Up @@ -165,15 +166,15 @@ def get_hive_thrift_http_port():
type=int,
help=_t('Timeout in seconds for zookeeper connection.'))

USE_GET_LOG_API = Config( # To remove in Hue 4
USE_GET_LOG_API = Config( # To remove in Hue 4
key='use_get_log_api',
default=False,
type=coerce_bool,
help=_t('Choose whether to use the old GetLog() Thrift call from before Hive 0.14 to retrieve the logs.'
'If false, use the FetchResults() Thrift call from Hive 1.0 or more instead.')
)

BROWSE_PARTITIONED_TABLE_LIMIT = Config( # Deprecated, to remove in Hue 4
BROWSE_PARTITIONED_TABLE_LIMIT = Config( # Deprecated, to remove in Hue 4
key='browse_partitioned_table_limit',
default=1000,
type=int,
Expand All @@ -187,10 +188,12 @@ def get_hive_thrift_http_port():
type=int,
help=_t('The maximum number of partitions that will be included in the SELECT * LIMIT sample query for partitioned tables.'))


def get_browse_partitioned_table_limit():
"""Get the old default"""
return BROWSE_PARTITIONED_TABLE_LIMIT.get()


LIST_PARTITIONS_LIMIT = Config(
key='list_partitions_limit',
dynamic_default=get_browse_partitioned_table_limit,
Expand All @@ -206,10 +209,12 @@ def get_browse_partitioned_table_limit():
'(e.g. - 10K rows * 1K columns = 10M cells.) '
'A value of -1 means there will be no limit.'))


def get_deprecated_download_cell_limit():
"""Get the old default"""
return math.floor(DOWNLOAD_CELL_LIMIT.get() / 100) if DOWNLOAD_CELL_LIMIT.get() > 0 else DOWNLOAD_CELL_LIMIT.get()


DOWNLOAD_ROW_LIMIT = Config(
key='download_row_limit',
dynamic_default=get_deprecated_download_cell_limit,
Expand Down Expand Up @@ -297,15 +302,18 @@ def get_deprecated_download_cell_limit():
)
)


def get_auth_username():
"""Get from top level default from desktop"""
return DEFAULT_AUTH_USERNAME.get()


AUTH_USERNAME = Config(
key="auth_username",
help=_t("Auth username of the hue user used for authentications."),
dynamic_default=get_auth_username)


def get_auth_password():
"""Get from script or backward compatibility"""
password = AUTH_PASSWORD_SCRIPT.get()
Expand All @@ -314,6 +322,7 @@ def get_auth_password():

return DEFAULT_AUTH_PASSWORD.get()


AUTH_PASSWORD = Config(
key="auth_password",
help=_t("LDAP/PAM/.. password of the hue user used for authentications."),
Expand All @@ -327,13 +336,15 @@ def get_auth_password():
type=coerce_password_from_script,
default=None)


def get_use_sasl_default():
"""Get from hive_site or backward compatibility"""
from beeswax.hive_site import get_hiveserver2_authentication, get_use_sasl # Cyclic dependency
use_sasl = get_use_sasl()
if use_sasl is not None:
return use_sasl.upper() == 'TRUE'
return get_hiveserver2_authentication() in ('KERBEROS', 'NONE', 'LDAP', 'PAM') # list for backward compatibility
return get_hiveserver2_authentication() in ('KERBEROS', 'NONE', 'LDAP', 'PAM') # list for backward compatibility


USE_SASL = Config(
key="use_sasl",
Expand All @@ -342,10 +353,12 @@ def get_use_sasl_default():
type=coerce_bool,
dynamic_default=get_use_sasl_default)


def has_multiple_sessions():
"""When true will create multiple sessions for user queries"""
return MAX_NUMBER_OF_SESSIONS.get() != 1


CLOSE_SESSIONS = Config(
key="close_sessions",
help=_t(
Expand All @@ -356,9 +369,11 @@ def has_multiple_sessions():
dynamic_default=has_multiple_sessions
)


def has_session_pool():
return has_multiple_sessions() and not CLOSE_SESSIONS.get()


MAX_CATALOG_SQL_ENTRIES = Config(
key="max_catalog_sql_entries",
help=_t(
Expand Down
Loading

0 comments on commit 74332ff

Please sign in to comment.