From 5cec0b8c7b43fe8d3e0f20ac96265b8780c3c442 Mon Sep 17 00:00:00 2001 From: Jeremy Cline Date: May 10 2017 19:10:28 +0000 Subject: Add a skeleton Python project Signed-off-by: Jeremy Cline --- diff --git a/dev-requirements.txt b/dev-requirements.txt new file mode 100644 index 0000000..0f26762 --- /dev/null +++ b/dev-requirements.txt @@ -0,0 +1,9 @@ +# Testing requirements +flake8 +mock +pytest +pytest-cov + +# Documentation build requirements +sphinx +sphinxcontrib-httpdomain diff --git a/greenwave/__init__.py b/greenwave/__init__.py new file mode 100644 index 0000000..8490c3e --- /dev/null +++ b/greenwave/__init__.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# +# This file is part of the Greenwave project. +# Copyright (C) 2017 Red Hat, Inc. +# +# 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 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +""" +Greenwave is a web application built using `Flask`_ and `SQLAlchemy`_. + +It provides a :ref:`http-api` for applications to use. + +.. _Flask: http://flask.pocoo.org/ +.. _SQLAlchemy: http://sqlalchemy.org/ +""" + +__version__ = '0.1.0' diff --git a/greenwave/tests/__init__.py b/greenwave/tests/__init__.py new file mode 100644 index 0000000..b3e8c0f --- /dev/null +++ b/greenwave/tests/__init__.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# +# This file is part of the Greenwave project. +# Copyright (C) 2017 Red Hat, Inc. +# +# 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 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +""" +Greenwave uses the Python `unittest`_ framework for unit tests. + +Patches should be accompanied by one or more tests to demonstrate the feature +or bugfix works. This makes the review process much easier since it allows the +reviewer to run your code with very little effort, and it lets developers know +when they break your code. + + +Running Tests +============= + +Tests are run with `py.test`_ via `tox`_. You can run individual environments by +using the ``-e`` flag. For example, ``tox -e lint`` runs the linter. + + +Test Organization +================= + +The test organization is as follows: + +1. Each module in the application has a corresponding test module. These + modules is organized in the test package to mirror the package they test. + That is, ``greenwave/app.py`` has a test module in located at + ``greenwave/tests/test_app.py`` + +2. Within each test module, follow the unittest code organization guidelines. + +3. Include documentation blocks for each test case that explain the goal of the + test. + + +.. _unittest: https://docs.python.org/3/library/unittest.html +.. _py.test: https://docs.pytest.org/en/latest/ +.. _tox: https://tox.readthedocs.io/en/latest/ +""" diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e39cea1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +flask +sqlalchemy diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..5f64370 --- /dev/null +++ b/setup.py @@ -0,0 +1,113 @@ +# -*- coding: utf-8 -*- +# +# This file is part of the Greenwave project. +# Copyright (C) 2017 Red Hat, Inc. +# +# 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 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +import os +import re + +from setuptools import setup, find_packages + + +here = os.path.abspath(os.path.dirname(__file__)) +with open(os.path.join(here, 'README.md')) as fd: + README = fd.read() + + +def get_project_version(version_file='greenwave/__init__.py'): + """ + Read the declared version of the project from the source code. + + Args: + version_file: The file with the version string in it. The version must + be in the format ``__version__ = ''`` and the file must be + UTF-8 encoded. + """ + with open(version_file, "rb") as f: + version_pattern = b"^__version__ = '(.+)'$" + match = re.search(version_pattern, f.read(), re.MULTILINE) + if match is None: + err_msg = "No line matching %r found in %r" + raise ValueError(err_msg % (version_pattern, version_file)) + return match.groups()[0].decode("utf-8") + + +def get_requirements(requirements_file='requirements.txt'): + """Get the contents of a file listing the requirements. + + Args: + requirements_file (str): The path to the requirements file, relative + to this file. + + Returns: + list: the list of requirements, or an empty list if + ``requirements_file`` could not be opened or read. + """ + with open(requirements_file) as fd: + lines = fd.readlines() + dependencies = [] + for line in lines: + maybe_dep = line.strip() + if maybe_dep.startswith('#'): + # Skip pure comment lines + continue + if maybe_dep.startswith('git+'): + # VCS reference for dev purposes, expect a trailing comment + # with the normal requirement + __, __, maybe_dep = maybe_dep.rpartition('#') + else: + # Ignore any trailing comment + maybe_dep, __, __ = maybe_dep.partition('#') + # Remove any whitespace and assume non-empty results are dependencies + maybe_dep = maybe_dep.strip() + if maybe_dep: + dependencies.append(maybe_dep) + return dependencies + + +setup( + name='greenwave', + version=get_project_version(), + description=( + 'Greenwave is a service to decide whether a software artifact can pass' + ' certain gating points in a software delivery pipeline' + ), + long_description=README, + # Possible options are at https://pypi.python.org/pypi?%3Aaction=list_classifiers + classifiers=[ + 'Development Status :: 1 - Planning', + 'Framework :: Flask', + 'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)', + 'Operating System :: POSIX :: Linux', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + ], + license='GPLv2+', + maintainer='Fedora Infrastructure Team', + maintainer_email='infrastructure@lists.fedoraproject.org', + platforms=['Fedora', 'GNU/Linux'], + url='https://pagure.io/greenwave/', + packages=find_packages(exclude=('greenwave.tests', 'greenwave.tests.*')), + include_package_data=True, + zip_safe=False, + install_requires=get_requirements(), + tests_require=get_requirements(requirements_file='dev-requirements.txt'), + test_suite='greenwave.tests', +)