From 11cd8a922505af992c295d3c4f6546521ea4ae57 Mon Sep 17 00:00:00 2001 From: clairemerker Date: Wed, 5 Apr 2023 18:22:45 +0200 Subject: [PATCH 01/28] add a hint in the documentation to execute the provided bash scripts instead of sourcing them --- tmpl/README.md.j2 | 2 ++ tmpl/docs/installation.rst.j2 | 1 + 2 files changed, 3 insertions(+) diff --git a/tmpl/README.md.j2 b/tmpl/README.md.j2 index de2302c..d4868ec 100644 --- a/tmpl/README.md.j2 +++ b/tmpl/README.md.j2 @@ -13,6 +13,8 @@ is based on top-level dependencies listed in `requirements/requirements.yml`. If ```bash tools/setup_env.sh -u -e -n ``` +*Hint*: Make sure to execute the bash scripts in `tools/` (do not source them as this can lead to issues)! + *Hint*: If you are the package administrator, it is a good idea to understand what this script does, you can do everything manually with `conda` instructions. *Hint*: Use the flag `-m` to speed up the installation using mamba. Of course you will have to install mamba first (we recommend to install mamba into your base diff --git a/tmpl/docs/installation.rst.j2 b/tmpl/docs/installation.rst.j2 index 553cbce..6f52f2d 100644 --- a/tmpl/docs/installation.rst.j2 +++ b/tmpl/docs/installation.rst.j2 @@ -11,6 +11,7 @@ Preparation ----------- To install {{ project_name }} you need a miniconda installation. You can either set up your miniconda installation manually or use the script `tools/setup_miniconda.sh`, which will download and install the latest version of miniconda. +Make sure to execute the script (do not source it as this can lead to issues)! Installation of dependencies From b0b487b8a9b8b949322cd2bf81e1ba6595342aba Mon Sep 17 00:00:00 2001 From: Daniel Leuenberger Date: Thu, 11 May 2023 09:00:05 +0200 Subject: [PATCH 02/28] re-introduce logging controlled with -v --- tmpl/src/{{module_name}}/cli.py.j2 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tmpl/src/{{module_name}}/cli.py.j2 b/tmpl/src/{{module_name}}/cli.py.j2 index 40d7c2e..46783e6 100644 --- a/tmpl/src/{{module_name}}/cli.py.j2 +++ b/tmpl/src/{{module_name}}/cli.py.j2 @@ -2,6 +2,9 @@ # Third-party import click +# First-party +from {{ module_name }}.utils import count_to_log_level + # Local from . import __version__ from .mutable_number import MutableNumber @@ -52,6 +55,10 @@ def print_number(ctx, *args, **kwargs) -> None: @click.pass_context def main(ctx, number: float, **kwargs) -> None: """Console script for test_cli_project.""" + " initialize logging + logging.getLogger(__name__) + logging.basicConfig(level=count_to_log_level(kwargs["verbose"])) + if ctx.obj is None: ctx.obj = {} ctx.obj["number"] = MutableNumber(number) From bf3c0429a2863fab8615cf6901a003d577f1a51f Mon Sep 17 00:00:00 2001 From: Daniel Leuenberger Date: Thu, 11 May 2023 09:12:36 +0200 Subject: [PATCH 03/28] bug fix --- tmpl/src/{{module_name}}/cli.py.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmpl/src/{{module_name}}/cli.py.j2 b/tmpl/src/{{module_name}}/cli.py.j2 index 46783e6..52a76d7 100644 --- a/tmpl/src/{{module_name}}/cli.py.j2 +++ b/tmpl/src/{{module_name}}/cli.py.j2 @@ -55,7 +55,7 @@ def print_number(ctx, *args, **kwargs) -> None: @click.pass_context def main(ctx, number: float, **kwargs) -> None: """Console script for test_cli_project.""" - " initialize logging + "initialize logging logging.getLogger(__name__) logging.basicConfig(level=count_to_log_level(kwargs["verbose"])) From ab8411aa6078a2ac25803c18ed8e7c29b7c98d86 Mon Sep 17 00:00:00 2001 From: Daniel Leuenberger Date: Thu, 11 May 2023 09:21:13 +0200 Subject: [PATCH 04/28] bug fix 2 --- tmpl/src/{{module_name}}/cli.py.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmpl/src/{{module_name}}/cli.py.j2 b/tmpl/src/{{module_name}}/cli.py.j2 index 52a76d7..6bab732 100644 --- a/tmpl/src/{{module_name}}/cli.py.j2 +++ b/tmpl/src/{{module_name}}/cli.py.j2 @@ -55,7 +55,7 @@ def print_number(ctx, *args, **kwargs) -> None: @click.pass_context def main(ctx, number: float, **kwargs) -> None: """Console script for test_cli_project.""" - "initialize logging + # initialize logging logging.getLogger(__name__) logging.basicConfig(level=count_to_log_level(kwargs["verbose"])) From 6a09577bef1e477e1a1fe7ca5e44f738a42efced Mon Sep 17 00:00:00 2001 From: Daniel Leuenberger Date: Thu, 11 May 2023 09:31:51 +0200 Subject: [PATCH 05/28] bug fix 3 --- tmpl/src/{{module_name}}/cli.py.j2 | 1 + 1 file changed, 1 insertion(+) diff --git a/tmpl/src/{{module_name}}/cli.py.j2 b/tmpl/src/{{module_name}}/cli.py.j2 index 6bab732..04b2d76 100644 --- a/tmpl/src/{{module_name}}/cli.py.j2 +++ b/tmpl/src/{{module_name}}/cli.py.j2 @@ -1,6 +1,7 @@ """Command line interface of {{ module_name }}.""" # Third-party import click +import logging # First-party from {{ module_name }}.utils import count_to_log_level From e4721e666d141c976a5589916eed2b9bafbdf213 Mon Sep 17 00:00:00 2001 From: Daniel Leuenberger Date: Thu, 11 May 2023 09:43:02 +0200 Subject: [PATCH 06/28] bug fix 4 --- tmpl/src/{{module_name}}/cli.py.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tmpl/src/{{module_name}}/cli.py.j2 b/tmpl/src/{{module_name}}/cli.py.j2 index 04b2d76..4c0025d 100644 --- a/tmpl/src/{{module_name}}/cli.py.j2 +++ b/tmpl/src/{{module_name}}/cli.py.j2 @@ -1,10 +1,10 @@ """Command line interface of {{ module_name }}.""" # Third-party -import click import logging +import click # First-party -from {{ module_name }}.utils import count_to_log_level +from {{module_name}}.utils import count_to_log_level # Local from . import __version__ From e69c99ee62833d376db9e025fdd27d7f42a15c48 Mon Sep 17 00:00:00 2001 From: Stefan Ruedisuehli Date: Thu, 11 May 2023 09:44:25 +0200 Subject: [PATCH 07/28] fix pylint directives --- tmpl/src/{{module_name}}/cli.py.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tmpl/src/{{module_name}}/cli.py.j2 b/tmpl/src/{{module_name}}/cli.py.j2 index 4c0025d..3eff14d 100644 --- a/tmpl/src/{{module_name}}/cli.py.j2 +++ b/tmpl/src/{{module_name}}/cli.py.j2 @@ -11,7 +11,7 @@ from . import __version__ from .mutable_number import MutableNumber -# pylint: disable=W0613 # unused-argument (param) +# pylint: disable-next=W0613 # unused-argument (param) def print_version(ctx, param, value: bool) -> None: """Print the version number and exit.""" if value: @@ -19,7 +19,7 @@ def print_version(ctx, param, value: bool) -> None: ctx.exit(0) -# pylint: disable=W0613 # unused-argument (args, kwargs) +# pylint: disable-next=W0613 # unused-argument (args, kwargs) @click.pass_context def print_number(ctx, *args, **kwargs) -> None: """Print the current number.""" From e5210572f9acc664b21210013f24012c622247fd Mon Sep 17 00:00:00 2001 From: Stefan Ruedisuehli Date: Thu, 11 May 2023 09:48:08 +0200 Subject: [PATCH 08/28] swap order of pylint disable-next and decorator --- tmpl/src/{{module_name}}/cli.py.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmpl/src/{{module_name}}/cli.py.j2 b/tmpl/src/{{module_name}}/cli.py.j2 index 3eff14d..810954d 100644 --- a/tmpl/src/{{module_name}}/cli.py.j2 +++ b/tmpl/src/{{module_name}}/cli.py.j2 @@ -19,8 +19,8 @@ def print_version(ctx, param, value: bool) -> None: ctx.exit(0) -# pylint: disable-next=W0613 # unused-argument (args, kwargs) @click.pass_context +# pylint: disable-next=W0613 # unused-argument (args, kwargs) def print_number(ctx, *args, **kwargs) -> None: """Print the current number.""" number = ctx.obj["number"].get() From e10c305810cd5f349e054fec9fb00b75c735022f Mon Sep 17 00:00:00 2001 From: Stefan Ruedisuehli Date: Thu, 11 May 2023 09:49:57 +0200 Subject: [PATCH 09/28] set logging level via callback --- tmpl/src/{{module_name}}/cli.py.j2 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tmpl/src/{{module_name}}/cli.py.j2 b/tmpl/src/{{module_name}}/cli.py.j2 index 810954d..3f9f8f7 100644 --- a/tmpl/src/{{module_name}}/cli.py.j2 +++ b/tmpl/src/{{module_name}}/cli.py.j2 @@ -19,6 +19,12 @@ def print_version(ctx, param, value: bool) -> None: ctx.exit(0) +# pylint: disable-next=W0613 # unused-argument (args, kwargs) +def set_log_level(ctx, param, value: int) -> None: + """Set the logging level.""" + logging.getLogger(__name__).setLevel(count_to_log_level(value)) + + @click.pass_context # pylint: disable-next=W0613 # unused-argument (args, kwargs) def print_number(ctx, *args, **kwargs) -> None: @@ -50,15 +56,13 @@ def print_number(ctx, *args, **kwargs) -> None: @click.option( "--verbose", "-v", - count=True, help="Increase verbosity (specify multiple times for more).", + count=True, + callback=set_log_level, ) @click.pass_context def main(ctx, number: float, **kwargs) -> None: """Console script for test_cli_project.""" - # initialize logging - logging.getLogger(__name__) - logging.basicConfig(level=count_to_log_level(kwargs["verbose"])) if ctx.obj is None: ctx.obj = {} From 3329f842a468aad67312fe20da2f567ad2cba49f Mon Sep 17 00:00:00 2001 From: Stefan Ruedisuehli Date: Thu, 11 May 2023 09:50:09 +0200 Subject: [PATCH 10/28] fix import headings --- tmpl/src/{{module_name}}/cli.py.j2 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tmpl/src/{{module_name}}/cli.py.j2 b/tmpl/src/{{module_name}}/cli.py.j2 index 3f9f8f7..d795af2 100644 --- a/tmpl/src/{{module_name}}/cli.py.j2 +++ b/tmpl/src/{{module_name}}/cli.py.j2 @@ -1,8 +1,10 @@ """Command line interface of {{ module_name }}.""" -# Third-party +# Standard library import logging +# Third-party import click + # First-party from {{module_name}}.utils import count_to_log_level From 66e8911d808564c5f54442675b4706c8174cb317 Mon Sep 17 00:00:00 2001 From: Stefan Ruedisuehli Date: Thu, 11 May 2023 09:51:55 +0200 Subject: [PATCH 11/28] uncomment command declaration --- tmpl/pyproject.toml.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmpl/pyproject.toml.j2 b/tmpl/pyproject.toml.j2 index 0ce9d9d..c2f8aef 100644 --- a/tmpl/pyproject.toml.j2 +++ b/tmpl/pyproject.toml.j2 @@ -33,7 +33,7 @@ documentation = "{{ project_doc_url }}" [project.scripts] # Format: = ".:" -# {{ project_slug }} = "{{ module_name }}.cli:main" +{{ project_slug }} = "{{ module_name }}.cli:main" [tool.pytest.ini_options] testpaths = ["tests"] From 97946b2effdb6a4f5b8f9dcc49ed4755f8e91f49 Mon Sep 17 00:00:00 2001 From: Daniel Leuenberger Date: Thu, 11 May 2023 10:10:53 +0200 Subject: [PATCH 12/28] bug fix 5 --- docs/conf.py | 151 +++++++++++++++-------------- tmpl/src/{{module_name}}/cli.py.j2 | 1 - 2 files changed, 78 insertions(+), 74 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index ca7fa59..0c2bb1d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -13,100 +13,100 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys import os import shlex +import sys # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -#sys.path.insert(0, os.path.abspath('.')) +# sys.path.insert(0, os.path.abspath('.')) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' +# needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.doctest', - 'sphinx.ext.todo', - 'sphinx.ext.coverage', - 'sphinx.ext.viewcode', - 'sphinx_mdinclude', + "sphinx.ext.autodoc", + "sphinx.ext.doctest", + "sphinx.ext.todo", + "sphinx.ext.coverage", + "sphinx.ext.viewcode", + "sphinx_mdinclude", ] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # source_suffix = ['.rst', '.md'] -source_suffix = '.rst' +source_suffix = ".rst" # The encoding of source files. -#source_encoding = 'utf-8-sig' +# source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = 'MCH Python Blueprint' -copyright = '2022, MeteoSwiss-APN' -author= 'MeteoSwiss-APN' +project = "MCH Python Blueprint" +copyright = "2022, MeteoSwiss-APN" +author = "MeteoSwiss-APN" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = '0.1.0' +version = "0.1.0" # The full version, including alpha/beta/rc tags. -release = '0.1.0' +release = "0.1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = 'en' +language = "en" # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -#today = '' +# today = '' # Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' +# today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -exclude_patterns = ['_build'] +exclude_patterns = ["_build"] # The reST default role (used for this markup: `text`) to use for all # documents. -#default_role = None +# default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True +# add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -#add_module_names = True +# add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -#show_authors = False +# show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. -#keep_warnings = False +# keep_warnings = False # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = True @@ -116,99 +116,99 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'alabaster' +html_theme = "alabaster" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -#html_theme_options = {} +# html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] +# html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -#html_title = None +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None +# html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. -#html_logo = None +# html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -#html_favicon = None +# html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. -#html_extra_path = [] +# html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' +# html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. -#html_use_smartypants = True +# html_use_smartypants = True # Custom sidebar templates, maps document names to template names. -#html_sidebars = {} +# html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +# html_additional_pages = {} # If false, no module index is generated. -#html_domain_indices = True +# html_domain_indices = True # If false, no index is generated. -#html_use_index = True +# html_use_index = True # If true, the index is split into individual pages for each letter. -#html_split_index = False +# html_split_index = False # If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True +# html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True +# html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True +# html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -#html_use_opensearch = '' +# html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None +# html_file_suffix = None # Language to be used for generating the HTML full-text search index. # Sphinx supports the following languages: # 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja' # 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr' -#html_search_language = 'en' +# html_search_language = 'en' # A dictionary with options for the search language support, empty by default. # Now only 'ja' uses this config value -#html_search_options = {'type': 'default'} +# html_search_options = {'type': 'default'} # The name of a javascript file (relative to the configuration directory) that # implements a search results scorer. If empty, the default will be used. -#html_search_scorer = 'scorer.js' +# html_search_scorer = 'scorer.js' # Output file base name for HTML help builder. -htmlhelp_basename = 'blueprint-pypackagedoc' +htmlhelp_basename = "blueprint-pypackagedoc" # -- Options for LaTeX output --------------------------------------------- @@ -224,35 +224,35 @@ # Latex figure (float) alignment #'figure_align': 'htbp', -#} +# } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). -#latex_documents = [ +# latex_documents = [ # (master_doc, 'cookiecutter-pypackage.tex', 'cookiecutter-pypackage Documentation', # 'Audrey Roy Greenfeld', 'manual'), -#] +# ] # The name of an image file (relative to this directory) to place at the top of # the title page. -#latex_logo = None +# latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -#latex_use_parts = False +# latex_use_parts = False # If true, show page references after internal links. -#latex_show_pagerefs = False +# latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +# latex_show_urls = False # Documents to append as an appendix to all manuals. -#latex_appendices = [] +# latex_appendices = [] # If false, no module index is generated. -#latex_domain_indices = True +# latex_domain_indices = True # -- Options for manual page output --------------------------------------- @@ -260,12 +260,11 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'APN Python Blueprint', 'Blueprint Documentation', - [author], 1) + (master_doc, "APN Python Blueprint", "Blueprint Documentation", [author], 1) ] # If true, show URL addresses after external links. -#man_show_urls = False +# man_show_urls = False # -- Options for Texinfo output ------------------------------------------- @@ -274,19 +273,25 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'APN Python Blueprint', 'Blueprint Documentation', - author, 'APN Python Blueprint', 'Create your Python packages from templates.', - 'Miscellaneous'), + ( + master_doc, + "APN Python Blueprint", + "Blueprint Documentation", + author, + "APN Python Blueprint", + "Create your Python packages from templates.", + "Miscellaneous", + ), ] # Documents to append as an appendix to all manuals. -#texinfo_appendices = [] +# texinfo_appendices = [] # If false, no module index is generated. -#texinfo_domain_indices = True +# texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' +# texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. -#texinfo_no_detailmenu = False +# texinfo_no_detailmenu = False diff --git a/tmpl/src/{{module_name}}/cli.py.j2 b/tmpl/src/{{module_name}}/cli.py.j2 index d795af2..a583397 100644 --- a/tmpl/src/{{module_name}}/cli.py.j2 +++ b/tmpl/src/{{module_name}}/cli.py.j2 @@ -65,7 +65,6 @@ def print_number(ctx, *args, **kwargs) -> None: @click.pass_context def main(ctx, number: float, **kwargs) -> None: """Console script for test_cli_project.""" - if ctx.obj is None: ctx.obj = {} ctx.obj["number"] = MutableNumber(number) From a733e6bbd136654156f30b81f172c2a494ff9d42 Mon Sep 17 00:00:00 2001 From: Stefan Ruedisuehli Date: Thu, 11 May 2023 10:23:18 +0200 Subject: [PATCH 13/28] use root logger --- tmpl/src/{{module_name}}/cli.py.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmpl/src/{{module_name}}/cli.py.j2 b/tmpl/src/{{module_name}}/cli.py.j2 index d795af2..57b3e5a 100644 --- a/tmpl/src/{{module_name}}/cli.py.j2 +++ b/tmpl/src/{{module_name}}/cli.py.j2 @@ -24,7 +24,7 @@ def print_version(ctx, param, value: bool) -> None: # pylint: disable-next=W0613 # unused-argument (args, kwargs) def set_log_level(ctx, param, value: int) -> None: """Set the logging level.""" - logging.getLogger(__name__).setLevel(count_to_log_level(value)) + logging.getLogger().setLevel(count_to_log_level(value)) @click.pass_context From a1040e7d85c661773feb19224bfb2fe725a56a38 Mon Sep 17 00:00:00 2001 From: Stefan Ruedisuehli Date: Thu, 11 May 2023 10:23:41 +0200 Subject: [PATCH 14/28] fix log level decorator --- tmpl/src/{{module_name}}/cli.py.j2 | 1 + 1 file changed, 1 insertion(+) diff --git a/tmpl/src/{{module_name}}/cli.py.j2 b/tmpl/src/{{module_name}}/cli.py.j2 index 57b3e5a..d2fdf94 100644 --- a/tmpl/src/{{module_name}}/cli.py.j2 +++ b/tmpl/src/{{module_name}}/cli.py.j2 @@ -25,6 +25,7 @@ def print_version(ctx, param, value: bool) -> None: def set_log_level(ctx, param, value: int) -> None: """Set the logging level.""" logging.getLogger().setLevel(count_to_log_level(value)) + return value @click.pass_context From ce2c690edcf9167e01813f33a7f57703b50c17f0 Mon Sep 17 00:00:00 2001 From: Stefan Ruedisuehli Date: Thu, 11 May 2023 10:24:40 +0200 Subject: [PATCH 15/28] rename internal verbosity level variable and move print_operation next to print_value --- tmpl/src/{{module_name}}/cli.py.j2 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tmpl/src/{{module_name}}/cli.py.j2 b/tmpl/src/{{module_name}}/cli.py.j2 index d2fdf94..e2b2a76 100644 --- a/tmpl/src/{{module_name}}/cli.py.j2 +++ b/tmpl/src/{{module_name}}/cli.py.j2 @@ -36,6 +36,12 @@ def print_number(ctx, *args, **kwargs) -> None: click.echo(f"{number:g}") +def print_operation(ctx, operator: str, value: float) -> None: + if ctx.obj["verbosity"]: + number = ctx.obj['number'] + click.echo(f"{number.get(-2):g} {operator} {value:g} = {number.get():g}") + + @click.group( context_settings={"help_option_names": ["-h", "--help"]}, no_args_is_help=True, @@ -59,6 +65,7 @@ def print_number(ctx, *args, **kwargs) -> None: @click.option( "--verbose", "-v", + "verbosity", help="Increase verbosity (specify multiple times for more).", count=True, callback=set_log_level, @@ -66,19 +73,12 @@ def print_number(ctx, *args, **kwargs) -> None: @click.pass_context def main(ctx, number: float, **kwargs) -> None: """Console script for test_cli_project.""" - if ctx.obj is None: ctx.obj = {} ctx.obj["number"] = MutableNumber(number) ctx.obj.update(kwargs) -def print_operation(ctx, operator: str, value: float) -> None: - if ctx.obj["verbose"]: - number = ctx.obj["number"] - click.echo(f"{number.get(-2):g} {operator} {value:g} = {number.get():g}") - - @main.command("plus", help="addition") @click.argument("addend", type=float, nargs=1) @click.pass_context From 2d0764b891a40230f03f04cebcbf4cba5373a5a1 Mon Sep 17 00:00:00 2001 From: Stefan Ruedisuehli Date: Thu, 11 May 2023 10:32:32 +0200 Subject: [PATCH 16/28] fix quotes (black) and return type (mypy) --- tmpl/src/{{module_name}}/cli.py.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tmpl/src/{{module_name}}/cli.py.j2 b/tmpl/src/{{module_name}}/cli.py.j2 index e2b2a76..72ca4a3 100644 --- a/tmpl/src/{{module_name}}/cli.py.j2 +++ b/tmpl/src/{{module_name}}/cli.py.j2 @@ -22,7 +22,7 @@ def print_version(ctx, param, value: bool) -> None: # pylint: disable-next=W0613 # unused-argument (args, kwargs) -def set_log_level(ctx, param, value: int) -> None: +def set_log_level(ctx, param, value: int) -> int: """Set the logging level.""" logging.getLogger().setLevel(count_to_log_level(value)) return value @@ -38,7 +38,7 @@ def print_number(ctx, *args, **kwargs) -> None: def print_operation(ctx, operator: str, value: float) -> None: if ctx.obj["verbosity"]: - number = ctx.obj['number'] + number = ctx.obj["number"] click.echo(f"{number.get(-2):g} {operator} {value:g} = {number.get():g}") From 836f68ce544ac4d8ebf5ddaf59f776e9f750437b Mon Sep 17 00:00:00 2001 From: Claire Merker Date: Mon, 21 Aug 2023 12:17:30 +0200 Subject: [PATCH 17/28] adapt bluprint to new copier version >=8.1.0 --- README.md | 7 ++++--- jenkins/Jenkinsfile | 2 +- requirements/requirements.yml | 2 +- tmpl/requirements/requirements.yml.j2 | 2 +- tools/update_env.sh | 2 +- tools/update_tmpl_env.sh | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 10d5af1..bc2b82e 100644 --- a/README.md +++ b/README.md @@ -20,18 +20,19 @@ conda activate blueprint conda install pip pip install copier ``` +Make sure to have at least copier version 8.1.0. Otherwise, please update copier. ## Create your Python package from our template You can now produce your Python package from a copier template by running ``` conda activate blueprint -copier git@github.com:MeteoSwiss-APN/mch-python-blueprint.git +copier copy git@github.com:MeteoSwiss-APN/mch-python-blueprint.git ``` If you need to generate your project from a specific commit hash or branch of the blueprint you can run with --vcs-ref ``` conda activate blueprint -copier --vcs-ref git@github.com:MeteoSwiss-APN/mch-python-blueprint.git +copier copy --vcs-ref git@github.com:MeteoSwiss-APN/mch-python-blueprint.git ``` **Warning:** @@ -69,7 +70,7 @@ out more about provided development tools and setting up CI/CD pipelines on http To update your package to the latest version of the underlying meta template, run: ```bash -copier -a .copier-answers.yml -f update +copier update -a .copier-answers.yml -f update ``` With `-f`, conflicting files are overwritten (which doesn't mean that in the end, the files are changed as those conflicts can be purely internal). diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile index 9a60aac..2f9264c 100644 --- a/jenkins/Jenkinsfile +++ b/jenkins/Jenkinsfile @@ -33,7 +33,7 @@ pipeline { conda create -n copier conda activate copier conda install -c conda-forge copier - copier --vcs-ref=HEAD --defaults copy . flying_circus + copier copy --vcs-ref=HEAD --defaults copy . flying_circus conda deactivate ''' } diff --git a/requirements/requirements.yml b/requirements/requirements.yml index ea667a3..5d7d884 100644 --- a/requirements/requirements.yml +++ b/requirements/requirements.yml @@ -9,6 +9,6 @@ dependencies: - sphinx>=4.3 - pip: # runtime - - copier>=6.1 + - copier>=8.1 # development - sphinx-mdinclude>=0.5 diff --git a/tmpl/requirements/requirements.yml.j2 b/tmpl/requirements/requirements.yml.j2 index 6d19177..95e7c8a 100644 --- a/tmpl/requirements/requirements.yml.j2 +++ b/tmpl/requirements/requirements.yml.j2 @@ -34,6 +34,6 @@ dependencies: - types-toml>=0.10 - pip: # development - - copier>=7.0 + - copier>=8.1 - flake8-pyproject>=1.2 - sphinx-mdinclude>=0.5 diff --git a/tools/update_env.sh b/tools/update_env.sh index 60c15ca..70ed648 100755 --- a/tools/update_env.sh +++ b/tools/update_env.sh @@ -10,7 +10,7 @@ main() if [[ -d "${tmpdir}" ]]; then \rm -rfv "${tmpdir}" || return fi - copier -f --vcs-ref=HEAD . "${tmpdir}" || return + copier copy -f --vcs-ref=HEAD . "${tmpdir}" || return # Use script in project to update the root environment file local env_name diff --git a/tools/update_tmpl_env.sh b/tools/update_tmpl_env.sh index d851673..6173db7 100755 --- a/tools/update_tmpl_env.sh +++ b/tools/update_tmpl_env.sh @@ -10,7 +10,7 @@ main() if [[ -d "${tmpdir}" ]]; then \rm -rfv "${tmpdir}" || return fi - copier -f --vcs-ref=HEAD . "${tmpdir}" || return + copier copy -f --vcs-ref=HEAD . "${tmpdir}" || return # Update the project's environment file \cd "${tmpdir}" || return From f7bee25383b875dc90d2cc8f2ee64e78906ab53a Mon Sep 17 00:00:00 2001 From: Claire Merker Date: Mon, 21 Aug 2023 13:37:01 +0200 Subject: [PATCH 18/28] adapt pre-commit github workflow to new copier version --- .github/workflows/blueprint-docs.yml | 2 +- .github/workflows/new-project.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/blueprint-docs.yml b/.github/workflows/blueprint-docs.yml index d849fb8..efc38d9 100644 --- a/.github/workflows/blueprint-docs.yml +++ b/.github/workflows/blueprint-docs.yml @@ -19,7 +19,7 @@ jobs: - name: Create new project run: | # Note: Make sure python_version is consistent with python-version hardcoded above - conda run --name blueprint copier --force --vcs-ref=HEAD python_version=3.9 copy . ./docs/example_project + conda run --name blueprint copier copy --force --vcs-ref=HEAD python_version=3.9 copy . ./docs/example_project ls echo "===================================" ls docs diff --git a/.github/workflows/new-project.yml b/.github/workflows/new-project.yml index 84cbfe3..403c545 100644 --- a/.github/workflows/new-project.yml +++ b/.github/workflows/new-project.yml @@ -32,7 +32,7 @@ jobs: - name: Create new project run: | # Note: Make sure python_version is consistent with python-version hardcoded above - conda run --name blueprint copier --force --vcs-ref=HEAD --data python_version=3.9 copy . flying_circus + conda run --name blueprint copier copy --force --vcs-ref=HEAD --data python_version=3.9 copy . flying_circus - name: Prepare new project working-directory: ./flying_circus run: | From 154a65abb7b8da04c5722644a4634b8164887156 Mon Sep 17 00:00:00 2001 From: Claire Merker Date: Mon, 21 Aug 2023 13:53:00 +0200 Subject: [PATCH 19/28] bug fix in copier command --- .github/workflows/blueprint-docs.yml | 2 +- .github/workflows/new-project.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/blueprint-docs.yml b/.github/workflows/blueprint-docs.yml index efc38d9..2118bdb 100644 --- a/.github/workflows/blueprint-docs.yml +++ b/.github/workflows/blueprint-docs.yml @@ -19,7 +19,7 @@ jobs: - name: Create new project run: | # Note: Make sure python_version is consistent with python-version hardcoded above - conda run --name blueprint copier copy --force --vcs-ref=HEAD python_version=3.9 copy . ./docs/example_project + conda run --name blueprint copier copy --force --vcs-ref=HEAD . ./docs/example_project ls echo "===================================" ls docs diff --git a/.github/workflows/new-project.yml b/.github/workflows/new-project.yml index 403c545..072aab0 100644 --- a/.github/workflows/new-project.yml +++ b/.github/workflows/new-project.yml @@ -32,7 +32,7 @@ jobs: - name: Create new project run: | # Note: Make sure python_version is consistent with python-version hardcoded above - conda run --name blueprint copier copy --force --vcs-ref=HEAD --data python_version=3.9 copy . flying_circus + conda run --name blueprint copier copy --force --vcs-ref=HEAD --data . flying_circus - name: Prepare new project working-directory: ./flying_circus run: | From 11f8e0e8e068e0687d5a9d9e4d69298ae0dd7f8c Mon Sep 17 00:00:00 2001 From: Claire Merker Date: Mon, 21 Aug 2023 14:23:47 +0200 Subject: [PATCH 20/28] bug fix in copier command --- .github/workflows/new-project.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/new-project.yml b/.github/workflows/new-project.yml index 072aab0..75ad3cd 100644 --- a/.github/workflows/new-project.yml +++ b/.github/workflows/new-project.yml @@ -32,7 +32,7 @@ jobs: - name: Create new project run: | # Note: Make sure python_version is consistent with python-version hardcoded above - conda run --name blueprint copier copy --force --vcs-ref=HEAD --data . flying_circus + conda run --name blueprint copier copy --force --vcs-ref=HEAD --data python_version=3.9 . flying_circus - name: Prepare new project working-directory: ./flying_circus run: | From 0a350ed05d07ba05525013465d02dcaf809e7b7d Mon Sep 17 00:00:00 2001 From: Claire Merker Date: Mon, 21 Aug 2023 15:10:35 +0200 Subject: [PATCH 21/28] add check to bash scripts to avoid sourcing --- tmpl/tools/run-mypy.sh.j2 | 5 +++++ tmpl/tools/setup_env.sh.j2 | 5 +++++ tmpl/tools/setup_miniconda.sh | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/tmpl/tools/run-mypy.sh.j2 b/tmpl/tools/run-mypy.sh.j2 index 44edb38..da9d049 100755 --- a/tmpl/tools/run-mypy.sh.j2 +++ b/tmpl/tools/run-mypy.sh.j2 @@ -9,6 +9,11 @@ # # src: https://jaredkhan.com/blog/mypy-pre-commit +if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then + echo "Please simply call the script instead of sourcing it!" + return +fi + set -o errexit VERBOSE=${VERBOSE:-false} diff --git a/tmpl/tools/setup_env.sh.j2 b/tmpl/tools/setup_env.sh.j2 index fe11f0a..e1f3f33 100755 --- a/tmpl/tools/setup_env.sh.j2 +++ b/tmpl/tools/setup_env.sh.j2 @@ -6,6 +6,11 @@ # - 2022-09 (S. Ruedisuehli) Refactor; add some options # +if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then + echo "Please simply call the script instead of sourcing it!" + return +fi + # Default env names DEFAULT_ENV_NAME="{{ project_slug }}" diff --git a/tmpl/tools/setup_miniconda.sh b/tmpl/tools/setup_miniconda.sh index a0fcb59..a5c36ab 100755 --- a/tmpl/tools/setup_miniconda.sh +++ b/tmpl/tools/setup_miniconda.sh @@ -6,6 +6,11 @@ # - 2022-09 (S. Ruedisuehli) Refactor # +if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then + echo "Please simply call the script instead of sourcing it!" + return +fi + # Default options INSTALL_PREFIX=${PWD} USER_INSTALL=false From b9ac391ae4413454372b000ffabaf970d928ed64 Mon Sep 17 00:00:00 2001 From: Stefan Ruedisuehli Date: Thu, 14 Sep 2023 18:13:17 +0200 Subject: [PATCH 22/28] move rstcheck to pip and add comment --- tmpl/requirements/requirements.yml.j2 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tmpl/requirements/requirements.yml.j2 b/tmpl/requirements/requirements.yml.j2 index 95e7c8a..9cdef7a 100644 --- a/tmpl/requirements/requirements.yml.j2 +++ b/tmpl/requirements/requirements.yml.j2 @@ -26,7 +26,8 @@ dependencies: - pytest>=7.2 - rich>=12.6 - rope>=1.6 - - rstcheck>=6.1 + # install rstcheck w/ pip to avoid pydantic runtime error due to copier 8 + # rstcheck>=6.1 - sphinx>=4.3 - sphinx-autobuild>=2021.3 - toml>=0.10 @@ -37,3 +38,5 @@ dependencies: - copier>=8.1 - flake8-pyproject>=1.2 - sphinx-mdinclude>=0.5 + # install rstcheck w/ pip to avoid pydantic runtime error due to copier 8 + - rstcheck>=6.1 From b6138c5410fc13082385a6b5b3bd83fba893d245 Mon Sep 17 00:00:00 2001 From: Stefan Ruedisuehli Date: Thu, 14 Sep 2023 18:44:04 +0200 Subject: [PATCH 23/28] update year --- copier.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/copier.yaml b/copier.yaml index 24731be..2407bc3 100644 --- a/copier.yaml +++ b/copier.yaml @@ -76,5 +76,5 @@ python_version: year: help: "This year" - default: "2022" + default: "2023" type: str From f82ec8dccbdff03cd1fe607e124df33b2d08042f Mon Sep 17 00:00:00 2001 From: Stefan Ruedisuehli Date: Tue, 10 Oct 2023 09:55:20 +0200 Subject: [PATCH 24/28] update codespell config --- pyproject.toml | 14 ++++++++++++-- tmpl/codespell_ignored_words.txt | 9 +++++++++ tmpl/pyproject.toml.j2 | 14 ++++++++++++-- 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 tmpl/codespell_ignored_words.txt diff --git a/pyproject.toml b/pyproject.toml index 77f6f6d..6c8d0a1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,5 +31,15 @@ ignore_directives = [ ] [tool.codespell] -ignore-words-list = "inout" -skip = "requirements/*" +ignore-regex = '(\b[A-Z]+\b|.*([#!"]|