My-Exporter
A Python tool to export the contents of a folder into a single text file while respecting .gitignore and optional include patterns, maintaining the hierarchical structure, and optionally handling Jupyter notebook outputs.
Table of Contents
Features
- Respect
.gitignorePatterns: Automatically excludes files and directories based on your.gitignorefile. - Include Patterns: Optionally specify an include file to define patterns of files that should always be included.
- Hierarchical Structure: Maintains the folder hierarchy in the exported output by using relative file paths as headers.
- Customizable Output: Specify the root directory, output file name, ignore file, and include file.
- Handles Non-Text Files: Gracefully handles non-text or unreadable files by indicating their presence without content.
- Jupyter Notebooks: By default, strips output cells from
.ipynbfiles. You can choose to include them, or convert notebooks entirely to.pyformat while omitting all outputs.
Installation
You can install my-exporter via PyPI using pip:
pip install my-exporter
Alternatively, you can install it directly from the source:
git clone https://github.com/RK0429/my-exporter.git
cd my-exporter
pip install .
Usage
Command-Line Interface
After installation, the my-exporter CLI tool is available.
Basic Usage:
my-exporter --root-dir path/to/project --output-file exported.txt
Options:
--root-dir: Specifies the root directory to start exporting from. Defaults to the current directory (.).--output-file: Defines the name of the output text file. Defaults tooutput.txt.--ignore-file: Specifies a custom ignore file (e.g.,.gitignore). Defaults to.gitignore.--include-file: Specifies a file containing patterns of files to include, even if they might otherwise be ignored.--include-nb-outputs: If provided, Jupyter notebook output cells are included in the exported content. By default, they are stripped.--export-nb-as-py: If provided, Jupyter notebooks (.ipynb) are converted into Python files (.py-like format) with all outputs omitted.
Examples:
-
Basic export:
my-exporter --root-dir ./my_project --output-file project_contents.txt
-
Using a custom ignore file:
my-exporter --root-dir ./my_project --ignore-file .myignore
-
Using an include file to ensure certain files are always included:
my-exporter --root-dir ./my_project --include-file include_patterns.txt
-
Including Jupyter notebook outputs:
my-exporter --root-dir ./my_project --include-nb-outputs
-
Converting Jupyter notebooks to Python files (excluding outputs):
my-exporter --root-dir ./my_project --export-nb-as-py
Programmatic Usage
You can also use my-exporter as a library within your Python projects.
Example:
from my_exporter import export_folder_contents
export_folder_contents(
root_dir='path/to/project',
output_file='exported_contents.txt',
ignore_file='.gitignore', # Optional
include_file='include_patterns.txt', # Optional
exclude_notebook_outputs=False, # Set to False to include notebook outputs
convert_notebook_to_py=False # Set to True to convert notebooks to .py format
)
Configuration
.gitignoreSupport: The tool uses your.gitignorefile to determine which files and directories to exclude. Ensure your.gitignoreis properly configured in the root directory you are exporting.- Custom Ignore Files: If you prefer to use a different ignore file, specify it using the
--ignore-fileoption. - Include Patterns: You can specify an
--include-filecontaining patterns of files that should always be included in the export. These patterns can override.gitignoreexclusions if desired.
Jupyter Notebook Outputs
By default, my-exporter removes output cells from Jupyter notebooks (.ipynb) to keep the exported file clean and focused on code and markdown cells. If you want to include the output cells, use the --include-nb-outputs option or set exclude_notebook_outputs=False programmatically.
Converting Notebooks to Python
If you use --export-nb-as-py, notebooks are converted into a .py-style format:
- Code cells are included as plain Python code.
- Markdown cells are included as commented-out text.
- No output cells are included, regardless of the
--include-nb-outputssetting.
This option is useful if you want a clean, output-free representation of your notebooks as Python scripts.
Testing
This project uses pytest for testing.
To run tests:
pytest
Make sure pytest is installed, or install it using:
pip install pytest
Contributing
Contributions are welcome! Please follow these steps:
-
Fork the Repository: Click the "Fork" button on the repository page.
-
Create a Feature Branch:
git checkout -b feature/my-new-feature
-
Commit Your Changes:
git commit -m "Add some feature"
-
Push to the Branch:
git push origin feature/my-new-feature
-
Open a Pull Request: Describe your changes and submit the pull request.
Please update tests as appropriate and adhere to the PEP 8 style guide.
License
This project is licensed under the MIT License.
Contact
Your Name
Email: s.woods.m.29@gmail.com
GitHub: https://github.com/RK0429
Metadata
Release files for my-exporter 0.4.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| my_exporter-0.4.3.tar.gz | 10.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| my_exporter-0.4.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.0 kB
Release files / my_exporter-0.4.3.tar.gz
| Download URL | my_exporter-0.4.3.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f4e42a5a66915aed2106c18aa9a1602d90f283f62b910925a42df82d853c2f1
|
|
BLAKE2b-256 checksum How to use checksums |
ddaec087d3465785c1637fcf4f700644e887d076bf0099f139480a46841a6fdf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.12.5 Windows/11
|
Release files / my_exporter-0.4.3-py3-none-any.whl
| Download URL | my_exporter-0.4.3-py3-none-any.whl |
|---|---|
| Size | 12.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6582023dc00f68f1dd646d82d693151fdb7c70c3f62598da85b9eb71e9c706ef
|
|
BLAKE2b-256 checksum How to use checksums |
af0ae72eda736698bb14ca3ff248653ca350619092492128db68be959231d9e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.12.5 Windows/11
|