Automatically generates ArgumentParser setups for Python classes and their methods.
Project description
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
:
pip install pyargwriter
Alternative from source code:
In root folder with pip:
pip install .
or with poetry:
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
: Generateparser.py
, which contains asetup_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 ha minimal structure like:
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
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
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
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:
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
python -m pyargwriter generate-argparser --input examples/shopping.py examples/car.py --output examples --pretty
Documentation
The complete documentation for PyArgWriter, including detailed usage instructions and examples, can be found in the official documentation or at the documentation website.
Further you can have a look into the test coverage.
License
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
Contributing
If you would like to contribute to PyArgWriter, please read our Contributing Guidelines for details on how to get started.
Contact
For any questions, issues, or feedback, please open an issue on our GitHub repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pyargwriter-1.0.0.tar.gz
.
File metadata
- Download URL: pyargwriter-1.0.0.tar.gz
- Upload date:
- Size: 24.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.7 Linux/6.5.0-17-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e2d0305f87ba8379fde13e278c8d6307544c2a75dcc9b0381bd8045cd9c81e4 |
|
MD5 | 6740f6f1f3af5d82c106a94b1eda17df |
|
BLAKE2b-256 | 41a65b6c61343d0fd0664f90d9e050642595e67cdb042bb00061dc3b1c777f7f |
File details
Details for the file pyargwriter-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: pyargwriter-1.0.0-py3-none-any.whl
- Upload date:
- Size: 29.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.7 Linux/6.5.0-17-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8885b7a47aeaa92195e8c137fff5f5bdde42e509fb8074e8cb092c52eeb58190 |
|
MD5 | df72da5587562ee82cc49dc1800ca4ce |
|
BLAKE2b-256 | fcf2def04cf624f46a1a6c576c3b8fd9158d8c053fac585c024a0be0426c6b7d |