Skip to content

Get rid of the "py" module dependency #77

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

Closed
wants to merge 1 commit into from
Closed

Get rid of the "py" module dependency #77

wants to merge 1 commit into from

Conversation

zentarim
Copy link

The "py" module is now in maintenance mode and should not be used in new code. Moreover, only one method from the "py" module is used in the pytest-timeout. I suppose it is better to try to remove this dependency.

Copy link
Member

@flub flub left a comment

Choose a reason for hiding this comment

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

Thanks, good idea!

Left some comments, and also please make sure the CI is happy with linting etc.

def _getdimensions():

if sys.version_info >= (3, 3, 0):
import shutil
Copy link
Member

Choose a reason for hiding this comment

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

Could we move the imports outside of the function together with the other imports? You can still use the if condition on the imports. Having the import machinery invoked in functions is not nice, it makes it much harder to know when what is happening and can result in weird locking issues and hard to debug circular import issues etc.

# pass to fallback below
pass

if width == 0:
Copy link
Member

Choose a reason for hiding this comment

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

Why have a sentinel of 0? You can just directly put the block of this if condition in the except block which I think is better style.

Comment on lines +454 to +456
except (KeyboardInterrupt, SystemExit, MemoryError, GeneratorExit):
raise
except:
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to do this rather than the more traditional single except clause?

except Exception:
    pass

Copy link
Member

@flub flub left a comment

Choose a reason for hiding this comment

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

Also, could you please add unittests for both these functions? Like make sure that _get_terminal_with() >= 40 and that _getdimension() returns some integer?

@@ -433,6 +432,43 @@ def dump_stacks():
write("".join(traceback.format_stack(frame)))


def _getdimensions():
Copy link
Member

Choose a reason for hiding this comment

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

I think this is more consistently named get_terminal_dimensions() given the other name (especially the consistency of when using underscores between words, the names are more bikesheddy and I don't mind as much).

Also no need to prefix either of these two functions with underscores here. This module does not have a public API and we haven't been doing this for other functions (uh, lol, that's not true, but probably should have been true)

@zentarim
Copy link
Author

Actually, I made a crude hack. I picked up these functions "as is" from the "py" codebase. Having a lot on my plate I can't dig deeper, but I hope I'll find some time to investigate and clean that hunk according to your demands.
But I have a question:
Do I need to maintain backward compatibility with Python2.7?

@flub
Copy link
Member

flub commented Oct 25, 2020 via email

@flub
Copy link
Member

flub commented Oct 25, 2020 via email

@@ -433,6 +432,43 @@ def dump_stacks():
write("".join(traceback.format_stack(frame)))


def _getdimensions():

if sys.version_info >= (3, 3, 0):
Copy link
Member

Choose a reason for hiding this comment

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

pytest-timeout only supports python 3.6+ now so this condition isn't needed

@flub
Copy link
Member

flub commented Oct 8, 2023

Can this be accomplished now?

@aqeelat
Copy link
Collaborator

aqeelat commented Oct 13, 2023

@flub this pr should no longer be needed since #116 got merged.

@flub
Copy link
Member

flub commented Oct 16, 2023

@flub this pr should no longer be needed since #116 got merged.

ah, thanks for noticing.
@aqeelat are you not able to close this yourself?

@flub flub closed this Oct 16, 2023
@aqeelat
Copy link
Collaborator

aqeelat commented Oct 19, 2023

@flub I can, but I prefer to get confirmation from another maintainer before closing PRs.

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.

4 participants