Skip to content

Commit

Permalink
CI: Add Ruff config and fix tons of linting issues (aristanetworks#4310)
Browse files Browse the repository at this point in the history
Co-authored-by: Guillaume Mulocher <[email protected]>
  • Loading branch information
2 people authored and jrecchia1029 committed Aug 14, 2024
1 parent 5c83137 commit 0d5f35d
Show file tree
Hide file tree
Showing 305 changed files with 4,259 additions and 4,334 deletions.
42 changes: 23 additions & 19 deletions .github/generate_release.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
"""
generate_release.py
generate_release.py.
This script is used to generate the release.yml file as per
https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes
"""

from pathlib import Path
from typing import Any

import yaml

SCOPES = [
Expand Down Expand Up @@ -37,23 +40,24 @@
"Fix": "Bug Fixes",
"Cut": "Cut",
"Doc": "Documentation",
# "CI": "CI",
# Excluding "CI": "CI",
"Bump": "Bump",
# "Test": "Test",
# Excluding "Test": "Test",
"Revert": "Revert",
"Refactor": "Refactoring",
}


class SafeDumper(yaml.SafeDumper):
"""
Make yamllint happy
Make yamllint happy.
https://github.com/yaml/pyyaml/issues/234#issuecomment-765894586
"""

# pylint: disable=R0901,W0613,W1113

def increase_indent(self, flow=False, *args, **kwargs):
def increase_indent(self, flow: bool = False, *_args: Any, **_kwargs: Any) -> None:
return super().increase_indent(flow=flow, indentless=False)


Expand Down Expand Up @@ -89,22 +93,22 @@ def increase_indent(self, flow=False, *args, **kwargs):
{
"title": "Breaking Changes",
"labels": breaking_labels,
}
},
)
# Add fixes in eos_cli_config_gen
categories_list.append(
{
"title": "Fixed issues in eos_cli_config_gen",
"labels": ["rn: Fix(eos_cli_config_gen)"],
}
},
)

# Add fixes in eos_designs
categories_list.append(
{
"title": "Fixed issues in eos_designs",
"labels": ["rn: Fix(eos_designs)"],
}
},
)
# Add fixes in eos_cli_config_gen|eos_designs or eos_designs|eos_cli_config_gen
categories_list.append(
Expand All @@ -114,7 +118,7 @@ def increase_indent(self, flow=False, *args, **kwargs):
"rn: Fix(eos_cli_config_gen|eos_designs)",
"rn: Fix(eos_designs|eos_cli_config_gen)",
],
}
},
)

# Add other fixes
Expand All @@ -125,7 +129,7 @@ def increase_indent(self, flow=False, *args, **kwargs):
{
"title": "Other Fixed issues",
"labels": other_fixes_labels,
}
},
)

# Add Documentation - except for PyAVD
Expand All @@ -136,23 +140,23 @@ def increase_indent(self, flow=False, *args, **kwargs):
{
"title": "Documentation",
"labels": doc_labels,
}
},
)

# Add new features in eos_cli_config_gen
categories_list.append(
{
"title": "New features and enhancements in eos_cli_config_gen",
"labels": ["rn: Feat(eos_cli_config_gen)"],
}
},
)

# Add new features in eos_designs
categories_list.append(
{
"title": "New features and enhancements in eos_designs",
"labels": ["rn: Feat(eos_designs)"],
}
},
)

# Add new features in both eos_cli_config_gen|eos_designs or eos_designs|eos_cli_config_gen
Expand All @@ -163,7 +167,7 @@ def increase_indent(self, flow=False, *args, **kwargs):
"rn: Feat(eos_cli_config_gen|eos_designs)",
"rn: Feat(eos_designs|eos_cli_config_gen)",
],
}
},
)

# Add other new features
Expand All @@ -174,7 +178,7 @@ def increase_indent(self, flow=False, *args, **kwargs):
{
"title": "Other new features and enhancements",
"labels": other_feat_labels,
}
},
)

# Add all PyAVD changes
Expand All @@ -183,23 +187,23 @@ def increase_indent(self, flow=False, *args, **kwargs):
{
"title": "PyAVD Changes",
"labels": pyavd_labels,
}
},
)

# Add the catch all
categories_list.append(
{
"title": "Other Changes",
"labels": ["*"],
}
},
)
with open(r"release.yml", "w", encoding="utf-8") as release_file:
with Path("release.yml").open("w", encoding="utf-8") as release_file:
yaml.dump(
{
"changelog": {
"exclude": {"labels": exclude_list},
"categories": categories_list,
}
},
},
release_file,
Dumper=SafeDumper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@

class CustomAvdInterfaceDescriptions(AvdInterfaceDescriptions):
@cached_property
def _custom_description_prefix(self):
def _custom_description_prefix(self) -> str:
return get(self._hostvars, "description_prefix", "")

@cached_property
def _switch_type(self):
def _switch_type(self) -> str:
return get(self._hostvars, "switch.type", "")

