Skip to content

Commit

Permalink
style: fix disorganized imports (#662)
Browse files Browse the repository at this point in the history
* build: set up flake8 and isort Google-like import order

* style: fix import order

* style: fix minor flake8 complaints
  • Loading branch information
michaelmhoffman authored Aug 15, 2023
1 parent d197443 commit 30148bc
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 97 deletions.
5 changes: 2 additions & 3 deletions gcalcli/actions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""Handlers for specific agendaupdate actions."""

from gcalcli.details import FIELD_HANDLERS, FIELDNAMES_READONLY
from gcalcli.exceptions import ReadonlyError

from .details import FIELD_HANDLERS, FIELDNAMES_READONLY
from .exceptions import ReadonlyError

CONFERENCE_DATA_VERSION = 1

Expand Down
18 changes: 11 additions & 7 deletions gcalcli/argparsers.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from __future__ import absolute_import

import argparse
import gcalcli
from gcalcli import utils
from gcalcli.details import DETAILS
from gcalcli.deprecations import parser_allow_deprecated, DeprecatedStoreTrue
from gcalcli.printer import valid_color_name
from oauth2client import tools
from shutil import get_terminal_size
import copy as _copy
import datetime
import locale
from shutil import get_terminal_size
import sys

from oauth2client import tools

import gcalcli

from . import utils
from .deprecations import DeprecatedStoreTrue, parser_allow_deprecated
from .details import DETAILS
from .printer import valid_color_name

PROGRAM_OPTIONS = {
'--client-id': {'default': gcalcli.__API_CLIENT_ID__,
'type': str,
Expand Down
22 changes: 10 additions & 12 deletions gcalcli/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
#############################################################################
# ######################################################################### #
# #
# ( ( ( #
# ( ( ( )\ ) ( )\ ) )\ ) #
Expand All @@ -18,21 +18,19 @@
# #
# Everything you need to know (Google API Calendar v3): http://goo.gl/HfTGQ #
# #
#############################################################################
# ######################################################################### #
from collections import namedtuple
import os
import signal
import sys
from collections import namedtuple

from gcalcli import utils
from gcalcli.argparsers import get_argument_parser, handle_unparsed
from gcalcli.exceptions import GcalcliError
from gcalcli.gcal import GoogleCalendarInterface
from gcalcli.printer import Printer, valid_color_name
from gcalcli.validators import (
PARSABLE_DATE, REMINDER, STR_ALLOW_EMPTY, STR_NOT_EMPTY,
PARSABLE_DURATION, get_input
)
from . import utils
from .argparsers import get_argument_parser, handle_unparsed
from .exceptions import GcalcliError
from .gcal import GoogleCalendarInterface
from .printer import Printer, valid_color_name
from .validators import (get_input, PARSABLE_DATE, PARSABLE_DURATION, REMINDER,
STR_ALLOW_EMPTY, STR_NOT_EMPTY)

CalName = namedtuple('CalName', ['name', 'color'])

Expand Down
2 changes: 1 addition & 1 deletion gcalcli/deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import functools

import gcalcli
from gcalcli.printer import valid_color_name, Printer

from .printer import Printer, valid_color_name

printer = Printer()

Expand Down
9 changes: 4 additions & 5 deletions gcalcli/details.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from collections import OrderedDict
from datetime import datetime
from itertools import chain
from typing import List
from typing import List # python3.9: can just use `list`

from dateutil.parser import isoparse, parse

from gcalcli.exceptions import ReadonlyError, ReadonlyCheckError
from gcalcli.utils import is_all_day
from .exceptions import ReadonlyCheckError, ReadonlyError
from .utils import is_all_day

FMT_DATE = '%Y-%m-%d'
FMT_TIME = '%H:%M'
Expand All @@ -33,8 +33,7 @@ class Handler:
"""Handler for a specific detail of an event."""

# list of strings for fieldnames provided by this object
# XXX: py36+: change to `fieldnames: List[str]`
fieldnames = [] # type: List[str]
fieldnames: List[str] = []

@classmethod
def get(cls, event):
Expand Down
59 changes: 29 additions & 30 deletions gcalcli/gcal.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
from collections import namedtuple
from csv import DictReader, excel_tab
import os
import re
import shlex
import httplib2
from datetime import date, datetime, timedelta
from itertools import chain
import time
import textwrap
import json
import os
import random
import re
import shlex
import sys
import textwrap
import time
from unicodedata import east_asian_width

from apiclient.discovery import build
from apiclient.errors import HttpError
from dateutil.parser import parse
from dateutil.relativedelta import relativedelta
from dateutil.tz import tzlocal
import httplib2
from oauth2client import tools
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.file import Storage

from . import __program__, __version__, actions, utils
from .actions import ACTIONS
from .conflicts import ShowConflicts
from .details import _valid_title, ACTION_DEFAULT, DETAILS_DEFAULT, HANDLERS
from .exceptions import GcalcliError
from .printer import Printer
from .utils import days_since_epoch, is_all_day
from .validators import (get_input, get_override_color_id, PARSABLE_DATE,
PARSABLE_DURATION, REMINDER, STR_ALLOW_EMPTY,
STR_NOT_EMPTY, STR_TO_INT, VALID_COLORS)

try:
import cPickle as pickle
except Exception:
import pickle

from gcalcli import __program__, __version__
from gcalcli import actions, utils
from gcalcli.actions import ACTIONS
from gcalcli.details import (
_valid_title, ACTION_DEFAULT, DETAILS_DEFAULT, HANDLERS)
from gcalcli.utils import days_since_epoch, is_all_day
from gcalcli.validators import (
get_input, get_override_color_id, STR_NOT_EMPTY, PARSABLE_DATE, STR_TO_INT,
VALID_COLORS, STR_ALLOW_EMPTY, REMINDER, PARSABLE_DURATION
)
from gcalcli.exceptions import GcalcliError
from gcalcli.printer import Printer
from gcalcli.conflicts import ShowConflicts

from dateutil.relativedelta import relativedelta
from datetime import datetime, timedelta, date
from dateutil.tz import tzlocal
from dateutil.parser import parse
from apiclient.discovery import build
from apiclient.errors import HttpError
from oauth2client.file import Storage
from oauth2client.client import OAuth2WebServerFlow
from oauth2client import tools
from collections import namedtuple

EventTitle = namedtuple('EventTitle', ['title', 'color'])

Expand Down
8 changes: 4 additions & 4 deletions gcalcli/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import calendar
import time
from datetime import datetime, timedelta
import locale
import re
from dateutil.tz import tzlocal
import time

from dateutil.parser import parse as dateutil_parse
from datetime import datetime, timedelta
from dateutil.tz import tzlocal
from parsedatetime.parsedatetime import Calendar


locale.setlocale(locale.LC_ALL, '')
fuzzy_date_parse = Calendar().parse
fuzzy_datetime_parse = Calendar().parseDT
Expand Down
5 changes: 2 additions & 3 deletions gcalcli/validators.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import re

from gcalcli.exceptions import ValidationError
from gcalcli.utils import (REMINDER_REGEX, get_time_from_str,
get_timedelta_from_str)
from .exceptions import ValidationError
from .utils import get_time_from_str, get_timedelta_from_str, REMINDER_REGEX

# TODO: in the future, pull these from the API
# https://developers.google.com/calendar/v3/reference/colors
Expand Down
10 changes: 10 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
[bdist_wheel]
universal = 1

[flake8]
import-order-style = google

[isort]
profile=google
force_single_line=False
float_to_top=True
combine_star=True
py_version=3
1 change: 1 addition & 0 deletions setup.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
from setuptools import setup

from gcalcli import __version__

try:
Expand Down
11 changes: 4 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from datetime import datetime
import os
import sys

import pytest

from datetime import datetime
from apiclient.discovery import build, HttpMock
from dateutil.tz import tzlocal
import pytest

from apiclient.discovery import HttpMock, build

from gcalcli.argparsers import (get_color_parser,
get_cal_query_parser,
from gcalcli.argparsers import (get_cal_query_parser, get_color_parser,
get_output_parser)
from gcalcli.gcal import GoogleCalendarInterface
from gcalcli.printer import Printer
Expand Down
4 changes: 3 additions & 1 deletion tests/test_argparsers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from gcalcli import argparsers
from collections import namedtuple
import shlex

import pytest

from gcalcli import argparsers


def test_get_argparser():
"""Just asserts no errors have been introduced"""
Expand Down
3 changes: 2 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from gcalcli.cli import run_add_prompt
from argparse import Namespace

from gcalcli.cli import run_add_prompt
from gcalcli.printer import Printer


Expand Down
4 changes: 3 additions & 1 deletion tests/test_conflicts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from gcalcli.conflicts import ShowConflicts
from datetime import datetime

from dateutil.tz import tzlocal

from gcalcli.conflicts import ShowConflicts

minimal_event = {
'e': datetime(2019, 1, 8, 15, 15, tzinfo=tzlocal()),
'id': 'minimial_event',
Expand Down
20 changes: 8 additions & 12 deletions tests/test_gcalcli.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
from __future__ import absolute_import

import os
from datetime import datetime
from json import load
import os

from dateutil.tz import tzutc
from datetime import datetime

from gcalcli.utils import parse_reminder
from gcalcli.argparsers import (get_start_end_parser,
get_color_parser,
get_cal_query_parser,
get_output_parser,
get_updates_parser,
get_conflicts_parser,
get_search_parser)
from gcalcli.gcal import GoogleCalendarInterface
from gcalcli.argparsers import (get_cal_query_parser, get_color_parser,
get_conflicts_parser, get_output_parser,
get_search_parser, get_start_end_parser,
get_updates_parser)
from gcalcli.cli import parse_cal_names

from gcalcli.gcal import GoogleCalendarInterface
from gcalcli.utils import parse_reminder

TEST_DATA_DIR = os.path.dirname(os.path.abspath(__file__)) + '/data'

Expand Down
12 changes: 4 additions & 8 deletions tests/test_input_validation.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import pytest

from gcalcli.validators import validate_input, ValidationError
from gcalcli.validators import (STR_NOT_EMPTY,
PARSABLE_DATE,
PARSABLE_DURATION,
STR_TO_INT,
STR_ALLOW_EMPTY,
REMINDER,
VALID_COLORS)
from gcalcli.validators import (PARSABLE_DATE, PARSABLE_DURATION, REMINDER,
STR_ALLOW_EMPTY, STR_NOT_EMPTY, STR_TO_INT,
VALID_COLORS, validate_input, ValidationError)

# Tests required:
#
# * Title: any string, not blank
Expand Down
3 changes: 2 additions & 1 deletion tests/test_printer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import sys
from argparse import ArgumentTypeError
from io import StringIO
import sys

import pytest

from gcalcli.printer import COLOR_NAMES, Printer, valid_color_name


Expand Down
4 changes: 3 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import gcalcli.utils as utils
from datetime import datetime, timedelta

from dateutil.tz import UTC
import pytest

import gcalcli.utils as utils


def test_get_time_from_str():
assert utils.get_time_from_str('7am tomorrow')
Expand Down

0 comments on commit 30148bc

Please sign in to comment.