Skip to content

Commit

Permalink
Fix pkgresources on PY3.13 (#3492)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktbyers authored Sep 2, 2024
1 parent de986f4 commit 92ca035
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion netmiko/scp_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def progress_bar(

# Percentage done
percent_complete = sent / size
percent_str = f"{percent_complete*100:.2f}%"
percent_str = f"{percent_complete * 100:.2f}%"
hash_count = int(percent_complete * max_width)
progress = hash_count * ">"

Expand Down
26 changes: 17 additions & 9 deletions netmiko/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,23 @@ def get_template_dir(_skip_ntc_package: bool = False) -> str:
else:
# Try 'pip installed' ntc-templates
try:
with pkg_resources.path(
package="ntc_templates", resource="parse.py"
) as posix_path:
# Example: /opt/venv/netmiko/lib/python3.8/site-packages/ntc_templates/templates
template_dir = str(posix_path.parent.joinpath("templates"))
# This is for Netmiko automated testing
if _skip_ntc_package:
raise ModuleNotFoundError()

# New API for Python 3.13+
if sys.version_info >= (3, 13):
with pkg_resources.path("ntc_templates", "parse.py") as posix_path:
# Example: /venv/netmiko/lib/python3.13/site-packages/ntc_templates/templates
template_dir = str(posix_path.parent.joinpath("templates"))
# This is for Netmiko automated testing
if _skip_ntc_package:
raise ModuleNotFoundError()
else:
with pkg_resources.path(
package="ntc_templates", resource="parse.py"
) as posix_path:
# Example: /opt/venv/netmiko/lib/python3.9/site-packages/ntc_templates/templates
template_dir = str(posix_path.parent.joinpath("templates"))
# This is for Netmiko automated testing
if _skip_ntc_package:
raise ModuleNotFoundError()
except ModuleNotFoundError:
# Finally check in ~/ntc-templates/ntc_templates/templates
home_dir = os.path.expanduser("~")
Expand Down

0 comments on commit 92ca035

Please sign in to comment.