mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
python: Sort imports with isort.
Fixes #2665. Regenerated by tabbott with `lint --fix` after a rebase and change in parameters. Note from tabbott: In a few cases, this converts technical debt in the form of unsorted imports into different technical debt in the form of our largest files having very long, ugly import sequences at the start. I expect this change will increase pressure for us to split those files, which isn't a bad thing. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
b666aef2d3
commit
365fe0b3d5
@@ -1,23 +1,35 @@
|
||||
import logging
|
||||
import time
|
||||
from collections import OrderedDict, defaultdict
|
||||
from datetime import datetime, timedelta
|
||||
import logging
|
||||
from typing import Callable, Dict, List, \
|
||||
Optional, Tuple, Type, Union
|
||||
from typing import Callable, Dict, List, Optional, Tuple, Type, Union
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import connection
|
||||
from django.db.models import F
|
||||
from psycopg2.sql import Composable, Identifier, Literal, SQL
|
||||
from psycopg2.sql import SQL, Composable, Identifier, Literal
|
||||
|
||||
from analytics.models import BaseCount, \
|
||||
FillState, InstallationCount, RealmCount, StreamCount, \
|
||||
UserCount, installation_epoch, last_successful_fill
|
||||
from analytics.models import (
|
||||
BaseCount,
|
||||
FillState,
|
||||
InstallationCount,
|
||||
RealmCount,
|
||||
StreamCount,
|
||||
UserCount,
|
||||
installation_epoch,
|
||||
last_successful_fill,
|
||||
)
|
||||
from zerver.lib.logging_util import log_to_file
|
||||
from zerver.lib.timestamp import ceiling_to_day, \
|
||||
ceiling_to_hour, floor_to_hour, verify_UTC
|
||||
from zerver.models import Message, Realm, RealmAuditLog, \
|
||||
Stream, UserActivityInterval, UserProfile, models
|
||||
from zerver.lib.timestamp import ceiling_to_day, ceiling_to_hour, floor_to_hour, verify_UTC
|
||||
from zerver.models import (
|
||||
Message,
|
||||
Realm,
|
||||
RealmAuditLog,
|
||||
Stream,
|
||||
UserActivityInterval,
|
||||
UserProfile,
|
||||
models,
|
||||
)
|
||||
|
||||
## Logging setup ##
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ from typing import List
|
||||
|
||||
from analytics.lib.counts import CountStat
|
||||
|
||||
|
||||
def generate_time_series_data(days: int=100, business_hours_base: float=10,
|
||||
non_business_hours_base: float=10, growth: float=1,
|
||||
autocorrelation: float=0, spikiness: float=1,
|
||||
|
||||
@@ -4,6 +4,7 @@ from typing import List, Optional
|
||||
from analytics.lib.counts import CountStat
|
||||
from zerver.lib.timestamp import floor_to_day, floor_to_hour, verify_UTC
|
||||
|
||||
|
||||
# If min_length is None, returns end_times from ceiling(start) to floor(end), inclusive.
|
||||
# If min_length is greater than 0, pads the list to the left.
|
||||
# So informally, time_range(Sep 20, Sep 22, day, None) returns [Sep 20, Sep 21, Sep 22],
|
||||
|
||||
@@ -8,8 +8,7 @@ from django.utils.timezone import now as timezone_now
|
||||
|
||||
from analytics.lib.counts import COUNT_STATS, CountStat
|
||||
from analytics.models import installation_epoch, last_successful_fill
|
||||
from zerver.lib.timestamp import TimezoneNotUTCException, floor_to_day, \
|
||||
floor_to_hour, verify_UTC
|
||||
from zerver.lib.timestamp import TimezoneNotUTCException, floor_to_day, floor_to_hour, verify_UTC
|
||||
from zerver.models import Realm
|
||||
|
||||
states = {
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
from datetime import timedelta
|
||||
from typing import Any, Dict, List, Mapping, Optional, Type
|
||||
|
||||
from unittest import mock
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.utils.timezone import now as timezone_now
|
||||
|
||||
from analytics.lib.counts import COUNT_STATS, CountStat, \
|
||||
do_drop_all_analytics_tables
|
||||
from analytics.lib.counts import COUNT_STATS, CountStat, do_drop_all_analytics_tables
|
||||
from analytics.lib.fixtures import generate_time_series_data
|
||||
from analytics.lib.time_utils import time_range
|
||||
from analytics.models import BaseCount, FillState, InstallationCount, \
|
||||
RealmCount, StreamCount, UserCount
|
||||
from analytics.models import (
|
||||
BaseCount,
|
||||
FillState,
|
||||
InstallationCount,
|
||||
RealmCount,
|
||||
StreamCount,
|
||||
UserCount,
|
||||
)
|
||||
from zerver.lib.actions import STREAM_ASSIGNMENT_COLORS, do_change_user_role
|
||||
from zerver.lib.create_user import create_user
|
||||
from zerver.lib.timestamp import floor_to_day
|
||||
from zerver.models import Client, Realm, Recipient, Stream, Subscription, \
|
||||
UserProfile
|
||||
from zerver.models import Client, Realm, Recipient, Stream, Subscription, UserProfile
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
@@ -6,8 +6,17 @@ from django.core.management.base import BaseCommand, CommandError
|
||||
from django.db.models import Count
|
||||
from django.utils.timezone import now as timezone_now
|
||||
|
||||
from zerver.models import Message, Realm, Recipient, Stream, Subscription, \
|
||||
UserActivity, UserMessage, UserProfile, get_realm
|
||||
from zerver.models import (
|
||||
Message,
|
||||
Realm,
|
||||
Recipient,
|
||||
Stream,
|
||||
Subscription,
|
||||
UserActivity,
|
||||
UserMessage,
|
||||
UserProfile,
|
||||
get_realm,
|
||||
)
|
||||
|
||||
MOBILE_CLIENT_LIST = ["Android", "ios"]
|
||||
HUMAN_CLIENT_LIST = MOBILE_CLIENT_LIST + ["website"]
|
||||
|
||||
@@ -4,8 +4,7 @@ from typing import Any
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.db.models import Q
|
||||
|
||||
from zerver.models import Message, Realm, Recipient, Stream, Subscription, \
|
||||
get_realm
|
||||
from zerver.models import Message, Realm, Recipient, Stream, Subscription, get_realm
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import os
|
||||
import time
|
||||
from argparse import ArgumentParser
|
||||
from typing import Any, Dict
|
||||
from datetime import timezone
|
||||
from typing import Any, Dict
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
@@ -3,6 +3,7 @@ from django.db.backends.postgresql.schema import DatabaseSchemaEditor
|
||||
from django.db.migrations.state import StateApps
|
||||
from django.db.models import Count, Sum
|
||||
|
||||
|
||||
def clear_duplicate_counts(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
|
||||
"""This is a preparatory migration for our Analytics tables.
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ from django.db.models import Q, UniqueConstraint
|
||||
from zerver.lib.timestamp import floor_to_day
|
||||
from zerver.models import Realm, Stream, UserProfile
|
||||
|
||||
|
||||
class FillState(models.Model):
|
||||
property: str = models.CharField(max_length=40, unique=True)
|
||||
end_time: datetime.datetime = models.DateTimeField()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from typing import Any, Dict, List, Optional, Tuple, Type
|
||||
|
||||
from unittest import mock
|
||||
|
||||
import ujson
|
||||
from django.apps import apps
|
||||
from django.db import models
|
||||
@@ -10,24 +10,58 @@ from django.test import TestCase
|
||||
from django.utils.timezone import now as timezone_now
|
||||
from psycopg2.sql import SQL, Literal
|
||||
|
||||
from analytics.lib.counts import COUNT_STATS, CountStat, get_count_stats, \
|
||||
DependentCountStat, LoggingCountStat, do_aggregate_to_summary_table, \
|
||||
do_drop_all_analytics_tables, do_drop_single_stat, \
|
||||
do_fill_count_stat_at_hour, do_increment_logging_stat, \
|
||||
process_count_stat, sql_data_collector
|
||||
from analytics.models import BaseCount, \
|
||||
FillState, InstallationCount, RealmCount, StreamCount, \
|
||||
UserCount, installation_epoch
|
||||
from zerver.lib.actions import do_activate_user, do_create_user, \
|
||||
do_deactivate_user, do_reactivate_user, update_user_activity_interval, \
|
||||
do_invite_users, do_revoke_user_invite, do_resend_user_invite_email, \
|
||||
InvitationError
|
||||
from analytics.lib.counts import (
|
||||
COUNT_STATS,
|
||||
CountStat,
|
||||
DependentCountStat,
|
||||
LoggingCountStat,
|
||||
do_aggregate_to_summary_table,
|
||||
do_drop_all_analytics_tables,
|
||||
do_drop_single_stat,
|
||||
do_fill_count_stat_at_hour,
|
||||
do_increment_logging_stat,
|
||||
get_count_stats,
|
||||
process_count_stat,
|
||||
sql_data_collector,
|
||||
)
|
||||
from analytics.models import (
|
||||
BaseCount,
|
||||
FillState,
|
||||
InstallationCount,
|
||||
RealmCount,
|
||||
StreamCount,
|
||||
UserCount,
|
||||
installation_epoch,
|
||||
)
|
||||
from zerver.lib.actions import (
|
||||
InvitationError,
|
||||
do_activate_user,
|
||||
do_create_user,
|
||||
do_deactivate_user,
|
||||
do_invite_users,
|
||||
do_reactivate_user,
|
||||
do_resend_user_invite_email,
|
||||
do_revoke_user_invite,
|
||||
update_user_activity_interval,
|
||||
)
|
||||
from zerver.lib.create_user import create_user
|
||||
from zerver.lib.timestamp import TimezoneNotUTCException, floor_to_day
|
||||
from zerver.lib.topic import DB_TOPIC_NAME
|
||||
from zerver.models import Client, Huddle, Message, Realm, \
|
||||
RealmAuditLog, Recipient, Stream, UserActivityInterval, \
|
||||
UserProfile, get_client, get_user, PreregistrationUser
|
||||
from zerver.models import (
|
||||
Client,
|
||||
Huddle,
|
||||
Message,
|
||||
PreregistrationUser,
|
||||
Realm,
|
||||
RealmAuditLog,
|
||||
Recipient,
|
||||
Stream,
|
||||
UserActivityInterval,
|
||||
UserProfile,
|
||||
get_client,
|
||||
get_user,
|
||||
)
|
||||
|
||||
|
||||
class AnalyticsTestCase(TestCase):
|
||||
MINUTE = timedelta(seconds = 60)
|
||||
|
||||
@@ -2,6 +2,7 @@ from analytics.lib.counts import CountStat
|
||||
from analytics.lib.fixtures import generate_time_series_data
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
|
||||
|
||||
# A very light test suite; the code being tested is not run in production.
|
||||
class TestFixtures(ZulipTestCase):
|
||||
def test_deterministic_settings(self) -> None:
|
||||
|
||||
@@ -1,24 +1,21 @@
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from typing import List, Optional
|
||||
|
||||
from unittest import mock
|
||||
from django.http import HttpResponse
|
||||
|
||||
import ujson
|
||||
from django.http import HttpResponse
|
||||
from django.utils.timezone import now as timezone_now
|
||||
|
||||
from analytics.lib.counts import COUNT_STATS, CountStat
|
||||
from analytics.lib.time_utils import time_range
|
||||
from analytics.models import FillState, \
|
||||
RealmCount, UserCount, last_successful_fill
|
||||
from analytics.views import rewrite_client_arrays, \
|
||||
sort_by_totals, sort_client_labels
|
||||
from zerver.lib.test_helpers import reset_emails_in_zulip_realm
|
||||
from analytics.models import FillState, RealmCount, UserCount, last_successful_fill
|
||||
from analytics.views import rewrite_client_arrays, sort_by_totals, sort_client_labels
|
||||
from zerver.lib.actions import do_create_multiuse_invite_link, do_send_realm_reactivation_email
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
from zerver.lib.timestamp import ceiling_to_day, \
|
||||
ceiling_to_hour, datetime_to_timestamp
|
||||
from zerver.lib.actions import do_create_multiuse_invite_link, \
|
||||
do_send_realm_reactivation_email
|
||||
from zerver.models import Client, get_realm, MultiuseInvite
|
||||
from zerver.lib.test_helpers import reset_emails_in_zulip_realm
|
||||
from zerver.lib.timestamp import ceiling_to_day, ceiling_to_hour, datetime_to_timestamp
|
||||
from zerver.models import Client, MultiuseInvite, get_realm
|
||||
|
||||
|
||||
class TestStatsEndpoint(ZulipTestCase):
|
||||
def test_stats(self) -> None:
|
||||
|
||||
@@ -6,54 +6,75 @@ import urllib
|
||||
from collections import defaultdict
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from decimal import Decimal
|
||||
|
||||
from typing import Any, Callable, Dict, List, \
|
||||
Optional, Set, Tuple, Type, Union
|
||||
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type, Union
|
||||
|
||||
import pytz
|
||||
from django.conf import settings
|
||||
from django.urls import reverse
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import URLValidator
|
||||
from django.db import connection
|
||||
from django.db.models.query import QuerySet
|
||||
from django.http import HttpRequest, HttpResponse, HttpResponseNotFound
|
||||
from django.shortcuts import render
|
||||
from django.template import loader
|
||||
from django.urls import reverse
|
||||
from django.utils.timesince import timesince
|
||||
from django.utils.timezone import now as timezone_now
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils.timesince import timesince
|
||||
from django.core.validators import URLValidator
|
||||
from django.core.exceptions import ValidationError
|
||||
from jinja2 import Markup as mark_safe
|
||||
from psycopg2.sql import Composable, Literal, SQL
|
||||
from psycopg2.sql import SQL, Composable, Literal
|
||||
|
||||
from analytics.lib.counts import COUNT_STATS, CountStat
|
||||
from analytics.lib.time_utils import time_range
|
||||
from analytics.models import BaseCount, InstallationCount, \
|
||||
RealmCount, StreamCount, UserCount, last_successful_fill, installation_epoch
|
||||
from confirmation.models import Confirmation, confirmation_url, _properties
|
||||
from zerver.decorator import require_server_admin, require_server_admin_api, \
|
||||
to_utc_datetime, zulip_login_required, require_non_guest_user
|
||||
from analytics.models import (
|
||||
BaseCount,
|
||||
InstallationCount,
|
||||
RealmCount,
|
||||
StreamCount,
|
||||
UserCount,
|
||||
installation_epoch,
|
||||
last_successful_fill,
|
||||
)
|
||||
from confirmation.models import Confirmation, _properties, confirmation_url
|
||||
from confirmation.settings import STATUS_ACTIVE
|
||||
from zerver.decorator import (
|
||||
require_non_guest_user,
|
||||
require_server_admin,
|
||||
require_server_admin_api,
|
||||
to_utc_datetime,
|
||||
zulip_login_required,
|
||||
)
|
||||
from zerver.lib.actions import (
|
||||
do_change_plan_type,
|
||||
do_deactivate_realm,
|
||||
do_scrub_realm,
|
||||
do_send_realm_reactivation_email,
|
||||
)
|
||||
from zerver.lib.exceptions import JsonableError
|
||||
from zerver.lib.realm_icon import realm_icon_url
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.timestamp import convert_to_UTC, timestamp_to_datetime
|
||||
from zerver.lib.realm_icon import realm_icon_url
|
||||
from zerver.views.invite import get_invitee_emails_set
|
||||
from zerver.lib.subdomains import get_subdomain_from_hostname
|
||||
from zerver.lib.actions import do_change_plan_type, do_deactivate_realm, \
|
||||
do_send_realm_reactivation_email, do_scrub_realm
|
||||
from zerver.lib.timestamp import convert_to_UTC, timestamp_to_datetime
|
||||
from zerver.lib.validator import to_non_negative_int
|
||||
from confirmation.settings import STATUS_ACTIVE
|
||||
from zerver.views.invite import get_invitee_emails_set
|
||||
|
||||
if settings.BILLING_ENABLED:
|
||||
from corporate.lib.stripe import attach_discount_to_realm, get_discount_for_realm
|
||||
|
||||
from zerver.models import Client, get_realm, Realm, UserActivity, UserActivityInterval, \
|
||||
UserProfile, PreregistrationUser, MultiuseInvite
|
||||
from zerver.models import (
|
||||
Client,
|
||||
MultiuseInvite,
|
||||
PreregistrationUser,
|
||||
Realm,
|
||||
UserActivity,
|
||||
UserActivityInterval,
|
||||
UserProfile,
|
||||
get_realm,
|
||||
)
|
||||
|
||||
if settings.ZILENCER_ENABLED:
|
||||
from zilencer.models import RemoteInstallationCount, RemoteRealmCount, \
|
||||
RemoteZulipServer
|
||||
from zilencer.models import RemoteInstallationCount, RemoteRealmCount, RemoteZulipServer
|
||||
else:
|
||||
from unittest.mock import Mock
|
||||
RemoteInstallationCount = Mock() # type: ignore[misc] # https://github.com/JukkaL/mypy/issues/1188
|
||||
|
||||
Reference in New Issue
Block a user