-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat(plugins): Add python classes built from schemas #4603
base: devel
Are you sure you want to change the base?
Feat(plugins): Add python classes built from schemas #4603
Conversation
Review docs on Read the Docs To test this pull request: # Create virtual environment for this testing below the current directory
python -m venv test-avd-pr-4603
# Activate the virtual environment
source test-avd-pr-4603/bin/activate
# Install all requirements including PyAVD
pip install "pyavd[ansible] @ git+https://github.com/ClausHolbechArista/avd.git@schemas-as-classes-no-validation-nested#subdirectory=python-avd" --force
# Point Ansible collections path to the Python virtual environment
export ANSIBLE_COLLECTIONS_PATH=$VIRTUAL_ENV/ansible_collections
# Install Ansible collection
ansible-galaxy collection install git+https://github.com/ClausHolbechArista/avd.git#/ansible_collections/arista/avd/,schemas-as-classes-no-validation-nested --force
# Optional: Install AVD examples
cd test-avd-pr-4603
ansible-playbook arista.avd.install_examples |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
2ca3b9b
to
bfeca85
Compare
Conflicts have been resolved. A maintainer will review the pull request shortly. |
b103dd9
to
032572f
Compare
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Conflicts have been resolved. A maintainer will review the pull request shortly. |
6de1bee
to
e101cc8
Compare
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
15b7c65
to
c0188b3
Compare
Conflicts have been resolved. A maintainer will review the pull request shortly. |
Conflicts have been resolved. A maintainer will review the pull request shortly. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very partial review so far ona couple of classes will carry on
|
||
|
||
class AvdBase: | ||
_is_avd_class: bool = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed? Could we not just use isinstance(foo, AvdBase)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will see it later in other functions where we wish to avoid circular imports.
if value is not None and not isinstance(value, field_type): | ||
msg = f"Invalid type '{type(value)}. Expected '{field_type}'. Value '{value}" | ||
raise TypeError(msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so it means we revalidate the type here in addtition to in the schema?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should never happen as long as the schema tooling ran first. But yes, it is a safeguard in case of validation running with warnings and we cannot coerce.
fa548bb
to
58413d5
Compare
Conflicts have been resolved. A maintainer will review the pull request shortly. |
for more information, see https://pre-commit.ci
|
||
dict_fields_src = [f'"type": {field_type}'] | ||
if field_type == "list": | ||
items_type = self.type_hints[0].list_item_type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so here it assumes that the first type_hints is always a list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes since field_type comes from the same place it will always be the case.
""" | ||
|
||
name: str | ||
type_hint: FieldTypeHintSrc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so no Union here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you mean we only accept a single type hint for the class var, and yes that is all we need.
if field.description: | ||
description = ( | ||
"\n".join(wrap(field.description, width=100, replace_whitespace=False)) | ||
.replace("Example:\n", "Example: # fmt: skip\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the fmt: skip
? is it for ruff?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we have any of these things in our descriptions, ruff picks it up as a docstring heading, so it messes up everything. Took quite some fiddling to get this working :)
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
dc8300a
to
3016e5a
Compare
Quality Gate passedIssues Measures |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Change Summary
Add python classes built from schemas
Component(s) name
arista.avd.eos_designs
arista.avd.eos_cli_config_gen
Proposed changes
eos_designs
plugins and classes to load inputs into anEosDesigns
class instance.EosDesigns
class - as a POC.How to test
No changes to molecule.
Checklist
User Checklist
Repository Checklist