From 2396fb2b0a0cde4841d939a8e0d11c6958ee1f21 Mon Sep 17 00:00:00 2001 From: Merlin Mathesius Date: Apr 20 2020 17:42:26 +0000 Subject: [PATCH 1/2] Add LICENSE and other initial project files Signed-off-by: Merlin Mathesius --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..de5adb9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.pyc +/.tox/ +/cccc.egg-info/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c869bb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2020 Red Hat, Inc. and contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..43b77b1 --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +ifndef PYTHON +PYTHON=$(shell which python3 2>/dev/null || which python 2>/dev/null) +endif +VERSION=$(shell $(PYTHON) setup.py --version 2>/dev/null) +SETUP_DEVELOP_ARGS=$(shell if ($(PYTHON) setup.py develop --help 2>/dev/null | grep -q '\-\-user'); then echo "--user"; else echo ""; fi) + + +default: + @echo + @echo "Targets:" + @echo "test: Run tests (tox)" + @echo "develop: Run setuptools developer build" + @echo "clean: Purge junk" + @echo + +develop: + $(PYTHON) setup.py develop $(SETUP_DEVELOP_ARGS) + +.PHONY: clean +clean: + $(PYTHON) setup.py clean + rm -rf *.egg-info .tox + find . -type f -name '*.pyc' -delete + find . -type d -name '__pycache__' | xargs rm -rf + +.PHONY: test +test: + tox + +variables: + @echo "PYTHON=$(PYTHON)" + @echo "VERSION=$(VERSION)" + @echo "SETUP_DEVELOP_ARGS=$(SETUP_DEVELOP_ARGS)" diff --git a/cccc/__init__.py b/cccc/__init__.py new file mode 100644 index 0000000..9caa44a --- /dev/null +++ b/cccc/__init__.py @@ -0,0 +1,3 @@ +def boom(): + print("Boom!") + return 0 diff --git a/cccc/__main__.py b/cccc/__main__.py new file mode 100644 index 0000000..a429044 --- /dev/null +++ b/cccc/__main__.py @@ -0,0 +1,15 @@ +import sys +import cccc + + +def main(argv=None): + if argv is None: + argv = sys.argv + + cccc.boom() + + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/docs/README.rst b/docs/README.rst new file mode 100644 index 0000000..eba1096 --- /dev/null +++ b/docs/README.rst @@ -0,0 +1,2 @@ +Compose Configuration Compare and Check tool (CCCC) +=================================================== diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/requirements.txt diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..3982128 --- /dev/null +++ b/setup.py @@ -0,0 +1,14 @@ +from setuptools import setup + +setup( + name="cccc", + description="Compose Configuration Compare and Check", + version="0.0.0", + url="https://pagure.io/fedora-ci/cccc/", + license="MIT", + entry_points={ + "console_scripts": [ + "cccc = cccc.__main__:main" + ], + }, +) diff --git a/tests-requirements.txt b/tests-requirements.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests-requirements.txt diff --git a/tests/test_cccc.py b/tests/test_cccc.py new file mode 100644 index 0000000..c474fe4 --- /dev/null +++ b/tests/test_cccc.py @@ -0,0 +1,11 @@ +import unittest +from cccc.__main__ import main + + +class TestConsole(unittest.TestCase): + + def test_placeholder(self): + self.assertTrue(True) + + def test_main(self): + main() diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..1039e30 --- /dev/null +++ b/tox.ini @@ -0,0 +1,19 @@ +[tox] +envlist = py27,py3,flake8 + +[flake8] +ignore = E731 +max-line-length = 100 +exclude = .tox,.git,build,.env + +[testenv] +deps = pytest +commands = pytest +setenv = + PYTHONPATH = {toxinidir} + +[testenv:flake8] +basepython = python3 +skip_install = true +deps = flake8 +commands = flake8 From 8e85295424f3886ea1ab5b23c5b7813a99eb2d8e Mon Sep 17 00:00:00 2001 From: Merlin Mathesius Date: Apr 20 2020 17:42:40 +0000 Subject: [PATCH 2/2] Add argument parsing to main command Signed-off-by: Merlin Mathesius --- diff --git a/cccc/__main__.py b/cccc/__main__.py index a429044..b493cd1 100644 --- a/cccc/__main__.py +++ b/cccc/__main__.py @@ -1,10 +1,67 @@ -import sys +import argparse import cccc +import sys def main(argv=None): if argv is None: - argv = sys.argv + argv = sys.argv[1:] + + parser = argparse.ArgumentParser( + description="Compose Configuration Compare and Check") + parser.add_argument( + "--verbose", + action="store_true", + required=False, + help="Enable verbose output", + ) + + default_group = parser.add_argument_group( + "default compose configuration arguments", + "All of the default compose parameters are required") + default_group.add_argument( + "--default-pungi-repo", + type=str, + required=True, + help="Default pungi configuration repository", + ) + default_group.add_argument( + "--default-pungi-file", + type=str, + required=True, + help="Default pungi configuration file name", + ) + + pr_group = parser.add_argument_group( + "PR compose configuration arguments", + "At least one of the PR compose parameters must be provided") + pr_group.add_argument( + "--pr-pungi-repo", + type=str, + required=False, + help="PR pungi configuration repository", + ) + pr_group.add_argument( + "--pr-comps-repo", + type=str, + required=False, + help="PR comps repository", + ) + pr_group.add_argument( + "--pr-mod-defaults-repo", + type=str, + required=False, + help="PR module-defaults repository", + ) + + # at least one of the PR arguments is required + + args = parser.parse_args(argv) + + if not (args.pr_pungi_repo + or args.pr_comps_repo + or args.pr_mod_defaults_repo): + parser.error("at least one PR parameter must be provided") cccc.boom() diff --git a/tests/test_cccc.py b/tests/test_cccc.py index c474fe4..7319da7 100644 --- a/tests/test_cccc.py +++ b/tests/test_cccc.py @@ -8,4 +8,6 @@ class TestConsole(unittest.TestCase): self.assertTrue(True) def test_main(self): - main() + with self.assertRaises(SystemExit) as cm: + main(['-h']) + self.assertEqual(cm.exception.code, 0) diff --git a/tox.ini b/tox.ini index 1039e30..ecab1d6 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,7 @@ envlist = py27,py3,flake8 [flake8] -ignore = E731 +ignore = E731,W503 max-line-length = 100 exclude = .tox,.git,build,.env