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

Use file object directly in temporary_config() #1598

Merged
merged 6 commits into from
Jun 21, 2024

Conversation

philip-paul-mueller
Copy link
Collaborator

The context manager uses NamedTemporaryFile to store the current configuration, to later restore them. Instead of passing the file object directly to the save function, it just passes the file name, i.e. the save (and the load function) will open the file again, which is in itself not a problem. However, on the Github Windows image this leads to a permission error (using the created file object is fine).

This commit solves this by adding the file argument to Config.save() that allows to pass a file object directly to the function. The same change is applied to the load function of the config object.

The context manager uses `NamedTemporaryFile` to store the current configuration, to later restore them.
Instead of passing the file object directly to the save function, it just passes the file name, i.e. the save (and the load function) will open the file again, which is in itself not a problem.
However, on the Github Windows image this leads to a permission error (using the created file object is fine).

This commit solves this by adding the `file` argument to `Config.save()` that allows to pass a file object directly to the function.
The same change is applied to the load function of the config object.
philip-paul-mueller added a commit to philip-paul-mueller/jace that referenced this pull request Jun 17, 2024
It is known that DaCe does not work out of the box on [MacOSX](https://spcldace.readthedocs.io/en/latest/setup/installation.html#common-issues-with-the-dace-python-module) and [Windows](spcl/dace#1598).
Furthermore, since JaCe is a pure Python project we relay on the portability of DaCe and Jax and in the end Python.
Thus every crossplatform problem should be handled by DaCe and Jax and not JaCe.
@tbennun tbennun changed the title Fixed an error in the temporary_config() context manager. Fix an error in the temporary_config() context manager Jun 20, 2024
@tbennun tbennun changed the title Fix an error in the temporary_config() context manager Use file object directly in temporary_config() Jun 20, 2024
@@ -39,10 +40,11 @@ def temporary_config():
Config.set("optimizer", "autooptimize", value=True)
foo()
"""
with tempfile.NamedTemporaryFile() as fp:
Config.save(fp.name)
with tempfile.NamedTemporaryFile(mode='w+t') as fp:
Copy link
Collaborator

Choose a reason for hiding this comment

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

what does 't' mean in mode?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It means text mode, on UNIX \n is the newline character, but on Windows it is \r\n (https://en.wikipedia.org/wiki/Newline#Representation). In that mode \r\n is transformed into \n it is essentially a compatibility layer, see help(open).
I used it because it preserves old behaviour, but it is probably not needed.

@tbennun tbennun added this pull request to the merge queue Jun 21, 2024
Merged via the queue into spcl:master with commit 6a490ec Jun 21, 2024
10 checks passed
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