first draft

This commit is contained in:
Kirill Markin 2024-06-08 09:44:34 +02:00
parent 996938f535
commit 752ca966c4
8 changed files with 1582 additions and 1 deletions

115
README.md
View file

@ -1,2 +1,115 @@
# repo-to-text # repo-to-text
Convert a directory structure and its contents into a single text file, including the tree output and file contents in markdown code blocks. Easy installation via pip and Homebrew.
`repo-to-text` is an open-source project that converts the structure and contents of a directory (repository) into a single text file. By executing a simple command in the terminal, this tool generates a text representation of the directory, including the output of the `tree` command and the contents of each file, formatted for easy reading and sharing.
## Features
- Generates a text representation of a directory's structure.
- Includes the output of the `tree` command.
- Saves the contents of each file, encapsulated in markdown code blocks.
- Easy to install and use via `pip` and Homebrew.
## Installation
### Using pip
To install `repo-to-text` via pip, run the following command:
```bash
pip install git+https://github.com/yourusername/repo-to-text.git
```
### Using Homebrew
To install `repo-to-text` via Homebrew, run the following command:
```bash
brew install yourusername/repo-to-text
```
### Install Locally
To install `repo-to-text` locally for development, follow these steps:
1. Clone the repository:
```bash
git clone https://github.com/yourusername/repo-to-text.git
cd repo-to-text
```
2. Install the package locally:
```bash
pip install -e .
```
## Usage
After installation, you can use the `repo-to-text` command in your terminal. Navigate to the directory you want to convert and run:
```bash
repo-to-text
```
This will create a file named `repo_structure.txt` in the current directory with the text representation of the repository.
## Example Output
The generated text file will include the directory structure and contents of each file. For example:
```
.
├── README.md
├── repo_to_text
│ ├── __init__.py
│ └── main.py
├── requirements.txt
├── setup.py
└── tests
├── __init__.py
└── test_main.py
README.md
```
```
# Contents of README.md
...
```
```
# Contents of repo_to_text/__init__.py
...
```
...
## Running Tests
To run the tests, use the following command:
```bash
pytest
```
Make sure you have `pytest` installed. If not, you can install it using:
```bash
pip install pytest
```
## Uninstall Locally
To uninstall the locally installed package, run the following command from the directory where the repository is located:
```bash
pip uninstall repo-to-text
```
## Contributing
Contributions are welcome! If you have any suggestions or find a bug, please open an issue or submit a pull request.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Contact
For any inquiries or feedback, please contact [yourname](mailto:youremail@example.com).

1424
repo_structure.txt Normal file

File diff suppressed because it is too large Load diff

0
repo_to_text/__init__.py Normal file
View file

30
repo_to_text/main.py Normal file
View file

@ -0,0 +1,30 @@
import os
import subprocess
def get_tree_structure(path='.') -> str:
result = subprocess.run(['tree', path], stdout=subprocess.PIPE)
return result.stdout.decode('utf-8')
def save_repo_to_text(path='.') -> None:
tree_structure: str = get_tree_structure(path)
with open('repo_structure.txt', 'w') as file:
file.write(tree_structure + '\n')
for root, _, files in os.walk(path):
for filename in files:
file_path: str = os.path.join(root, filename)
relative_path: str = os.path.relpath(file_path, path)
file.write(f'\n{relative_path}\n')
file.write('```\n')
try:
with open(file_path, 'r', encoding='utf-8') as f:
file.write(f.read())
except UnicodeDecodeError:
file.write('[Could not decode file contents]\n')
file.write('\n```\n')
def main() -> None:
save_repo_to_text()
if __name__ == '__main__':
main()

1
requirements.txt Normal file
View file

@ -0,0 +1 @@
setuptools==70.0.0

13
setup.py Normal file
View file

@ -0,0 +1,13 @@
from setuptools import setup, find_packages
setup(
name='repo-to-text',
version='0.1',
packages=find_packages(),
install_requires=[],
entry_points={
'console_scripts': [
'repo-to-text=repo_to_text.main:main',
],
},
)

0
tests/__init__.py Normal file
View file

0
tests/test_main.py Normal file
View file