alphabetize


Namealphabetize JSON
Version 0.0.15 PyPI version JSON
download
home_pagehttps://github.com/JakeAdey/alphabetize
SummaryAlphabetize variables within your files
upload_time2023-05-12 09:57:38
maintainer
docs_urlNone
authorJake Adey
requires_python
licenseMIT
keywords alphabetise alphabetize ordering sorting variable sorting
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Alphabetize

Alphabetize finds grouped lines of variables  within your files and orders them alphabetically. This is useful for cleaning up codebases.

The organisation priority is:

1. independent variables
2. dependent variables

The variable 'a' is ordered last as it depends on the other variables.

```
b = 10
c = 20
d = 40
a = b + c + d
```

UPPERCASE and lowercase variables are separated when ordered.

```
A = 10
B = 20
C = 30
a = 10
b = 20
c = 30
```

## Installation

    pip install alphabetize

## Usage

    alphabetize myfile.py
    alphabetize path/to/myfile.py

The provided argument can either be the relative path or absolute path to a Python file.

## Examples

### Example 1 - single use
Consider the following Python script (`unordered_code.py`)

```
import datetime
from time import time

# First Variable Block
c_variable = 60
A_variable = 10
a_variable = 40
B_variable = 20
b_variable = 50
C_variable = 30


class TestClass:
    def __init__(self):
        self.c_variable = 30
        self.a_variable = 10
        self.b_variable = 20


def test_function():
    c_variable = time()
    a_variable = 10
    b_variable = datetime
    a_list = [a_variable, b_variable, c_variable]
    bb_variable = 20
    aa_variable = 10
    cc_variable = aa_variable + bb_variable

    return a_list, cc_variable
    
```

Calling:

    alphabetize unordered_code.py

Results in the following output:

```
import datetime
from time import time

# First Variable Block
A_variable = 10
B_variable = 20
C_variable = 30
a_variable = 40
b_variable = 50
c_variable = 60


class TestClass:
    def __init__(self):
        self.a_variable = 10
        self.b_variable = 20
        self.c_variable = 30


def test_function():
    a_variable = 10
    b_variable = datetime
    c_variable = time()
    a_list = [a_variable, b_variable, c_variable]
    aa_variable = 10
    bb_variable = 20
    cc_variable = aa_variable + bb_variable

    return a_list, cc_variable
    
```

### Example 2 - multiple uses

Depending on the variable names found within grouped lines, `alphabetize` can be called multiple times to further reorder the grouped lines of variables.

This particularly comes into play when independent and dependent variables are mixed within the same grouped lines block.

Consider the following Python script (`unordered_code_multi.py`)

```
def test_function():
    c_variable = 30
    a_variable = 10
    b_variable = 20
    list = [a_variable, b_variable, c_variable]
    bb_variable = 20
    aa_variable = 10
    cc_variable = aa_variable + bb_variable

    return list, cc_variable
    
```

Calling `alphabetize unordered_code_multi.py` for the first time produces:

```
def test_function():
    a_variable = 10
    b_variable = 20
    c_variable = 30
    aa_variable = 10
    bb_variable = 20
    list = [a_variable, b_variable, c_variable]
    cc_variable = aa_variable + bb_variable

    return list, cc_variable

```

Then calling `alphabetize unordered_code_multi.py` a second time produces a further ordered file:

```
def test_function():
    a_variable = 10
    aa_variable = 10
    b_variable = 20
    bb_variable = 20
    c_variable = 30
    cc_variable = aa_variable + bb_variable
    list = [a_variable, b_variable, c_variable]

    return list, cc_variable

```

## Recommended Running

When using `alphabetize` it is recommended that you lint and format your files in the following order:

