Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[proposal] use isort to organize python imports #91

Merged
merged 7 commits into from
Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ install:
- pip install tox-travis
- pip install codecov
- pip install flake8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO isort shouldn't be added on requirements-test.txt file because it's not used in the project's test suite. Instead it should be installed here with other checkers such as flake8.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

- pip install isort

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

script:
- tox
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")
24 changes: 17 additions & 7 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.utils import to_decimal, to_integer, get_wsdl_path
from correios.models.data import EXTRA_SERVICE_AR, EXTRA_SERVICE_MP
from correios.utils import get_wsdl_path, 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like alphabetical ordering. I prefer to import in the same sequence as we use modules/packages on code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@osantana isort has this settings. How do you want it?

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
19 changes: 16 additions & 3 deletions correios/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
# Copyright 2016 Osvaldo Santana Neto
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import re
from datetime import datetime
from decimal import Decimal
from itertools import chain
from typing import Container, Iterable, Sized, Union

import os
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,12 +19,18 @@

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 correios.utils import get_wsdl_path

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
Loading