Skip to content
This repository has been archived by the owner on Mar 13, 2021. It is now read-only.

WIP pytest experimental #1

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions config/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ packages:

- Configuration for a pure python package which supports PyPy.

* pure-python-without-pypy

- Configuration for a pure python package which does not supports PyPy,
e. g. the packages Zope depends on.


Contents
--------
Expand Down Expand Up @@ -117,6 +112,8 @@ The following arguments are supported.
--no-push
Avoid pushing at the end of the configuration run.

--with-pypy
Enable PyPy support. (Only needed one time as it is stored in .meta.cfg.)

Options
+++++++
Expand Down
6 changes: 4 additions & 2 deletions config/buildout-recipe/packages.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Packages configured as buildout recipe are listed here.
# Packages configured for the pure python version are listed here.
# Do not edit the file by hand but use the script config-package.py as
# described in README.rst
z3c.recipe.tag
#
# This was cleaned for gocept packages and has to be merged by hand when merged
# from upstram
12 changes: 12 additions & 0 deletions config/buildout-recipe/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[bdist_wheel]
universal = 1

[flake8]
doctests = 1
# provided to doctests by buildoutSetUp()
builtins = write, system, cat, join

[check-manifest]
ignore =
.editorconfig
.meta.cfg
56 changes: 0 additions & 56 deletions config/buildout-recipe/tests.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@
# https://github.com/zopefoundation/meta/tree/master/config/buildout-recipe
[tox]
envlist =
lint,
py27,
pypy,
py35,
py36,
py37,
py38,
py39,
pypy3,
lint,%(python_environs)s%(additional_environs)s
coverage

[testenv]
Expand All @@ -33,11 +25,6 @@ commands =
check-manifest
check-python-versions

[flake8]
doctests = 1
# provided to doctests by buildoutSetUp()
builtins = write, system, cat, join

[testenv:coverage]
basepython = python3
setenv =
Expand Down
130 changes: 117 additions & 13 deletions config/config-package.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,45 @@

META_HINT = """\
# Generated from:
# https://github.com/zopefoundation/meta/tree/master/config/{config_type}
# https://github.com/gocept/meta/tree/master/config/{config_type}
"""
TESTS_MATRIX_PYPY = """
- ["pypy2", "pypy"]
- ["pypy3", "pypy3"]"""
TOX_INI_PYPY = """
pypy,
pypy3,"""

MAX_PYTHON = (3, 9)


def get_supported_versions(args):
"""Get the supported versions from cli args."""
versions = [
(3, minor)
for minor in range(args.min_version[1], MAX_PYTHON[1] + 1)
]
if args.support_legacy_python:
versions.insert(0, (2, 7))
return versions


def get_tox_ini_versions(versions):
"""Return the snippet to be inserted in tox.ini."""
env_versions = (
f"py{major}{minor}"
for major, minor in versions
)
return "".join(f'\n {ver},' for ver in env_versions)


def get_test_matrix_versions(versions):
"""Return the snippet to be inserted in github actions tests.yml."""
env_versions = (
(f"{major}.{minor}", f"py{major}{minor}")
for major, minor in versions
)
return "".join(f'\n - ["{v1}", "{v2}"]' for v1, v2 in env_versions)


def call(*args, capture_output=False):
Expand Down Expand Up @@ -49,14 +86,44 @@ def copy_with_meta(source, destination, config_type, **kw):
dest='no_push',
action='store_true',
help='Prevent direct push.')
parser.add_argument(
'--with-pypy',
dest='with_pypy',
action='store_true',
default=False,
help='Activate PyPy support if not already configured in .meta.cfg.')
parser.add_argument(
'type',
choices=[
choices=[
'buildout-recipe',
'pure-python',
'pure-python-without-pypy',
'pytest',
],
help='type of the config to be used, see README.rst')
parser.add_argument(
'--with-py27',
action='store_true', dest='support_legacy_python', default=False,
)
parser.add_argument(
'--with-py35', '--py3-only',
action='store_const', dest='min_version', default=(3, 6), const=(3, 5),
)
parser.add_argument(
'--with-py36-plus',
action='store_const', dest='min_version', const=(3, 6),
)
parser.add_argument(
'--with-py37-plus',
action='store_const', dest='min_version', const=(3, 7),
)
parser.add_argument(
'--with-py38-plus',
action='store_const', dest='min_version', const=(3, 8),
)
parser.add_argument(
'--with-py39-plus',
action='store_const', dest='min_version', const=(3, 9),
)


args = parser.parse_args()
Expand Down Expand Up @@ -90,20 +157,23 @@ def copy_with_meta(source, destination, config_type, **kw):
meta_opts['template'] = config_type
meta_opts['commit-id'] = call(
'git', 'log', '-n1', '--format=format:%H', capture_output=True).stdout
with_pypy = meta_opts.getboolean('with-pypy', False) or args.with_pypy
meta_opts['with-pypy'] = str(with_pypy)
support_legacy_python = meta_opts.getboolean(
'support_legacy_python', False) or args.support_legacy_python
meta_opts['support_legacy_python'] = str(support_legacy_python)

# Copy template files
copy_with_meta(
default_path / 'setup.cfg', path / 'setup.cfg', config_type)
config_type_path / 'setup.cfg', path / 'setup.cfg', config_type)
copy_with_meta(
default_path / 'MANIFEST.in', path / 'MANIFEST.in', config_type)
copy_with_meta(
default_path / 'editorconfig', path / '.editorconfig', config_type)
copy_with_meta(
default_path / 'gitignore', path / '.gitignore', config_type)
shutil.copy(config_type_path / 'tox.ini', path)
workflows = path / '.github' / 'workflows'
workflows.mkdir(parents=True, exist_ok=True)
shutil.copy(config_type_path / 'tests.yml', workflows / 'tests.yml')

