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

grass.jupyter: Use weakref.finalize to manage TemporaryDirectory #2206

Merged
merged 6 commits into from
Feb 14, 2022

Conversation

wenzeslaus
Copy link
Member

@wenzeslaus wenzeslaus commented Feb 13, 2022

Although tempfile.TemporaryDirectory uses weakref.finalize to delete the directory and its documentation does mention deletion during garbage-collection and during interpreter shutdown, the intention in its source code is that a with statement or explicit cleanup call is made because otherwise it generates a warning about implicit deletion. Pylint correctly generates warning suggesting with statement (consider-using-with).

In the future, we may consider implementing context-manager and cleanup method to the render classes, but even with that we need to stretch the existence of the temporary directory beyond one method, so the with statement is not applicable. For now, the classes are using only weakref.finalize which is sufficient for a notebook where the object life time is linked with the notebook's kernel life time which is relatively short. The Pylint warning is disabled and an explanatory comment is above.

Use UTF-8 as encoding for text files (JSON files here) in grass.benchmark result reading and writing. This explicitly specifies an encoding and thus it avoids unspecified-encoding warning from Pylint.
Although tempfile.TemporaryDirectory uses weakref.finalize to delete the directory and its documentation does mention deletion during garbage-collection and during interpreter shutdown, the intention in its source code is that a with statement or explicit cleanup call is made because otherwise it generates a warning about implicit deletion. Pylint correctly generates warning suggesting with statement (consider-using-with).

In the future, we may consider implementing context-manager and cleanup method to the render classes, but even with that we need to stretch the existence of the temporary directory beyond one method, so the with statement is not applicable. For now, the classes are using only weakref.finalize which is sufficient for a notebook where the object life time is linked with the notebook's kernel life time which is relatively short. The Pylint warning is disabled and an explanatory comment is above.
@wenzeslaus wenzeslaus changed the title use finalizer to handle tmpdir grass.jupyter: Use weakref.finalize to manage TemporaryDirectory Feb 13, 2022
@wenzeslaus wenzeslaus added bug Something isn't working Python Related code is in Python labels Feb 13, 2022
@wenzeslaus wenzeslaus added this to the 8.2.0 milestone Feb 13, 2022
@wenzeslaus
Copy link
Member Author

@chaedri Can you please look at this?

Copy link
Contributor

@chaedri chaedri left a comment

Choose a reason for hiding this comment

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

@wenzeslaus Looks good to me! I'll implement something similar in the space time dataset visualizations and interactive displays.

@wenzeslaus wenzeslaus merged commit 74aac0a into OSGeo:main Feb 14, 2022
@wenzeslaus wenzeslaus deleted the use-finalizer-to-handle-tmpdir branch February 14, 2022 22:01
wenzeslaus added a commit that referenced this pull request Feb 15, 2022
This adds Pylint check job in a new workflow. It uses the current latest Pylint and latest Python. It uses Pylint to check for minimal supported Python version.

The check runs for the grass package (python/grass) and for wxGUI (gui/wxpython). However, most of the files are ignored. Each of the directories has its own .pylintrc file.

