diff --git a/gcalcli/actions.py b/gcalcli/actions.py index 18f887bd..8fbd69e9 100644 --- a/gcalcli/actions.py +++ b/gcalcli/actions.py @@ -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 diff --git a/gcalcli/argparsers.py b/gcalcli/argparsers.py index 858b4a5f..1d56878c 100644 --- a/gcalcli/argparsers.py +++ b/gcalcli/argparsers.py @@ -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, diff --git a/gcalcli/cli.py b/gcalcli/cli.py index 99b82dd4..f36dc4f0 100755 --- a/gcalcli/cli.py +++ b/gcalcli/cli.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -############################################################################# +# ######################################################################### # # # # ( ( ( # # ( ( ( )\ ) ( )\ ) )\ ) # @@ -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']) diff --git a/gcalcli/deprecations.py b/gcalcli/deprecations.py index b89c238c..6c643c11 100644 --- a/gcalcli/deprecations.py +++ b/gcalcli/deprecations.py @@ -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() diff --git a/gcalcli/details.py b/gcalcli/details.py index 8cfd6b6b..d5a408ea 100644 --- a/gcalcli/details.py +++ b/gcalcli/details.py @@ -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' @@ -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): diff --git a/gcalcli/gcal.py b/gcalcli/gcal.py index 098357ab..65b512d3 100644 --- a/gcalcli/gcal.py +++ b/gcalcli/gcal.py @@ -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']) diff --git a/gcalcli/utils.py b/gcalcli/utils.py index 86ece362..8d87500d 100644 --- a/gcalcli/utils.py +++ b/gcalcli/utils.py @@ -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 diff --git a/gcalcli/validators.py b/gcalcli/validators.py index bd8e9ccd..437ed58d 100644 --- a/gcalcli/validators.py +++ b/gcalcli/validators.py @@ -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 diff --git a/setup.cfg b/setup.cfg index 2a9acf13..6a9c3ba8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 index 929ae2a1..1c0eb6d7 --- a/setup.py +++ b/setup.py @@ -1,5 +1,6 @@ #!/usr/bin/env python from setuptools import setup + from gcalcli import __version__ try: diff --git a/tests/conftest.py b/tests/conftest.py index 2daa97fb..96f95537 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 diff --git a/tests/test_argparsers.py b/tests/test_argparsers.py index 03ab5562..5c4c6800 100644 --- a/tests/test_argparsers.py +++ b/tests/test_argparsers.py @@ -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""" diff --git a/tests/test_cli.py b/tests/test_cli.py index e85752cb..ef3482d7 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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 diff --git a/tests/test_conflicts.py b/tests/test_conflicts.py index 6d390de1..65480f1e 100644 --- a/tests/test_conflicts.py +++ b/tests/test_conflicts.py @@ -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', diff --git a/tests/test_gcalcli.py b/tests/test_gcalcli.py index dddf86e9..e0069238 100644 --- a/tests/test_gcalcli.py +++ b/tests/test_gcalcli.py @@ -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' diff --git a/tests/test_input_validation.py b/tests/test_input_validation.py index f1d60deb..ec0fd6b7 100644 --- a/tests/test_input_validation.py +++ b/tests/test_input_validation.py @@ -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 diff --git a/tests/test_printer.py b/tests/test_printer.py index 9e420717..2aa7a17d 100644 --- a/tests/test_printer.py +++ b/tests/test_printer.py @@ -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 diff --git a/tests/test_utils.py b/tests/test_utils.py index b47f496f..59ff1e39 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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')