From 5d921d3add473b28fcc96da51f7e786472899f7f Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: May 25 2020 07:53:02 +0000 Subject: Add and use setup.py, requirements.txt In the course, designate the team as maintainers of the container image, too. Signed-off-by: Nils Philippsen --- diff --git a/Dockerfile b/Dockerfile index 1cadbb3..c63ef54 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # This Dockerfile is used to build and run monitor-gating on Openshift FROM fedora:31 -LABEL maintainer "Pierre-Yves Chibon " +LABEL maintainer "Fedora Infrastructure Team " RUN dnf -y install python3-requests bodhi-client fedpkg fedpkg-stage \ python3-toml git python3-koji python3-fedora-messaging cracklib-dicts \ @@ -9,7 +9,7 @@ RUN dnf -y install python3-requests bodhi-client fedpkg fedpkg-stage \ COPY . /opt/code -RUN cd /opt/code && mkdir /opt/config && cp runner.cfg /opt/config \ +RUN cd /opt/code && python3 setup.py install && mkdir /opt/config && cp runner.cfg /opt/config \ && echo "packagerbot" > /.fedora.upn \ && chgrp -R 0 /opt/code \ && chmod -R g=u /opt/code \ @@ -26,4 +26,4 @@ RUN cd /opt/code && mkdir /opt/config && cp runner.cfg /opt/config \ USER 1000 WORKDIR / ENTRYPOINT ["/opt/code/entrypoint.sh"] -CMD ["python3", "/opt/code/runner.py", "/opt/config/runner.cfg"] +CMD ["monitor-gating", "/opt/config/runner.cfg"] diff --git a/monitor_gating/clean_up_side_tags.py b/monitor_gating/clean_up_side_tags.py index 982cc06..9c3e994 100644 --- a/monitor_gating/clean_up_side_tags.py +++ b/monitor_gating/clean_up_side_tags.py @@ -43,7 +43,9 @@ def run_command(command) -> bytes: return output -def main(args): +def main(): + """ Main method. """ + args = get_cli_args(sys.argv[1:]) conf = toml.load(args.conf) if conf.get("kb_principal") and conf.get("kb_keytab_file"): @@ -72,7 +74,4 @@ def main(args): if __name__ == "__main__": - """ Main method. """ - - args = get_cli_args(sys.argv[1:]) - main(args) + main() diff --git a/monitor_gating/runner.py b/monitor_gating/runner.py index 924605d..413b94a 100644 --- a/monitor_gating/runner.py +++ b/monitor_gating/runner.py @@ -16,8 +16,8 @@ import fedora_messaging.exceptions import toml -from . import single_build from . import multi_builds +from . import single_build from .utils import MonitoringUtils, blocking_issues, run_command @@ -168,17 +168,13 @@ def schedule(conf): s.enter(delay, 1, schedule, argument=(conf,)) -def main(args): - """ Schedule the first test and run the scheduler. """ - args = get_arguments(args) - conf = toml.load(args.conf) - s.enter(0, 1, schedule, argument=(conf,)) - s.run() - - -if __name__ == "__main__": +def main(): + """ Main method. """ try: - main(sys.argv[1:]) + args = get_arguments(sys.argv[1:]) + conf = toml.load(args.conf) + s.enter(0, 1, schedule, argument=(conf,)) + s.run() except KeyboardInterrupt: from code import InteractiveConsole @@ -186,3 +182,7 @@ if __name__ == "__main__": "ENTERING THE DEBUG CONSOLE:\n s is the scheduler\n ^d to quit", "LEAVING THE DEBUG CONSOLE", ) + + +if __name__ == "__main__": + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..778e4a6 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +fedora_messaging +requests +toml diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..7638255 --- /dev/null +++ b/setup.py @@ -0,0 +1,66 @@ +import os + +from setuptools import setup + + +def get_requirements(): + requirements = [] + with open("requirements.txt", "r") as f: + for line in f: + line = line.strip() + before, _, after = line.partition("#") + # Allow source control references for development. + if before.startswith("git+"): + if not after: + # The name is in the fragment + continue + _, _, requirement = after.rpartition("=") + requirement, _, _ = requirement.partition("#") + else: + requirement = before + + requirement = requirement.strip() + + if requirement: + requirements.append(requirement) + return requirements + + +here = os.path.abspath(os.path.dirname(__file__)) +with open(os.path.join(here, "README.rst"), "r") as f: + README = f.read() + + +setup( + name="monitor-gating", + version="0.0.1", + # Possible options are at https://pypi.python.org/pypi?%3Aaction=list_classifiers + classifiers=[ + "Development Status :: 5 - Alpha", + "Intended Audience :: Developers", + "Intended Audience :: System Administrators", + # 'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)', + "Operating System :: POSIX :: Linux", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Topic :: System :: Software Distribution", + ], + # license=LICENSE, + maintainer="Fedora Infrastructure Team", + maintainer_email="infrastructure@lists.fedoraproject.org", + platforms=["Fedora", "GNU/Linux"], + url="https://pagure.io/fedora-ci/monitor-gating", + description="Monitor the health of gating in Fedora", + long_description=README, + keywords="fedora", + packages=["monitor_gating"], + include_package_data=True, + zip_safe=False, + install_requires=get_requirements(), + entry_points=""" + [console_scripts] + monitor-gating = monitor_gating.runner:main + monitor-gating-clean-up-side-tags = monitor_gating.clean_up_side_tags:main + """, +)