From 3c533079e230be7855ae2f3f3623cccfd31f6864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Gmach?= Date: Fri, 15 May 2020 10:55:51 +0200 Subject: [PATCH 1/3] Configuring for pure-python --- .editorconfig | 39 +++++++++++ .gitignore | 33 ++++++--- .meta.cfg | 7 ++ .travis.yml | 35 +++++++++- MANIFEST.in | 20 ++++-- bootstrap.py | 189 -------------------------------------------------- setup.cfg | 11 +++ tox.ini | 64 ++++++++++++----- 8 files changed, 176 insertions(+), 222 deletions(-) create mode 100644 .editorconfig create mode 100644 .meta.cfg delete mode 100644 bootstrap.py diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f3e46f5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,39 @@ +# Generated from: +# https://github.com/zopefoundation/meta/tree/master/config/pure-python +# +# EditorConfig Configuration file, for more details see: +# http://EditorConfig.org +# EditorConfig is a convention description, that could be interpreted +# by multiple editors to enforce common coding conventions for specific +# file types + +# top-most EditorConfig file: +# Will ignore other EditorConfig files in Home directory or upper tree level. +root = true + + +[*] # For All Files +# Unix-style newlines with a newline ending every file +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +# Set default charset +charset = utf-8 +# Indent style default +indent_style = space +# Max Line Length - a hard line wrap, should be disabled +max_line_length = off + +[*.{py,cfg,ini}] +# 4 space indentation +indent_size = 4 + +[*.{yml,zpt,pt,dtml}] +# 2 space indentation +indent_size = 2 + +[{Makefile,.gitmodules}] +# Tab indentation (no size specified, but view as 4 spaces) +indent_style = tab +indent_size = unset +tab_width = unset diff --git a/.gitignore b/.gitignore index 3f5b0a2..7bd5e56 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,24 @@ -*.egg +# Generated from: +# https://github.com/zopefoundation/meta/tree/master/config/pure-python +*.egg-info/ +*.profraw *.pyc -/*.egg-info -/.coverage -/.installed.cfg -/.tox -/bin -/develop-eggs -/doc.txt -/eggs -/parts +*.pyo +.coverage +.coverage.* +.installed.cfg +.mr.developer.cfg +.tox/ +__pycache__/ +bin/ +build/ +coverage.xml +develop-eggs/ +dist/ +docs/_build +eggs/ +htmlcov/ +lib/ +lib64 +parts/ +pyvenv.cfg diff --git a/.meta.cfg b/.meta.cfg new file mode 100644 index 0000000..4597e7f --- /dev/null +++ b/.meta.cfg @@ -0,0 +1,7 @@ +# Generated from: +# https://github.com/zopefoundation/meta/tree/master/config/pure-python +[meta] +template = pure-python +commit-id = 05894360cac01f1027889dd14a23ae372e808b3f +fail-under = 0 + diff --git a/.travis.yml b/.travis.yml index daf324b..3ca6074 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,34 @@ -version: ~> 1.0 +# Generated from: +# https://github.com/zopefoundation/meta/tree/master/config/pure-python language: python -import: zopefoundation/meta:travis-ci-config/minimal.yml +python: + - 2.7 + - pypy + - 3.5 + - 3.6 + - 3.7 + - 3.8 + - pypy3 + +matrix: + include: + - name: "lint" + python: 3.7 + env: TOXENV="lint" + - name: "coverage" + python: 3.7 + env: TOXENV="coverage" + after_success: + - coveralls + +install: + - pip install -U pip + - pip install -U tox-travis coveralls + +script: + - tox + +notifications: + email: false + +cache: pip diff --git a/MANIFEST.in b/MANIFEST.in index e1d34fd..52bb42c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,7 +1,19 @@ -include *.py +# Generated from: +# https://github.com/zopefoundation/meta/tree/master/config/pure-python +include *.rst +include *.txt include buildout.cfg +include tox.ini -recursive-include zc *.txt +exclude MANIFEST.in -global-exclude *.pyc -global-exclude *.pyo +recursive-include docs *.bat +recursive-include docs *.py +recursive-include docs *.rst +recursive-include docs Makefile + +recursive-include src *.pt +recursive-include src *.rst +recursive-include src *.txt +recursive-include src *.xml +recursive-include src *.zcml diff --git a/bootstrap.py b/bootstrap.py deleted file mode 100644 index a629566..0000000 --- a/bootstrap.py +++ /dev/null @@ -1,189 +0,0 @@ -############################################################################## -# -# Copyright (c) 2006 Zope Foundation and Contributors. -# All Rights Reserved. -# -# This software is subject to the provisions of the Zope Public License, -# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. -# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED -# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS -# FOR A PARTICULAR PURPOSE. -# -############################################################################## -"""Bootstrap a buildout-based project - -Simply run this script in a directory containing a buildout.cfg. -The script accepts buildout command-line options, so you can -use the -c option to specify an alternate configuration file. -""" - -import os -import shutil -import sys -import tempfile - -from optparse import OptionParser - -tmpeggs = tempfile.mkdtemp() - -usage = '''\ -[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options] - -Bootstraps a buildout-based project. - -Simply run this script in a directory containing a buildout.cfg, using the -Python that you want bin/buildout to use. - -Note that by using --find-links to point to local resources, you can keep -this script from going over the network. -''' - -parser = OptionParser(usage=usage) -parser.add_option("-v", "--version", help="use a specific zc.buildout version") - -parser.add_option("-t", "--accept-buildout-test-releases", - dest='accept_buildout_test_releases', - action="store_true", default=False, - help=("Normally, if you do not specify a --version, the " - "bootstrap script and buildout gets the newest " - "*final* versions of zc.buildout and its recipes and " - "extensions for you. If you use this flag, " - "bootstrap and buildout will get the newest releases " - "even if they are alphas or betas.")) -parser.add_option("-c", "--config-file", - help=("Specify the path to the buildout configuration " - "file to be used.")) -parser.add_option("-f", "--find-links", - help=("Specify a URL to search for buildout releases")) -parser.add_option("--allow-site-packages", - action="store_true", default=False, - help=("Let bootstrap.py use existing site packages")) -parser.add_option("--setuptools-version", - help="use a specific setuptools version") - - -options, args = parser.parse_args() - -###################################################################### -# load/install setuptools - -try: - if options.allow_site_packages: - import setuptools - import pkg_resources - from urllib.request import urlopen -except ImportError: - from urllib2 import urlopen - -ez = {} -exec(urlopen('https://bootstrap.pypa.io/ez_setup.py').read(), ez) - -if not options.allow_site_packages: - # ez_setup imports site, which adds site packages - # this will remove them from the path to ensure that incompatible versions - # of setuptools are not in the path - import site - # inside a virtualenv, there is no 'getsitepackages'. - # We can't remove these reliably - if hasattr(site, 'getsitepackages'): - for sitepackage_path in site.getsitepackages(): - sys.path[:] = [x for x in sys.path if sitepackage_path not in x] - -setup_args = dict(to_dir=tmpeggs, download_delay=0) - -if options.setuptools_version is not None: - setup_args['version'] = options.setuptools_version - -ez['use_setuptools'](**setup_args) -import setuptools -import pkg_resources - -# This does not (always?) update the default working set. We will -# do it. -for path in sys.path: - if path not in pkg_resources.working_set.entries: - pkg_resources.working_set.add_entry(path) - -###################################################################### -# Install buildout - -ws = pkg_resources.working_set - -cmd = [sys.executable, '-c', - 'from setuptools.command.easy_install import main; main()', - '-mZqNxd', tmpeggs] - -find_links = os.environ.get( - 'bootstrap-testing-find-links', - options.find_links or - ('http://downloads.buildout.org/' - if options.accept_buildout_test_releases else None) - ) -if find_links: - cmd.extend(['-f', find_links]) - -setuptools_path = ws.find( - pkg_resources.Requirement.parse('setuptools')).location - -requirement = 'zc.buildout' -version = options.version -if version is None and not options.accept_buildout_test_releases: - # Figure out the most recent final version of zc.buildout. - import setuptools.package_index - _final_parts = '*final-', '*final' - - def _final_version(parsed_version): - try: - return not parsed_version.is_prerelease - except AttributeError: - # Older setuptools - for part in parsed_version: - if (part[:1] == '*') and (part not in _final_parts): - return False - return True - - index = setuptools.package_index.PackageIndex( - search_path=[setuptools_path]) - if find_links: - index.add_find_links((find_links,)) - req = pkg_resources.Requirement.parse(requirement) - if index.obtain(req) is not None: - best = [] - bestv = None - for dist in index[req.project_name]: - distv = dist.parsed_version - if _final_version(distv): - if bestv is None or distv > bestv: - best = [dist] - bestv = distv - elif distv == bestv: - best.append(dist) - if best: - best.sort() - version = best[-1].version -if version: - requirement = '=='.join((requirement, version)) -cmd.append(requirement) - -import subprocess -if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=setuptools_path)) != 0: - raise Exception( - "Failed to execute command:\n%s" % repr(cmd)[1:-1]) - -###################################################################### -# Import and run buildout - -ws.add_entry(tmpeggs) -ws.require(requirement) -import zc.buildout.buildout - -if not [a for a in args if '=' not in a]: - args.append('bootstrap') - -# if -c was provided, we push it back into args for buildout' main function -if options.config_file is not None: - args[0:0] = ['-c', options.config_file] - -zc.buildout.buildout.main(args) -shutil.rmtree(tmpeggs) diff --git a/setup.cfg b/setup.cfg index 2f7b073..9f7321c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,13 @@ +# Generated from: +# https://github.com/zopefoundation/meta/tree/master/config/pure-python +[bdist_wheel] +universal = 1 + [flake8] doctests = 1 + +[check-manifest] +ignore = + .editorconfig + .meta.cfg + .travis.yml diff --git a/tox.ini b/tox.ini index ed4e3f7..99b8d87 100644 --- a/tox.ini +++ b/tox.ini @@ -1,30 +1,60 @@ +# Generated from: +# https://github.com/zopefoundation/meta/tree/master/config/pure-python [tox] -envlist = flake8, - py27, - py35, - py36, - py37, - py38, - pypy, - pypy3, - coverage +envlist = + lint, + py27, + pypy, + py35, + py36, + py37, + py38, + pypy3, + coverage [testenv] usedevelop = true +deps = + zope.testrunner commands = zope-testrunner --test-path=src [] extras = test -[testenv:coverage] +[testenv:lint] basepython = python3 +skip_install = true +deps = + flake8 + check-manifest + check-python-versions commands = - coverage run -m zope.testrunner --test-path=src [] - coverage report --fail-under=86 + flake8 src setup.py + check-manifest + check-python-versions . + +[testenv:coverage] +basepython = python3 deps = coverage + coverage-python-version + zope.testrunner +commands = + coverage run -m zope.testrunner --test-path=src [] + coverage html + coverage report -m --fail-under=0 -[testenv:flake8] -basepython = python3 -skip_install = true -deps = flake8 -commands = flake8 src setup.py +[coverage:run] +branch = True +plugins = coverage_python_version +source = src + +[coverage:report] +precision = 2 +exclude_lines = + pragma: nocover + except ImportError: + raise NotImplementedError + if __name__ == '__main__': + +[coverage:html] +directory = htmlcov From 4fd65ab7116d8473279d8f13936478535f60c7f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Gmach?= Date: Fri, 15 May 2020 11:37:44 +0200 Subject: [PATCH 2/3] Fix linting errors ... and make some adjustments, as this repo has no `src` top level directory. modified: MANIFEST.in modified: setup.py modified: tox.ini modified: zc/zdaemonrecipe/__init__.py modified: zc/zdaemonrecipe/tests.py --- MANIFEST.in | 1 + setup.py | 31 ++++++++++++++++--------------- tox.ini | 6 +++--- zc/zdaemonrecipe/__init__.py | 23 ++++++++++++----------- zc/zdaemonrecipe/tests.py | 24 ++++++++++++------------ 5 files changed, 44 insertions(+), 41 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 52bb42c..e99288b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -10,6 +10,7 @@ exclude MANIFEST.in recursive-include docs *.bat recursive-include docs *.py recursive-include docs *.rst +recursive-include zc *.txt recursive-include docs Makefile recursive-include src *.pt diff --git a/setup.py b/setup.py index 69f8754..65a5362 100644 --- a/setup.py +++ b/setup.py @@ -11,20 +11,22 @@ # FOR A PARTICULAR PURPOSE. # ############################################################################## -name = 'zc.zdaemonrecipe' - import os from setuptools import setup, find_packages +name = 'zc.zdaemonrecipe' + entry_points = ''' [zc.buildout] default=zc.zdaemonrecipe:Recipe ''' + def read(*rnames): return open(os.path.join(os.path.dirname(__file__), *rnames)).read() -long_description=( + +long_description = ( read('README.rst') + '\n' + 'Detailed Documentation\n' @@ -44,22 +46,21 @@ def read(*rnames): ] setup( - name = name, + name=name, version='0.3.2.dev0', - author = 'Jim Fulton', - author_email = 'jim@zope.com', - description = 'ZC Buildout recipe for zdaemon scripts', + author='Jim Fulton', + author_email='jim@zope.com', + description='ZC Buildout recipe for zdaemon scripts', long_description=long_description, - license = 'ZPL 2.1', + license='ZPL 2.1', entry_points=entry_points, - packages = find_packages('.'), - namespace_packages = ['zc'], - extras_require = dict(test=tests_require), - install_requires = ['setuptools', - 'zc.buildout', 'zc.recipe.egg', - 'ZConfig'], - test_suite='zc.zdaemonrecipe.tests.test_suite', + packages=find_packages('.'), + namespace_packages=['zc'], + extras_require=dict(test=tests_require), + install_requires=['setuptools', + 'zc.buildout', 'zc.recipe.egg', + 'ZConfig'], tests_require=tests_require, zip_safe=False, classifiers=[ diff --git a/tox.ini b/tox.ini index 99b8d87..bbd0981 100644 --- a/tox.ini +++ b/tox.ini @@ -28,7 +28,7 @@ deps = check-manifest check-python-versions commands = - flake8 src setup.py + flake8 zc setup.py check-manifest check-python-versions . @@ -39,14 +39,14 @@ deps = coverage-python-version zope.testrunner commands = - coverage run -m zope.testrunner --test-path=src [] + coverage run -m zope.testrunner coverage html coverage report -m --fail-under=0 [coverage:run] branch = True plugins = coverage_python_version -source = src +source = zc [coverage:report] precision = 2 diff --git a/zc/zdaemonrecipe/__init__.py b/zc/zdaemonrecipe/__init__.py index ee59c13..74966f6 100644 --- a/zc/zdaemonrecipe/__init__.py +++ b/zc/zdaemonrecipe/__init__.py @@ -86,7 +86,7 @@ def install(self): self.name+'-zdaemon.sock') rc = deployment + '-' + self.name - rc=os.path.join(options['rc-directory'], rc) + rc = os.path.join(options['rc-directory'], rc) logrotate = options['logrotate'] options.created(logrotate) @@ -117,7 +117,7 @@ def install(self): 'daemon': 'on', 'transcript': event_log_path, 'socket-name': socket_path, - 'directory' : run_directory, + 'directory': run_directory, } if deployment: defaults['user'] = options['user'] @@ -146,7 +146,7 @@ def install(self): options.created(rc) if self.shell_script: if not os.path.exists(options['zdaemon']): - logger.warn(no_zdaemon % options['zdaemon']) + logger.warn("Path does not exist: %s" % options['zdaemon']) contents = "%(zdaemon)s -C '%(conf)s' $*" % dict( zdaemon=options['zdaemon'], @@ -169,25 +169,26 @@ def install(self): zc.buildout.easy_install.scripts( [(rc, 'zdaemon.zdctl', 'main')], ws, options['executable'], options['rc-directory'], - arguments = ('[' - '\n %r, %r,' - '\n ]+sys.argv[1:]' - '\n ' - % ('-C', zdaemon_conf_path, - ) - ), + arguments=('[' + '\n %r, %r,' + '\n ]+sys.argv[1:]' + '\n ' + % ('-C', zdaemon_conf_path, + ) + ), ) return options.created() - update = install + def event_log(path, *data): return ZConfig.schemaless.Section( 'eventlog', '', None, [ZConfig.schemaless.Section('logfile', '', dict(path=[path]))]) + event_log_template = """ diff --git a/zc/zdaemonrecipe/tests.py b/zc/zdaemonrecipe/tests.py index 47e106a..e1d1103 100644 --- a/zc/zdaemonrecipe/tests.py +++ b/zc/zdaemonrecipe/tests.py @@ -13,14 +13,12 @@ ############################################################################## from six import print_ -import os, re, shutil, sys, tempfile -import pkg_resources +import re import zc.buildout.testing import doctest import unittest -import zope.testing from zope.testing import renormalizing try: @@ -29,7 +27,9 @@ not_found = (re.compile(r'Not found: [^\n]+/(\w|\.)+/\r?\n'), '') setuptools_or_distribute = ( - re.compile(r"[d-] (setuptools|distribute)([.]egg-link|-pyN.N.egg)"), "setuptools-pyN.N.egg") + re.compile( + r"[d-] (setuptools|distribute)([.]egg-link|-pyN.N.egg)" + ), "setuptools-pyN.N.egg") def newlines_in_program(): @@ -66,7 +66,7 @@ def newlines_in_program(): path /sample-buildout/parts/run/transcript.log - """ + """ # noqa: F821 def setUp(test): @@ -81,18 +81,18 @@ def setUp(test): checker = renormalizing.RENormalizing([ zc.buildout.testing.normalize_path, (re.compile( - "Couldn't find index page for '[a-zA-Z0-9.]+' " - "\(maybe misspelled\?\)" - "\n" + r"Couldn't find index page for '[a-zA-Z0-9.]+' " + r"\(maybe misspelled\?\)" + r"\n" ), ''), - (re.compile('#![^\n]+\n'), ''), - (re.compile('-\S+-py\d[.]\d(-\S+)?.egg'), - '-pyN.N.egg', - ), + (re.compile(r'#![^\n]+\n'), ''), + (re.compile(r'-\S+-py\d[.]\d(-\S+)?.egg'), + '-pyN.N.egg',), not_found, setuptools_or_distribute, ]) + def test_suite(): return unittest.TestSuite(( doctest.DocFileSuite( From 10b12393ac879e036a33779355727640a83f3a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Gmach?= Date: Fri, 15 May 2020 11:52:37 +0200 Subject: [PATCH 3/3] Apply suggested changes Swap `src` and `rc` in MANIFEST.in. modified: MANIFEST.in --- MANIFEST.in | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index e99288b..9979182 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -10,11 +10,10 @@ exclude MANIFEST.in recursive-include docs *.bat recursive-include docs *.py recursive-include docs *.rst -recursive-include zc *.txt recursive-include docs Makefile -recursive-include src *.pt -recursive-include src *.rst -recursive-include src *.txt -recursive-include src *.xml -recursive-include src *.zcml +recursive-include zc *.pt +recursive-include zc *.rst +recursive-include zc *.txt +recursive-include zc *.xml +recursive-include zc *.zcml