Skip to content

Commit

Permalink
use isort to organize python imports
Browse files Browse the repository at this point in the history
  • Loading branch information
jairhenrique committed Aug 29, 2017
1 parent 8d5a25d commit 7816ac9
Show file tree
Hide file tree
Showing 23 changed files with 113 additions and 66 deletions.
1 change: 0 additions & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ tag = True
tag_name = {new_version}

[bumpversion:file:setup.py]

6 changes: 6 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[settings]
line_length = 120
known_first_party = correios
multi_line_output = 3
atomic = true
not_skip = __init__.py
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ install:
- pip install tox-travis
- pip install codecov
- pip install flake8
- pip install isort

before_script:
- isort --check --diff
- flake8 --max-line-length=120 .

script:
Expand Down
1 change: 0 additions & 1 deletion correios/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@

import os


DATADIR = os.path.join(os.path.dirname(__file__), "data")
22 changes: 16 additions & 6 deletions correios/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,26 @@
import os
from datetime import datetime
from decimal import Decimal
from typing import Union, Sequence, List, Dict, Optional
from typing import Dict, List, Optional, Sequence, Union

from correios import xml_utils, DATADIR
from correios import DATADIR, xml_utils
from correios.exceptions import PostingListSerializerError, TrackingCodesLimitExceededError
from correios.models.data import EXTRA_SERVICE_MP, EXTRA_SERVICE_AR
from correios.models.data import EXTRA_SERVICE_AR, EXTRA_SERVICE_MP
from correios.utils import to_decimal, to_integer

from .models.address import ZipAddress, ZipCode
from .models.posting import (NotFoundTrackingEvent, TrackingCode, PostingList, ShippingLabel,
TrackingEvent, EventStatus, Package, Freight, FreightError)
from .models.user import User, FederalTaxNumber, StateTaxNumber, Contract, PostingCard, Service, ExtraService
from .models.posting import (
EventStatus,
Freight,
FreightError,
NotFoundTrackingEvent,
Package,
PostingList,
ShippingLabel,
TrackingCode,
TrackingEvent
)
from .models.user import Contract, ExtraService, FederalTaxNumber, PostingCard, Service, StateTaxNumber, User
from .soap import SoapClient

KG = 1000 # g
Expand Down
11 changes: 5 additions & 6 deletions correios/models/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
# limitations under the License.


from decimal import Decimal
import re
from typing import List, Union, Tuple
import warnings
from decimal import Decimal
from typing import List, Tuple, Union

from phonenumbers import NumberParseException
from phonenumbers import PhoneNumberFormat, parse, format_number
from phonenumbers import NumberParseException, PhoneNumberFormat, format_number, parse

from correios.exceptions import InvalidZipCodeError, InvalidStateError
from correios.models.data import ZIP_CODES, ZIP_CODE_MAP
from correios.exceptions import InvalidStateError, InvalidZipCodeError
from correios.models.data import ZIP_CODE_MAP, ZIP_CODES
from correios.utils import capitalize_phrase, rreplace

ZIP_CODE_LENGTH = 8
Expand Down
1 change: 0 additions & 1 deletion correios/models/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

from ..utils import RangeSet


