Skip to main content

No project description provided

Project description

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 .gitignore Patterns: Automatically excludes files and directories based on your .gitignore file.
  • 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 .ipynb files. You can choose to include them, or convert notebooks entirely to .py format 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 to output.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:

  1. Basic export:

    my-exporter --root-dir ./my_project --output-file project_contents.txt
    
  2. Using a custom ignore file:

    my-exporter --root-dir ./my_project --ignore-file .myignore
    
  3. Using an include file to ensure certain files are always included:

    my-exporter --root-dir ./my_project --include-file include_patterns.txt
    
  4. Including Jupyter notebook outputs:

    my-exporter --root-dir ./my_project --include-nb-outputs
    
  5. 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

  • .gitignore Support: The tool uses your .gitignore file to determine which files and directories to exclude. Ensure your .gitignore is 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-file option.
  • Include Patterns: You can specify an --include-file containing patterns of files that should always be included in the export. These patterns can override .gitignore exclusions 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-outputs setting.

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:

  1. Fork the Repository: Click the "Fork" button on the repository page.

  2. Create a Feature Branch:

    git checkout -b feature/my-new-feature
    
  3. Commit Your Changes:

    git commit -m "Add some feature"
    
  4. Push to the Branch:

    git push origin feature/my-new-feature
    
  5. 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

my_exporter-0.4.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

my_exporter-0.4.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file my_exporter-0.4.0.tar.gz.

File metadata

  • Download URL: my_exporter-0.4.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.5 Windows/11

File hashes

Hashes for my_exporter-0.4.0.tar.gz
Algorithm Hash digest
SHA256 d5a369c736107480941f8c4c3bb258a0d6ac881b1b118d788a14e3e55a56d728
MD5 1dbd0d2812346fe9529599988085267b
BLAKE2b-256 5d673a54adbad22ce58783d643d1df749149109660969f7883b9fc8d5ec63835

See more details on using hashes here.

File details

Details for the file my_exporter-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: my_exporter-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.5 Windows/11

File hashes

Hashes for my_exporter-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2429a8800fc3e1cf774240962fbd4111d3bce431537b62c975a05a5b5138246f
MD5 4bdd6db99386d9b1b01f752dccf8a77e
BLAKE2b-256 b0cefd63c9e15036fb0c6f4bbf448650c3638dd04d483ef5db907cd18ad89931

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page