diff options
author | Jens Diemer <github.com@jensdiemer.de> | 2020-02-01 16:38:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-01 16:38:48 +0100 |
commit | 1d2fb1c6ac76674939e6f0c34c8623bb6d22e841 (patch) | |
tree | 1bfe84ba3ccb2c6100943e282269a82e36016990 | |
parent | 69037331053950a1a03324ef3486769cc88ed591 (diff) | |
parent | 42af9043fc37dcc81767c2466139b3360d17bc7a (diff) | |
download | creole-1d2fb1c6ac76674939e6f0c34c8623bb6d22e841.tar.gz |
Merge pull request #42 from jedie/setup-utils
Setup utils
-rw-r--r-- | .travis.yml | 27 | ||||
-rw-r--r-- | Makefile | 20 | ||||
-rw-r--r-- | README.creole | 33 | ||||
-rw-r--r-- | README.rst | 43 | ||||
-rw-r--r-- | creole/__init__.py | 2 | ||||
-rw-r--r-- | creole/setup_utils.py | 50 | ||||
-rw-r--r-- | creole/tests/constants.py | 5 | ||||
-rw-r--r-- | creole/tests/test_project_setup.py | 37 | ||||
-rw-r--r-- | creole/tests/test_setup_utils.py | 74 | ||||
-rw-r--r-- | creole/tests/utils/utils.py | 54 | ||||
-rw-r--r-- | pyproject.toml | 2 |
11 files changed, 238 insertions, 109 deletions
diff --git a/.travis.yml b/.travis.yml index 5ff3ee0..eda48d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,24 @@ # Config file for automatic testing at travis-ci.org language: python +cache: pip -python: - - "3.8" - - "3.7" - - "3.6" - - "pypy3" +matrix: + include: + - os: linux + python: 3.6 + env: TOXENV=py36 + - os: linux + python: 3.7 + env: TOXENV=py37 + - os: linux + python: 3.8 + env: TOXENV=py38 + - os: linux + python: pypy3 + # TODO: + #- os: osx + # language: generic install: - make install-poetry @@ -16,8 +28,9 @@ install: - make tox-listenvs script: - - make pytest - - make lint + - if [ "$TOXENV" == "" ]; then make pytest; fi + - if [ "$TOXENV" != "" ]; then make tox; fi + - if [ "$TOXENV" != "" ]; then make lint; fi after_success: - coveralls @@ -56,15 +56,11 @@ tox-py38: check-poetry ## Run pytest via tox with *python v3.8* pytest: check-poetry ## Run pytest poetry run pytest -release: ## Release new version [usage: v=rule] - # Update pyproject and changelog - poetry version $(v) - sed -i "" "s/\[Unreleased\]/\[$(VERSION)\] - $(shell date +%F)/" CHANGELOG.md - # Create commit and tag - git commit pyproject.toml CHANGELOG.md -m "Bump version to $(VERSION)" && git tag "v$(VERSION)" - git push && git push --tags - # Publish to pypi - poetry publish --build - - -.PHONY: help install lint fix test release
\ No newline at end of file +update-rst-readme: ## update README.rst from README.creole + poetry run update_rst_readme + +publish: ## Release new version to PyPi + poetry run publish + + +.PHONY: help install lint fix test publish
\ No newline at end of file diff --git a/README.creole b/README.creole index ea48cdb..e5a19d2 100644 --- a/README.creole +++ b/README.creole @@ -180,23 +180,42 @@ Creole Markup Cheat Sheet can be found here: http://www.wikicreole.org/wiki/Chea ~$ cd python-creole # install or update poetry: -~/python-crole$ make install-poetry +~/python-creole$ make install-poetry # install python-creole via poetry: -~/python-crole$ make install +~/python-creole$ make install # Run pytest: -~/python-crole$ make pytest +~/python-creole$ make pytest # Run pytest via tox with all environments: -~/python-crole$ make tox +~/python-creole$ make tox # Run pytest via tox with one Python version: -~/python-crole$ make tox-py38 -~/python-crole$ make tox-py37 -~/python-crole$ make tox-py36 +~/python-creole$ make tox-py38 +~/python-creole$ make tox-py37 +~/python-creole$ make tox-py36 }}} +== make targets == + +To see all make targets, just call {{{make}}}: +{{{ +~/python-creole$ make +help List all commands +install-poetry install or update poetry +install install python-creole via poetry +lint Run code formatters and linter +fix-code-style Fix code formatting +tox-listenvs List all tox test environments +tox Run pytest via tox with all environments +tox-py36 Run pytest via tox with *python v3.6* +tox-py37 Run pytest via tox with *python v3.7* +tox-py38 Run pytest via tox with *python v3.8* +pytest Run pytest +update-rst-readme update README.rst from README.creole +publish Release new version to PyPi +}}} == Use creole in README == @@ -34,6 +34,8 @@ The creole2html part based on the creole markup parser and emitter from the Moin +-----------------------------------+ | |Status on landscape.io| | +-----------------------------------+ +| |PyPi version| | ++-----------------------------------+ .. |Build Status on github| image:: https://github.com/jedie/python-creole/workflows/test/badge.svg?branch=master .. |Build Status on travis-ci.org| image:: https://travis-ci.org/jedie/python-creole.svg @@ -42,6 +44,8 @@ The creole2html part based on the creole markup parser and emitter from the Moin .. _coveralls.io/r/jedie/python-creole: https://coveralls.io/r/jedie/python-creole .. |Status on landscape.io| image:: https://landscape.io/github/jedie/python-creole/master/landscape.svg .. _landscape.io/github/jedie/python-creole/master: https://landscape.io/github/jedie/python-creole/master +.. |PyPi version| image:: https://badge.fury.io/py/python-creole.svg +.. _pypi.org/project/python-creole/: https://pypi.org/project/python-creole/ ======= install @@ -242,21 +246,44 @@ unittests ~$ cd python-creole # install or update poetry: - ~/python-crole$ make install-poetry + ~/python-creole$ make install-poetry # install python-creole via poetry: - ~/python-crole$ make install + ~/python-creole$ make install # Run pytest: - ~/python-crole$ make pytest + ~/python-creole$ make pytest # Run pytest via tox with all environments: - ~/python-crole$ make tox + ~/python-creole$ make tox # Run pytest via tox with one Python version: - ~/python-crole$ make tox-py38 - ~/python-crole$ make tox-py37 - ~/python-crole$ make tox-py36 + ~/python-creole$ make tox-py38 + ~/python-creole$ make tox-py37 + ~/python-creole$ make tox-py36 + +------------ +make targets +------------ + +To see all make targets, just call ``make``: + +:: + + ~/python-creole$ make + help List all commands + install-poetry install or update poetry + install install python-creole via poetry + lint Run code formatters and linter + fix-code-style Fix code formatting + tox-listenvs List all tox test environments + tox Run pytest via tox with all environments + tox-py36 Run pytest via tox with *python v3.6* + tox-py37 Run pytest via tox with *python v3.7* + tox-py38 Run pytest via tox with *python v3.8* + pytest Run pytest + update-rst-readme update README.rst from README.creole + publish Release new version to PyPi -------------------- Use creole in README @@ -616,4 +643,4 @@ donation ------------ -``Note: this file is generated from README.creole with "python-creole" at 2020-02-01 12:50:27``
\ No newline at end of file +``Note: this file is generated from README.creole 2020-02-01 15:25:27 with "python-creole"``
\ No newline at end of file diff --git a/creole/__init__.py b/creole/__init__.py index e5d6324..7fd9766 100644 --- a/creole/__init__.py +++ b/creole/__init__.py @@ -23,7 +23,7 @@ from creole.emitter.html2textile_emitter import TextileEmitter from creole.parser.creol2html_parser import CreoleParser from creole.parser.html_parser import HtmlParser -__version__ = "1.4.2.dev1" +__version__ = "1.4.2.dev2" __api__ = "1.0" # Creole 1.0 spec - http://wikicreole.org/ VERSION_STRING = __version__ # remove in future diff --git a/creole/setup_utils.py b/creole/setup_utils.py index 24b1b1a..f7d1bfd 100644 --- a/creole/setup_utils.py +++ b/creole/setup_utils.py @@ -1,40 +1,12 @@ """ - utils for distutils setup + Python setup.py utilities ~~~~~~~~~~~~~~~~~~~~~~~~~ - Get README.creole as ReStructuredText on-the-fly for setup.long_description + Generate ReStructuredText README from README.creole. + Usable for other python packages, too. More information: - https://code.google.com/p/python-creole/wiki/UseInSetup - - usage in setup.py e.g.: - --------------------------------------------------------------------------- - #!/usr/bin/env python - # coding: utf-8 - - import os - import sys - from setuptools import setup, find_packages - - PACKAGE_ROOT = os.path.dirname(os.path.abspath(__file__)) - - try: - from creole.setup_utils import get_long_description - except ImportError: - if 'register' in sys.argv or 'sdist' in sys.argv or '--long-description' in sys.argv: - etype, evalue, etb = sys.exc_info() - evalue = etype('%s - Please install python-creole >= v0.8 - e.g.: pip install python-creole' % evalue) - raise etype, evalue, etb - long_description = None - else: - long_description = get_long_description(PACKAGE_ROOT) - - setup( - ... - long_description = long_description, - ... - ) - --------------------------------------------------------------------------- + https://github.com/jedie/python-creole/wiki/Use-In-Setup :copyleft: 2011-2020 by the python-creole team, see AUTHORS for more details. :license: GNU GPL v3 or above, see LICENSE for more details. @@ -51,6 +23,7 @@ from pathlib import Path from creole import __version__, creole2html, html2rest from creole.shared.unknown_tags import raise_unknown_node, transparent_unknown_nodes +from creole.tests.test_project_setup import test_version RAISE_ERRORS_ARGS = ( 'check', 'register', 'sdist', 'bdist', 'upload', @@ -160,17 +133,23 @@ def update_rst_readme(package_root, filename='README.creole'): with rest_readme_path.open('w') as f: f.write(rest_readme) + + # Add a note about generation with modification time from source: + f.write('\n\n------------\n\n') - dt = datetime.datetime.utcnow() + + modification_time = creole_readme_path.stat().st_mtime + dt = datetime.datetime.fromtimestamp(modification_time) dt = dt.replace(microsecond=0) dt = dt.isoformat(sep=' ') - f.write(f'``Note: this file is generated from {filename} with "python-creole" at {dt}``') + f.write(f'``Note: this file is generated from {filename} {dt} with "python-creole"``') print('done.') + return rest_readme_path def update_creole_rst_readme(): - update_rst_readme( + return update_rst_readme( package_root=Path(__file__).parent.parent, filename='README.creole' ) @@ -336,6 +315,7 @@ def publish_python_creole(): Call this via: $ poetry run publish """ + test_version() poetry_publish( package_root=Path(__file__).parent.parent, version=__version__, diff --git a/creole/tests/constants.py b/creole/tests/constants.py new file mode 100644 index 0000000..0e276d4 --- /dev/null +++ b/creole/tests/constants.py @@ -0,0 +1,5 @@ +from pathlib import Path + +import creole + +CREOLE_PACKAGE_ROOT = Path(creole.__file__).parent.parent diff --git a/creole/tests/test_project_setup.py b/creole/tests/test_project_setup.py new file mode 100644 index 0000000..b589acf --- /dev/null +++ b/creole/tests/test_project_setup.py @@ -0,0 +1,37 @@ +""" + :copyleft: 2020 by python-creole team, see AUTHORS for more details. + :license: GNU GPL v3 or above, see LICENSE for more details. +""" + +from pathlib import Path + +from creole import __version__ +from creole.tests.constants import CREOLE_PACKAGE_ROOT + + +def assert_file_contains_string(file_path, string): + with file_path.open('r') as f: + for line in f: + if string in line: + return + raise AssertionError(f'File {file_path} does not contain {string!r} !') + + +def test_version(): + if 'dev' not in __version__: + version_string = f'v{__version__}' + + assert_file_contains_string( + file_path=Path(CREOLE_PACKAGE_ROOT, 'README.creole'), + string=version_string + ) + + assert_file_contains_string( + file_path=Path(CREOLE_PACKAGE_ROOT, 'README.rst'), + string=version_string + ) + + assert_file_contains_string( + file_path=Path(CREOLE_PACKAGE_ROOT, 'pyproject.toml'), + string=f'version = "{__version__}"' + ) diff --git a/creole/tests/test_setup_utils.py b/creole/tests/test_setup_utils.py index 33d998c..5a7b366 100644 --- a/creole/tests/test_setup_utils.py +++ b/creole/tests/test_setup_utils.py @@ -1,45 +1,29 @@ - """ unittest for setup_utils ~~~~~~~~~~~~~~~~~~~~~~~~ - https://code.google.com/p/python-creole/wiki/UseInSetup + https://github.com/jedie/python-creole/wiki/Use-In-Setup :copyleft: 2011-2020 by python-creole team, see AUTHORS for more details. :license: GNU GPL v3 or above, see LICENSE for more details. """ - - +import difflib +import filecmp import os +import shutil import tempfile -import warnings +from pathlib import Path -import creole -from creole.setup_utils import get_long_description +from creole.setup_utils import get_long_description, update_creole_rst_readme +from creole.tests.constants import CREOLE_PACKAGE_ROOT from creole.tests.utils.base_unittest import BaseCreoleTest +from creole.tests.utils.utils import IsolatedFilesystem -try: - import docutils # noqa flake8 - DOCUTILS = True -except ImportError: - DOCUTILS = False - - -CREOLE_PACKAGE_ROOT = os.path.abspath(os.path.join(os.path.dirname(creole.__file__), "..")) -TEST_README_DIR = os.path.abspath(os.path.dirname(__file__)) +TEST_README_DIR = Path(__file__).parent TEST_README_FILENAME = "test_README.creole" -# TODO: Use @unittest.skipIf if python 2.6 will be not support anymore. -# @unittest.skipIf(DOCUTILS == False, "docutils not installed.") class SetupUtilsTests(BaseCreoleTest): - def run(self, *args, **kwargs): - # TODO: Remove if python 2.6 will be not support anymore. - if not DOCUTILS: - warnings.warn("Skip SetupUtilsTests, because 'docutils' not installed.") - return - return super(SetupUtilsTests, self).run(*args, **kwargs) - def test_creole_package_path(self): self.assertTrue( os.path.isdir(CREOLE_PACKAGE_ROOT), @@ -123,3 +107,43 @@ class SetupUtilsTests(BaseCreoleTest): txt = "German Umlaute: ä ö ü ß Ä Ö Ü" self.assertIn(txt, long_description) + + +def test_update_rst_readme(): + with IsolatedFilesystem(prefix="temp_dir_prefix"): + old_rest_readme_path = Path(Path().cwd(), 'README.rst') + shutil.copy( + Path(CREOLE_PACKAGE_ROOT, 'README.rst'), + old_rest_readme_path + ) + try: + rest_readme_path = update_creole_rst_readme() + assert str(rest_readme_path.relative_to(CREOLE_PACKAGE_ROOT)) == 'README.rst' + + if filecmp.cmp(rest_readme_path, old_rest_readme_path, shallow=False) is True: + return + + # On CI the file modification time maybe not the same. + # So skip the last line and compare again. + + with old_rest_readme_path.open('r') as f: + from_file = [line.rstrip() for line in f][:-1] + + with rest_readme_path.open('r') as f: + to_file = [line.rstrip() for line in f][:-1] + + if from_file == to_file: + return + + diff = '\n'.join( + line + for line in difflib.Differ().compare(from_file, to_file) + if line[0] != ' ' + ) + raise AssertionError(f'README.rst is not up-to-date:\n{diff}') + finally: + # restore the origin file + shutil.copy( + old_rest_readme_path, + Path(CREOLE_PACKAGE_ROOT, 'README.rst'), + ) diff --git a/creole/tests/utils/utils.py b/creole/tests/utils/utils.py index 005f6c4..dd60454 100644 --- a/creole/tests/utils/utils.py +++ b/creole/tests/utils/utils.py @@ -1,26 +1,21 @@ -# coding: utf-8 - - """ unitest generic utils ~~~~~~~~~~~~~~~~~~~~~ Generic utils useable for a markup test. - :copyleft: 2008-2011 by python-creole team, see AUTHORS for more details. + :copyleft: 2008-2020 by python-creole team, see AUTHORS for more details. :license: GNU GPL v3 or above, see LICENSE for more details. """ import difflib +import os +import shutil +import tempfile import textwrap import unittest - -# error output format: -# =1 -> via repr() -# =2 -> raw -VERBOSE = 1 -#VERBOSE = 2 +from pathlib import Path def make_diff(block1, block2): @@ -31,7 +26,7 @@ def make_diff(block1, block2): diff = d.compare(block1, block2) - result = ["%2s %s\n" % (line, i) for line, i in enumerate(diff)] + result = [f"{line:>2} {i}\n" for line, i in enumerate(diff)] return "".join(result) @@ -40,11 +35,17 @@ class MarkupTest(unittest.TestCase): Special error class: Try to display markup errors in a better way. """ + # error output format: + # =1 -> via repr() + # =2 -> raw + VERBOSE = 1 + #VERBOSE = 2 + def _format_output(self, txt): txt = txt.split("\\n") - if VERBOSE == 1: + if self.VERBOSE == 1: txt = "".join(['%s\\n\n' % i for i in txt]) - elif VERBOSE == 2: + elif self.VERBOSE == 2: txt = "".join(['%s\n' % i for i in txt]) return txt @@ -83,3 +84,30 @@ class MarkupTest(unittest.TestCase): txt = txt[1:] return txt + + +class IsolatedFilesystem: + """ + Context manager, e.g.: + with IsolatedFilesystem(prefix="temp_dir_prefix"): + print("I'm in the temp path here: %s" % Path().cwd()) + """ + + def __init__(self, prefix=None): + super().__init__() + + self.prefix = prefix + + def __enter__(self): + print(f"Use prefix: {self.prefix!r}") + + self.cwd = Path().cwd() + self.temp_path = tempfile.mkdtemp(prefix=self.prefix) + os.chdir(self.temp_path) + + def __exit__(self, exc_type, exc_value, traceback): + os.chdir(str(self.cwd)) # str() needed for older python <=3.5 + try: + shutil.rmtree(self.temp_path) + except OSError: + pass diff --git a/pyproject.toml b/pyproject.toml index cb88369..19dd446 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = 'python-creole' -version = "1.4.2.dev1" +version = "1.4.2.dev2" description = 'python-creole is an open-source (GPL) markup converter in pure Python for: creole2html, html2creole, html2ReSt, html2textile' # Will be generated from README.creole with: 'poetry run update_rst_readme' |