From a2b121ae143f930dd2cc20fc3c974e8f65e50550 Mon Sep 17 00:00:00 2001 From: David J Pugh <6003255+djpugh@users.noreply.github.com> Date: Fri, 23 Feb 2024 18:22:25 +0000 Subject: [PATCH 1/5] Fix recipe template to correctly include entrypoint * Fixing recipe * Fixing template --- .../recipes/python/ingredients/docs/mkdocs.yml.template | 7 ++++++- .../recipes/python/ingredients/pyproject.toml.template | 2 ++ .../python/ingredients/recipe/pyproject.toml.template | 4 ++-- .../recipes/python/ingredients/recipe/readme.md.template | 2 +- src/nskit/recipes/recipe.py | 2 ++ 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/nskit/recipes/python/ingredients/docs/mkdocs.yml.template b/src/nskit/recipes/python/ingredients/docs/mkdocs.yml.template index 3bf1ca1..2174697 100644 --- a/src/nskit/recipes/python/ingredients/docs/mkdocs.yml.template +++ b/src/nskit/recipes/python/ingredients/docs/mkdocs.yml.template @@ -13,8 +13,10 @@ nav: {% if license %} - developing/license.md {% endif %} + - developing/dependencies.md - 'Test Coverage': coverage.md {% if "github.com" in "" ~ repo.url %} + - changelog.md - 'Issue Tracker': {{repo.url}}/issues {% endif %} exclude_docs: | @@ -62,7 +64,10 @@ plugins: type: iso_date - include-markdown # https://github.com/mondeja/mkdocs-include-markdown-plugin - + - mkdocs_github_changelog + # https://github.com/djpugh/mkdocs_github_changelog + - mkdocs_licenseinfo + # https://github.com/djpugh/mkdocs_licenseinfo # https://mkdocstrings.github.io/recipes/#automatic-code-reference-pages extra: diff --git a/src/nskit/recipes/python/ingredients/pyproject.toml.template b/src/nskit/recipes/python/ingredients/pyproject.toml.template index 6cbd8a9..34560ef 100644 --- a/src/nskit/recipes/python/ingredients/pyproject.toml.template +++ b/src/nskit/recipes/python/ingredients/pyproject.toml.template @@ -76,6 +76,8 @@ dev-docs = [ "mkdocs-git-authors-plugin", "mkdocs-coverage", "mkdocs-include-markdown-plugin", + "mkdocs-github-changelog", + "mkdocs-licenseinfo", "mike" ] dev-build = [ diff --git a/src/nskit/recipes/python/ingredients/recipe/pyproject.toml.template b/src/nskit/recipes/python/ingredients/recipe/pyproject.toml.template index ffdee66..1f3ebff 100644 --- a/src/nskit/recipes/python/ingredients/recipe/pyproject.toml.template +++ b/src/nskit/recipes/python/ingredients/recipe/pyproject.toml.template @@ -1,8 +1,8 @@ {% extends "nskit.recipes.python.ingredients:pyproject.toml.template" %} {% block EntryPoints %} # Enter the template entrypoints here -[project.entry-points."{{ recipe.entry_point}}"] - example = {{ repo.name }}.templates.example:ExampleTemplate +[project.entry-points."{{ recipe_entrypoint }}"] + example = "{{ repo.name }}.templates.example:ExampleTemplate" {% endblock EntryPoints %} {% block Dependencies %} {{ super() }} diff --git a/src/nskit/recipes/python/ingredients/recipe/readme.md.template b/src/nskit/recipes/python/ingredients/recipe/readme.md.template index be1dd83..5d96fd1 100644 --- a/src/nskit/recipes/python/ingredients/recipe/readme.md.template +++ b/src/nskit/recipes/python/ingredients/recipe/readme.md.template @@ -7,6 +7,6 @@ This repo is configured for nskit recipes using ``nskit.mixer`` to build them. {% block Development %} {{super()}} -When you create a recipe, it should be added to the ``[project.entry_points."{{recipe.entrypoint}}"]`` section in ``pyproject.toml``. +When you create a recipe, it should be added to the ``[project.entry_points."{{recipe_entrypoint}}"]`` section in ``pyproject.toml``. {% endblock Development %} \ No newline at end of file diff --git a/src/nskit/recipes/recipe.py b/src/nskit/recipes/recipe.py index d765e6c..35b01d6 100644 --- a/src/nskit/recipes/recipe.py +++ b/src/nskit/recipes/recipe.py @@ -4,6 +4,7 @@ from pydantic import Field from nskit.mixer import File, Folder, LicenseFile +from nskit.mixer.components.recipe import RECIPE_ENTRYPOINT from nskit.recipes.python import ingredients, PyRecipe from nskit.recipes.python.ingredients import recipe as recipe_ingredients @@ -11,6 +12,7 @@ class RecipeRecipe(PyRecipe): """A Recipe for creating Recipes, meta!""" + recipe_entrypoint: str = RECIPE_ENTRYPOINT contents: List[Union[File, Folder]] = Field( [ ingredients.gitignore, From 1b2414102b63cf3044c1609e760d8224bea84a9b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 23 Feb 2024 18:40:54 +0000 Subject: [PATCH 2/5] Update toolmantim/release-drafter action to v6 (#30) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/release-management.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-management.yaml b/.github/workflows/release-management.yaml index 8deed18..df74da2 100644 --- a/.github/workflows/release-management.yaml +++ b/.github/workflows/release-management.yaml @@ -15,6 +15,6 @@ jobs: pull-requests: read steps: # Drafts your next Release notes as Pull Requests are merged into "master" - - uses: toolmantim/release-drafter@v5.25.0 + - uses: toolmantim/release-drafter@v6.0.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 57814da7bcb86979740c4c95f9faf36836984d93 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 23 Feb 2024 18:56:44 +0000 Subject: [PATCH 3/5] Update codecov/codecov-action action to v4 (#29) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/pipeline.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml index 7fd007b..25918f3 100644 --- a/.github/workflows/pipeline.yaml +++ b/.github/workflows/pipeline.yaml @@ -171,7 +171,7 @@ jobs: env: GITHUB_TOKEN: ${{ github.token}} - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: directory: ./reports/ flags: tests From c562ff4d0b875c250ed46978975e71872078bd7d Mon Sep 17 00:00:00 2001 From: David J Pugh <6003255+djpugh@users.noreply.github.com> Date: Fri, 23 Feb 2024 22:05:13 +0000 Subject: [PATCH 4/5] Fixing bug introduced by pydantic-settings 2.2.0+ (#36) --- pyproject.toml | 6 +++++- src/nskit/vcs/providers/azure_devops.py | 8 +++++++- src/nskit/vcs/providers/github.py | 18 ++++++++++++++++-- src/nskit/vcs/repo.py | 7 +++++++ src/nskit/vcs/settings.py | 8 +++++++- .../test_configuration/test_base_config.py | 19 +++++++++++++++++++ 6 files changed, 61 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 254ccd9..954a934 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,11 @@ dependencies = [ "logzero", "orjson", "pydantic[email]", - "pydantic-settings", + "pydantic-settings<2.2.0", + # This is not an ideal pin, but diue to the issue highlighted in https://github.com/pydantic/pydantic-settings/issues/245 + # and the non-semver compliant versioning in pydantic-settings, we need to add this pin + # this version would change the API behaviour for nskit as it will also ignore additional + # inputs in the python initialisation so We will pin to version < 2.2.0 "python-dotenv", "ruamel.yaml", "tomlkit", diff --git a/src/nskit/vcs/providers/azure_devops.py b/src/nskit/vcs/providers/azure_devops.py index 2550848..ab02528 100644 --- a/src/nskit/vcs/providers/azure_devops.py +++ b/src/nskit/vcs/providers/azure_devops.py @@ -18,7 +18,13 @@ class AzureDevOpsSettings(VCSProviderSettings): """Azure DevOps settings.""" - model_config = SettingsConfigDict(env_prefix='AZURE_DEVOPS_', env_file='.env') + # This is not ideal behaviour, but due to the issue highlighted in + # https://github.com/pydantic/pydantic-settings/issues/245 and the + # non-semver compliant versioning in pydantic-settings, we need to add this behaviour + # this now changes the API behaviour for these objects as they will + # also ignore additional inputs in the python initialisation + #  We will pin to version < 2.1.0 instead of allowing 2.2.0+ as it requires the code below: + model_config = SettingsConfigDict(env_prefix='AZURE_DEVOPS_', env_file='.env') # , extra='ignore') noqa: E800 url: HttpUrl = "https://dev.azure.com" organisation: str project: str diff --git a/src/nskit/vcs/providers/github.py b/src/nskit/vcs/providers/github.py index 61ca9d4..6fac67b 100644 --- a/src/nskit/vcs/providers/github.py +++ b/src/nskit/vcs/providers/github.py @@ -17,6 +17,14 @@ class GithubRepoSettings(BaseConfiguration): """Github Repo settings.""" + + # # This is not ideal behaviour, but due to the issue highlighted in + # # https://github.com/pydantic/pydantic-settings/issues/245 and the + # # non-semver compliant versioning in pydantic-settings, we need to add this behaviour + # # this now changes the API behaviour for these objects as they will + # # also ignore additional inputs in the python initialisation + # # We will pin to version < 2.1.0 instead of allowing 2.2.0+ as it requires the code below: + # model_config = ConfigDict(extra='ignore') noqa: E800 private: bool = True has_issues: Optional[bool] = None has_wiki: Optional[bool] = None @@ -34,12 +42,18 @@ class GithubSettings(VCSProviderSettings): Uses PAT token for auth (set in environment variables as GITHUB_TOKEN) """ - model_config = SettingsConfigDict(env_prefix='GITHUB_', env_file='.env') + # This is not ideal behaviour, but due to the issue highlighted in + # https://github.com/pydantic/pydantic-settings/issues/245 and the + # non-semver compliant versioning in pydantic-settings, we need to add this behaviour + # this now changes the API behaviour for these objects as they will + # also ignore additional inputs in the python initialisation + # We will pin to version < 2.1.0 instead of allowing 2.2.0+ as it requires the code below: + model_config = SettingsConfigDict(env_prefix='GITHUB_', env_file='.env') # extra='ignore') noqa: E800 interactive: bool = Field(False, description='Use Interactive Validation for token') url: HttpUrl = "https://api.github.com" organisation: Optional[str] = Field(None, description='Organisation to work in, otherwise uses the user for the token') token: SecretStr = Field(None, validate_default=True, description='Token to use for authentication, falls back to interactive device authentication if not provided') - repo: GithubRepoSettings = GithubRepoSettings() + repo: GithubRepoSettings = Field(default_factory=GithubRepoSettings) @property def repo_client(self) -> 'GithubRepoClient': diff --git a/src/nskit/vcs/repo.py b/src/nskit/vcs/repo.py index 219e0e6..07aaa7c 100644 --- a/src/nskit/vcs/repo.py +++ b/src/nskit/vcs/repo.py @@ -231,6 +231,13 @@ def install(self, codebase: Codebase | None = None, deps: bool = True): class NamespaceValidationRepo(_Repo): """Repo for managing namespace validation.""" + # # This is not ideal behaviour, but due to the issue highlighted in + # # https://github.com/pydantic/pydantic-settings/issues/245 and the + # # non-semver compliant versioning in pydantic-settings, we need to add this behaviour + # # this now changes the API behaviour for these objects as they will + # # also ignore additional inputs in the python initialisation + # # We will pin to version < 2.1.0 instead of allowing 2.2.0+ as it requires the code below: + # model_config = ConfigDict(extra='ignore') noqa: E800 name: str = '.namespaces' namespaces_filename: Union[str, Path] = 'namespaces.yaml' local_dir: Annotated[Path, Field(validate_default=True)] = None diff --git a/src/nskit/vcs/settings.py b/src/nskit/vcs/settings.py index ce6dcc3..e830100 100644 --- a/src/nskit/vcs/settings.py +++ b/src/nskit/vcs/settings.py @@ -24,7 +24,13 @@ class CodebaseSettings(BaseConfiguration): """Codebase settings object.""" - model_config = SettingsConfigDict(env_file='.env', env_prefix='NSKIT_VCS_CODEBASE_') + # This is not ideal behaviour, but due to the issue highlighted in + # https://github.com/pydantic/pydantic-settings/issues/245 and the + # non-semver compliant versioning in pydantic-settings, we need to add this behaviour + # this now changes the API behaviour for these objects as they will + # also ignore additional inputs in the python initialisation + # We will pin to version < 2.1.0 instead of allowing 2.2.0+ as it requires the code below: + model_config = SettingsConfigDict(env_file='.env', env_prefix='NSKIT_VCS_CODEBASE_') # , extra='ignore') default_branch: str = 'main' vcs_provider: Annotated[ProviderEnum, Field(validate_default=True)] = None diff --git a/tests/unit/test_common/test_configuration/test_base_config.py b/tests/unit/test_common/test_configuration/test_base_config.py index abbd1e8..d7a7d26 100644 --- a/tests/unit/test_common/test_configuration/test_base_config.py +++ b/tests/unit/test_common/test_configuration/test_base_config.py @@ -1,5 +1,7 @@ import unittest +from pydantic import ConfigDict + from nskit.common.configuration import BaseConfiguration from nskit.common.contextmanagers import ChDir from nskit.common.io import json, toml, yaml @@ -113,3 +115,20 @@ def test_dump_toml(self): def test_dump_yaml(self): self.assertEqual(self.expected.model_dump_yaml(), yaml.dumps(self.file_config)) + + def test_nested_properties(self): + + class ASettings(BaseConfiguration): + model_config = ConfigDict(extra='ignore') + c: str = 'a' + d: int = 1 + + @property + def a(self): + return True + class TestModel(BaseConfiguration): + a: ASettings + b: int + + t = TestModel(a=ASettings(), b=2) + From c7d99a2783ad7c08bdf58d971a407b5a9f610e7b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 23 Feb 2024 22:16:59 +0000 Subject: [PATCH 5/5] Update dependency pydantic-settings to <2.2.2 (#37) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 954a934..1986f4f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,7 @@ dependencies = [ "logzero", "orjson", "pydantic[email]", - "pydantic-settings<2.2.0", + "pydantic-settings<2.2.2", # This is not an ideal pin, but diue to the issue highlighted in https://github.com/pydantic/pydantic-settings/issues/245 # and the non-semver compliant versioning in pydantic-settings, we need to add this pin # this version would change the API behaviour for nskit as it will also ignore additional