flake8-alphabetize


Nameflake8-alphabetize JSON
Version 0.0.21 PyPI version JSON
download
home_page
SummaryA Python style checker for alphabetizing import and __all__.
upload_time2023-04-13 19:34:12
maintainer
docs_urlNone
author
requires_python>=3.7
licenseMIT No Attribution
keywords flake8
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ==================
Flake8 Alphabetize
==================

Alphabetize is a `Flake8 <https://flake8.pycqa.org/en/latest/>`_ plugin for checking the
order of ``import`` statements, the ``__all__`` list and ``except`` lists. It is
designed to work well with the
`Black <https://black.readthedocs.io/en/stable/index.html>`_ formatting tool, in that
Black never alters the
`Abstract Syntax Tree <https://en.wikipedia.org/wiki/Abstract_syntax_tree>`_ (AST),
while Alphabetize is *only* interested in the AST, and so the two tools never conflict.
In the spirit of Black, Alphabetize is an 'uncompromising import style checker' in that
the style can't be configured, there's just one style (see below for the rules).

Alphabetise is released under the `MIT-0 licence
<https://choosealicense.com/licenses/mit-0/>`_. It is tested on Python 3.7+.

.. image:: https://github.com/tlocke/flake8-alphabetize/actions/workflows/test.yaml/badge.svg
   :alt: Build Status

.. contents:: Table of Contents
   :depth: 1
   :local:


Installation
------------

1. Create a virtual environment: ``python3 -m venv venv``

#. Activate it: ``source venv/bin/activate``

2. Install: ``pip install flake8-alphabetize``


Examples
--------

Say we have a Python file ``myfile.py``:

.. code:: python

   from datetime import time, date

   print(time(9, 39), date(2021, 4, 11))


by running the command ``flake8`` we'll get::

   myfile.py:1:1: AZ200 Imported names are in the wrong order. Should be date, time

We can tell Alphabetize what the package name is, and then it'll know that its imports
should be in a group at the bottom of the imports. Here's an example:

.. code:: python

   import uuid

   from myapp import myfunc

   print(uuid.UUID4(), myfunc())


by running the command ``flake8 --application-names myapp`` we won't get any errors.


Usage
-----

As you use Flake8 in the normal way, Alphabetize will report errors using the following
codes:

.. table:: Error Codes

   +-------+----------------------------------------------------------------+
   | Code  | Error Type                                                     |
   +=======+================================================================+
   | AZ100 | Import statements are in the wrong order                       |
   +-------+----------------------------------------------------------------+
   | AZ200 | The names in the ``import from`` are in the wrong order        |
   +-------+----------------------------------------------------------------+
   | AZ300 | Two ``import from`` statements must be combined.               |
   +-------+----------------------------------------------------------------+
   | AZ400 | The names in the ``__all__`` are in the wrong order            |
   +-------+----------------------------------------------------------------+
   | AZ500 | The names in the exception handler list are in the wrong order |
   +-------+----------------------------------------------------------------+

Alphabetize follows the Black formatter's uncompromising approach and so there's only
one configuration option which is ``application-names``. This is a comma-separated list
of top-level, package names that are to be treated as application imports, eg. 'myapp'.
Since Alphabetize is a Flake8 plugin, this configuration option is set using
`Flake8 configuration <https://flake8.pycqa.org/en/latest/user/configuration.html>`_.


Rules Of Import Ordering
------------------------

Here are the ordering rules that Alphabetize follows:

1. The special case ``from __future__`` import comes first.

#. Imports from the standard library come next, followed by third party imports,
   followed by application imports.

#. Relative imports are assumed to be application imports.

#. The standard library group has ``import`` statements first (in alphabetical order),
   followed by ``from import`` statements (in alphabetical order).

#. The third party group is further grouped by library name. Then each library subgroup
   has ``import`` statements first (in alphabetical order), followed by ``from import``
   statements (in alphabetical order).

#. The application group is further grouped by import level, with absolute imports first
   and then relative imports of increasing level. Within each level, the imports should
   be ordered by library name. Then each library subgroup has ``import`` statements
   first (in alphabetical order), followed by ``from import`` statements (in
   alphabetical order).

#. ``from import`` statements for the same library must be combined.

#. Alphabetize only looks at imports at the module level, any imports within the code
   are ignored.


Running Tests
-------------

Run `tox <https://tox.wiki/en/latest/>`_ to run the tests.

* Install tox: ``pip install tox``
* Run tox: ``tox``


OpenSSF Scorecard
-----------------

It might be worth running the `OpenSSF Scorecard <https://securityscorecards.dev/>`_::

  sudo docker run -e GITHUB_AUTH_TOKEN=<auth_token> gcr.io/openssf/scorecard:stable \
  --repo=github.com/tlocke/flake8-alphabetize


