PyCQA / flake8-import-order

Flake8 plugin that checks import order against various Python Style Guides
GNU Lesser General Public License v3.0
278 stars 72 forks source link

"from _ import _" not being sorted below "import _" #42

Closed Robpol86 closed 8 years ago

Robpol86 commented 9 years ago

In 0.5 this worked fine:

import atexit
import codecs
import os
import re
import subprocess
import sys
from distutils.spawn import find_executable

import setuptools
from setuptools.command.test import test

But in 0.6 I'm getting:

./setup.py:10:1: I100 Imports statements are in the wrong order. from distutils.spawn should be before from sys
1       I100 Imports statements are in the wrong order. from distutils.spawn should be before from sys

0.6 wants to put "from distutils..." between codecs and os.

public commented 9 years ago

Are you in Google mode?

Robpol86 commented 9 years ago

Yep I am.

ashb commented 9 years ago

I also see this.

Minimal test case. Here is the file

import json
import logging
import os
import sys

import yaml

from troposphere import Base64, FindInMap, GetAZs, GetAtt, Join, Output, Ref, Tags, Template
from troposphere.autoscaling import AutoScalingGroup, BlockDeviceMapping, \
    EBSBlockDevice, LaunchConfiguration, Tag
from troposphere.ec2 import InternetGateway, Route, RouteTable, SecurityGroup, \
    SecurityGroupIngress, Subnet, SubnetRouteTableAssociation, VPC, \
    VPCGatewayAttachment
from troposphere.elasticloadbalancing import ConnectionDrainingPolicy, \
    HealthCheck, LoadBalancer, Policy
from troposphere.iam import InstanceProfile, PolicyType, Role
from troposphere.rds import DBInstance, DBSubnetGroup
from troposphere.route53 import AliasTarget, RecordSet, RecordSetGroup
from troposphere.s3 import Bucket, BucketPolicy

from bootstrap_cfn import errors, utils

And the command to run

flake8 --import-order-style=cryptography --application-import-names=tests,bootstrap_cfn  -j 0 --ignore F811,F401,F403 test.py

Gives this output:

test.py:8:1: I100 Imports statements are in the wrong order. from troposphere should be before import yaml

Or is this a different case and I'm min-understanding how it works. I thought all 'imports' should come before 'from' imports.
pgjones commented 8 years ago

This is not google style, although cryptography and Smarkets style are. The recommended fix is to chose one of those styles.