Metadata-Version: 2.1
Name: codestructure
Version: 1.0.0
Summary: CodeStructure is a Python package that analyzes the structure of a Python file and extracts information about its classes, functions, and their associated attributes.
Author-email: Bas Nijholt <bas@nijho.lt>
Project-URL: Homepage, https://github.com/basnijholt/codestructure
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Provides-Extra: test
Provides-Extra: docs
License-File: LICENSE

# :building_construction: CodeStructure

CodeStructure is a Python package that analyzes the structure of a Python file and extracts information about its classes, functions, and their associated attributes.
It is particularly useful for understanding and documenting complex codebases and writing design docs.

## :star: Features

- Extract class and function signatures
- Extract class attributes
- Extract function parameters and their types
- Extract function return types
- Extract decorators and docstrings
- Display the extracted information in a human-readable format

## :books: Table of Contents

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [:package: Installation](#package-installation)
- [:book: Usage](#book-usage)
- [:memo: Example](#memo-example)
- [:busts_in_silhouette: Contributing](#busts_in_silhouette-contributing)
- [:page_with_curl: License](#page_with_curl-license)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->


## :package: Installation

You can install CodeStructure via pip:

```bash
pip install codestructure
```

## :book: Usage

To use CodeStructure, simply run the script with the path to the Python file you want to analyze:

```bash
codestructure path/to/your/python_file.py
```

The script will output the analyzed code structure and copy it to the clipboard if the `pyperclip` package is installed.

Run the script with the `--help` flag to see all available options:

```bash
codestructure --help
```
Which should output:

<!-- CODE:BASH:START -->
<!-- echo '```bash' -->
<!-- codestructure --help -->
<!-- echo '```' -->
<!-- CODE:END -->

<!-- OUTPUT:START -->
<!-- ⚠️ This content is auto-generated by `markdown-code-runner`. -->
```bash
usage: codestructure [-h] [--no-private] [--no-copy] [--backticks] [--no-rich]
                     [--line-numbers]
                     module_file_path

Analyze the code structure of a Python file.

positional arguments:
  module_file_path  Path to the Python file.

options:
  -h, --help        show this help message and exit
  --no-private      Do not print private functions.
  --no-copy         Do not copy the output to the clipboard.
  --backticks       Use backticks for code blocks.
  --no-rich         Do not use rich to print the output.
  --line-numbers    Print line numbers for the code blocks.
```

<!-- OUTPUT:END -->


## :memo: Example

Given a Python file with the following content:

```python
class MyClass:
    my_attr: str

    def my_method(self, arg1: int) -> bool:
        """My docstring."""
        a = 1 + 1
        ...

def my_function(arg2: float) -> None:
    arg2 = arg2 + 1
    ...
```

CodeStructure will output:

```python
class MyClass:
    my_attr: str

    def my_method(self, arg1: int) -> bool:
        """My docstring."""

def my_function(arg2: float) -> None:
    ...
```

## :busts_in_silhouette: Contributing

We welcome contributions to CodeStructure! If you find a bug or have a feature request, please create an issue on the [GitHub repository](https://github.com/basnijholt/codestructure). If you would like to contribute code, please fork the repository and submit a pull request.

## :page_with_curl: License

CodeStructure is released under the Apache 2.0 License. For more information, please see the [LICENSE](LICENSE) file.
