mvdef


Namemvdef JSON
Version 0.9.4 PyPI version JSON
download
home_page
SummaryPackage providing command line tools to move/copy function/classes and their associated import statements between files.
upload_time2024-03-03 16:44:30
maintainer
docs_urlNone
author
requires_python<3.12,>=3.10
licenseMIT
keywords ast
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # mvdef

[![Documentation](https://readthedocs.org/projects/mvdef/badge/?version=latest)](https://mvdef.readthedocs.io/en/latest/)
[![CI Status](https://github.com/lmmx/mvdef/actions/workflows/master.yml/badge.svg)](https://github.com/lmmx/mvdef/actions/workflows/master.yml)
[![Coverage](https://codecov.io/gh/lmmx/mvdef/branch/master/graph/badge.svg)](https://codecov.io/github/lmmx/mvdef)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

Package providing command line tools to move/copy function/classes and their associated import statements between files

[Read The Docs](https://mvdef.readthedocs.io/en/latest/)

## Requires

- Python 3.10+

## Installation

```sh
pip install mvdef
```

## Usage

### `mvdef`

Moves functions named by `-m`/`--mv` and their associated imports from `src` to `dst`,
or just previews the changes as a diff if passed `-d`/`--dry-run`.

```
usage: mvdef [-h] -m [MV ...] [-d] [-e] [-c] [-f] [-v] src dst

  Move function definitions from one file to another, moving/copying
  any necessary associated import statements along with them.

  Option     Description                                Type        Default
  —————————— —————————————————————————————————————————— ——————————— ———————
• src        source file to take definitions from       Path        -
• dst        destination file (may not exist)           Path        -
• mv         names to move from the source file         list[str]   -
• dry_run    whether to only preview the change diffs   bool        False
• escalate   whether to raise an error upon failure     bool        False
• cls_defs   whether to use only class definitions      bool        False
• func_defs  whether to use only function definitions   bool        False
• verbose    whether to log anything                    bool        False

positional arguments:
  src
  dst

options:
  -h, --help            show this help message and exit
  -m [MV ...], --mv [MV ...]
  -d, --dry-run
  -e, --escalate
  -c, --cls-defs
  -f, --func-defs
  -v, --verbose
```

### `cpdef`

Copies functions named by `-m`/`--mv` and their associated imports from `src` to `dst`,
or just previews the changes as a diff if passed `-d`/`--dry-run`.

Has the same flags and signature as `mvdef`, but never changes `src`.

```
usage: cpdef [-h] -m [MV ...] [-d] [-e] [-c] [-f] [-v] src dst

  Copy function definitions from one file to another, and any necessary
  associated import statements along with them.

  Option     Description                                Type        Default
  —————————— —————————————————————————————————————————— ——————————— ———————
• src        source file to copy definitions from       Path        -
• dst        destination file (may not exist)           Path        -
• mv         names to copy from the source file         list[str]   -
• dry_run    whether to only preview the change diffs   bool        False
• escalate   whether to raise an error upon failure     bool        False
• cls_defs   whether to use only class definitions      bool        False
• func_defs  whether to use only function definitions   bool        False
• verbose    whether to log anything                    bool        False

positional arguments:
  src
  dst

options:
  -h, --help            show this help message and exit
  -m [MV ...], --mv [MV ...]
  -d, --dry-run
  -e, --escalate
  -c, --cls-defs
  -f, --func-defs
  -v, --verbose
```

### `lsdef`

Has a similar signature, but no `dst` (it operates on just one file) and the `mv` argument
is replaced by `match`, which can specify regular expressions (default `*` matches any name).

```
usage: lsdef [-h] [-m [MATCH ...]] [-d] [-l] [-e] [-c] [-f] [-v] src

  List function definitions in a given file.

  Option     Description                                Type        Default
  —————————— —————————————————————————————————————————— ——————————— ———————
• src        source file to list definitions from       Path        -
• match      name regex to list from the source file    list[str]   ['*']
• dry_run    whether to print the __all__ diff          bool        False
• list       whether to print the list of names         bool        False
• escalate   whether to raise an error upon failure     bool        False
• cls_defs   whether to use only class definitions      bool        False
• func_defs  whether to use only function definitions   bool        False
• verbose    whether to log anything                    bool        False

positional arguments:
  src

options:
  -h, --help            show this help message and exit
  -m [MATCH ...], --match [MATCH ...]
  -d, --dry-run
  -l, --list
  -e, --escalate
  -c, --cls-defs
  -f, --func-defs
  -v, --verbose
```

## How it works

### The structure of a `mvdef` invocation

When you call `mvdef foo.py bar.py -d -c -m A`, equivalent to:

```sh
mvdef foo.py bar.py --dry-run --cls-defs --mv A
```

You're requesting to show the file diffs it'd take (`--dry-run`)
to move the class definition (`--cls-defs`) named `A` (`--mv A`)
from `foo.py` (the `src`, first positional argument)
to `bar.py` (the `dst`, second positional argument).

### Parsing the request

The request to move a definition is stored on a dataclass `mvdef.transfer.MvDef`
immediately upon invoking the program command.

Upon creation, this class stores 2 attributes `src_diff` and `dst_diff`
(both are `mvdef.diff.Differ` objects) which will coordinate the creation of patches,
or 'diffs'. These start their life with empty agendas (`mvdef.agenda.Agenda`).

Next, the main `MvDef` class calls its `check()` method, which returns an exception
(or raises it if `escalate` is True), preventing further work if the source file
does not contain a class named `A` as requested.

If the source file has the required definitions to fulfil the request,
then the `MvDef.diffs()` method gets called next,
populates the empty agendas on the `Differ` objects for the 2 files,
then produces the diffs they imply.

If the dry run setting is not used, the source and destination files are overwritten
with the changes, instead of just displaying the diffs.

### `lsdef` approach

`lsdef` is similar, but instead of making a `src_diff` it makes a `src_manifest`
(`mvdef.manifest.Manifest` object), and there is no `dst` file to handle.

Error handling is the same as above.

---

> _mvdef_ is available from [PyPI](https://pypi.org/project/mvdef), and
> the code is on [GitHub](https://github.com/lmmx/mvdef)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "mvdef",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "<3.12,>=3.10",
    "maintainer_email": "",
    "keywords": "ast",
    "author": "",
    "author_email": "Louis Maddox <louismmx@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/74/2a/fd7d63bdd6e375e6d42dfba5717dbd167edcea69085a0e3a91b169f0cf3a/mvdef-0.9.4.tar.gz",
    "platform": null,
    "description": "# mvdef\n\n[![Documentation](https://readthedocs.org/projects/mvdef/badge/?version=latest)](https://mvdef.readthedocs.io/en/latest/)\n[![CI Status](https://github.com/lmmx/mvdef/actions/workflows/master.yml/badge.svg)](https://github.com/lmmx/mvdef/actions/workflows/master.yml)\n[![Coverage](https://codecov.io/gh/lmmx/mvdef/branch/master/graph/badge.svg)](https://codecov.io/github/lmmx/mvdef)\n[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\nPackage providing command line tools to move/copy function/classes and their associated import statements between files\n\n[Read The Docs](https://mvdef.readthedocs.io/en/latest/)\n\n## Requires\n\n- Python 3.10+\n\n## Installation\n\n```sh\npip install mvdef\n```\n\n## Usage\n\n### `mvdef`\n\nMoves functions named by `-m`/`--mv` and their associated imports from `src` to `dst`,\nor just previews the changes as a diff if passed `-d`/`--dry-run`.\n\n```\nusage: mvdef [-h] -m [MV ...] [-d] [-e] [-c] [-f] [-v] src dst\n\n\u00a0\u00a0Move function definitions from one file to another, moving/copying\n\u00a0\u00a0any necessary associated import statements along with them.\n\n\u00a0 Option     Description                                Type        Default\n\u00a0 \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 \u2014\u2014\u2014\u2014\u2014\u2014\u2014\n\u2022\u00a0src        source file to take definitions from       Path        -\n\u2022\u00a0dst        destination file (may not exist)           Path        -\n\u2022\u00a0mv         names to move from the source file         list[str]   -\n\u2022\u00a0dry_run    whether to only preview the change diffs   bool        False\n\u2022\u00a0escalate   whether to raise an error upon failure     bool        False\n\u2022\u00a0cls_defs   whether to use only class definitions      bool        False\n\u2022\u00a0func_defs  whether to use only function definitions   bool        False\n\u2022\u00a0verbose    whether to log anything                    bool        False\n\npositional arguments:\n  src\n  dst\n\noptions:\n  -h, --help            show this help message and exit\n  -m [MV ...], --mv [MV ...]\n  -d, --dry-run\n  -e, --escalate\n  -c, --cls-defs\n  -f, --func-defs\n  -v, --verbose\n```\n\n### `cpdef`\n\nCopies functions named by `-m`/`--mv` and their associated imports from `src` to `dst`,\nor just previews the changes as a diff if passed `-d`/`--dry-run`.\n\nHas the same flags and signature as `mvdef`, but never changes `src`.\n\n```\nusage: cpdef [-h] -m [MV ...] [-d] [-e] [-c] [-f] [-v] src dst\n\n\u00a0\u00a0Copy function definitions from one file to another, and any necessary\n\u00a0\u00a0associated import statements along with them.\n\n\u00a0 Option     Description                                Type        Default\n\u00a0 \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 \u2014\u2014\u2014\u2014\u2014\u2014\u2014\n\u2022\u00a0src        source file to copy definitions from       Path        -\n\u2022\u00a0dst        destination file (may not exist)           Path        -\n\u2022\u00a0mv         names to copy from the source file         list[str]   -\n\u2022\u00a0dry_run    whether to only preview the change diffs   bool        False\n\u2022\u00a0escalate   whether to raise an error upon failure     bool        False\n\u2022\u00a0cls_defs   whether to use only class definitions      bool        False\n\u2022\u00a0func_defs  whether to use only function definitions   bool        False\n\u2022\u00a0verbose    whether to log anything                    bool        False\n\npositional arguments:\n  src\n  dst\n\noptions:\n  -h, --help            show this help message and exit\n  -m [MV ...], --mv [MV ...]\n  -d, --dry-run\n  -e, --escalate\n  -c, --cls-defs\n  -f, --func-defs\n  -v, --verbose\n```\n\n### `lsdef`\n\nHas a similar signature, but no `dst` (it operates on just one file) and the `mv` argument\nis replaced by `match`, which can specify regular expressions (default `*` matches any name).\n\n```\nusage: lsdef [-h] [-m [MATCH ...]] [-d] [-l] [-e] [-c] [-f] [-v] src\n\n\u00a0\u00a0List function definitions in a given file.\n\n\u00a0 Option     Description                                Type        Default\n\u00a0 \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 \u2014\u2014\u2014\u2014\u2014\u2014\u2014\n\u2022\u00a0src        source file to list definitions from       Path        -\n\u2022\u00a0match      name regex to list from the source file    list[str]   ['*']\n\u2022\u00a0dry_run    whether to print the __all__ diff          bool        False\n\u2022\u00a0list       whether to print the list of names         bool        False\n\u2022\u00a0escalate   whether to raise an error upon failure     bool        False\n\u2022\u00a0cls_defs   whether to use only class definitions      bool        False\n\u2022\u00a0func_defs  whether to use only function definitions   bool        False\n\u2022\u00a0verbose    whether to log anything                    bool        False\n\npositional arguments:\n  src\n\noptions:\n  -h, --help            show this help message and exit\n  -m [MATCH ...], --match [MATCH ...]\n  -d, --dry-run\n  -l, --list\n  -e, --escalate\n  -c, --cls-defs\n  -f, --func-defs\n  -v, --verbose\n```\n\n## How it works\n\n### The structure of a `mvdef` invocation\n\nWhen you call `mvdef foo.py bar.py -d -c -m A`, equivalent to:\n\n```sh\nmvdef foo.py bar.py --dry-run --cls-defs --mv A\n```\n\nYou're requesting to show the file diffs it'd take (`--dry-run`)\nto move the class definition (`--cls-defs`) named `A` (`--mv A`)\nfrom `foo.py` (the `src`, first positional argument)\nto `bar.py` (the `dst`, second positional argument).\n\n### Parsing the request\n\nThe request to move a definition is stored on a dataclass `mvdef.transfer.MvDef`\nimmediately upon invoking the program command.\n\nUpon creation, this class stores 2 attributes `src_diff` and `dst_diff`\n(both are `mvdef.diff.Differ` objects) which will coordinate the creation of patches,\nor 'diffs'. These start their life with empty agendas (`mvdef.agenda.Agenda`).\n\nNext, the main `MvDef` class calls its `check()` method, which returns an exception\n(or raises it if `escalate` is True), preventing further work if the source file\ndoes not contain a class named `A` as requested.\n\nIf the source file has the required definitions to fulfil the request,\nthen the `MvDef.diffs()` method gets called next,\npopulates the empty agendas on the `Differ` objects for the 2 files,\nthen produces the diffs they imply.\n\nIf the dry run setting is not used, the source and destination files are overwritten\nwith the changes, instead of just displaying the diffs.\n\n### `lsdef` approach\n\n`lsdef` is similar, but instead of making a `src_diff` it makes a `src_manifest`\n(`mvdef.manifest.Manifest` object), and there is no `dst` file to handle.\n\nError handling is the same as above.\n\n---\n\n> _mvdef_ is available from [PyPI](https://pypi.org/project/mvdef), and\n> the code is on [GitHub](https://github.com/lmmx/mvdef)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Package providing command line tools to move/copy function/classes and their associated import statements between files.",
    "version": "0.9.4",
    "project_urls": {
        "Documentation": "https://mvdef.readthedocs.io/",
        "Homepage": "https://github.com/lmmx/fugit",
        "Repository": "https://github.com/lmmx/fugit.git"
    },
    "split_keywords": [
        "ast"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d9d998817d1d0eba6ff97bba0c1d035dcb3cd69b25307d3adae6d1249c1ca131",
                "md5": "f96594188f9e3c27a123360e52d37e36",
                "sha256": "e17fe8ad1a182da281585e62577b127037d59c22757134169b52011cd73df048"
            },
            "downloads": -1,
            "filename": "mvdef-0.9.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f96594188f9e3c27a123360e52d37e36",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.12,>=3.10",
            "size": 410141,
            "upload_time": "2024-03-03T16:44:28",
            "upload_time_iso_8601": "2024-03-03T16:44:28.239311Z",
            "url": "https://files.pythonhosted.org/packages/d9/d9/98817d1d0eba6ff97bba0c1d035dcb3cd69b25307d3adae6d1249c1ca131/mvdef-0.9.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "742afd7d63bdd6e375e6d42dfba5717dbd167edcea69085a0e3a91b169f0cf3a",
                "md5": "f020e569a4c8e114151d386357a5021c",
                "sha256": "1f7ed65276eecb6a448aace12932dfd74b2bd72e1c95f03a30a529fac985d25f"
            },
            "downloads": -1,
            "filename": "mvdef-0.9.4.tar.gz",
            "has_sig": false,
            "md5_digest": "f020e569a4c8e114151d386357a5021c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.12,>=3.10",
            "size": 411231,
            "upload_time": "2024-03-03T16:44:30",
            "upload_time_iso_8601": "2024-03-03T16:44:30.434627Z",
            "url": "https://files.pythonhosted.org/packages/74/2a/fd7d63bdd6e375e6d42dfba5717dbd167edcea69085a0e3a91b169f0cf3a/mvdef-0.9.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-03 16:44:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lmmx",
    "github_project": "fugit",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "mvdef"
}
        
Elapsed time: 0.19809s