indentation-converter


Nameindentation-converter JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/HenestrosaDev/indentation-converter
SummaryConvert indentation between spaces and tabs in text files and directories, ignoring hidden files, binary files, and files in `.gitiginore`.
upload_time2024-06-23 10:47:13
maintainerNone
docs_urlNone
authorHenestrosaDev
requires_python<4.0,>=3.9
licenseMIT
keywords indentation tabs spaces converter
VCS
bugtrack_url
requirements binaryornot pathspec
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div id="top"></div>

<!-- PROJECT LOGO -->
<div align="center">
	<h1>Indentation Converter</h1>
	<p>
		Convert indentation between spaces and tabs in text files and directories, ignoring hidden files, binary files, and files in <code>.gitiginore</code>.
	</p>
	<p>
		<a href="https://pypi.org/project/indentation-converter/">
			<img 
				alt="PyPI version" 
				src="https://img.shields.io/pypi/v/indentation-converter" 
			/>
		</a>
		<a href="https://pypi.org/project/indentation-converter/">
			<img 
				alt="Python versions support" 
				src="https://img.shields.io/pypi/pyversions/indentation-converter" 
			/>
		</a>
		<br />
		<a href="https://github.com/HenestrosaDev/indentation-converter/actions/workflows/build.yaml">
			<img 
				alt="GitHub action: Build" 
				src="https://github.com/HenestrosaDev/indentation-converter/actions/workflows/build.yaml/badge.svg" 
			/>
		</a>
		<a href="https://codecov.io/gh/HenestrosaDev/indentation-converter/">
			<img 
				alt="Codecov" 
				src="https://codecov.io/gh/HenestrosaDev/indentation-converter/branch/main/graph/badge.svg" 
			/>
		</a>
		<a href="https://github.com/HenestrosaDev/indentation-converter/blob/main/LICENSE">
			<img 
				alt="License" 
				src="https://img.shields.io/github/license/HenestrosaDev/indentation-converter" 
			/>
		</a>
		<br />
		<a href="https://github.com/HenestrosaDev/indentation-converter/graphs/contributors">
			<img 
				alt="GitHub Contributors" 
				src="https://img.shields.io/github/contributors/HenestrosaDev/indentation-converter" 
			/>
		</a>
		<a href="https://github.com/HenestrosaDev/indentation-converter/issues">
			<img 
				alt="Issues" 
				src="https://img.shields.io/github/issues/HenestrosaDev/indentation-converter" 
			/>
		</a>
		<a href="https://github.com/HenestrosaDev/indentation-converter/pulls">
			<img 
				alt="GitHub pull requests" 
				src="https://img.shields.io/github/issues-pr/HenestrosaDev/indentation-converter" 
			/>
		</a>
	</p>
	<p>
		<a href="https://github.com/HenestrosaDev/indentation-converter/issues/new/choose">
			Report Bug
		</a> 
		· 
		<a href="https://github.com/HenestrosaDev/indentation-converter/issues/new/choose">
			Request Feature
		</a> 
		· 
		<a href="https://github.com/HenestrosaDev/indentation-converter/discussions">
			Ask Question
		</a>
	</p>
</div>

<!-- TABLE OF CONTENTS -->

## Table of Contents

- [About the Project](#about-the-project)
  - [Project Structure](#project-structure)
  - [Built With](#built-with)
- [Getting Started](#getting-started)
  - [Script Installation](#script-installation)
  - [Package Installation](#package-installation)
- [Usage](#usage)
  - [Running the Program](#running-the-program)
    - [Script Flags](#script-flags)
  - [Using the Package in Your Project](#using-the-package-in-your-project)
- [Roadmap](#roadmap)
- [Contributing](#contributing)
- [License](#license)
- [Authors](#authors)
- [Support](#support)

<!-- ABOUT THE PROJECT -->

## About the Project

This Python script provides a flexible tool for converting indentation styles in text files between spaces and tabs. It supports converting leading spaces to tabs, leading tabs to spaces, and even converting from one number of spaces to another, all while respecting the files detailed in the `.gitignore`, hidden files, and binary files.

In addition to being able to run this script on its own, you can also installed it as a package via **PyPI** (more information on how to install it [here](#use-the-package-in-your-project)).

<!-- PROJECT STRUCTURE -->

### Project Structure

<details>
	<summary>ASCII directory structure</summary>

```
/
│   .gitignore
│   .pre-commit-config.yaml
│   LICENSE
│   poetry.lock
│   pyproject.toml
│   README.md
│   requirements.txt
│
├───.github
│   └───workflows
│           build.yaml
│           publish.yaml
│
├───src
│   └───indentation_converter
│           __init__.py
│           indentation_converter.py
│
└───tests
        test_indentation_converter.py
```

</details>

### Built With

- [pathspec](https://github.com/cpburnz/python-pathspec) for `.gitignore` style pattern matching of file paths.
- [binaryornot](https://github.com/binaryornot/binaryornot) to guess whether a file is binary or text.

<!-- GETTING STARTED -->

## Getting Started

### Script Installation

1. Download the `.zip` file from the [latest release](https://github.com/HenestrosaDev/indentation-converter/releases/latest/download/indentation-converter.zip).
2. (Optional but recommended) Create a Python virtual environment in the project root. If you're using `virtualenv`, you would run `virtualenv venv`.
3. (Optional but recommended) Activate the virtual environment:

	 ```bash
	 # on Windows
	 . venv/Scripts/activate
	 # if you get the error `FullyQualifiedErrorId : UnauthorizedAccess`, run this:
	 Set-ExecutionPolicy Unrestricted -Scope Process
	 # and then . venv/Scripts/activate

	 # on macOS and Linux
	 source venv/Scripts/activate
	 ```

4. Open the command line and run `pip install -r path/to/requirements.txt` to install the required packages to run the script.

### Package Installation

Install the PyPI package by running `pip install indentation-converter`.

<p align="right">(<a href="#top">back to top</a>)</p>

<!-- USAGE -->

## Usage

### Running the Program

**NOTE**: The commands in each usage example do the same thing. The only thing that changes is the value passed to the conversion mode (`-m`).

---

To convert the indentation of a file from 2 spaces to tabs:

```
python path/to/indentation_converter.py [FILE_PATH] -m st -s 2
python path/to/indentation_converter.py [FILE_PATH] -m spaces_to_tabs -s 2
```

---

To convert the indentation of a file from 4 spaces to tabs:

```
python path/to/indentation_converter.py [FILE_PATH] -m st
python path/to/indentation_converter.py [FILE_PATH] -m spaces_to_tabs 
```

The value of the `-s` flag defaults to 4, so it's not necessary to specify it in this case.

---

To convert the indentation of the files of a directory from 4 spaces to tabs:

```
python path/to/indentation_converter.py [DIRECTORY_PATH] -m st
python path/to/indentation_converter.py [DIRECTORY_PATH] -m spaces_to_tabs
```

---

To convert the indentation of a file from tabs to 2 spaces:

```
python path/to/indentation_converter.py [FILE_PATH] -m ts -s 2
python path/to/indentation_converter.py [FILE_PATH] -m tabs_to_spaces -s 2
```

---

#### Script Flags

| Flag                       | Description                                                                                                                                                                             |
|:---------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `-h` or `--help`           | Displays help text for the program.                                                                                                                                                     |
| `-m` or `--mode`           | Conversion mode. The possible inputs are `spaces-to-tabs`, `st`, `tabs-to-spaces`, and `ts`. `st` is the short form of `spaces_to_tabs` and `ts` is the short form of `tabs_to_spaces`. |
| `-s` or `--spaces-per-tab` | Number of spaces per tab. The default value is `4`.                                                                                                                                     |

### Using the Package in Your Project

After following the steps in the [Getting Started](#getting-started) section, import the package and the wrapper function(s) you want to use:

```python
# Using the `process_file` and `convert_leading_spaces_to_tabs` functions
import indentation_converter as ic

ic.process_file("file.txt", ic.convert_leading_spaces_to_tabs, spaces_per_tab=4)
```

<p align="right">(<a href="#top">back to top</a>)</p>

<!-- ROADMAP -->

## Roadmap

You can propose a new feature creating an [issue](https://github.com/HenestrosaDev/indentation-converter/new/choose).

<!-- CONTRIBUTING -->

## Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.

<!-- LICENSE -->

## License

Distributed under the MIT License. See [`LICENSE`](https://github.com/HenestrosaDev/indentation-converter/blob/main/LICENSE) for more information.

<!-- AUTHORS -->

## Authors

- HenestrosaDev <henestrosadev@gmail.com> (José Carlos López Henestrosa)

See also the list of [contributors](https://github.com/HenestrosaDev/indentation-converter/contributors) who participated in this project.

<!-- SUPPORT -->

## Support

Would you like to support the project? That's very kind of you! You can go to my Ko-Fi profile by clicking on the button down below.

[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/henestrosadev)

<p align="right">(<a href="#top">back to top</a>)</p>

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/HenestrosaDev/indentation-converter",
    "name": "indentation-converter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "indentation, tabs, spaces, converter",
    "author": "HenestrosaDev",
    "author_email": "henestrosadev@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/4e/6a/fc5d332ac00baf7c35f3dff6b9ffcd05b037c66b26121404a360610ef4cf/indentation_converter-0.1.0.tar.gz",
    "platform": null,
    "description": "<div id=\"top\"></div>\n\n<!-- PROJECT LOGO -->\n<div align=\"center\">\n\t<h1>Indentation Converter</h1>\n\t<p>\n\t\tConvert indentation between spaces and tabs in text files and directories, ignoring hidden files, binary files, and files in <code>.gitiginore</code>.\n\t</p>\n\t<p>\n\t\t<a href=\"https://pypi.org/project/indentation-converter/\">\n\t\t\t<img \n\t\t\t\talt=\"PyPI version\" \n\t\t\t\tsrc=\"https://img.shields.io/pypi/v/indentation-converter\" \n\t\t\t/>\n\t\t</a>\n\t\t<a href=\"https://pypi.org/project/indentation-converter/\">\n\t\t\t<img \n\t\t\t\talt=\"Python versions support\" \n\t\t\t\tsrc=\"https://img.shields.io/pypi/pyversions/indentation-converter\" \n\t\t\t/>\n\t\t</a>\n\t\t<br />\n\t\t<a href=\"https://github.com/HenestrosaDev/indentation-converter/actions/workflows/build.yaml\">\n\t\t\t<img \n\t\t\t\talt=\"GitHub action: Build\" \n\t\t\t\tsrc=\"https://github.com/HenestrosaDev/indentation-converter/actions/workflows/build.yaml/badge.svg\" \n\t\t\t/>\n\t\t</a>\n\t\t<a href=\"https://codecov.io/gh/HenestrosaDev/indentation-converter/\">\n\t\t\t<img \n\t\t\t\talt=\"Codecov\" \n\t\t\t\tsrc=\"https://codecov.io/gh/HenestrosaDev/indentation-converter/branch/main/graph/badge.svg\" \n\t\t\t/>\n\t\t</a>\n\t\t<a href=\"https://github.com/HenestrosaDev/indentation-converter/blob/main/LICENSE\">\n\t\t\t<img \n\t\t\t\talt=\"License\" \n\t\t\t\tsrc=\"https://img.shields.io/github/license/HenestrosaDev/indentation-converter\" \n\t\t\t/>\n\t\t</a>\n\t\t<br />\n\t\t<a href=\"https://github.com/HenestrosaDev/indentation-converter/graphs/contributors\">\n\t\t\t<img \n\t\t\t\talt=\"GitHub Contributors\" \n\t\t\t\tsrc=\"https://img.shields.io/github/contributors/HenestrosaDev/indentation-converter\" \n\t\t\t/>\n\t\t</a>\n\t\t<a href=\"https://github.com/HenestrosaDev/indentation-converter/issues\">\n\t\t\t<img \n\t\t\t\talt=\"Issues\" \n\t\t\t\tsrc=\"https://img.shields.io/github/issues/HenestrosaDev/indentation-converter\" \n\t\t\t/>\n\t\t</a>\n\t\t<a href=\"https://github.com/HenestrosaDev/indentation-converter/pulls\">\n\t\t\t<img \n\t\t\t\talt=\"GitHub pull requests\" \n\t\t\t\tsrc=\"https://img.shields.io/github/issues-pr/HenestrosaDev/indentation-converter\" \n\t\t\t/>\n\t\t</a>\n\t</p>\n\t<p>\n\t\t<a href=\"https://github.com/HenestrosaDev/indentation-converter/issues/new/choose\">\n\t\t\tReport Bug\n\t\t</a> \n\t\t\u00b7 \n\t\t<a href=\"https://github.com/HenestrosaDev/indentation-converter/issues/new/choose\">\n\t\t\tRequest Feature\n\t\t</a> \n\t\t\u00b7 \n\t\t<a href=\"https://github.com/HenestrosaDev/indentation-converter/discussions\">\n\t\t\tAsk Question\n\t\t</a>\n\t</p>\n</div>\n\n<!-- TABLE OF CONTENTS -->\n\n## Table of Contents\n\n- [About the Project](#about-the-project)\n  - [Project Structure](#project-structure)\n  - [Built With](#built-with)\n- [Getting Started](#getting-started)\n  - [Script Installation](#script-installation)\n  - [Package Installation](#package-installation)\n- [Usage](#usage)\n  - [Running the Program](#running-the-program)\n    - [Script Flags](#script-flags)\n  - [Using the Package in Your Project](#using-the-package-in-your-project)\n- [Roadmap](#roadmap)\n- [Contributing](#contributing)\n- [License](#license)\n- [Authors](#authors)\n- [Support](#support)\n\n<!-- ABOUT THE PROJECT -->\n\n## About the Project\n\nThis Python script provides a flexible tool for converting indentation styles in text files between spaces and tabs. It supports converting leading spaces to tabs, leading tabs to spaces, and even converting from one number of spaces to another, all while respecting the files detailed in the `.gitignore`, hidden files, and binary files.\n\nIn addition to being able to run this script on its own, you can also installed it as a package via **PyPI** (more information on how to install it [here](#use-the-package-in-your-project)).\n\n<!-- PROJECT STRUCTURE -->\n\n### Project Structure\n\n<details>\n\t<summary>ASCII directory structure</summary>\n\n```\n/\n\u2502   .gitignore\n\u2502   .pre-commit-config.yaml\n\u2502   LICENSE\n\u2502   poetry.lock\n\u2502   pyproject.toml\n\u2502   README.md\n\u2502   requirements.txt\n\u2502\n\u251c\u2500\u2500\u2500.github\n\u2502   \u2514\u2500\u2500\u2500workflows\n\u2502           build.yaml\n\u2502           publish.yaml\n\u2502\n\u251c\u2500\u2500\u2500src\n\u2502   \u2514\u2500\u2500\u2500indentation_converter\n\u2502           __init__.py\n\u2502           indentation_converter.py\n\u2502\n\u2514\u2500\u2500\u2500tests\n        test_indentation_converter.py\n```\n\n</details>\n\n### Built With\n\n- [pathspec](https://github.com/cpburnz/python-pathspec) for `.gitignore` style pattern matching of file paths.\n- [binaryornot](https://github.com/binaryornot/binaryornot) to guess whether a file is binary or text.\n\n<!-- GETTING STARTED -->\n\n## Getting Started\n\n### Script Installation\n\n1. Download the `.zip` file from the [latest release](https://github.com/HenestrosaDev/indentation-converter/releases/latest/download/indentation-converter.zip).\n2. (Optional but recommended) Create a Python virtual environment in the project root. If you're using `virtualenv`, you would run `virtualenv venv`.\n3. (Optional but recommended) Activate the virtual environment:\n\n\t ```bash\n\t # on Windows\n\t . venv/Scripts/activate\n\t # if you get the error `FullyQualifiedErrorId : UnauthorizedAccess`, run this:\n\t Set-ExecutionPolicy Unrestricted -Scope Process\n\t # and then . venv/Scripts/activate\n\n\t # on macOS and Linux\n\t source venv/Scripts/activate\n\t ```\n\n4. Open the command line and run `pip install -r path/to/requirements.txt` to install the required packages to run the script.\n\n### Package Installation\n\nInstall the PyPI package by running `pip install indentation-converter`.\n\n<p align=\"right\">(<a href=\"#top\">back to top</a>)</p>\n\n<!-- USAGE -->\n\n## Usage\n\n### Running the Program\n\n**NOTE**: The commands in each usage example do the same thing. The only thing that changes is the value passed to the conversion mode (`-m`).\n\n---\n\nTo convert the indentation of a file from 2 spaces to tabs:\n\n```\npython path/to/indentation_converter.py [FILE_PATH] -m st -s 2\npython path/to/indentation_converter.py [FILE_PATH] -m spaces_to_tabs -s 2\n```\n\n---\n\nTo convert the indentation of a file from 4 spaces to tabs:\n\n```\npython path/to/indentation_converter.py [FILE_PATH] -m st\npython path/to/indentation_converter.py [FILE_PATH] -m spaces_to_tabs \n```\n\nThe value of the `-s` flag defaults to 4, so it's not necessary to specify it in this case.\n\n---\n\nTo convert the indentation of the files of a directory from 4 spaces to tabs:\n\n```\npython path/to/indentation_converter.py [DIRECTORY_PATH] -m st\npython path/to/indentation_converter.py [DIRECTORY_PATH] -m spaces_to_tabs\n```\n\n---\n\nTo convert the indentation of a file from tabs to 2 spaces:\n\n```\npython path/to/indentation_converter.py [FILE_PATH] -m ts -s 2\npython path/to/indentation_converter.py [FILE_PATH] -m tabs_to_spaces -s 2\n```\n\n---\n\n#### Script Flags\n\n| Flag                       | Description                                                                                                                                                                             |\n|:---------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `-h` or `--help`           | Displays help text for the program.                                                                                                                                                     |\n| `-m` or `--mode`           | Conversion mode. The possible inputs are `spaces-to-tabs`, `st`, `tabs-to-spaces`, and `ts`. `st` is the short form of `spaces_to_tabs` and `ts` is the short form of `tabs_to_spaces`. |\n| `-s` or `--spaces-per-tab` | Number of spaces per tab. The default value is `4`.                                                                                                                                     |\n\n### Using the Package in Your Project\n\nAfter following the steps in the [Getting Started](#getting-started) section, import the package and the wrapper function(s) you want to use:\n\n```python\n# Using the `process_file` and `convert_leading_spaces_to_tabs` functions\nimport indentation_converter as ic\n\nic.process_file(\"file.txt\", ic.convert_leading_spaces_to_tabs, spaces_per_tab=4)\n```\n\n<p align=\"right\">(<a href=\"#top\">back to top</a>)</p>\n\n<!-- ROADMAP -->\n\n## Roadmap\n\nYou can propose a new feature creating an [issue](https://github.com/HenestrosaDev/indentation-converter/new/choose).\n\n<!-- CONTRIBUTING -->\n\n## Contributing\n\nContributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.\n\n<!-- LICENSE -->\n\n## License\n\nDistributed under the MIT License. See [`LICENSE`](https://github.com/HenestrosaDev/indentation-converter/blob/main/LICENSE) for more information.\n\n<!-- AUTHORS -->\n\n## Authors\n\n- HenestrosaDev <henestrosadev@gmail.com> (Jos\u00e9 Carlos L\u00f3pez Henestrosa)\n\nSee also the list of [contributors](https://github.com/HenestrosaDev/indentation-converter/contributors) who participated in this project.\n\n<!-- SUPPORT -->\n\n## Support\n\nWould you like to support the project? That's very kind of you! You can go to my Ko-Fi profile by clicking on the button down below.\n\n[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/henestrosadev)\n\n<p align=\"right\">(<a href=\"#top\">back to top</a>)</p>\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Convert indentation between spaces and tabs in text files and directories, ignoring hidden files, binary files, and files in `.gitiginore`.",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/HenestrosaDev/indentation-converter",
        "Repository": "https://github.com/HenestrosaDev/indentation-converter"
    },
    "split_keywords": [
        "indentation",
        " tabs",
        " spaces",
        " converter"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "261e2cdaa60d68f328a6280ecf355f33bc85b3184874099f8db0179668b3bd01",
                "md5": "6b0854be62b9e488408e6a8f9b5aa179",
                "sha256": "587c03b8508a6efa16ee28f7925cf722a3ca63a5b32699b00035868a934f87b7"
            },
            "downloads": -1,
            "filename": "indentation_converter-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6b0854be62b9e488408e6a8f9b5aa179",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 7604,
            "upload_time": "2024-06-23T10:47:11",
            "upload_time_iso_8601": "2024-06-23T10:47:11.660827Z",
            "url": "https://files.pythonhosted.org/packages/26/1e/2cdaa60d68f328a6280ecf355f33bc85b3184874099f8db0179668b3bd01/indentation_converter-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4e6afc5d332ac00baf7c35f3dff6b9ffcd05b037c66b26121404a360610ef4cf",
                "md5": "87b83103c592044bd9d7f99f845c0d90",
                "sha256": "045e4bd10a323c8e37a780ea4cad7b3a0061ec6ff191c3eb07a0730e6dbecd6f"
            },
            "downloads": -1,
            "filename": "indentation_converter-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "87b83103c592044bd9d7f99f845c0d90",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 7368,
            "upload_time": "2024-06-23T10:47:13",
            "upload_time_iso_8601": "2024-06-23T10:47:13.833084Z",
            "url": "https://files.pythonhosted.org/packages/4e/6a/fc5d332ac00baf7c35f3dff6b9ffcd05b037c66b26121404a360610ef4cf/indentation_converter-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-23 10:47:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "HenestrosaDev",
    "github_project": "indentation-converter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "binaryornot",
            "specs": [
                [
                    "==",
                    "0.4.4"
                ]
            ]
        },
        {
            "name": "pathspec",
            "specs": [
                [
                    "==",
                    "0.12.1"
                ]
            ]
        }
    ],
    "lcname": "indentation-converter"
}
        
Elapsed time: 0.49927s