def underlay_ethernet_interfaces(self, link_type: str, link_peer: str, link_peer_interface: str) -> str:
"""
Implementation of custom code similar to jinja in
custom_templates/interface_descriptions/underlay/ethernet-interfaces.j2
"""
"""Implementation of custom code similar to jinja in custom_templates/interface_descriptions/underlay/ethernet-interfaces.j2."""
link_peer = str(link_peer).upper()
if link_type == "underlay_p2p":
return f"{self._custom_description_prefix}_P2P_LINK_TO_{link_peer}_{link_peer_interface}"
Expand All @@ -33,10 +30,11 @@ def underlay_ethernet_interfaces(self, link_type: str, link_peer: str, link_peer

return ""

def underlay_port_channel_interfaces(self, link_peer: str, link_peer_channel_group_id: int, link_channel_description: str) -> str:
def underlay_port_channel_interfaces(self, link_peer: str, link_peer_channel_group_id: int, link_channel_description: str | None) -> str:
"""
Implementation of custom code similar to jinja:
custom_templates/interface_descriptions/underlay/port-channel-interfaces.j2
Implementation of custom code similar to jinja.
custom_templates/interface_descriptions/underlay/port-channel-interfaces.j2.
"""
if link_channel_description is not None:
link_channel_description = str(link_channel_description).upper()
Expand All @@ -47,45 +45,48 @@ def underlay_port_channel_interfaces(self, link_peer: str, link_peer_channel_gro

def mlag_ethernet_interfaces(self, mlag_interface: str) -> str:
"""
Implementation of custom code similar to jinja:
custom_templates/interface_descriptions/mlag/ethernet-interfaces.j2
Implementation of custom code similar to jinja.
custom_templates/interface_descriptions/mlag/ethernet-interfaces.j2.
"""
return f"{self._custom_description_prefix}_MLAG_PEER_{self._mlag_peer}_{mlag_interface}"

def mlag_port_channel_interfaces(self) -> str:
"""
Implementation of custom code similar to jinja:
custom_templates/interface_descriptions/mlag/port-channel-interfaces.j2
Implementation of custom code similar to jinja.
custom_templates/interface_descriptions/mlag/port-channel-interfaces.j2.
"""
return f"{self._custom_description_prefix}_MLAG_PEER_{self._mlag_peer}_Po{self._mlag_port_channel_id}"

def connected_endpoints_ethernet_interfaces(self, peer: str = None, peer_interface: str = None) -> str:
def connected_endpoints_ethernet_interfaces(self, peer: str | None = None, peer_interface: str | None = None) -> str:
"""
Implementation of custom code similar to jinja:
custom_templates/interface_descriptions/connected-endpoints/ethernet-interfaces.j2
Implementation of custom code similar to jinja.
custom_templates/interface_descriptions/connected-endpoints/ethernet-interfaces.j2.
"""
elements = [peer, peer_interface]
return "_".join([str(element) for element in elements if element is not None])

def connected_endpoints_port_channel_interfaces(self, peer: str = None, adapter_port_channel_description: str = None) -> str:
def connected_endpoints_port_channel_interfaces(self, peer: str | None = None, adapter_port_channel_description: str | None = None) -> str:
"""
Implementation of custom code similar to jinja:
custom_templates/interface_descriptions/connected-endpoints/port-channel-interfaces.j2
Implementation of custom code similar to jinja.
custom_templates/interface_descriptions/connected-endpoints/port-channel-interfaces.j2.
"""
elements = [self._custom_description_prefix, peer, adapter_port_channel_description]
return "_".join([str(element) for element in elements if element is not None])

def overlay_loopback_interface(self, overlay_loopback_description: str = None) -> str:
def overlay_loopback_interface(self, overlay_loopback_description: str | None = None) -> str: # noqa: ARG002
"""
Implementation of custom code similar to jinja:
custom_templates/interface_descriptions/loopbacks/overlay-loopback.j2
Implementation of custom code similar to jinja.
custom_templates/interface_descriptions/loopbacks/overlay-loopback.j2.
"""
switch_type = str(self._switch_type).upper()
return f"{self._custom_description_prefix}_EVPN_Overlay_Peering_{switch_type}"

def vtep_loopback_interface(self) -> str:
"""
Implementation of custom code similar to jinja:
"""
"""Implementation of custom code similar to jinja."""
switch_type = str(self._switch_type).upper()
return f"{self._custom_description_prefix}_VTEP_VXLAN_Tunnel_Source_{switch_type}"
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class CustomAvdInterfaceDescriptions(AvdInterfaceDescriptions):
@cached_property
def _custom_description_prefix(self):
def _custom_description_prefix(self) -> str:
return get(self._hostvars, "description_prefix", "")

def underlay_ethernet_interface(self, data: InterfaceDescriptionData) -> str:
Expand Down Expand Up @@ -120,20 +120,23 @@ def connected_endpoints_port_channel_interface(self, data: InterfaceDescriptionD

def router_id_loopback_interface(self, data: InterfaceDescriptionData) -> str:
"""
Called per device.
Available data:
- description
- mpls_overlay_role
- mpls_lsr
- overlay_routing_protocol
- type
- description
- mpls_overlay_role
- mpls_lsr
- overlay_routing_protocol
- type
"""
switch_type = str(data.type).upper()
return f"{self._custom_description_prefix}_EVPN_Overlay_Peering_{switch_type}"

def vtep_loopback_interface(self) -> str:
"""
Implementation of custom code similar to jinja.
TODO: AVD5.0.0 Update to use InterfaceDescriptionData
TODO: AVD5.0.0 Update to use InterfaceDescriptionData.
"""
switch_type = str(self.shared_utils.type).upper()
return f"{self._custom_description_prefix}_VTEP_VXLAN_Tunnel_Source_{switch_type}"
Loading

0 comments on commit 0d5f35d

Please sign in to comment.