Skip to content
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

Update utilities.py #3514

Closed
wants to merge 1 commit into from
Closed

Update utilities.py #3514

wants to merge 1 commit into from

Conversation

MrVicknair
Copy link

added a minor correction to the way arguments get passed to the pkg_resources.path() function

minor correction to the way arguments get passed to the pkg_resources.path() function
@ktbyers
Copy link
Owner

ktbyers commented Oct 23, 2024

Why make this change?

named arguments are generally safer than positional arguments--was there something specific that was breaking that necessitates this?

@MrVicknair
Copy link
Author

MrVicknair commented Oct 24, 2024

I received an error while attempting to use the named argument 'package' with importlib.resources.path()

This behavior may be reproduced with python 3.13 , netmiko 4.4.0, ntc_templates 7.3.0

TypeError: path() got an unexpected keyword argument 'package'

This behavior can be seen while setting textFSM=True, while NET_TEXTFSM environment is NOT set i.e:
output = net_connect.send_command('show version', use_textfsm=True)

@MrVicknair
Copy link
Author

@ktbyers - While the proposed change does fix the issue I encountered, this code will never be ran with properly set NET_TEXTFSM environment value pointing to the ntc_templates\templates directory.

@MrVicknair MrVicknair closed this Oct 24, 2024
@ktbyers
Copy link
Owner

ktbyers commented Oct 24, 2024

Okay, I am going to re-open this as I want to reproduce the issue/behavior. I am suspecting it is a Python 3.13 change (that I haven't tested/fixed yet).

@ktbyers ktbyers reopened this Oct 24, 2024
@ktbyers
Copy link
Owner

ktbyers commented Oct 31, 2024

If you are running Python 3.13, this code (which is already in Netmiko) will be run anyways:

        try:
            # 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()

In other words, this fix has already been implemented.

@ktbyers ktbyers closed this Oct 31, 2024
@ktbyers
Copy link
Owner

ktbyers commented Oct 31, 2024

Fix is here:

MrVicknair@92ca035

it is only in the develop branch right now.

@MrVicknair MrVicknair deleted the patch-1 branch October 31, 2024 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants