Skip to content

Commit

Permalink
Merge branch 'main' into fix/namespace_validator_from_env
Browse files Browse the repository at this point in the history
  • Loading branch information
djpugh authored Feb 25, 2024
2 parents 4db5af6 + c7d99a2 commit c76a979
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-management.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ dependencies = [
"logzero",
"orjson",
"pydantic[email]",
"pydantic-settings",
"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
# inputs in the python initialisation so We will pin to version < 2.2.0
"python-dotenv",
"ruamel.yaml",
"tomlkit",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions src/nskit/recipes/python/ingredients/pyproject.toml.template
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ dev-docs = [
"mkdocs-git-authors-plugin",
"mkdocs-coverage",
"mkdocs-include-markdown-plugin",
"mkdocs-github-changelog",
"mkdocs-licenseinfo",
"mike"
]
dev-build = [
Expand Down
Original file line number Diff line number Diff line change
@@ -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() }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
2 changes: 2 additions & 0 deletions src/nskit/recipes/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
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


class RecipeRecipe(PyRecipe):
"""A Recipe for creating Recipes, meta!"""

recipe_entrypoint: str = RECIPE_ENTRYPOINT
contents: List[Union[File, Folder]] = Field(
[
ingredients.gitignore,
Expand Down
8 changes: 7 additions & 1 deletion src/nskit/vcs/providers/azure_devops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions src/nskit/vcs/providers/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
class GithubRepoSettings(BaseConfiguration):
"""Github Repo settings."""
model_config = SettingsConfigDict(env_prefix='GITHUB_REPO', env_file='.env')

private: bool = True
has_issues: Optional[bool] = None
has_wiki: Optional[bool] = None
Expand All @@ -35,12 +36,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':
Expand Down
7 changes: 7 additions & 0 deletions src/nskit/vcs/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/nskit/vcs/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/test_common/test_configuration/test_base_config.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

0 comments on commit c76a979

Please sign in to comment.