From 34e9738aead5f252feccd4510d72bd0642ad728a Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Sat, 1 Feb 2020 22:33:51 +0100 Subject: use poetry-publish https://github.com/jedie/poetry-publish https://pypi.org/project/poetry-publish/ --- creole/__init__.py | 2 +- creole/publish.py | 17 ++++ creole/setup_utils.py | 172 +------------------------------------ creole/tests/test_project_setup.py | 4 +- pyproject.toml | 2 +- 5 files changed, 22 insertions(+), 175 deletions(-) create mode 100644 creole/publish.py diff --git a/creole/__init__.py b/creole/__init__.py index 7cc7113..ad4495a 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" +__version__ = "1.4.3.rc0" __api__ = "1.0" # Creole 1.0 spec - http://wikicreole.org/ VERSION_STRING = __version__ # remove in future diff --git a/creole/publish.py b/creole/publish.py new file mode 100644 index 0000000..1939d25 --- /dev/null +++ b/creole/publish.py @@ -0,0 +1,17 @@ +from pathlib import Path + +from poetry_publish.publish import poetry_publish + +import creole + + +def publish(): + """ + Publish python-creole to PyPi + Call this via: + $ poetry run publish + """ + poetry_publish( + package_root=Path(creole.__file__).parent.parent, + version=creole.__version__, + ) diff --git a/creole/setup_utils.py b/creole/setup_utils.py index f7d1bfd..cd980a6 100644 --- a/creole/setup_utils.py +++ b/creole/setup_utils.py @@ -15,15 +15,12 @@ import codecs import datetime import os -import shutil -import subprocess import sys import warnings from pathlib import Path -from creole import __version__, creole2html, html2rest +from creole import 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', @@ -155,172 +152,5 @@ def update_creole_rst_readme(): ) -def verbose_check_output(*args, log=None): - """ 'verbose' version of subprocess.check_output() """ - call_info = 'Call: %r' % ' '.join(args) - try: - output = subprocess.check_output( - args, universal_newlines=True, stderr=subprocess.STDOUT - ) - except subprocess.CalledProcessError as err: - print('\n***ERROR:') - print(err.output) - if log is not None: - log.write(err.output) - raise - return call_info, output - - -def verbose_check_call(*args): - """ 'verbose' version of subprocess.check_call() """ - print('\tCall: %r\n' % ' '.join(args)) - subprocess.check_call(args, universal_newlines=True) - - -def confirm(txt): - print(f'\n{txt}') - if input('\nPublish anyhow? (Y/N)').lower() not in ('y', 'j'): - print('Bye.') - sys.exit(-1) - - -def poetry_publish(package_root, version, filename='README.creole', log_filename='publish.log'): - """ - Helper to build and upload to PyPi, with prechecks and update README.rst from README.creole - - Optional arguments are passed to `poetry publish` e.g.: - - $ poetry config repositories.testpypi https://test.pypi.org/simple - $ poetry run publish --repository=testpypi - - Build and upload to PyPi, if... - ... __version__ doesn't contains 'dev' - ... we are on git "master" branch - ... git repository is 'clean' (no changed files) - - Upload with 'poetry', git tag the current version and git push --tag - - The cli arguments will be pass to 'twine'. So this is possible: - * Display 'twine' help page...: ./setup.py publish --help - * use testpypi................: ./setup.py publish --repository=test - - add this to poetry pyproject.toml, e.g.: - - [tool.poetry.scripts] - publish = 'foo.bar:publish' - - based on: - https://github.com/jedie/python-code-snippets/blob/master/CodeSnippets/setup_publish.py - """ - update_rst_readme(package_root=package_root, filename=filename) - - for key in ('dev', 'rc'): - if key in version: - confirm(f'WARNING: Version contains {key!r}: v{version}\n') - break - - print('\nCheck if we are on "master" branch:') - call_info, output = verbose_check_output('git', 'branch', '--no-color') - print(f'\t{call_info}') - if '* master' in output: - print('OK') - else: - confirm(f'\nNOTE: It seems you are not on "master":\n{output}') - - print('\ncheck if if git repro is clean:') - call_info, output = verbose_check_output('git', 'status', '--porcelain') - print(f'\t{call_info}') - if output == '': - print('OK') - else: - print('\n *** ERROR: git repro not clean:') - print(output) - sys.exit(-1) - - print('\nRun "poetry check":') - call_info, output = verbose_check_output('poetry', 'check') - if 'All set!' not in output: - print(output) - confirm('Check failed!') - else: - print('OK') - - print('\ncheck if pull is needed') - verbose_check_call('git', 'fetch', '--all') - call_info, output = verbose_check_output('git', 'log', 'HEAD..origin/master', '--oneline') - print(f'\t{call_info}') - if output == '': - print('OK') - else: - print('\n *** ERROR: git repro is not up-to-date:') - print(output) - sys.exit(-1) - verbose_check_call('git', 'push') - - print('\nCleanup old builds:') - - def rmtree(path): - path = os.path.abspath(path) - if os.path.isdir(path): - print('\tremove tree:', path) - shutil.rmtree(path) - rmtree('./dist') - rmtree('./build') - - print(f'\nSet new version to: v{version}') - verbose_check_call('poetry', 'version', version) - - print('\nbuild but do not upload...') - - with open(log_filename, 'a') as log: - log.write('\n') - log.write('-' * 100) - log.write('\n') - call_info, output = verbose_check_output('poetry', 'build', log=log) - print(f'\t{call_info}') - log.write(call_info) - log.write(output) - - print(f'Build log file is here: {log_filename!r}') - - git_tag = f'v{version}' - - print('\ncheck git tag') - call_info, output = verbose_check_output( - 'git', 'log', 'HEAD..origin/master', '--oneline', - ) - if git_tag in output: - print(f'\n *** ERROR: git tag {git_tag!r} already exists!') - print(output) - sys.exit(-1) - else: - print('OK') - - print('\nUpload to PyPi via poetry:') - args = ['poetry', 'publish'] + sys.argv[1:] - verbose_check_call(*args) - - print('\ngit tag version') - verbose_check_call('git', 'tag', git_tag) - - print('\ngit push tag to server') - verbose_check_call('git', 'push', '--tags') - - sys.exit(0) - - -def publish_python_creole(): - """ - Publish python-creole to PyPi - Call this via: - $ poetry run publish - """ - test_version() - poetry_publish( - package_root=Path(__file__).parent.parent, - version=__version__, - ) - - if __name__ == '__main__': update_creole_rst_readme() diff --git a/creole/tests/test_project_setup.py b/creole/tests/test_project_setup.py index fc6dd37..7491daa 100644 --- a/creole/tests/test_project_setup.py +++ b/creole/tests/test_project_setup.py @@ -18,7 +18,7 @@ def assert_file_contains_string(file_path, string): def test_version(): - if 'dev' not in __version__: + if 'dev' not in __version__ and 'rc' not in __version__: version_string = f'v{__version__}' assert_file_contains_string( @@ -33,5 +33,5 @@ def test_version(): assert_file_contains_string( file_path=Path(CREOLE_PACKAGE_ROOT, 'pyproject.toml'), - string=f"version = '{__version__}'" + string=f'version = "{__version__}"' ) diff --git a/pyproject.toml b/pyproject.toml index c3f1800..143b0a6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "python-creole" -version = "1.4.2" +version = "1.4.3.rc0" 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" -- cgit v1.2.1