Skip to content

Commit

Permalink
chore: convert to setup.cfg and pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
jerivas committed Sep 9, 2020
1 parent 82dd9f1 commit 1ae2b1b
Show file tree
Hide file tree
Showing 16 changed files with 247 additions and 381 deletions.
4 changes: 3 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
include CHANGELOG LICENSE README.rst
include AUTHORS CHANGELOG LICENSE *.rst
recursive-include docs *
recursive-exclude docs/build *
recursive-include mezzanine *
recursive-exclude */project_template/static *
global-exclude __pycache__
global-exclude *.py[co]
prune .tx
prune tests
76 changes: 0 additions & 76 deletions mezzanine/bin/runtests.py

This file was deleted.

116 changes: 0 additions & 116 deletions mezzanine/utils/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from _ast import PyCF_ONLY_AST
import os
from shutil import copyfile, copytree

Expand All @@ -12,31 +11,6 @@
from mezzanine.utils.importing import path_for_import


# Ignore these warnings in pyflakes - if added to, please comment why.
IGNORE_ERRORS = (
# Used to version subpackages.
".__version__' imported but unused",
# No caching fallback.
"redefinition of function 'nevercache'",
# Dummy fallback in templates for django-compressor.
"redefinition of function 'compress'",
# Fabic config fallback.
"redefinition of unused 'conf'",
# Fixing these would make the code ugiler IMO.
"continuation line",
"closing bracket does not match",
# Jython compatiblity.
"redefinition of unused 'Image",
# Django custom user compatibility.
"'get_user_model' imported but unused",
# lambdas are OK.
"do not assign a lambda",
# checks modules need to be imported to register check functions, they will
# be run by Django.
"'.checks' imported but unused",
)


class TestCase(BaseTestCase):
"""
This is the base test case providing common features for all tests
Expand Down Expand Up @@ -110,93 +84,3 @@ def copy_test_to_media(module, name):
copy(test_path, to_path)
except OSError:
pass


def _run_checker_for_package(checker, package_name, extra_ignore=None):
"""
Runs the checker function across every Python module in the
given package.
"""
ignore_strings = IGNORE_ERRORS
if extra_ignore:
ignore_strings += extra_ignore
package_path = path_for_import(package_name)
for (root, dirs, files) in os.walk(str(package_path)):
for f in files:
if (
f == "local_settings.py"
or not f.endswith(".py")
or root.split(os.sep)[-1] in ["migrations"]
):
# Ignore
continue
for warning in checker(os.path.join(root, f)):
for ignore in ignore_strings:
if ignore in warning:
break
else:
yield warning.replace(package_path, package_name, 1)


def run_pyflakes_for_package(package_name, extra_ignore=None):
"""
If pyflakes is installed, run it across the given package name
returning any warnings found.
"""
from pyflakes.checker import Checker

def pyflakes_checker(path):
with open(path, "U") as source_file:
source = source_file.read()
try:
tree = compile(source, path, "exec", PyCF_ONLY_AST)
except (SyntaxError, IndentationError) as value:
info = (path, value.lineno, value.args[0])
yield "Invalid syntax in %s:%d: %s" % info
else:
result = Checker(tree, path)
for warning in result.messages:
yield str(warning)

args = (pyflakes_checker, package_name, extra_ignore)
return _run_checker_for_package(*args)


def run_pep8_for_package(package_name, extra_ignore=None):
"""
If pep8 is installed, run it across the given package name
returning any warnings or errors found.
"""
import pep8

class Checker(pep8.Checker):
"""
Subclass pep8's Checker to hook into error reporting.
"""

def __init__(self, *args, **kwargs):
super(Checker, self).__init__(*args, **kwargs)
self.report_error = self._report_error

def _report_error(self, line_number, offset, text, check):
"""
Store pairs of line numbers and errors.
"""
self.errors.append((line_number, text.split(" ", 1)[1]))

def check_all(self, *args, **kwargs):
"""
Assign the errors attribute and return it after running.
"""
self.errors = []
super(Checker, self).check_all(*args, **kwargs)
return self.errors

style_guide = pep8.StyleGuide(config_file="setup.cfg")

def pep8_checker(path):
for line_number, text in Checker(path, options=style_guide.options).check_all():
yield "%s:%s: %s" % (path, line_number, text)

args = (pep8_checker, package_name, extra_ignore)
return _run_checker_for_package(*args)
125 changes: 124 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,11 +1,127 @@
[wheel]
[metadata]
name = Mezzanine
version = attr: mezzanine.__version__
description = An open source content management platform built using the Django framework.
long_description = file: README.rst
long_description_content_type = text/x-rst
author = Stephen McDonald
author_email = [email protected]
url = http://mezzanine.jupo.org/
license = BSD
license_file = LICENSE
classifiers =
Development Status :: 5 - Production/Stable
Environment :: Web Environment
Framework :: Django
Intended Audience :: Developers
License :: OSI Approved :: BSD License
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Topic :: Internet :: WWW/HTTP
Topic :: Internet :: WWW/HTTP :: Dynamic Content
Topic :: Internet :: WWW/HTTP :: WSGI
Topic :: Software Development :: Libraries :: Application Frameworks
Topic :: Software Development :: Libraries :: Python Modules

[options]
python_requires = >=3.6, <3.9
packages = find:
include_package_data = True
install_requires =
django-contrib-comments >= 1.9, <1.10
django >= 2.2, < 3.0
filebrowser_safe==1.0.0a1
grappelli_safe==1.0.0a1
tzlocal >= 2, <3
bleach >= 2, <4
beautifulsoup4 >= 4.5.3
future >= 0.9
requests >= 2.1.0, <3
requests-oauthlib >= 1.3, <2
pillow >= 7, <8
chardet

[options.extras_require]
testing =
tox >= 3, <4

[entry_points.console_scripts]
mezzanine-project = mezzanine.bin.mezzanine_project:create_project

# Building

[bdist_wheel]
universal = 1

# Testing

[tox:tox]
envlist =
py{36,37,38}-dj{22}
flake8
black
package

[testenv]
# Run test suite
allowlist_externals =
find
deps =
pytest-django >=3, <4
dj22: Django>=2.2, <3
djmaster: https://github.com/django/django/archive/master.tar.gz#egg=Django
setenv =
PYTHONPATH={toxinidir}
commands =
find {toxinidir} -type f -name "*.pyc" -delete
pytest --basetemp="{envtmpdir}" {posargs}

[testenv:package]
# Check package integrity and compatibility with PyPI
allowlist_externals =
rm
deps =
twine
check-manifest
skip_install = true
commands =
python setup.py -q sdist
twine check dist/*
rm -rf dist
check-manifest --ignore-bad-ideas '*.mo' {toxinidir}

[testenv:black]
# Lint with black
skip_install = true
deps =
black==20.8b1
commands = black . --check --exclude "(\.tox|\.git|build|dist|migrations)"

[testenv:format]
# This env is not run by default. It's provided here for you
# to easily autoformat code by running `tox -e format`
skip_install = true
deps =
black==20.8b1
commands = black . --exclude "(\.tox|\.git|build|dist|migrations)"

[testenv:flake8]
# Lint with flake8
skip_install = true
deps =
flake8 >= 3, <4
commands = flake8 .

[flake8]
# Configured to match black
ignore =
E203
W503
E731
max-line-length = 88
exclude =
migrations
Expand All @@ -15,3 +131,10 @@ exclude =
*.egg-info
build
dist

[gh-actions]
# Connect GitHub Action matrices with tox envs
python =
3.6: py36
3.7: py37
3.8: py38, flake8, black, package
Loading

0 comments on commit 1ae2b1b

Please sign in to comment.