Skip to content

Commit

Permalink
add automatic code format enforcer - black (#813)
Browse files Browse the repository at this point in the history
* add automatic code format enforcer - black
* convert % to format
* fix double quotes in one line
* some more % to format changes
* use stable release of black
* allow unicode in description
  • Loading branch information
gaborbernat authored and obestwalter committed May 13, 2018
1 parent 236cfa6 commit 7a589ea
Show file tree
Hide file tree
Showing 26 changed files with 2,843 additions and 1,967 deletions.
12 changes: 8 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
repos:
- repo: https://github.com/ambv/black
rev: 18.4a4
hooks:
- id: black
args: [--line-length=99, --safe]
python_version: python3.6
- repo: https://github.com/pre-commit/pre-commit-hooks
sha: v1.1.1
rev: v1.2.3
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
- id: flake8
- repo: https://github.com/asottile/pyupgrade
sha: v1.2.0
rev: v1.2.0
hooks:
- id: pyupgrade
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
.. image:: https://readthedocs.org/projects/tox/badge/?version=latest
:target: http://tox.readthedocs.io/en/latest/?badge=latest
:alt: Documentation status
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/ambv/black
:alt: Code style: black

tox automation project
======================
Expand Down
66 changes: 34 additions & 32 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,59 @@
from pkg_resources import get_distribution

sys.path.insert(0, os.path.dirname(__file__))
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.extlinks',
'sphinx.ext.intersphinx',
'sphinx.ext.viewcode']
extensions = [
"sphinx.ext.autodoc", "sphinx.ext.extlinks", "sphinx.ext.intersphinx", "sphinx.ext.viewcode"
]

project = u'tox'
project = u"tox"
_full_version = get_distribution(project).version
release = _full_version.split('+', 1)[0]
version = '.'.join(release.split('.')[:2])
release = _full_version.split("+", 1)[0]
version = ".".join(release.split(".")[:2])

author = 'holger krekel and others'
author = "holger krekel and others"
year = date.today().year
copyright = u'2010-{}, {}'.format(year, author)
copyright = u"2010-{}, {}".format(year, author)

master_doc = 'index'
source_suffix = '.rst'
master_doc = "index"
source_suffix = ".rst"

exclude_patterns = ['_build']
exclude_patterns = ["_build"]

templates_path = ['_templates']
pygments_style = 'sphinx'
html_theme = 'alabaster'
html_logo = 'img/tox.png'
html_favicon = 'img/toxfavi.ico'
html_static_path = ['_static']
templates_path = ["_templates"]
pygments_style = "sphinx"
html_theme = "alabaster"
html_logo = "img/tox.png"
html_favicon = "img/toxfavi.ico"
html_static_path = ["_static"]
html_show_sourcelink = False
htmlhelp_basename = '{}doc'.format(project)
latex_documents = [('index', 'tox.tex', u'{} Documentation'.format(project),
author, 'manual')]
man_pages = [('index', project, u'{} Documentation'.format(project),
[author], 1)]
htmlhelp_basename = "{}doc".format(project)
latex_documents = [("index", "tox.tex", u"{} Documentation".format(project), author, "manual")]
man_pages = [("index", project, u"{} Documentation".format(project), [author], 1)]
epub_title = project
epub_author = author
epub_publisher = author
epub_copyright = copyright

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


def setup(app):
# from sphinx.ext.autodoc import cut_lines
# app.connect('autodoc-process-docstring', cut_lines(4, what=['module']))
app.add_description_unit('confval', 'confval',
objname='configuration value',
indextemplate='pair: %s; configuration value')
app.add_description_unit(
"confval",
"confval",
objname="configuration value",
indextemplate="pair: %s; configuration value",
)


tls_cacerts = os.getenv('SSL_CERT_FILE') # we don't care here about the validity of certificates
tls_cacerts = os.getenv("SSL_CERT_FILE") # we don't care here about the validity of certificates
linkcheck_timeout = 30
linkcheck_ignore = [r'http://holgerkrekel.net']
linkcheck_ignore = [r"http://holgerkrekel.net"]

extlinks = {'issue': ('https://github.com/tox-dev/tox/issues/%s', '#'),
'pull': ('https://github.com/tox-dev/tox/pull/%s', 'p'),
'user': ('https://github.com/%s', '@')}
extlinks = {
"issue": ("https://github.com/tox-dev/tox/issues/%s", "#"),
"pull": ("https://github.com/tox-dev/tox/pull/%s", "p"),
"user": ("https://github.com/%s", "@"),
}
91 changes: 45 additions & 46 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,66 +17,65 @@ def has_environment_marker_support():
* https://www.python.org/dev/peps/pep-0426/#environment-markers
"""
import pkg_resources

try:
v = pkg_resources.parse_version(setuptools.__version__)
return v >= pkg_resources.parse_version('0.7.2')
return v >= pkg_resources.parse_version("0.7.2")
except Exception as e:
sys.stderr.write("Could not test setuptool's version: %s\n" % e)
sys.stderr.write("Could not test setuptool's version: {}\n".format(e))
return False


def get_long_description():
with io.open('README.rst', encoding='utf-8') as f:
with io.open('CHANGELOG.rst', encoding='utf-8') as g:
return "%s\n\n%s" % (f.read(), g.read())
with io.open("README.rst", encoding="utf-8") as f:
with io.open("CHANGELOG.rst", encoding="utf-8") as g:
return u"{}\n\n{}".format(f.read(), g.read())


def main():
setuptools.setup(
name='tox',
description='virtualenv-based automation of test activities',
name="tox",
description="virtualenv-based automation of test activities",
long_description=get_long_description(),
url='https://tox.readthedocs.org/',
url="https://tox.readthedocs.org/",
use_scm_version=True,
license='http://opensource.org/licenses/MIT',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
author='holger krekel',
author_email='holger@merlinux.eu',
packages=['tox'],
entry_points={'console_scripts': ['tox=tox:cmdline',
'tox-quickstart=tox._quickstart:main']},
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
setup_requires=['setuptools_scm'],
install_requires=['py>=1.4.17',
'pluggy>=0.3.0,<1.0',
'six',
'virtualenv>=1.11.2'],
extras_require={'testing': ['pytest >= 3.0.0',
'pytest-cov',
'pytest-mock',
'pytest-timeout',
'pytest-xdist'],
'docs': ['sphinx >= 1.6.3, < 2',
'towncrier >= 17.8.0'],
'lint': ['flake8 == 3.4.1',
'flake8-bugbear == 17.4.0',
'pre-commit == 1.4.4'],
'publish': ['devpi',
'twine']},
classifiers=['Development Status :: 5 - Production/Stable',
'Framework :: tox',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: POSIX',
'Operating System :: Microsoft :: Windows',
'Operating System :: MacOS :: MacOS X',
'Topic :: Software Development :: Testing',
'Topic :: Software Development :: Libraries',
'Topic :: Utilities'] + [
('Programming Language :: Python :: {}'.format(x)) for
x in '2 2.7 3 3.4 3.5 3.6'.split()]
license="http://opensource.org/licenses/MIT",
platforms=["unix", "linux", "osx", "cygwin", "win32"],
author="holger krekel",
author_email="holger@merlinux.eu",
packages=["tox"],
entry_points={
"console_scripts": ["tox=tox:cmdline", "tox-quickstart=tox._quickstart:main"]
},
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
setup_requires=["setuptools_scm"],
install_requires=["py>=1.4.17", "pluggy>=0.3.0,<1.0", "six", "virtualenv>=1.11.2"],
extras_require={
"testing": [
"pytest >= 3.0.0", "pytest-cov", "pytest-mock", "pytest-timeout", "pytest-xdist"
],
"docs": ["sphinx >= 1.6.3, < 2", "towncrier >= 17.8.0"],
"lint": ["flake8 == 3.5.0", "flake8-bugbear == 18.2.0", "pre-commit == 1.8.2"],
"publish": ["devpi", "twine"],
},
classifiers=[
"Development Status :: 5 - Production/Stable",
"Framework :: tox",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: POSIX",
"Operating System :: Microsoft :: Windows",
"Operating System :: MacOS :: MacOS X",
"Topic :: Software Development :: Testing",
"Topic :: Software Development :: Libraries",
"Topic :: Utilities",
]
+ [
("Programming Language :: Python :: {}".format(x))
for x in "2 2.7 3 3.4 3.5 3.6".split()
],
)


if __name__ == '__main__':
if __name__ == "__main__":
main()
20 changes: 10 additions & 10 deletions tasks/pre-process-changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ def include_draft_newsfragments():
current_path = os.getcwd()
try:
os.chdir(project_root)
cmd = ['towncrier', '--draft', '--dir', project_root]
out = subprocess.check_output(cmd).decode('utf-8').strip()
docs_build_dir = project_root / '.tox' / 'docs' / 'fragments.rst'
cmd = ["towncrier", "--draft", "--dir", project_root]
out = subprocess.check_output(cmd).decode("utf-8").strip()
docs_build_dir = project_root / ".tox" / "docs" / "fragments.rst"
docs_build_dir.write(out)
finally:
os.chdir(current_path)


def manipulate_the_news():
home = 'https://github.com'
issue = '%s/issue' % home
fragmentsPath = Path(__file__).parents[1] / 'tox' / 'changelog'
home = "https://github.com"
issue = "{}/issue".format(home)
fragmentsPath = Path(__file__).parents[1] / "tox" / "changelog"
for pattern, replacement in (
(r'[^`]@([^,\s]+)', r'`@\1 <%s/\1>`_' % home),
(r'[^`]#([\d]+)', r'`#pr\1 <%s/\1>`_' % issue),
(r"[^`]@([^,\s]+)", r"`@\1 <{}/\1>`_".format(home)),
(r"[^`]#([\d]+)", r"`#pr\1 <{}/\1>`_".format(issue)),
):
for path in fragmentsPath.glob('*.rst'):
for path in fragmentsPath.glob("*.rst"):
path.write_text(re.sub(pattern, replacement, path.read_text()))


main = manipulate_the_news


if __name__ == '__main__':
if __name__ == "__main__":
sys.exit(main())
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# FIXME this seems unnecessary
# TODO move fixtures here and only keep helper functions/classes in the plugin
# TODO _pytest_helpers might be a better name than _pytestplugin then?
# noinspection PyUnresolvedReferences
from tox._pytestplugin import * # noqa
Loading

0 comments on commit 7a589ea

Please sign in to comment.