Pylint runs for grass.jupyter and grass.benchmark with only slightly modified configuration after fixes in targeted files (#2199, #2200, #2201, #2206). The approach for future compliance is that the other sub-packages should also eventually comply with default or almost default configuration.

For wxGUI, many Pylint messages are disabled and numbers driving coding standard limits, such as max number of local variables, are greatly loosened. Many of the disabled messages show real errors, but ignoring these for now allowed for enabling the check right away at least for the least problematic directories. The approach for future compliance is that new directories can be added (removed from ignore paths) and new issues can be checked (removed from disable) when fixed.

This compiles the code. Just testing Python functions from the grass package in the python directory does not require compiled code and package on path when started from the python directory, but checking other files requires packages on path.

The config file is in the python directory because that's the focus of this PR. (In the future, GUI may have a different config file, e.g., due to different naming conventions. On the other hand, in an ideal case, the whole source code will use this file or even a more strict version of this file in the future.)

Pylint should produce warning for disabled warnings which are not generated, although that seems to not be the case right now (useless-suppression).

The only code change here is that Pylint disable comment needs to be on the same line or inside ().

It needs to install also all optional Python dependencies because Pylint checks (can check unless disabled) all imports. This change is applied also to pytest workflow.

Using workflow on settings to run on push only to main and release branches and semver tags.

It uses strategy.matrix.include to get job-level config variables without using environmental variables.
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Oct 26, 2022
…Geo#2206)

Although tempfile.TemporaryDirectory uses weakref.finalize to delete the directory and its documentation does mention deletion during garbage-collection and during interpreter shutdown, the intention in its source code is that a with statement is used or explicit cleanup call is made because otherwise it generates a warning about implicit deletion. Pylint correctly generates warning suggesting with statement (consider-using-with).

In the future, we may consider implementing context-manager and cleanup method to the render classes, but even with that we need to stretch the existence of the temporary directory beyond one method, so the with statement is not applicable. For now, the classes are using only weakref.finalize which is sufficient for a notebook where the object life time is linked with the notebook's kernel life time which is relatively short. The Pylint warning is disabled and an explanatory comment is above.
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Oct 26, 2022
This adds Pylint check job in a new workflow. It uses the current latest Pylint and latest Python. It uses Pylint to check for minimal supported Python version.

The check runs for the grass package (python/grass) and for wxGUI (gui/wxpython). However, most of the files are ignored. Each of the directories has its own .pylintrc file.

Pylint runs for grass.jupyter and grass.benchmark with only slightly modified configuration after fixes in targeted files (OSGeo#2199, OSGeo#2200, OSGeo#2201, OSGeo#2206). The approach for future compliance is that the other sub-packages should also eventually comply with default or almost default configuration.

For wxGUI, many Pylint messages are disabled and numbers driving coding standard limits, such as max number of local variables, are greatly loosened. Many of the disabled messages show real errors, but ignoring these for now allowed for enabling the check right away at least for the least problematic directories. The approach for future compliance is that new directories can be added (removed from ignore paths) and new issues can be checked (removed from disable) when fixed.

This compiles the code. Just testing Python functions from the grass package in the python directory does not require compiled code and package on path when started from the python directory, but checking other files requires packages on path.

The config file is in the python directory because that's the focus of this PR. (In the future, GUI may have a different config file, e.g., due to different naming conventions. On the other hand, in an ideal case, the whole source code will use this file or even a more strict version of this file in the future.)

Pylint should produce warning for disabled warnings which are not generated, although that seems to not be the case right now (useless-suppression).

The only code change here is that Pylint disable comment needs to be on the same line or inside ().

It needs to install also all optional Python dependencies because Pylint checks (can check unless disabled) all imports. This change is applied also to pytest workflow.

Using workflow on settings to run on push only to main and release branches and semver tags.

It uses strategy.matrix.include to get job-level config variables without using environmental variables.
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Feb 17, 2023
…Geo#2206)

Although tempfile.TemporaryDirectory uses weakref.finalize to delete the directory and its documentation does mention deletion during garbage-collection and during interpreter shutdown, the intention in its source code is that a with statement is used or explicit cleanup call is made because otherwise it generates a warning about implicit deletion. Pylint correctly generates warning suggesting with statement (consider-using-with).

In the future, we may consider implementing context-manager and cleanup method to the render classes, but even with that we need to stretch the existence of the temporary directory beyond one method, so the with statement is not applicable. For now, the classes are using only weakref.finalize which is sufficient for a notebook where the object life time is linked with the notebook's kernel life time which is relatively short. The Pylint warning is disabled and an explanatory comment is above.
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Feb 17, 2023
This adds Pylint check job in a new workflow. It uses the current latest Pylint and latest Python. It uses Pylint to check for minimal supported Python version.

The check runs for the grass package (python/grass) and for wxGUI (gui/wxpython). However, most of the files are ignored. Each of the directories has its own .pylintrc file.

Pylint runs for grass.jupyter and grass.benchmark with only slightly modified configuration after fixes in targeted files (OSGeo#2199, OSGeo#2200, OSGeo#2201, OSGeo#2206). The approach for future compliance is that the other sub-packages should also eventually comply with default or almost default configuration.

For wxGUI, many Pylint messages are disabled and numbers driving coding standard limits, such as max number of local variables, are greatly loosened. Many of the disabled messages show real errors, but ignoring these for now allowed for enabling the check right away at least for the least problematic directories. The approach for future compliance is that new directories can be added (removed from ignore paths) and new issues can be checked (removed from disable) when fixed.

This compiles the code. Just testing Python functions from the grass package in the python directory does not require compiled code and package on path when started from the python directory, but checking other files requires packages on path.

The config file is in the python directory because that's the focus of this PR. (In the future, GUI may have a different config file, e.g., due to different naming conventions. On the other hand, in an ideal case, the whole source code will use this file or even a more strict version of this file in the future.)

Pylint should produce warning for disabled warnings which are not generated, although that seems to not be the case right now (useless-suppression).

The only code change here is that Pylint disable comment needs to be on the same line or inside ().

It needs to install also all optional Python dependencies because Pylint checks (can check unless disabled) all imports. This change is applied also to pytest workflow.

Using workflow on settings to run on push only to main and release branches and semver tags.

It uses strategy.matrix.include to get job-level config variables without using environmental variables.
neteler pushed a commit to nilason/grass that referenced this pull request Nov 7, 2023
…Geo#2206)

Although tempfile.TemporaryDirectory uses weakref.finalize to delete the directory and its documentation does mention deletion during garbage-collection and during interpreter shutdown, the intention in its source code is that a with statement is used or explicit cleanup call is made because otherwise it generates a warning about implicit deletion. Pylint correctly generates warning suggesting with statement (consider-using-with).

In the future, we may consider implementing context-manager and cleanup method to the render classes, but even with that we need to stretch the existence of the temporary directory beyond one method, so the with statement is not applicable. For now, the classes are using only weakref.finalize which is sufficient for a notebook where the object life time is linked with the notebook's kernel life time which is relatively short. The Pylint warning is disabled and an explanatory comment is above.
neteler pushed a commit to nilason/grass that referenced this pull request Nov 7, 2023
This adds Pylint check job in a new workflow. It uses the current latest Pylint and latest Python. It uses Pylint to check for minimal supported Python version.

The check runs for the grass package (python/grass) and for wxGUI (gui/wxpython). However, most of the files are ignored. Each of the directories has its own .pylintrc file.

Pylint runs for grass.jupyter and grass.benchmark with only slightly modified configuration after fixes in targeted files (OSGeo#2199, OSGeo#2200, OSGeo#2201, OSGeo#2206). The approach for future compliance is that the other sub-packages should also eventually comply with default or almost default configuration.

For wxGUI, many Pylint messages are disabled and numbers driving coding standard limits, such as max number of local variables, are greatly loosened. Many of the disabled messages show real errors, but ignoring these for now allowed for enabling the check right away at least for the least problematic directories. The approach for future compliance is that new directories can be added (removed from ignore paths) and new issues can be checked (removed from disable) when fixed.

This compiles the code. Just testing Python functions from the grass package in the python directory does not require compiled code and package on path when started from the python directory, but checking other files requires packages on path.

The config file is in the python directory because that's the focus of this PR. (In the future, GUI may have a different config file, e.g., due to different naming conventions. On the other hand, in an ideal case, the whole source code will use this file or even a more strict version of this file in the future.)

Pylint should produce warning for disabled warnings which are not generated, although that seems to not be the case right now (useless-suppression).

The only code change here is that Pylint disable comment needs to be on the same line or inside ().

It needs to install also all optional Python dependencies because Pylint checks (can check unless disabled) all imports. This change is applied also to pytest workflow.

Using workflow on settings to run on push only to main and release branches and semver tags.

It uses strategy.matrix.include to get job-level config variables without using environmental variables.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Python Related code is in Python
Development

Successfully merging this pull request may close these issues.

2 participants