Skip to content

Instantly share code, notes, and snippets.

@Integralist
Created January 6, 2020 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Integralist/0ce27db1d7294f3af9896c0807ccfeed to your computer and use it in GitHub Desktop.
Save Integralist/0ce27db1d7294f3af9896c0807ccfeed to your computer and use it in GitHub Desktop.
[Flake8 Import Order] #python #flake8 #import #order
; tox.ini

[flake8]
max-line-length = 120
import-order-style = cryptography
application-import-names = foo

Note: don't try and put flake8-import-order configuration under its own section (e.g. [flake8-import-order]) as Flake8 doesn't look at values outside of its own block (i.e. [flake8]) -- see explanation here.

# standard library packages/modules

import asyncio
import time

# third-party packages/modules

from tornado.httpclient import AsyncHTTPClient
from tornado.ioloop import IOLoop

# application packages/modules

from foo.bar import baz

AsyncHTTPClient.configure(None, defaults=dict(user_agent="MyUserAgent"))
http_client = AsyncHTTPClient()


async def do_thing():
    await asyncio.sleep(1)
    time.sleep(1)
    response = await http_client.fetch("https://www.integralist.co.uk")
    print(response.code)
    baz()

io_loop = IOLoop.current()
io_loop.run_sync(do_thing)

Note: to ensure foo package isn't identified as "Third-Party" we have to specify it as "Application" via configuration with application-import-names, which is a comma-separated list of your own application packages/modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment