# *nginx* config file formatter/beautifier
*nginx* config file formatter/beautifier written in Python with no additional dependencies. It can be used as library or standalone script. It formats *nginx* configuration files in consistent way, described below:
* All lines are indented in uniform manner, with 4 spaces per level. Number of spaces is customizable.
* Neighbouring empty lines are collapsed to at most two empty lines.
* Curly braces placement follows Java convention.
* Whitespaces are collapsed, except in comments and quotation marks.
## Installation
Python 3.4 or later is needed to run this program. The easiest way is to download package from PyPI:
```bash
pip3 install nginxfmt
```
### Manual installation
The simplest form of installation would be copying `nginxfmt.py` to
your scripts' directory. It has no 3-rd party dependencies.
You can also clone the repository and symlink the executable:
```
cd
git clone https://github.com/slomkowski/nginx-config-formatter.git
ln -s ~/nginx-config-formatter/nginxfmt.py ~/bin/nginxfmt.py
```
## Usage as standalone script
It can format one or several files. Result is by default saved to the original file, but can be redirected to *stdout*.
It can also function in piping mode, with `--pipe` switch.
```
usage: nginxfmt.py [-h] [-v] [-] [-p | -b] [-i INDENT] [config_files ...]
Formats nginx configuration files in consistent way.
positional arguments:
config_files configuration files to format
optional arguments:
-h, --help show this help message and exit
-v, --verbose show formatted file names
-, --pipe reads content from standard input, prints result to stdout
-p, --print-result prints result to stdout, original file is not changed
-b, --backup-original
backup original config file as filename.conf~
formatting options:
-i INDENT, --indent INDENT
specify number of spaces for indentation
```
## Using as library
Main logic is within `Formatter` class, which can be used in 3rd-party code.
```python
import nginxfmt
# initializing with standard FormatterOptions
f = nginxfmt.Formatter()
# format from string
formatted_text = f.format_string(unformatted_text)
# format file and save result to the same file
f.format_file(unformatted_file_path)
# format file and save result to the same file, original unformatted content is backed up
f.format_file(unformatted_file_path, backup_path)
```
Customizing formatting options:
```python
import nginxfmt
fo = nginxfmt.FormatterOptions()
fo.indentation = 2 # 2 spaces instead of default 4
# initializing with standard FormatterOptions
f = nginxfmt.Formatter(fo)
```
## Reporting bugs
Please create issue under https://github.com/slomkowski/nginx-config-formatter/issues. Be sure to add config snippets to
reproduce the issue, preferably:
* snippet do be formatted
* actual result with invalid formatting
* desired result
## Credits
Copyright 2021 Michał Słomkowski. License: Apache 2.0. Previously published under https://github.com/1connect/nginx-config-formatter.
Raw data
{
"_id": null,
"home_page": "https://github.com/slomkowski/nginx-config-formatter",
"name": "nginxfmt",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.4",
"maintainer_email": null,
"keywords": "nginx, formatter, formatting, beautifier",
"author": "Micha\u0142 S\u0142omkowski",
"author_email": "michal@slomkowski.eu",
"download_url": "https://files.pythonhosted.org/packages/e8/4e/afb3f89bc6f2a71ffa9b9b15d26b6ed0fc85f700172f177ab7e76eaccbe8/nginxfmt-1.2.3.tar.gz",
"platform": null,
"description": "# *nginx* config file formatter/beautifier\n\n*nginx* config file formatter/beautifier written in Python with no additional dependencies. It can be used as library or standalone script. It formats *nginx* configuration files in consistent way, described below:\n\n* All lines are indented in uniform manner, with 4 spaces per level. Number of spaces is customizable.\n* Neighbouring empty lines are collapsed to at most two empty lines.\n* Curly braces placement follows Java convention.\n* Whitespaces are collapsed, except in comments and quotation marks.\n\n\n## Installation\n\nPython 3.4 or later is needed to run this program. The easiest way is to download package from PyPI:\n\n```bash\npip3 install nginxfmt\n```\n\n\n### Manual installation\n\nThe simplest form of installation would be copying `nginxfmt.py` to\nyour scripts' directory. It has no 3-rd party dependencies.\n\nYou can also clone the repository and symlink the executable:\n\n```\ncd\ngit clone https://github.com/slomkowski/nginx-config-formatter.git\nln -s ~/nginx-config-formatter/nginxfmt.py ~/bin/nginxfmt.py\n```\n\n\n## Usage as standalone script\n\nIt can format one or several files. Result is by default saved to the original file, but can be redirected to *stdout*.\nIt can also function in piping mode, with `--pipe` switch.\n\n```\nusage: nginxfmt.py [-h] [-v] [-] [-p | -b] [-i INDENT] [config_files ...]\n\nFormats nginx configuration files in consistent way.\n\npositional arguments:\n config_files configuration files to format\n\noptional arguments:\n -h, --help show this help message and exit\n -v, --verbose show formatted file names\n -, --pipe reads content from standard input, prints result to stdout\n -p, --print-result prints result to stdout, original file is not changed\n -b, --backup-original\n backup original config file as filename.conf~\n\nformatting options:\n -i INDENT, --indent INDENT\n specify number of spaces for indentation\n```\n\n\n## Using as library\n\nMain logic is within `Formatter` class, which can be used in 3rd-party code.\n\n```python\nimport nginxfmt\n\n# initializing with standard FormatterOptions\nf = nginxfmt.Formatter()\n\n# format from string\nformatted_text = f.format_string(unformatted_text)\n\n# format file and save result to the same file\nf.format_file(unformatted_file_path)\n\n# format file and save result to the same file, original unformatted content is backed up\nf.format_file(unformatted_file_path, backup_path)\n```\n\nCustomizing formatting options:\n\n```python\nimport nginxfmt\n\nfo = nginxfmt.FormatterOptions()\nfo.indentation = 2 # 2 spaces instead of default 4\n\n# initializing with standard FormatterOptions\nf = nginxfmt.Formatter(fo)\n```\n\n\n## Reporting bugs\n\nPlease create issue under https://github.com/slomkowski/nginx-config-formatter/issues. Be sure to add config snippets to\nreproduce the issue, preferably:\n\n* snippet do be formatted\n* actual result with invalid formatting\n* desired result\n\n\n## Credits\n\nCopyright 2021 Micha\u0142 S\u0142omkowski. License: Apache 2.0. Previously published under https://github.com/1connect/nginx-config-formatter.\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "nginx config file formatter/beautifier with no additional dependencies.",
"version": "1.2.3",
"project_urls": {
"Homepage": "https://github.com/slomkowski/nginx-config-formatter",
"Repository": "https://github.com/slomkowski/nginx-config-formatter"
},
"split_keywords": [
"nginx",
" formatter",
" formatting",
" beautifier"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7692f5227b197cf9122960f1a16824e8a2240d859a076f1ce8c8fdbfd460da72",
"md5": "d26d1acc9ccfda85004918e8180822d5",
"sha256": "9276e7084d20d6613e7db3a2e900c62dcdcd07e2f5639aa5016e871c0029af4f"
},
"downloads": -1,
"filename": "nginxfmt-1.2.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d26d1acc9ccfda85004918e8180822d5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.4",
"size": 10652,
"upload_time": "2024-10-11T15:35:41",
"upload_time_iso_8601": "2024-10-11T15:35:41.528899Z",
"url": "https://files.pythonhosted.org/packages/76/92/f5227b197cf9122960f1a16824e8a2240d859a076f1ce8c8fdbfd460da72/nginxfmt-1.2.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e84eafb3f89bc6f2a71ffa9b9b15d26b6ed0fc85f700172f177ab7e76eaccbe8",
"md5": "a940b6ad5692ffcc4b04fa06317940cc",
"sha256": "d7f13a6a6172a9267fe621a18102d014f099f2fe4702b0dc7a107f7d0cce0e0d"
},
"downloads": -1,
"filename": "nginxfmt-1.2.3.tar.gz",
"has_sig": false,
"md5_digest": "a940b6ad5692ffcc4b04fa06317940cc",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.4",
"size": 9658,
"upload_time": "2024-10-11T15:35:42",
"upload_time_iso_8601": "2024-10-11T15:35:42.621911Z",
"url": "https://files.pythonhosted.org/packages/e8/4e/afb3f89bc6f2a71ffa9b9b15d26b6ed0fc85f700172f177ab7e76eaccbe8/nginxfmt-1.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-11 15:35:42",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "slomkowski",
"github_project": "nginx-config-formatter",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "nginxfmt"
}