From 17b6946ce62137d649a1663d2f3fe9c538d6c1be Mon Sep 17 00:00:00 2001 From: sommersoft Date: Thu, 20 Aug 2020 23:14:27 -0500 Subject: [PATCH 1/3] add choices list for README format --- cookiecutter.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cookiecutter.json b/cookiecutter.json index cf37890..46b9182 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -18,5 +18,9 @@ "GNU GPL v3.0", "Apache Software License 2.0", "Mozilla Public License 2.0" + ], + "readme_format": [ + "reStructred Text (.rst)", + "Markdown (.md)" ] } From 034b165ba499bea8c5849d07111975ebd5ab9df7 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Thu, 20 Aug 2020 23:15:16 -0500 Subject: [PATCH 2/3] update README template to include both rST and Markdown versions --- .../README.rst | 80 --------- .../README.template | 152 ++++++++++++++++++ 2 files changed, 152 insertions(+), 80 deletions(-) delete mode 100644 pytest-{{cookiecutter.plugin_name}}/README.rst create mode 100644 pytest-{{cookiecutter.plugin_name}}/README.template diff --git a/pytest-{{cookiecutter.plugin_name}}/README.rst b/pytest-{{cookiecutter.plugin_name}}/README.rst deleted file mode 100644 index d595deb..0000000 --- a/pytest-{{cookiecutter.plugin_name}}/README.rst +++ /dev/null @@ -1,80 +0,0 @@ -{%- from "macros/rst" import doc_title, doc_subtitle -%} - -{{ doc_title('pytest-' + cookiecutter.plugin_name) }} - -.. image:: https://img.shields.io/pypi/v/pytest-{{cookiecutter.plugin_name}}.svg - :target: https://pypi.org/project/pytest-{{cookiecutter.plugin_name}} - :alt: PyPI version - -.. image:: https://img.shields.io/pypi/pyversions/pytest-{{cookiecutter.plugin_name}}.svg - :target: https://pypi.org/project/pytest-{{cookiecutter.plugin_name}} - :alt: Python versions - -.. image:: https://travis-ci.org/{{cookiecutter.github_username}}/pytest-{{cookiecutter.plugin_name}}.svg?branch=master - :target: https://travis-ci.org/{{cookiecutter.github_username}}/pytest-{{cookiecutter.plugin_name}} - :alt: See Build Status on Travis CI - -.. image:: https://ci.appveyor.com/api/projects/status/github/{{cookiecutter.github_username}}/pytest-{{cookiecutter.plugin_name}}?branch=master - :target: https://ci.appveyor.com/project/{{cookiecutter.github_username}}/pytest-{{cookiecutter.plugin_name}}/branch/master - :alt: See Build Status on AppVeyor - -{{cookiecutter.short_description}} - ----- - -This `pytest`_ plugin was generated with `Cookiecutter`_ along with `@hackebrot`_'s `cookiecutter-pytest-plugin`_ template. - - -Features --------- - -* TODO - - -Requirements ------------- - -* TODO - - -Installation ------------- - -You can install "pytest-{{cookiecutter.plugin_name}}" via `pip`_ from `PyPI`_:: - - $ pip install pytest-{{cookiecutter.plugin_name}} - - -Usage ------ - -* TODO - -Contributing ------------- -Contributions are very welcome. Tests can be run with `tox`_, please ensure -the coverage at least stays the same before you submit a pull request. - -License -------- - -Distributed under the terms of the `{{cookiecutter.license}}`_ license, "pytest-{{cookiecutter.plugin_name}}" is free and open source software - - -Issues ------- - -If you encounter any problems, please `file an issue`_ along with a detailed description. - -.. _`Cookiecutter`: https://github.com/audreyr/cookiecutter -.. _`@hackebrot`: https://github.com/hackebrot -.. _`MIT`: http://opensource.org/licenses/MIT -.. _`BSD-3`: http://opensource.org/licenses/BSD-3-Clause -.. _`GNU GPL v3.0`: http://www.gnu.org/licenses/gpl-3.0.txt -.. _`Apache Software License 2.0`: http://www.apache.org/licenses/LICENSE-2.0 -.. _`cookiecutter-pytest-plugin`: https://github.com/pytest-dev/cookiecutter-pytest-plugin -.. _`file an issue`: https://github.com/{{cookiecutter.github_username}}/pytest-{{cookiecutter.plugin_name}}/issues -.. _`pytest`: https://github.com/pytest-dev/pytest -.. _`tox`: https://tox.readthedocs.io/en/latest/ -.. _`pip`: https://pypi.org/project/pip/ -.. _`PyPI`: https://pypi.org/project diff --git a/pytest-{{cookiecutter.plugin_name}}/README.template b/pytest-{{cookiecutter.plugin_name}}/README.template new file mode 100644 index 0000000..a38dfbf --- /dev/null +++ b/pytest-{{cookiecutter.plugin_name}}/README.template @@ -0,0 +1,152 @@ +{% if cookiecutter.readme_format == "reStructred Text (.rst)" %} +{%- from "macros/rst" import doc_title, doc_subtitle -%} + +{{ doc_title('pytest-' + cookiecutter.plugin_name) }} + +.. image:: https://img.shields.io/pypi/v/pytest-{{cookiecutter.plugin_name}}.svg + :target: https://pypi.org/project/pytest-{{cookiecutter.plugin_name}} + :alt: PyPI version + +.. image:: https://img.shields.io/pypi/pyversions/pytest-{{cookiecutter.plugin_name}}.svg + :target: https://pypi.org/project/pytest-{{cookiecutter.plugin_name}} + :alt: Python versions + +.. image:: https://travis-ci.org/{{cookiecutter.github_username}}/pytest-{{cookiecutter.plugin_name}}.svg?branch=master + :target: https://travis-ci.org/{{cookiecutter.github_username}}/pytest-{{cookiecutter.plugin_name}} + :alt: See Build Status on Travis CI + +.. image:: https://ci.appveyor.com/api/projects/status/github/{{cookiecutter.github_username}}/pytest-{{cookiecutter.plugin_name}}?branch=master + :target: https://ci.appveyor.com/project/{{cookiecutter.github_username}}/pytest-{{cookiecutter.plugin_name}}/branch/master + :alt: See Build Status on AppVeyor + +{{cookiecutter.short_description}} + +---- + +This `pytest`_ plugin was generated with `Cookiecutter`_ along with `@hackebrot`_'s `cookiecutter-pytest-plugin`_ template. + + +Features +-------- + +* TODO + + +Requirements +------------ + +* TODO + + +Installation +------------ + +You can install "pytest-{{cookiecutter.plugin_name}}" via `pip`_ from `PyPI`_:: + + $ pip install pytest-{{cookiecutter.plugin_name}} + + +Usage +----- + +* TODO + +Contributing +------------ +Contributions are very welcome. Tests can be run with `tox`_, please ensure +the coverage at least stays the same before you submit a pull request. + +License +------- + +Distributed under the terms of the `{{cookiecutter.license}}`_ license, "pytest-{{cookiecutter.plugin_name}}" is free and open source software + + +Issues +------ + +If you encounter any problems, please `file an issue`_ along with a detailed description. + +.. _`Cookiecutter`: https://github.com/audreyr/cookiecutter +.. _`@hackebrot`: https://github.com/hackebrot +.. _`MIT`: http://opensource.org/licenses/MIT +.. _`BSD-3`: http://opensource.org/licenses/BSD-3-Clause +.. _`GNU GPL v3.0`: http://www.gnu.org/licenses/gpl-3.0.txt +.. _`Apache Software License 2.0`: http://www.apache.org/licenses/LICENSE-2.0 +.. _`cookiecutter-pytest-plugin`: https://github.com/pytest-dev/cookiecutter-pytest-plugin +.. _`file an issue`: https://github.com/{{cookiecutter.github_username}}/pytest-{{cookiecutter.plugin_name}}/issues +.. _`pytest`: https://github.com/pytest-dev/pytest +.. _`tox`: https://tox.readthedocs.io/en/latest/ +.. _`pip`: https://pypi.org/project/pip/ +.. _`PyPI`: https://pypi.org/project + +{# #} +{# ----- END rST SECTION ----- #} +{# #} + +{% elif cookiecutter.readme_format == "Markdown (.md)" %} +# "pytest-"{{ cookiecutter.plugin_name }} + +[![PyPI version](https://img.shields.io/pypi/v/pytest-{{cookiecutter.plugin_name}}.svg)](https://pypi.org/project/pytest-{{cookiecutter.plugin_name}}) + +[![Python versions](https://img.shields.io/pypi/pyversions/pytest-{{cookiecutter.plugin_name}}.svg)](https://pypi.org/project/pytest-{{cookiecutter.plugin_name}}) + +[![See Build Status on Travis CI](https://travis-ci.org/{{cookiecutter.github_username}}/pytest-{{cookiecutter.plugin_name}}.svg?branch=master)](https://travis-ci.org/{{cookiecutter.github_username}}/pytest-{{cookiecutter.plugin_name}}) + +[![See Build Status on AppVeyor](https://ci.appveyor.com/api/projects/status/github/{{cookiecutter.github_username}}/pytest-{{cookiecutter.plugin_name}}?branch=master)](https://ci.appveyor.com/project/{{cookiecutter.github_username}}/pytest-{{cookiecutter.plugin_name}}/branch/master) + +{{cookiecutter.short_description}} + + +This [pytest][pytest] plugin was generated with [Cookiecutter][cookiecutter] along with [@hackebrot][hackebrot]'s [cookiecutter-pytest-plugin][plugin-template] template. + +[cookiecutter]: https://github.com/audreyr/cookiecutter +[hackebrot]: https://github.com/hackebrot +[pytest]: https://github.com/pytest-dev/pytest +[plugin-template]: https://github.com/pytest-dev/cookiecutter-pytest-plugin + +## Features + +* TODO + +## Requirements + +* TODO + +## Installation + +You can install "pytest-{{cookiecutter.plugin_name}}" via [pip][pip] from [PyPI][PyPI] + +``` +$ pip install pytest-{{cookiecutter.plugin_name}} +``` + +[pip]: https://pypi.python.org/pypi/pip +[PyPI]: https://pypi.org/project/pytest-{{cookiecutter.plugin_name}} + +## Usage + +* TODO + +## Contributing + +Contributions are very welcome. Tests can be run with [tox][tox], please ensure +the coverage at least stays the same before you submit a pull request. + +[tox]: https://tox.readthedocs.io/en/latest/ + +## License + +Distributed under the terms of the [{{cookiecutter.license}}][{{cookiecutter.license}}] license, "pytest-{{cookiecutter.plugin_name}}" is free and open source software + +## Issues + +If you encounter any problems, please [file an issue][issue-link] along with a detailed description. + +[MIT]: http://opensource.org/licenses/MIT +[BSD-3]: http://opensource.org/licenses/BSD-3-Clause +[GNU GPL v3.0]: http://www.gnu.org/licenses/gpl-3.0.txt +[Apache Software License 2.0]: http://www.apache.org/licenses/LICENSE-2.0 +[issue-link]: https://github.com/{{cookiecutter.github_username}}/pytest-{{cookiecutter.plugin_name}}/issues + +{% endif %} From fcc4278b6de1a6e1396b9ef8f8ec71c5ca73a594 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Thu, 20 Aug 2020 23:16:39 -0500 Subject: [PATCH 3/3] add post-gen hook to update the README file extension to the selected format --- hooks/post_gen_project.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index a300dd3..a43b95b 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -4,6 +4,7 @@ import logging import os import shutil +import sys logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger("post_gen_project") @@ -44,7 +45,29 @@ def remove_temp_folders(temp_folders): logger.info("Remove temporary folder: %s", folder) shutil.rmtree(folder) +def apply_readme_file_extension(extension): + if extension.endswith("(.rst)"): + extension = ".rst" + elif extension.endswith("(.md)"): + extension = ".md" + else: + logger.warning("README file extension unknown: %s", extension) + sys.exit(1) + + readme_path = os.path.join( + os.getcwd(), + "README.template" + ) + + if os.path.exists(readme_path): + new_path = os.path.join( + os.getcwd(), + "README" + extension + ) + os.rename(readme_path, new_path) + if __name__ == "__main__": + apply_readme_file_extension("{{cookiecutter.readme_format}}") move_docs_files("{{cookiecutter.docs_tool}}", DOCS_FILES_BY_TOOL, DOCS_SOURCES) remove_temp_folders(ALL_TEMP_FOLDERS)