From 8fb6519e2a282655b486f901c7ee78cc9aa133a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Alet?= Date: Tue, 15 Mar 2022 15:17:06 +1100 Subject: [PATCH] feat. Adds support for PyPi. Closes #8. --- MANIFEST.in | 3 +++ README.md | 6 ++--- pyproject.toml | 3 +++ setup.cfg | 42 ++++++++++++++++++++++++++++++ yamlfixer => yamlfixer/__init__.py | 21 ++++++++------- yamlfixer/__main__.py | 6 +++++ 6 files changed, 67 insertions(+), 14 deletions(-) create mode 100644 MANIFEST.in create mode 100644 pyproject.toml create mode 100644 setup.cfg rename yamlfixer => yamlfixer/__init__.py (97%) create mode 100755 yamlfixer/__main__.py diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..b8767c3 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,3 @@ +include requirements.txt +include Dockerfile +recursive-include examples/ *.yml *.yaml diff --git a/README.md b/README.md index 10439b3..c59cc6a 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,10 @@ in your `$PATH` : - [x] `Python v3.6` (or higher) - [x] `yamllint v1.26.3` (or higher) -Then simply copy the `yamlfixer` file to a directory present in your -`$PATH`, and ensure it is executable, for example: +Then simply install `yamlfixer` from [pypi](https://pypi.org/) ```shell -cp yamlfixer /usr/local/bin -chmod 0755 /usr/local/bin/yamlfixer +python3 -m pip install yamlfixer-opt-nc ``` diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..fed528d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..b16813b --- /dev/null +++ b/setup.cfg @@ -0,0 +1,42 @@ +[metadata] +version = 0.3.0 +name = yamlfixer-opt-nc +description = automates the fixing of problems reported by yamllint +long_description = file: README.md +author = "OPT-NC" +author_email = "jerome.alet@opt.nc" +license = "GPLv3+" +license_file = LICENSE +long_description_content_type = text/markdown +url = https://github.com/opt-nc/yamlfixer +project_urls = + Bug Tracker = https://github.com/opt-nc/yamlfixer/issues + Releases = https://github.com/opt-nc/yamlfixer/releases +classifiers = + Programming Language :: Python :: 3 + License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+) + Operating System :: OS Independent + Environment :: Console + Topic :: Utilities + Topic :: Text Processing + Development Status :: 5 - Production/Stable + Intended Audience :: System Administrators + Intended Audience :: Developers + Natural Language :: English + + +[options] +packages = find: +python_requires = >=3.6 +include_package_data = True +install_requires = + yamllint >= 1.26.3 + setuptools + +[options.package_data] +yamlfixer = examples/*.yaml examples/*.yml + +[options.entry_points] +console_scripts = + yamlfixer = yamlfixer:run + \ No newline at end of file diff --git a/yamlfixer b/yamlfixer/__init__.py similarity index 97% rename from yamlfixer rename to yamlfixer/__init__.py index f228e10..928aa13 100755 --- a/yamlfixer +++ b/yamlfixer/__init__.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python3 # -*- coding: utf-8 -*- """yamlfixer automates the fixing of problems reported by yamllint @@ -6,13 +5,19 @@ import sys import os +import time import subprocess import argparse import json -VERSION = '0.2.0' -GPLBLURB = """Copyright (C) 2021-2022 OPT-NC +__version__ = "0.3.0" +__author__ = "OPT-NC" +__license__ = "GPLv3+" +__copyright__ = "Copyright (C) 2021-%s %s" % (time.strftime("%Y", + time.localtime(time.time())), + __author__) +GPLBLURB = """ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or @@ -467,7 +472,7 @@ def fix(self): return EXIT_NOK -def main(): +def run(): """Main function.""" # Ensure we read from stdin in case it's redirected if ("-" not in sys.argv[1:]) and not sys.stdin.isatty(): @@ -476,11 +481,11 @@ def main(): # Parse the command line arguments cmdline = argparse.ArgumentParser(description="Fix formatting problems in YAML documents. " "If no file is specified,\nthen reads input from `stdin`.", - epilog=GPLBLURB, + epilog=f"{__copyright__}\n{GPLBLURB}", formatter_class=argparse.RawDescriptionHelpFormatter) cmdline.add_argument("-v", "--version", action="version", - version=f"yamlfixer v{VERSION}", + version=f"yamlfixer v{__version__}", help="display this program's version number") cmdline.add_argument("-b", "--backup", action="store_true", @@ -502,7 +507,3 @@ def main(): help="the YAML files to fix. Use `-` to read from `stdin`.") arguments = cmdline.parse_args() return YAMLFixer(arguments).fix() - - -if __name__ == '__main__': - sys.exit(main()) diff --git a/yamlfixer/__main__.py b/yamlfixer/__main__.py new file mode 100755 index 0000000..1af0248 --- /dev/null +++ b/yamlfixer/__main__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- + +from . import run + +if __name__ == '__main__': + sys.exit(run())