TRACKING_PREFIX = {
"AL": "Agentes de leitura",
"AR": "Avisos de recebimento",
Expand Down
21 changes: 14 additions & 7 deletions correios/models/posting.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,29 @@
# limitations under the License.


import os
import math
import os
from datetime import datetime, timedelta
from decimal import Decimal
from typing import Optional, Tuple, Union, List, Dict # noqa: F401
from typing import Dict, List, Optional, Tuple, Union # noqa: F401

from PIL import Image

from correios import DATADIR
from correios import exceptions
from correios import DATADIR, exceptions
from correios.utils import to_decimal

from .address import Address, ZipCode
from .data import (INSURANCE_VALUE_THRESHOLD_PAC, INSURANCE_VALUE_THRESHOLD_SEDEX, INSURANCE_PERCENTUAL_COST,
SERVICE_PAC, SERVICE_SEDEX, TRACKING_EVENT_TYPES, TRACKING_STATUS)
from .data import (
INSURANCE_PERCENTUAL_COST,
INSURANCE_VALUE_THRESHOLD_PAC,
INSURANCE_VALUE_THRESHOLD_SEDEX,
SERVICE_PAC,
SERVICE_SEDEX,
TRACKING_EVENT_TYPES,
TRACKING_STATUS
)
from .user import Contract # noqa: F401
from .user import Service, ExtraService, PostingCard
from .user import ExtraService, PostingCard, Service

TRACKING_CODE_SIZE = 13
TRACKING_CODE_NUMBER_SIZE = 8
Expand Down
20 changes: 13 additions & 7 deletions correios/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,25 @@
# limitations under the License.


import os
from datetime import datetime # noqa: F401
from decimal import Decimal
from typing import Union, Optional, Sequence, List # noqa: F401
from typing import List, Optional, Sequence, Union # noqa: F401

import os
from PIL import Image

from correios import DATADIR
from correios.exceptions import (InvalidFederalTaxNumberError, InvalidExtraServiceError,
InvalidRegionalDirectionError, InvalidUserContractError,
MaximumDeclaredValueError, MinimumDeclaredValueError)
from correios.utils import to_integer, to_datetime
from .data import EXTRA_SERVICES, REGIONAL_DIRECTIONS, SERVICES, EXTRA_SERVICE_VD
from correios.exceptions import (
InvalidExtraServiceError,
InvalidFederalTaxNumberError,
InvalidRegionalDirectionError,
InvalidUserContractError,
MaximumDeclaredValueError,
MinimumDeclaredValueError
)
from correios.utils import to_datetime, to_integer

from .data import EXTRA_SERVICE_VD, EXTRA_SERVICES, REGIONAL_DIRECTIONS, SERVICES

EXTRA_SERVICE_CODE_SIZE = 2

Expand Down
2 changes: 1 addition & 1 deletion correios/renderers/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from correios.exceptions import RendererError
from correios.models.data import EXTRA_SERVICE_AR, EXTRA_SERVICE_MP, EXTRA_SERVICE_VD
from correios.models.posting import ShippingLabel, PostingList
from correios.models.posting import PostingList, ShippingLabel
from correios.models.user import ExtraService

VERTICAL_SECURITY_MARGIN = 6 # pt
Expand Down
1 change: 0 additions & 1 deletion correios/soap.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from requests import Session
from zeep import Client, Transport


logger = logging.getLogger(__name__)


Expand Down
3 changes: 1 addition & 2 deletions correios/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import re
from datetime import datetime
from decimal import Decimal
from itertools import chain
from typing import Container, Iterable, Sized, Union

import re


def capitalize_phrase(phrase: str) -> str:
return ' '.join(word.capitalize() for word in phrase.split(' '))
Expand Down
3 changes: 1 addition & 2 deletions documentation/gen_data_module.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env python3.5

import sys
import csv
import sys
from collections import OrderedDict


status = OrderedDict()

with open(sys.argv[1]) as csvfile:
Expand Down
3 changes: 1 addition & 2 deletions documentation/process_correios_status.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/env python3.5

import csv
import re
import sys
import csv


result = []

Expand Down
2 changes: 1 addition & 1 deletion samples/request_tracking_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


from ..correios.client import Correios
from ..correios.models.user import User, Service
from ..correios.models.user import Service, User


def get_tracking_codes(service, quantity):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


from setuptools import setup, find_packages
from setuptools import find_packages, setup


def load_requirements(filename):
Expand Down
7 changes: 3 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
from datetime import datetime

import pytest
from factory import Factory, SubFactory, Faker, LazyFunction, Sequence, faker
from factory import Factory, Faker, LazyFunction, Sequence, SubFactory, faker
from pytest_factoryboy import register

from correios.models import data
from correios.models.address import Address, ReceiverAddress, SenderAddress
from correios.models.data import TRACKING_PREFIX
from correios.models.posting import (PostingList, Package, ShippingLabel, TrackingCode,
TrackingEvent)
from correios.models.user import FederalTaxNumber, StateTaxNumber, Contract, PostingCard, User
from correios.models.posting import Package, PostingList, ShippingLabel, TrackingCode, TrackingEvent
from correios.models.user import Contract, FederalTaxNumber, PostingCard, StateTaxNumber, User

try:
from correios import client as correios
Expand Down
7 changes: 3 additions & 4 deletions tests/test_address_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
# limitations under the License.


from decimal import Decimal
import warnings
from decimal import Decimal

import pytest

from correios.exceptions import InvalidZipCodeError, InvalidStateError
from correios.models.address import (ZipCode, State, Address, Phone, ReceiverAddress,
SenderAddress)
from correios.exceptions import InvalidStateError, InvalidZipCodeError
from correios.models.address import Address, Phone, ReceiverAddress, SenderAddress, State, ZipCode


def test_basic_zip():
Expand Down
16 changes: 11 additions & 5 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@

from correios.exceptions import PostingListSerializerError, TrackingCodesLimitExceededError
from correios.models.address import ZipCode
from correios.models.data import (SERVICE_SEDEX10, SERVICE_SEDEX, EXTRA_SERVICE_VD, SERVICE_PAC, EXTRA_SERVICE_AR,
EXTRA_SERVICE_MP)
from correios.models.posting import (NotFoundTrackingEvent, PostingList, ShippingLabel,
TrackingCode, Package)
from correios.models.user import PostingCard, Service, ExtraService
from correios.models.data import (
EXTRA_SERVICE_AR,
EXTRA_SERVICE_MP,
EXTRA_SERVICE_VD,
SERVICE_PAC,
SERVICE_SEDEX,
SERVICE_SEDEX10
)
from correios.models.posting import NotFoundTrackingEvent, Package, PostingList, ShippingLabel, TrackingCode
from correios.models.user import ExtraService, PostingCard, Service

from .vcr import vcr

try:
Expand Down
1 change: 1 addition & 0 deletions tests/test_pdf_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from correios.models.posting import PostingList
from correios.models.user import PostingCard

from .conftest import ShippingLabelFactory

try:
Expand Down
18 changes: 12 additions & 6 deletions tests/test_posting_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,25 @@
# limitations under the License.


import os
from datetime import datetime, timedelta
from decimal import Decimal

import os
import pytest
from PIL.Image import Image

from correios import DATADIR
from correios import exceptions
from correios import DATADIR, exceptions
from correios.models import posting
from correios.models.data import (SERVICE_SEDEX, SERVICE_PAC, EXTRA_SERVICE_RR, EXTRA_SERVICE_AR,
TRACKING_EVENT_TYPES, EXTRA_SERVICE_VD)
from correios.models.user import Service, ExtraService
from correios.models.data import (
EXTRA_SERVICE_AR,
EXTRA_SERVICE_RR,
EXTRA_SERVICE_VD,
SERVICE_PAC,
SERVICE_SEDEX,
TRACKING_EVENT_TYPES
)
from correios.models.user import ExtraService, Service

from .conftest import ShippingLabelFactory

FIXTURESDIR = os.path.join(os.path.dirname(__file__), "fixtures")
Expand Down
27 changes: 20 additions & 7 deletions tests/test_user_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,31 @@


import os
from datetime import timedelta, datetime, timezone
from datetime import datetime, timedelta, timezone

import pytest
from PIL.Image import Image

from correios import DATADIR
from correios.exceptions import (InvalidFederalTaxNumberError, InvalidExtraServiceError,
InvalidRegionalDirectionError, InvalidUserContractError, MaximumDeclaredValueError,
MinimumDeclaredValueError)
from correios.models.data import EXTRA_SERVICE_AR, SERVICE_SEDEX, SERVICE_PAC
from correios.models.user import (FederalTaxNumber, StateTaxNumber, User, Contract, PostingCard, Service, ExtraService,
RegionalDirection)
from correios.exceptions import (
InvalidExtraServiceError,
InvalidFederalTaxNumberError,
InvalidRegionalDirectionError,
InvalidUserContractError,
MaximumDeclaredValueError,
MinimumDeclaredValueError
)
from correios.models.data import EXTRA_SERVICE_AR, SERVICE_PAC, SERVICE_SEDEX
from correios.models.user import (
Contract,
ExtraService,
FederalTaxNumber,
PostingCard,
RegionalDirection,
Service,
StateTaxNumber,
User
)


def test_basic_federal_tax_number_tax_number():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from correios.utils import capitalize_phrase, RangeSet, rreplace, to_decimal, to_integer
from correios.utils import RangeSet, capitalize_phrase, rreplace, to_decimal, to_integer

phrase = 'FOo bAr BAZ qux'

Expand Down

0 comments on commit 7816ac9

Please sign in to comment.