pyargwriter


Namepyargwriter JSON
Version 1.1.1 PyPI version JSON
download
home_pagehttps://github.com/RobinU434/PyArgWriter
SummaryAutomatically generates ArgumentParser setups for Python classes and their methods.
upload_time2025-01-26 13:31:53
maintainerNone
docs_urlNone
authorRobin Uhrich
requires_python<4.0,>=3.10
licenseMIT
keywords python code-generation argumentparser tooling argument-parser documentation-tool python3
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyArgWriter

[![Coverage Status](https://coveralls.io/repos/github/RobinU434/PyArgWriter/badge.svg?branch=main)](https://coveralls.io/github/RobinU434/PyArgWriter?branch=main)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyargwriter)
![PyPI - Downloads](https://img.shields.io/pypi/dm/pyargwriter)
![PyPI - Version](https://img.shields.io/pypi/v/pyargwriter)

PyArgWriter is a Python module that simplifies the generation of ArgumentParser setups for Python classes and their methods. It provides a convenient way to define and manage command-line arguments for your Python applications.

## Installation

You can install PyArgWriter using `pip`:

```bash
pip install pyargwriter
```

Alternative from source code:

In root folder with pip:

```bash
pip install .
```

or with poetry:

```bash
poetry install
```

## Command-Line Interface

PyArgWriter offers the following command-line commands:

- `parse-code`: Parse given files and create YAML structure with structural parser information.
- `write-code`: Read given parser YAML structure and create argument parser Python code.
- `generate-argparser`: Generate `parser.py`, which contains a `setup_parser` function to set up an appropriate parser.

For more detailed information on available command-line arguments and usage examples, refer to the official documentation.

## Requirements

PyArgWriter depends strongly on information stated in the docstring. Your docstring should have a minimal structure like:

```python       
def add(a: int, b: int) -> int:
    """_summary_

    Args:
        a (int): _description_
        b (int): _description_

    Returns:
        int: _description_
    """
    return a + b
```

## Usage

Usage
PyArgWriter offers a command-line interface for generating and managing ArgumentParser setups.
Below are the available commands and their usage:

### parse-code

```bash
python -m pyargwriter parse-code --input file1.py file2.py --output output.yaml [--log-level LOG_LEVEL]
```

Parse given Python files and create a YAML structure with structural parser information.

### write-code

```bash
python -m pyargwriter write-code --input input.yaml [--output OUTPUT_DIR] [--pretty] [--log-level LOG_LEVEL]
```

Read a given parser YAML structure and generate argument parser Python code.

### generate-argparser

```bash
python -m pyargwriter generate-argparser --input file1.py file2.py [--output OUTPUT_DIR] [--pretty] [--log-level LOG_LEVEL]
```

Generate a parser.py file that contains a setup_parser function to set up an appropriate ArgumentParser.
Common Options
--log-level LOG_LEVEL: Sets the log level for command execution (default is "WARN").
--pretty (-p): If set, the generated code will be formatted with Black.
For more detailed information on each command and additional options, run:

```bash
python -m pyargwriter <command> --help
```

### Supported Argument Types

In the function of the process class you want to create the argument parser, following types of an argument are supported:

- int
- float
- str
- bool flags
- list[int]
- List[int]     # from typing
- list[float]
- List[float]   # from typing
- list[str]
- List[str]     # from typing
- list[bool]
- List[bool]    # from typing

## Example

```bash
python -m pyargwriter generate-argparser --input examples/shopping.py examples/car.py --output examples --pretty
```

## Hydra Integration

As an additional feature we support to combine your existing `ArgumentParser` with the [Hydra](https://hydra.cc/docs/intro/) framework. All you need to do is to use a decorator we provide with our framework. A short example can be viewed below. 

```python
from omegaconf import DictConfig
from pyargwriter.decorator import add_hydra

class Entrypoint:
    """ML training pipeline"""
    def __init__(self):
        """initiate pipeline"""
        pass
    @add_hydra("config", version_base=None)
    def train(config: DictConfig, device: str):
        """start training process
        
        Args:
            config (DictConfig): container which contains
            device (str): where to train on
        """
```
The decorator is indeed callable. Additionally to the usual hydra-arguments you have to pass in the `config_var_name` which specifies which argument in the `train` signature is the config object. After calling the pyargwriter tool you are now ready to go with a CLI which can now handle also almost all Hydra commands. Except the normal `help` message you get from Hydra. For further interest in this message please refer to their [website](https://hydra.cc/docs/intro/)


## Documentation

The complete documentation for PyArgWriter, including detailed usage instructions and examples, can be found in the [official documentation](documentation/latex/refman.pdf) or at the [documentation website](https://htmlpreview.github.io/?https://github.com/RobinU434/PyArgWriter/blob/main/documentation/html/index.htm).

Further you can have a look into the [test coverage](documentation/test_coverage.md).

## License

This project is licensed under the Apache 2.0 License - see the [LICENSE](LICENSE) file for details.

## Contributing

If you would like to contribute to PyArgWriter, please read our [Contributing Guidelines](CONTRIBUTING.md) for details on how to get started.

## Contact

For any questions, issues, or feedback, please [open an issue](https://github.com/RobinU434/PyArgWriter/issues) on our GitHub repository.


## Ideas for Naming

Here are some potential names for your tool, focusing on its functionality and the concept of automatically generating CLI interfaces:

### Functional and Descriptive Names
1. **AutoCLI**
2. **ClassCLI**
3. **MethodCLI**
4. **CLIBuilder**
5. **ArgParserGen**
6. **ClassParser**
7. **Method2CLI**
8. **CLIForge**

### Playful and Catchy Names
1. **CLImate** (a nod to "CLI" and "automate")
2. **CLIonize** (like ionizing a class into a CLI)
3. **CLIckIt** (emphasizing ease and speed)
4. **Parse-o-Matic**
5. **Argonaut** (exploring arguments and generating interfaces)

### Tech-Inspired Names
1. **CommandCrafter**
2. **InterfaceSmith**
3. **AutoArg**
4. **PyCLI**
5. **CodeCommander**

### Generalized and Creative Names
1. **Argitect** (argument architect)
2. **CommandWeaver**
3. **ParseMaster**
4. **CLIMaker**
5. **MethodBridge**

Each of these names is tailored to different branding styles. Do you have preferences about whether the name should be more functional, playful, or tech-inspired?

If you want the name to be short, easy to type, and terminal-friendly, here are some concise options:

1. **cli-gen**
2. **argen** (short for "argument generator")
3. **clify**
4. **m2cli** (short for "method to CLI")
5. **pycli**
6. **cligen**
7. **argcli**
8. **cly** (a super-short take on "CLI")
9. **cmdgen**
10. **methcli** (short for "method CLI")
11  . **clipy**

These names are minimal, straightforward, and easy to remember for developers. Let me know if any of these stand out!
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/RobinU434/PyArgWriter",
    "name": "pyargwriter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "python, code-generation, ArgumentParser, tooling, argument-parser, documentation-tool, python3",
    "author": "Robin Uhrich",
    "author_email": "robin.uhrich@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/17/35/48679f9cdece444d73c0963b7fd56c98501dc7cb409525d5113488d68753/pyargwriter-1.1.1.tar.gz",
    "platform": null,
    "description": "# PyArgWriter\n\n[![Coverage Status](https://coveralls.io/repos/github/RobinU434/PyArgWriter/badge.svg?branch=main)](https://coveralls.io/github/RobinU434/PyArgWriter?branch=main)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyargwriter)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/pyargwriter)\n![PyPI - Version](https://img.shields.io/pypi/v/pyargwriter)\n\nPyArgWriter is a Python module that simplifies the generation of ArgumentParser setups for Python classes and their methods. It provides a convenient way to define and manage command-line arguments for your Python applications.\n\n## Installation\n\nYou can install PyArgWriter using `pip`:\n\n```bash\npip install pyargwriter\n```\n\nAlternative from source code:\n\nIn root folder with pip:\n\n```bash\npip install .\n```\n\nor with poetry:\n\n```bash\npoetry install\n```\n\n## Command-Line Interface\n\nPyArgWriter offers the following command-line commands:\n\n- `parse-code`: Parse given files and create YAML structure with structural parser information.\n- `write-code`: Read given parser YAML structure and create argument parser Python code.\n- `generate-argparser`: Generate `parser.py`, which contains a `setup_parser` function to set up an appropriate parser.\n\nFor more detailed information on available command-line arguments and usage examples, refer to the official documentation.\n\n## Requirements\n\nPyArgWriter depends strongly on information stated in the docstring. Your docstring should have a minimal structure like:\n\n```python       \ndef add(a: int, b: int) -> int:\n    \"\"\"_summary_\n\n    Args:\n        a (int): _description_\n        b (int): _description_\n\n    Returns:\n        int: _description_\n    \"\"\"\n    return a + b\n```\n\n## Usage\n\nUsage\nPyArgWriter offers a command-line interface for generating and managing ArgumentParser setups.\nBelow are the available commands and their usage:\n\n### parse-code\n\n```bash\npython -m pyargwriter parse-code --input file1.py file2.py --output output.yaml [--log-level LOG_LEVEL]\n```\n\nParse given Python files and create a YAML structure with structural parser information.\n\n### write-code\n\n```bash\npython -m pyargwriter write-code --input input.yaml [--output OUTPUT_DIR] [--pretty] [--log-level LOG_LEVEL]\n```\n\nRead a given parser YAML structure and generate argument parser Python code.\n\n### generate-argparser\n\n```bash\npython -m pyargwriter generate-argparser --input file1.py file2.py [--output OUTPUT_DIR] [--pretty] [--log-level LOG_LEVEL]\n```\n\nGenerate a parser.py file that contains a setup_parser function to set up an appropriate ArgumentParser.\nCommon Options\n--log-level LOG_LEVEL: Sets the log level for command execution (default is \"WARN\").\n--pretty (-p): If set, the generated code will be formatted with Black.\nFor more detailed information on each command and additional options, run:\n\n```bash\npython -m pyargwriter <command> --help\n```\n\n### Supported Argument Types\n\nIn the function of the process class you want to create the argument parser, following types of an argument are supported:\n\n- int\n- float\n- str\n- bool flags\n- list[int]\n- List[int]     # from typing\n- list[float]\n- List[float]   # from typing\n- list[str]\n- List[str]     # from typing\n- list[bool]\n- List[bool]    # from typing\n\n## Example\n\n```bash\npython -m pyargwriter generate-argparser --input examples/shopping.py examples/car.py --output examples --pretty\n```\n\n## Hydra Integration\n\nAs an additional feature we support to combine your existing `ArgumentParser` with the [Hydra](https://hydra.cc/docs/intro/) framework. All you need to do is to use a decorator we provide with our framework. A short example can be viewed below. \n\n```python\nfrom omegaconf import DictConfig\nfrom pyargwriter.decorator import add_hydra\n\nclass Entrypoint:\n    \"\"\"ML training pipeline\"\"\"\n    def __init__(self):\n        \"\"\"initiate pipeline\"\"\"\n        pass\n    @add_hydra(\"config\", version_base=None)\n    def train(config: DictConfig, device: str):\n        \"\"\"start training process\n        \n        Args:\n            config (DictConfig): container which contains\n            device (str): where to train on\n        \"\"\"\n```\nThe decorator is indeed callable. Additionally to the usual hydra-arguments you have to pass in the `config_var_name` which specifies which argument in the `train` signature is the config object. After calling the pyargwriter tool you are now ready to go with a CLI which can now handle also almost all Hydra commands. Except the normal `help` message you get from Hydra. For further interest in this message please refer to their [website](https://hydra.cc/docs/intro/)\n\n\n## Documentation\n\nThe complete documentation for PyArgWriter, including detailed usage instructions and examples, can be found in the [official documentation](documentation/latex/refman.pdf) or at the [documentation website](https://htmlpreview.github.io/?https://github.com/RobinU434/PyArgWriter/blob/main/documentation/html/index.htm).\n\nFurther you can have a look into the [test coverage](documentation/test_coverage.md).\n\n## License\n\nThis project is licensed under the Apache 2.0 License - see the [LICENSE](LICENSE) file for details.\n\n## Contributing\n\nIf you would like to contribute to PyArgWriter, please read our [Contributing Guidelines](CONTRIBUTING.md) for details on how to get started.\n\n## Contact\n\nFor any questions, issues, or feedback, please [open an issue](https://github.com/RobinU434/PyArgWriter/issues) on our GitHub repository.\n\n\n## Ideas for Naming\n\nHere are some potential names for your tool, focusing on its functionality and the concept of automatically generating CLI interfaces:\n\n### Functional and Descriptive Names\n1. **AutoCLI**\n2. **ClassCLI**\n3. **MethodCLI**\n4. **CLIBuilder**\n5. **ArgParserGen**\n6. **ClassParser**\n7. **Method2CLI**\n8. **CLIForge**\n\n### Playful and Catchy Names\n1. **CLImate** (a nod to \"CLI\" and \"automate\")\n2. **CLIonize** (like ionizing a class into a CLI)\n3. **CLIckIt** (emphasizing ease and speed)\n4. **Parse-o-Matic**\n5. **Argonaut** (exploring arguments and generating interfaces)\n\n### Tech-Inspired Names\n1. **CommandCrafter**\n2. **InterfaceSmith**\n3. **AutoArg**\n4. **PyCLI**\n5. **CodeCommander**\n\n### Generalized and Creative Names\n1. **Argitect** (argument architect)\n2. **CommandWeaver**\n3. **ParseMaster**\n4. **CLIMaker**\n5. **MethodBridge**\n\nEach of these names is tailored to different branding styles. Do you have preferences about whether the name should be more functional, playful, or tech-inspired?\n\nIf you want the name to be short, easy to type, and terminal-friendly, here are some concise options:\n\n1. **cli-gen**\n2. **argen** (short for \"argument generator\")\n3. **clify**\n4. **m2cli** (short for \"method to CLI\")\n5. **pycli**\n6. **cligen**\n7. **argcli**\n8. **cly** (a super-short take on \"CLI\")\n9. **cmdgen**\n10. **methcli** (short for \"method CLI\")\n11  . **clipy**\n\nThese names are minimal, straightforward, and easy to remember for developers. Let me know if any of these stand out!",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Automatically generates ArgumentParser setups for Python classes and their methods.",
    "version": "1.1.1",
    "project_urls": {
        "Homepage": "https://github.com/RobinU434/PyArgWriter",
        "Repository": "https://github.com/RobinU434/PyArgWriter"
    },
    "split_keywords": [
        "python",
        " code-generation",
        " argumentparser",
        " tooling",
        " argument-parser",
        " documentation-tool",
        " python3"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8dbd98e2146be0e56adc45150530a232edf96dd7b262b573d5d8701817ed8a00",
                "md5": "1b7516b89663c0e6a07e71e32a368dcb",
                "sha256": "16d73e778925ad9996b032fbd90598e39909b65cea8dbf5eb0f3109ccca79e49"
            },
            "downloads": -1,
            "filename": "pyargwriter-1.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1b7516b89663c0e6a07e71e32a368dcb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 37501,
            "upload_time": "2025-01-26T13:31:51",
            "upload_time_iso_8601": "2025-01-26T13:31:51.894490Z",
            "url": "https://files.pythonhosted.org/packages/8d/bd/98e2146be0e56adc45150530a232edf96dd7b262b573d5d8701817ed8a00/pyargwriter-1.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "173548679f9cdece444d73c0963b7fd56c98501dc7cb409525d5113488d68753",
                "md5": "199f977f3e3a26e28496d1bb6ca150cc",
                "sha256": "565a771cc50f4c95aed883c92e9b7fe5123c3dac81f42958411c01bab81cd43f"
            },
            "downloads": -1,
            "filename": "pyargwriter-1.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "199f977f3e3a26e28496d1bb6ca150cc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 33140,
            "upload_time": "2025-01-26T13:31:53",
            "upload_time_iso_8601": "2025-01-26T13:31:53.255322Z",
            "url": "https://files.pythonhosted.org/packages/17/35/48679f9cdece444d73c0963b7fd56c98501dc7cb409525d5113488d68753/pyargwriter-1.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-26 13:31:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "RobinU434",
    "github_project": "PyArgWriter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pyargwriter"
}
        
Elapsed time: 0.41497s