#1 Add some boilerplate for the project
Merged 6 years ago by jcline. Opened 6 years ago by jcline.
jcline/greenwave skeleton  into  master

file added
+13
@@ -0,0 +1,13 @@ 

+ [run]

+ branch = True

+ include =

+     greenwave/*

+ 

+ [report]

+ fail_under = 100

Although I like how ambitious this is, should we consider lowering this amount to something like 95%?

We can leave it at 100 now, but it's something to consider in the future.

This is, of course, something maintainers all have to agree to, but coverage has great exclusion support, so you can exclude individual lines, conditional branches, functions, classes, and whole source files from the coverage report. If there's code it doesn't make sense to test, it's easy to exclude it.

I'm certainly not advocating tests for literally every line of code even when it makes no sense. In my opinion, everything should either be tested or be excluded and justified and this is enforced with the 100% coverage requirement.

Okay, I'm good with that. Thank you for the explanation.

+ exclude_lines =

+     pragma: no cover

+     if __name__ == .__main__.:

+ omit =

+     greenwave/tests/*

+ 

file added
+22
@@ -0,0 +1,22 @@ 

+ # Build artifacts

+ __pycache__/

+ *.py[cod]

+ build/

+ dist/

+ sdist/

+ docs/_build/

+ eggs/

+ *egg-info/

+ *.egg

+ 

+ # Vim temporary files

+ *~

+ *.swp

+ *.swo

+ 

+ # Unit tests and coverage reports

+ .tox/

+ .coverage

+ .cache

+ coverage.xml

+ htmlcov

@@ -0,0 +1,9 @@ 

+ # Testing requirements

+ flake8

+ mock

+ pytest

+ pytest-cov

+ 

+ # Documentation build requirements

+ sphinx

+ sphinxcontrib-httpdomain

file added
+20
@@ -0,0 +1,20 @@ 

+ # Minimal makefile for Sphinx documentation

+ #

+ 

+ # You can set these variables from the command line.

+ SPHINXOPTS    =

+ SPHINXBUILD   = sphinx-build

+ SPHINXPROJ    = Greenwave

+ SOURCEDIR     = .

+ BUILDDIR      = _build

+ 

+ # Put it first so that "make" without argument is like "make help".

+ help:

+ 	@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

+ 

+ .PHONY: help Makefile

+ 

+ # Catch-all target: route all unknown targets to Sphinx using the new

+ # "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).

+ %: Makefile

+ 	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 

\ No newline at end of file

file added
+11
@@ -0,0 +1,11 @@ 

+ ==============

+ Greenwave APIs

+ ==============

+ 

+ .. automodule:: greenwave

+ 

+ 

+ .. _http-api:

+ 

+ HTTP REST API

+ =============

file added
+185
@@ -0,0 +1,185 @@ 

+ #!/usr/bin/env python3

+ # -*- coding: utf-8 -*-

+ #

+ # Greenwave documentation build configuration file, created by

+ # sphinx-quickstart on Wed May 10 13:18:15 2017.

+ #

+ # This file is execfile()d with the current directory set to its

+ # containing dir.

+ #

+ # Note that not all possible configuration values are present in this

+ # autogenerated file.

+ #

+ # All configuration values have a default; values that are commented out

+ # serve to show the default.

+ 

+ # If extensions (or modules to document with autodoc) are in another directory,

+ # add these directories to sys.path here. If the directory is relative to the

+ # documentation root, use os.path.abspath to make it absolute, like shown here.

+ #

+ # import os

+ # import sys

+ # sys.path.insert(0, os.path.abspath('.'))

+ import greenwave

+ 

+ 

+ # -- General configuration ------------------------------------------------

+ 

+ # If your documentation needs a minimal Sphinx version, state it here.

+ #

+ needs_sphinx = '1.3'

+ 

+ # Add any Sphinx extension module names here, as strings. They can be

+ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom

+ # ones.

+ extensions = [

+     'sphinx.ext.autodoc',

+     'sphinx.ext.intersphinx',

+     'sphinx.ext.viewcode',

+     'sphinx.ext.napoleon',

+     'sphinxcontrib.autohttp.flask',

+ ]

+ 

+ # Add any paths that contain templates here, relative to this directory.

+ templates_path = ['_templates']

+ 

+ # The suffix(es) of source filenames.

+ # You can specify multiple suffix as a list of string:

+ #

+ source_suffix = ['.rst', '.md']

+ 

+ # The master toctree document.

+ master_doc = 'index'

+ 

+ # General information about the project.

+ project = 'Greenwave'

+ copyright = '2017, Red Hat, Inc. and others'

+ author = 'Red Hat, Inc. and others'

+ 

+ # The version info for the project you're documenting, acts as replacement for

+ # |version| and |release|, also used in various other places throughout the

+ # built documents.

+ #

+ # The short X.Y version.

+ version = '.'.join(greenwave.__version__.split('.')[:2])

+ # The full version, including alpha/beta/rc tags.

+ release = greenwave.__version__

+ 

+ # The language for content autogenerated by Sphinx. Refer to documentation

+ # for a list of supported languages.

+ #

+ # This is also used if you do content translation via gettext catalogs.

+ # Usually you set "language" from the command line for these cases.

+ language = None

+ 

+ # List of patterns, relative to source directory, that match files and

+ # directories to ignore when looking for source files.

+ # This patterns also effect to html_static_path and html_extra_path

+ exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

+ 

+ # The name of the Pygments (syntax highlighting) style to use.

+ pygments_style = 'sphinx'

+ 

+ # If true, `todo` and `todoList` produce output, else they produce nothing.

+ todo_include_todos = False

+ 

+ 

+ # -- Options for HTML output ----------------------------------------------

+ 

+ # The theme to use for HTML and HTML Help pages.  See the documentation for

+ # a list of builtin themes.

+ #

+ html_theme = 'alabaster'

+ 

+ # Theme options are theme-specific and customize the look and feel of a theme

+ # further.  For a list of options available for each theme, see the

+ # documentation.

+ #

+ # html_theme_options = {}

+ 

+ # Add any paths that contain custom static files (such as style sheets) here,

+ # relative to this directory. They are copied after the builtin static files,

+ # so a file named "default.css" will overwrite the builtin "default.css".

+ html_static_path = ['_static']

+ 

+ 

+ # -- Options for HTMLHelp output ------------------------------------------

+ 

+ # Output file base name for HTML help builder.

+ htmlhelp_basename = 'Greenwavedoc'

+ 

+ 

+ # -- Options for LaTeX output ---------------------------------------------

+ 

+ latex_elements = {

+     # The paper size ('letterpaper' or 'a4paper').

+     #

+     # 'papersize': 'letterpaper',

+ 

+     # The font size ('10pt', '11pt' or '12pt').

+     #

+     # 'pointsize': '10pt',

+ 

+     # Additional stuff for the LaTeX preamble.

+     #

+     # 'preamble': '',

+ 

+     # Latex figure (float) alignment

+     #

+     # 'figure_align': 'htbp',

+ }

+ 

+ # Grouping the document tree into LaTeX files. List of tuples

+ # (source start file, target name, title,

+ #  author, documentclass [howto, manual, or own class]).

+ latex_documents = [

+     (master_doc, 'Greenwave.tex', 'Greenwave Documentation',

+      'Red Hat, Inc. and others', 'manual'),

+ ]

+ 

+ 

+ # -- Options for manual page output ---------------------------------------

+ 

+ # One entry per manual page. List of tuples

+ # (source start file, name, description, authors, manual section).

+ man_pages = [

+     (master_doc, 'greenwave', 'Greenwave Documentation',

+      [author], 1)

+ ]

+ 

+ 

+ # -- Options for Texinfo output -------------------------------------------

+ 

+ # Grouping the document tree into Texinfo files. List of tuples

+ # (source start file, target name, title, author,

+ #  dir menu entry, description, category)

+ texinfo_documents = [

+     (master_doc, 'Greenwave', 'Greenwave Documentation',

+      author, 'Greenwave', 'One line description of project.',

+      'Miscellaneous'),

+ ]

+ 

+ 

+ # -- Options for Epub output ----------------------------------------------

+ 

+ # Bibliographic Dublin Core info.

+ epub_title = project

+ epub_author = author

+ epub_publisher = author

+ epub_copyright = copyright

+ 

+ # The unique identifier of the text. This can be a ISBN number

+ # or the project homepage.

+ #

+ # epub_identifier = ''

+ 

+ # A unique identification for the text.

+ #

+ # epub_uid = ''

+ 

+ # A list of files that should not be packed into the epub file.

+ epub_exclude_files = ['search.html']

+ 

+ 

+ # Example configuration for intersphinx: refer to the Python standard library.

+ intersphinx_mapping = {'https://docs.python.org/': None}

@@ -0,0 +1,45 @@ 

+ =======================

+ Contribution Guidelines

+ =======================

+ 

+ Please follow the following contribution guidelines when contributing a pull

+ request.

+ 

+ 

+ Code style

+ ==========

+ 

+ We follow the `PEP 8`_ style guide for Python. The test suite includes a test

+ that enforces the required style, so all you need to do is run the tests to

+ ensure your code follows the style. If the unit test passes, you are good to go!

+ 

+ 

+ Unit tests

+ ==========

+ 

+ .. automodule:: greenwave.tests

+ 

+ 

+ Documentation

+ =============

+ Greenwave uses `sphinx <http://www.sphinx-doc.org/>`_ to create its documentation.

+ New packages, modules, classes, methods, functions, and attributes all should be

+ documented using `"Google style" <http://www.sphinx-doc.org/en/latest/ext/example_google.html>`_

+ docstrings.

+ 

+ Python API documentation is automatically generated from the code using Sphinx's

+ `autodoc <http://www.sphinx-doc.org/en/stable/tutorial.html#autodoc>`_ extension.

+ HTTP REST API documentation is automatically generated from the code using the

+ `httpdomain <http://pythonhosted.org/sphinxcontrib-httpdomain/>`_ extension.

+ 

+ 

+ Development Environment

+ =======================

+ 

+ Set up a Python virtual environment and then install Greenwave::

+ 

+   $ pip install -r dev-requirements.txt

+   $ pip install -e .

+ 

+ 

+ .. _PEP 8: https://www.python.org/dev/peps/pep-0008/

file added
+22
@@ -0,0 +1,22 @@ 

+ .. Greenwave documentation master file, created by

+    sphinx-quickstart on Wed May 10 13:18:15 2017.

+    You can adapt this file completely to your liking, but it should at least

+    contain the root `toctree` directive.

+ 

+ Greenwave

+ =========

+ 

+ .. toctree::

+    :maxdepth: 2

+    :caption: Contents:

+ 

+    contributing

+    api

+ 

+ 

+ Indices and tables

+ ==================

+ 

+ * :ref:`genindex`

+ * :ref:`modindex`

+ * :ref:`search`

@@ -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'

@@ -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/

+ """

file added
+2
@@ -0,0 +1,2 @@ 

+ flask

+ sqlalchemy

file added
+113
@@ -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__ = '<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',

+ )

file added
+36
@@ -0,0 +1,36 @@ 

+ [tox]

+ envlist = lint,py27,py34,py35,py36,docs

+ # If the user is missing an interpreter, don't fail

+ skip_missing_interpreters = True

+ 

+ [testenv]

+ deps =

+     -rrequirements.txt

+     -rdev-requirements.txt

+ whitelist_externals =

+     rm

+ commands =

+     rm -rf htmlcov coverage.xml

+     py.test --cov-config .coveragerc --cov=greenwave --cov-report term \

+         --cov-report xml --cov-report html

+ 

+ [testenv:docs]

+ changedir = docs

+ whitelist_externals =

+     mkdir

+     rm

+ commands=

+     mkdir -p _static

+     rm -rf _build/

+     sphinx-build -W -b html -d {envtmpdir}/doctrees .  _build/html

+ 

+ [testenv:lint]

+ deps =

+     flake8 > 3.0

+ commands =

+     python -m flake8 {posargs}

+ 

+ [flake8]

+ show-source = True

+ max-line-length = 100

+ exclude = .git,.tox,dist,*egg

This just adds a bunch of boilerplate configuration and skeletons to the project:

  • A setup.py

  • A Python package with some basic documentation

  • A sphinx project with some initial documentation about contribution/style/etc

  • A test coverage configuration

  • A tox.ini file

:100:

@jcline, you should have rights to merge.

Pull-Request has been merged by jcline

6 years ago

Although I like how ambitious this is, should we consider lowering this amount to something like 95%?

We can leave it at 100 now, but it's something to consider in the future.

This is, of course, something maintainers all have to agree to, but coverage has great exclusion support, so you can exclude individual lines, conditional branches, functions, classes, and whole source files from the coverage report. If there's code it doesn't make sense to test, it's easy to exclude it.

I'm certainly not advocating tests for literally every line of code even when it makes no sense. In my opinion, everything should either be tested or be excluded and justified and this is enforced with the 100% coverage requirement.

Okay, I'm good with that. Thank you for the explanation.