1. [flake8](https://pypi.org/project/flake8/) is a wrapper around the tools:
   1. Pyflakes 
   2. pycodestyle
   3. Ned Batchelder's McCabe script
2. [vulture](https://pypi.org/project/vulture/) finds unused code in Python programs.
3. [alphabetize](https://pypi.org/project/alphabetize/) finds and orders variables within files

It is recommended to run `alphabetize` a second time to catch any caught dependent variables. Then a further `flake8` to ensure your file is formatted and adheres to PEP8 correctly.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/JakeAdey/alphabetize",
    "name": "alphabetize",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "alphabetise,alphabetize,ordering,sorting,variable sorting",
    "author": "Jake Adey",
    "author_email": "jakespenceradey@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ff/81/33c06ed2f5028845e9faa393b933b1b11fc06dd9f955d0c7bcf975a098ee/alphabetize-0.0.15.tar.gz",
    "platform": null,
    "description": "# Alphabetize\r\n\r\nAlphabetize finds grouped lines of variables  within your files and orders them alphabetically. This is useful for cleaning up codebases.\r\n\r\nThe organisation priority is:\r\n\r\n1. independent variables\r\n2. dependent variables\r\n\r\nThe variable 'a' is ordered last as it depends on the other variables.\r\n\r\n```\r\nb = 10\r\nc = 20\r\nd = 40\r\na = b + c + d\r\n```\r\n\r\nUPPERCASE and lowercase variables are separated when ordered.\r\n\r\n```\r\nA = 10\r\nB = 20\r\nC = 30\r\na = 10\r\nb = 20\r\nc = 30\r\n```\r\n\r\n## Installation\r\n\r\n    pip install alphabetize\r\n\r\n## Usage\r\n\r\n    alphabetize myfile.py\r\n    alphabetize path/to/myfile.py\r\n\r\nThe provided argument can either be the relative path or absolute path to a Python file.\r\n\r\n## Examples\r\n\r\n### Example 1 - single use\r\nConsider the following Python script (`unordered_code.py`)\r\n\r\n```\r\nimport datetime\r\nfrom time import time\r\n\r\n# First Variable Block\r\nc_variable = 60\r\nA_variable = 10\r\na_variable = 40\r\nB_variable = 20\r\nb_variable = 50\r\nC_variable = 30\r\n\r\n\r\nclass TestClass:\r\n    def __init__(self):\r\n        self.c_variable = 30\r\n        self.a_variable = 10\r\n        self.b_variable = 20\r\n\r\n\r\ndef test_function():\r\n    c_variable = time()\r\n    a_variable = 10\r\n    b_variable = datetime\r\n    a_list = [a_variable, b_variable, c_variable]\r\n    bb_variable = 20\r\n    aa_variable = 10\r\n    cc_variable = aa_variable + bb_variable\r\n\r\n    return a_list, cc_variable\r\n    \r\n```\r\n\r\nCalling:\r\n\r\n    alphabetize unordered_code.py\r\n\r\nResults in the following output:\r\n\r\n```\r\nimport datetime\r\nfrom time import time\r\n\r\n# First Variable Block\r\nA_variable = 10\r\nB_variable = 20\r\nC_variable = 30\r\na_variable = 40\r\nb_variable = 50\r\nc_variable = 60\r\n\r\n\r\nclass TestClass:\r\n    def __init__(self):\r\n        self.a_variable = 10\r\n        self.b_variable = 20\r\n        self.c_variable = 30\r\n\r\n\r\ndef test_function():\r\n    a_variable = 10\r\n    b_variable = datetime\r\n    c_variable = time()\r\n    a_list = [a_variable, b_variable, c_variable]\r\n    aa_variable = 10\r\n    bb_variable = 20\r\n    cc_variable = aa_variable + bb_variable\r\n\r\n    return a_list, cc_variable\r\n    \r\n```\r\n\r\n### Example 2 - multiple uses\r\n\r\nDepending on the variable names found within grouped lines, `alphabetize` can be called multiple times to further reorder the grouped lines of variables.\r\n\r\nThis particularly comes into play when independent and dependent variables are mixed within the same grouped lines block.\r\n\r\nConsider the following Python script (`unordered_code_multi.py`)\r\n\r\n```\r\ndef test_function():\r\n    c_variable = 30\r\n    a_variable = 10\r\n    b_variable = 20\r\n    list = [a_variable, b_variable, c_variable]\r\n    bb_variable = 20\r\n    aa_variable = 10\r\n    cc_variable = aa_variable + bb_variable\r\n\r\n    return list, cc_variable\r\n    \r\n```\r\n\r\nCalling `alphabetize unordered_code_multi.py` for the first time produces:\r\n\r\n```\r\ndef test_function():\r\n    a_variable = 10\r\n    b_variable = 20\r\n    c_variable = 30\r\n    aa_variable = 10\r\n    bb_variable = 20\r\n    list = [a_variable, b_variable, c_variable]\r\n    cc_variable = aa_variable + bb_variable\r\n\r\n    return list, cc_variable\r\n\r\n```\r\n\r\nThen calling `alphabetize unordered_code_multi.py` a second time produces a further ordered file:\r\n\r\n```\r\ndef test_function():\r\n    a_variable = 10\r\n    aa_variable = 10\r\n    b_variable = 20\r\n    bb_variable = 20\r\n    c_variable = 30\r\n    cc_variable = aa_variable + bb_variable\r\n    list = [a_variable, b_variable, c_variable]\r\n\r\n    return list, cc_variable\r\n\r\n```\r\n\r\n## Recommended Running\r\n\r\nWhen using `alphabetize` it is recommended that you lint and format your files in the following order:\r\n\r\n1. [flake8](https://pypi.org/project/flake8/) is a wrapper around the tools:\r\n   1. Pyflakes \r\n   2. pycodestyle\r\n   3. Ned Batchelder's McCabe script\r\n2. [vulture](https://pypi.org/project/vulture/) finds unused code in Python programs.\r\n3. [alphabetize](https://pypi.org/project/alphabetize/) finds and orders variables within files\r\n\r\nIt is recommended to run `alphabetize` a second time to catch any caught dependent variables. Then a further `flake8` to ensure your file is formatted and adheres to PEP8 correctly.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Alphabetize variables within your files",
    "version": "0.0.15",
    "project_urls": {
        "Homepage": "https://github.com/JakeAdey/alphabetize"
    },
    "split_keywords": [
        "alphabetise",
        "alphabetize",
        "ordering",
        "sorting",
        "variable sorting"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3917339c4c468d6f685ead8469a7ab07f68461c2d5151162de9a1f5597aebb0c",
                "md5": "2ace4512ede0afd797b4d42e0ea5b000",
                "sha256": "6d12d20fb74fa4429e759477a6290c843b6d0a9d08a2aba276fb5fec3f12c20d"
            },
            "downloads": -1,
            "filename": "alphabetize-0.0.15-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2ace4512ede0afd797b4d42e0ea5b000",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5389,
            "upload_time": "2023-05-12T09:57:26",
            "upload_time_iso_8601": "2023-05-12T09:57:26.148068Z",
            "url": "https://files.pythonhosted.org/packages/39/17/339c4c468d6f685ead8469a7ab07f68461c2d5151162de9a1f5597aebb0c/alphabetize-0.0.15-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ff8133c06ed2f5028845e9faa393b933b1b11fc06dd9f955d0c7bcf975a098ee",
                "md5": "292029043de13401d8990afd45352ce0",
                "sha256": "60ec85f87c4ff606bf60e23b621b61b6bd8b86ec082dbb54a4b324346be209dd"
            },
            "downloads": -1,
            "filename": "alphabetize-0.0.15.tar.gz",
            "has_sig": false,
            "md5_digest": "292029043de13401d8990afd45352ce0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5315,
            "upload_time": "2023-05-12T09:57:38",
            "upload_time_iso_8601": "2023-05-12T09:57:38.624008Z",
            "url": "https://files.pythonhosted.org/packages/ff/81/33c06ed2f5028845e9faa393b933b1b11fc06dd9f955d0c7bcf975a098ee/alphabetize-0.0.15.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-12 09:57:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "JakeAdey",
    "github_project": "alphabetize",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "alphabetize"
}
        
Elapsed time: 0.08018s