Skip to content

fix: Use getattr for tcl/tk library paths #2945

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

Merged
merged 4 commits into from
Aug 14, 2025

Conversation

esafak
Copy link
Contributor

@esafak esafak commented Aug 6, 2025

  • Safely access tcl_lib and tk_lib attributes on the interpreter.
  • This prevents AttributeError if these attributes are not present.
  • Applied to nushell, bash, fish, and via_template activation scripts.

Fixes #2944

  • ran the linter to address style issues (tox -e fix)
  • wrote descriptive pull request text
  • ensured there are test(s) validating the fix
  • added news fragment in docs/changelog folder
  • updated/extended the documentation

* Safely access tcl_lib and tk_lib attributes on the interpreter.
* This prevents AttributeError if these attributes are not present.
* Applied to nushell, bash, fish, and via_template activation scripts.

Fixes pypa#2944

Signed-off-by: Emre Şafak <[email protected]>
@@ -15,8 +15,8 @@ def as_name(self, template):
def replacements(self, creator, dest):
data = super().replacements(creator, dest)
data.update({
"__TCL_LIBRARY__": creator.interpreter.tcl_lib or "",
"__TK_LIBRARY__": creator.interpreter.tk_lib or "",
"__TCL_LIBRARY__": getattr(creator.interpreter, "tcl_lib", ""),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come these can be not present?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, I asked the reporter for the logs.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't understand why, but here is an example of a failing build: https://github.com/douwevandermeij/test-virtualenv/actions/runs/16797823289/job/47572059324

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a Poetry problem

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a Poetry problem

Open an issue there please 🤔 and link it to this.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look like a poetry problem, PythonInfo is constructed and used only by virtualenv code, it is hard for me to guess how this would be anything but a virtualenv problem.

I expect you have some path that fails to populate the new fields. Probably the stuff that gets it from cache.

@gaborbernat gaborbernat marked this pull request as draft August 6, 2025 20:49
esafak and others added 3 commits August 6, 2025 17:54
@gaborbernat gaborbernat marked this pull request as ready for review August 14, 2025 15:50
@gaborbernat gaborbernat merged commit dad9369 into pypa:main Aug 14, 2025
42 checks passed
@esafak esafak deleted the fix/2944-attribute-error branch August 14, 2025 15:54
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.

AttributeError in version 20.33.1: 'PythonInfo' object has no attribute 'tcl_lib'
4 participants