add_coveragerc = False
rm_coveragerc = False
Expand All @@ -115,18 +185,52 @@ def copy_with_meta(source, destination, config_type, **kw):
elif (path / '.coveragerc').exists():
rm_coveragerc = True

# Calculate and format supported versions
versions = get_supported_versions(args)
versions_config = get_test_matrix_versions(versions)
python_environs = get_tox_ini_versions(versions)


# Modify setup.cfg with meta options.
with open(config_type_path / 'setup.cfg') as f_:
setup_cfg = f_.read()

with open(path / 'setup.cfg', 'w') as f_:
universal_wheel = 0
if support_legacy_python:
universal_wheel = 1
f_.write(setup_cfg % dict(universal_wheel=universal_wheel))

# Modify templates with meta options.
tox_ini_path = path / 'tox.ini'
with open(tox_ini_path) as f_:

# Modify tox.ini with meta options.
with open(config_type_path / 'tox.ini.in') as f_:
tox_ini = f_.read()

with open(tox_ini_path, 'w') as f_:
with open(path / 'tox.ini', 'w') as f_:
# initialize configuration if not already present
fail_under = meta_opts.setdefault('fail-under', '0')
f_.write(tox_ini.format(
coverage_report_options=f'--fail-under={fail_under}'))
if with_pypy:
additional_environs = TOX_INI_PYPY
else:
additional_environs = ''
f_.write(tox_ini % dict(
coverage_report_options=f'--fail-under={fail_under}',
python_environs=python_environs,
additional_environs=additional_environs))

# Modify GHA config with meta options.
with open(default_path / 'tests.yml.in') as f_:
tests_yml = f_.read()

with open(workflows / 'tests.yml', 'w') as f_:

if with_pypy:
additional_config = TESTS_MATRIX_PYPY
else:
additional_config = ''
f_.write(tests_yml % dict(
version_config=versions_config,
additional_config=additional_config))

cwd = os.getcwd()
branch_name = f'config-with-{config_type}'
Expand All @@ -142,7 +246,7 @@ def copy_with_meta(source, destination, config_type, **kw):
with open('.meta.cfg', 'w') as meta_f:
meta_f.write(
'# Generated from:\n'
'# https://github.com/zopefoundation/meta/tree/master/config/'
'# https://github.com/gocept/meta/tree/master/config/'
f'{config_type}\n')
meta_cfg.write(meta_f)

Expand Down
2 changes: 1 addition & 1 deletion config/default/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include *.rst
include *.txt
include buildout.cfg
include tox.ini
include *.ini
include .coveragerc

recursive-include docs *.bat
Expand Down
1 change: 1 addition & 0 deletions config/default/gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
__pycache__/
bin/
build/
coverage-report/
coverage.xml
develop-eggs/
dist/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated from:
# Generated from:
# https://github.com/zopefoundation/meta/tree/master/config/pure-python
name: tests

Expand All @@ -15,13 +15,7 @@ jobs:
matrix:
config:
# [Python version, tox env]
- ["3.8", "lint"]
- ["2.7", "py27"]
- ["3.5", "py35"]
- ["3.6", "py36"]
- ["3.7", "py37"]
- ["3.8", "py38"]
- ["3.9", "py39"]
- ["3.8", "lint"]%(version_config)s%(additional_config)s
- ["3.8", "coverage"]

runs-on: ubuntu-latest
Expand Down
11 changes: 3 additions & 8 deletions config/pure-python/packages.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# Packages configured for the pure python version are listed here.
# Do not edit the file by hand but use the script config-package.py as
# described in README.rst
zope.authentication
z3c.wizard
zope.browsermenu
zope.app.publication
zope.app.broken
zope.app.appsetup
zope.browser
zope.dublincore
#
# This was cleaned for gocept packages and has to be merged by hand when merged
# from upstram
3 changes: 3 additions & 0 deletions config/default/setup.cfg → config/pure-python/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[bdist_wheel]
universal = 1

[flake8]
doctests = 1

[check-manifest]
ignore =
.editorconfig
Expand Down
Loading