Doing A Release Of Alphabetize
------------------------------

Run ``tox`` to make sure all tests pass, then update the release notes, then do::

   git tag -a x.y.z -m "version x.y.z"
   rm -r dist
   python -m build
   twine upload --sign dist/*


Release Notes
-------------

Version 0.0.21, 2023-04-13
``````````````````````````

- Fixed a bug where it crashes on qualified names in an exception list.


Version 0.0.20, 2023-04-02
``````````````````````````

- Check the ordering of ``except`` handler lists.


Version 0.0.19, 2022-11-24
``````````````````````````

- Make Alphabetize compatible with Flake8 6.0.0


Version 0.0.18, 2022-10-29
``````````````````````````

- Fix bug where sub-packages (eg. ``collections.abc``) aren't recognised as being part
  of the standard library for versions of Python >= 3.10.


Version 0.0.17, 2021-11-17
``````````````````````````

- Handle the case of an ``__all__`` being a ``tuple``.


Version 0.0.16, 2021-07-26
``````````````````````````

* Don't perform any import order checks if there are multiple imports on a line, as
  this will be reported by Flake8. Once the Flake8 error has been fixed, checks can
  continue.


Version 0.0.15, 2021-06-17
``````````````````````````

* Fix bug where the ``--application-names`` command line option failed with a
  comma-separated list.


Version 0.0.14, 2021-04-20
``````````````````````````

* Fix bug where ``from . import logging`` appears in message as ``from .None import
  logging``.


Version 0.0.13, 2021-04-20
``````````````````````````

* Fix bug where it fails on a relative import such as ``from . import logging``.


Version 0.0.12, 2021-04-12
``````````````````````````

* Check the order of the elements of ``__all__``.


Version 0.0.11, 2021-04-11
``````````````````````````

* Order application imports by import level, absolute imports at the top.


Version 0.0.10, 2021-04-11
``````````````````````````

* Fix bug where potentially fails with > 2 imports.


Version 0.0.9, 2021-04-11
`````````````````````````

* There's a clash of option names, so now application imports can now be identified by
  setting the ``application-names`` configuration option.


Version 0.0.8, 2021-04-11
`````````````````````````

* Application imports can now be identified by setting the ``application-package-names``
  configuration option.


Version 0.0.7, 2021-04-10
`````````````````````````

* Import of ``__future__``. Should always be first.


Version 0.0.6, 2021-04-10
`````````````````````````

* Third party libraries should be grouped by top-level name.


Version 0.0.5, 2021-04-10
`````````````````````````

* Take into account whether a module is in the standard library or not.


Version 0.0.4, 2021-04-10
`````````````````````````

* Make entry point AZ instead of ALP.


Version 0.0.3, 2021-04-10
`````````````````````````

* Check the order within ``from import`` statements.


Version 0.0.2, 2021-04-09
`````````````````````````

* Partially support ``from import`` statements.


Version 0.0.1, 2021-04-09
`````````````````````````

* Now partially supports ``import`` statements.


Version 0.0.0, 2021-04-09
`````````````````````````

* Initial release. Doesn't do much at this stage.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "flake8-alphabetize",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "flake8",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/ac/66/1bf33195a89be1682c5410fc03e72311dd34d49b51cbae3e0ddb52955356/flake8-alphabetize-0.0.21.tar.gz",
    "platform": null,
    "description": "==================\nFlake8 Alphabetize\n==================\n\nAlphabetize is a `Flake8 <https://flake8.pycqa.org/en/latest/>`_ plugin for checking the\norder of ``import`` statements, the ``__all__`` list and ``except`` lists. It is\ndesigned to work well with the\n`Black <https://black.readthedocs.io/en/stable/index.html>`_ formatting tool, in that\nBlack never alters the\n`Abstract Syntax Tree <https://en.wikipedia.org/wiki/Abstract_syntax_tree>`_ (AST),\nwhile Alphabetize is *only* interested in the AST, and so the two tools never conflict.\nIn the spirit of Black, Alphabetize is an 'uncompromising import style checker' in that\nthe style can't be configured, there's just one style (see below for the rules).\n\nAlphabetise is released under the `MIT-0 licence\n<https://choosealicense.com/licenses/mit-0/>`_. It is tested on Python 3.7+.\n\n.. image:: https://github.com/tlocke/flake8-alphabetize/actions/workflows/test.yaml/badge.svg\n   :alt: Build Status\n\n.. contents:: Table of Contents\n   :depth: 1\n   :local:\n\n\nInstallation\n------------\n\n1. Create a virtual environment: ``python3 -m venv venv``\n\n#. Activate it: ``source venv/bin/activate``\n\n2. Install: ``pip install flake8-alphabetize``\n\n\nExamples\n--------\n\nSay we have a Python file ``myfile.py``:\n\n.. code:: python\n\n   from datetime import time, date\n\n   print(time(9, 39), date(2021, 4, 11))\n\n\nby running the command ``flake8`` we'll get::\n\n   myfile.py:1:1: AZ200 Imported names are in the wrong order. Should be date, time\n\nWe can tell Alphabetize what the package name is, and then it'll know that its imports\nshould be in a group at the bottom of the imports. Here's an example:\n\n.. code:: python\n\n   import uuid\n\n   from myapp import myfunc\n\n   print(uuid.UUID4(), myfunc())\n\n\nby running the command ``flake8 --application-names myapp`` we won't get any errors.\n\n\nUsage\n-----\n\nAs you use Flake8 in the normal way, Alphabetize will report errors using the following\ncodes:\n\n.. table:: Error Codes\n\n   +-------+----------------------------------------------------------------+\n   | Code  | Error Type                                                     |\n   +=======+================================================================+\n   | AZ100 | Import statements are in the wrong order                       |\n   +-------+----------------------------------------------------------------+\n   | AZ200 | The names in the ``import from`` are in the wrong order        |\n   +-------+----------------------------------------------------------------+\n   | AZ300 | Two ``import from`` statements must be combined.               |\n   +-------+----------------------------------------------------------------+\n   | AZ400 | The names in the ``__all__`` are in the wrong order            |\n   +-------+----------------------------------------------------------------+\n   | AZ500 | The names in the exception handler list are in the wrong order |\n   +-------+----------------------------------------------------------------+\n\nAlphabetize follows the Black formatter's uncompromising approach and so there's only\none configuration option which is ``application-names``. This is a comma-separated list\nof top-level, package names that are to be treated as application imports, eg. 'myapp'.\nSince Alphabetize is a Flake8 plugin, this configuration option is set using\n`Flake8 configuration <https://flake8.pycqa.org/en/latest/user/configuration.html>`_.\n\n\nRules Of Import Ordering\n------------------------\n\nHere are the ordering rules that Alphabetize follows:\n\n1. The special case ``from __future__`` import comes first.\n\n#. Imports from the standard library come next, followed by third party imports,\n   followed by application imports.\n\n#. Relative imports are assumed to be application imports.\n\n#. The standard library group has ``import`` statements first (in alphabetical order),\n   followed by ``from import`` statements (in alphabetical order).\n\n#. The third party group is further grouped by library name. Then each library subgroup\n   has ``import`` statements first (in alphabetical order), followed by ``from import``\n   statements (in alphabetical order).\n\n#. The application group is further grouped by import level, with absolute imports first\n   and then relative imports of increasing level. Within each level, the imports should\n   be ordered by library name. Then each library subgroup has ``import`` statements\n   first (in alphabetical order), followed by ``from import`` statements (in\n   alphabetical order).\n\n#. ``from import`` statements for the same library must be combined.\n\n#. Alphabetize only looks at imports at the module level, any imports within the code\n   are ignored.\n\n\nRunning Tests\n-------------\n\nRun `tox <https://tox.wiki/en/latest/>`_ to run the tests.\n\n* Install tox: ``pip install tox``\n* Run tox: ``tox``\n\n\nOpenSSF Scorecard\n-----------------\n\nIt might be worth running the `OpenSSF Scorecard <https://securityscorecards.dev/>`_::\n\n  sudo docker run -e GITHUB_AUTH_TOKEN=<auth_token> gcr.io/openssf/scorecard:stable \\\n  --repo=github.com/tlocke/flake8-alphabetize\n\n\nDoing A Release Of Alphabetize\n------------------------------\n\nRun ``tox`` to make sure all tests pass, then update the release notes, then do::\n\n   git tag -a x.y.z -m \"version x.y.z\"\n   rm -r dist\n   python -m build\n   twine upload --sign dist/*\n\n\nRelease Notes\n-------------\n\nVersion 0.0.21, 2023-04-13\n``````````````````````````\n\n- Fixed a bug where it crashes on qualified names in an exception list.\n\n\nVersion 0.0.20, 2023-04-02\n``````````````````````````\n\n- Check the ordering of ``except`` handler lists.\n\n\nVersion 0.0.19, 2022-11-24\n``````````````````````````\n\n- Make Alphabetize compatible with Flake8 6.0.0\n\n\nVersion 0.0.18, 2022-10-29\n``````````````````````````\n\n- Fix bug where sub-packages (eg. ``collections.abc``) aren't recognised as being part\n  of the standard library for versions of Python >= 3.10.\n\n\nVersion 0.0.17, 2021-11-17\n``````````````````````````\n\n- Handle the case of an ``__all__`` being a ``tuple``.\n\n\nVersion 0.0.16, 2021-07-26\n``````````````````````````\n\n* Don't perform any import order checks if there are multiple imports on a line, as\n  this will be reported by Flake8. Once the Flake8 error has been fixed, checks can\n  continue.\n\n\nVersion 0.0.15, 2021-06-17\n``````````````````````````\n\n* Fix bug where the ``--application-names`` command line option failed with a\n  comma-separated list.\n\n\nVersion 0.0.14, 2021-04-20\n``````````````````````````\n\n* Fix bug where ``from . import logging`` appears in message as ``from .None import\n  logging``.\n\n\nVersion 0.0.13, 2021-04-20\n``````````````````````````\n\n* Fix bug where it fails on a relative import such as ``from . import logging``.\n\n\nVersion 0.0.12, 2021-04-12\n``````````````````````````\n\n* Check the order of the elements of ``__all__``.\n\n\nVersion 0.0.11, 2021-04-11\n``````````````````````````\n\n* Order application imports by import level, absolute imports at the top.\n\n\nVersion 0.0.10, 2021-04-11\n``````````````````````````\n\n* Fix bug where potentially fails with > 2 imports.\n\n\nVersion 0.0.9, 2021-04-11\n`````````````````````````\n\n* There's a clash of option names, so now application imports can now be identified by\n  setting the ``application-names`` configuration option.\n\n\nVersion 0.0.8, 2021-04-11\n`````````````````````````\n\n* Application imports can now be identified by setting the ``application-package-names``\n  configuration option.\n\n\nVersion 0.0.7, 2021-04-10\n`````````````````````````\n\n* Import of ``__future__``. Should always be first.\n\n\nVersion 0.0.6, 2021-04-10\n`````````````````````````\n\n* Third party libraries should be grouped by top-level name.\n\n\nVersion 0.0.5, 2021-04-10\n`````````````````````````\n\n* Take into account whether a module is in the standard library or not.\n\n\nVersion 0.0.4, 2021-04-10\n`````````````````````````\n\n* Make entry point AZ instead of ALP.\n\n\nVersion 0.0.3, 2021-04-10\n`````````````````````````\n\n* Check the order within ``from import`` statements.\n\n\nVersion 0.0.2, 2021-04-09\n`````````````````````````\n\n* Partially support ``from import`` statements.\n\n\nVersion 0.0.1, 2021-04-09\n`````````````````````````\n\n* Now partially supports ``import`` statements.\n\n\nVersion 0.0.0, 2021-04-09\n`````````````````````````\n\n* Initial release. Doesn't do much at this stage.\n",
    "bugtrack_url": null,
    "license": "MIT No Attribution",
    "summary": "A Python style checker for alphabetizing import and __all__.",
    "version": "0.0.21",
    "split_keywords": [
        "flake8"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ee2ce9bd9b0929e23850aadc58dc174f05f7c7c71311d5ae943b88ad175ea597",
                "md5": "2c0d7785e47a6e4d8205881e7c772e6d",
                "sha256": "4ffb6c6c27bc642ca55584fd6c14564d1c0ca657631573ee2b5ad1d2c159b4ae"
            },
            "downloads": -1,
            "filename": "flake8_alphabetize-0.0.21-py3-none-any.whl",
            "has_sig": true,
            "md5_digest": "2c0d7785e47a6e4d8205881e7c772e6d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7869,
            "upload_time": "2023-04-13T19:34:11",
            "upload_time_iso_8601": "2023-04-13T19:34:11.221378Z",
            "url": "https://files.pythonhosted.org/packages/ee/2c/e9bd9b0929e23850aadc58dc174f05f7c7c71311d5ae943b88ad175ea597/flake8_alphabetize-0.0.21-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ac661bf33195a89be1682c5410fc03e72311dd34d49b51cbae3e0ddb52955356",
                "md5": "494731e7550537298615fdb9d53b6e12",
                "sha256": "8dbc66568d13c1c826c30e7ebe34380c0c4e25edfde3dc51bc0484c04c10b029"
            },
            "downloads": -1,
            "filename": "flake8-alphabetize-0.0.21.tar.gz",
            "has_sig": true,
            "md5_digest": "494731e7550537298615fdb9d53b6e12",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 10278,
            "upload_time": "2023-04-13T19:34:12",
            "upload_time_iso_8601": "2023-04-13T19:34:12.991076Z",
            "url": "https://files.pythonhosted.org/packages/ac/66/1bf33195a89be1682c5410fc03e72311dd34d49b51cbae3e0ddb52955356/flake8-alphabetize-0.0.21.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-13 19:34:12",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "flake8-alphabetize"
}
        
Elapsed time: 0.05844s