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

fix #313 remove handle #315

Merged
merged 6 commits into from
May 5, 2022
Merged

fix #313 remove handle #315

merged 6 commits into from
May 5, 2022

Conversation

sygout
Copy link
Collaborator

@sygout sygout commented Dec 1, 2021

Description:

Type of change:

  • Bug fix.
  • New feature.
  • Documentation update.

Checklist:

This checklist can be used as a help for the reviewer.

  • Is the code easy to read and understand?
  • Are comments for humans to read, not computers to disregard?
  • Does a new feature has an accompanying new test (in the CI or unit testing schemes)?
  • Has the documentation been updated as necessary?
  • Does this close the issue?
  • Is the change limited to the issue?
  • Are errors handled for all outcomes?
  • Does the new feature provide new restrictions on dependencies, and if so is this documented?

Comments:

the following code creates a problem on Windows:

with tempfile.NamedTemporaryFile(suffix=".owl") as handle:
   super().save(file=handle.name, format="rdfxml", **kwargs)
   graph = rdflib.Graph() 
   graph.parse(handle.name, format="xml") 
   graph.serialize(destination=filename, format=format)

It is related to an issue with tempfile library. The problem comes from reopening the temporary file. the first line create and open the file. so the modification simply create a file name located in the temporary folder and use that path for the successive operations.

@sygout sygout linked an issue Dec 1, 2021 that may be closed by this pull request
Copy link
Collaborator

@francescalb francescalb left a comment

Choose a reason for hiding this comment

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

Nice, works well.

Copy link
Collaborator

@CasperWA CasperWA left a comment

Choose a reason for hiding this comment

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

The smart thing about the with statement and the use of tempfile.NamedTemporaryFile() is that the temporary file is deleted upon exiting the with block.
Could you possibly add this deletion manually here instead to ensure we don't clog up the temporary location?

@francescalb
Copy link
Collaborator

The smart thing about the with statement and the use of tempfile.NamedTemporaryFile() is that the temporary file is deleted upon exiting the with block. Could you possibly add this deletion manually here instead to ensure we don't clog up the temporary location?

According to the documentation we cannot use tempfile.NamedTemporaryFile() in this way on windows:
´´´
tempfile.NamedTemporaryFile(mode='w+b', buffering=-1, encoding=None, newline=None, suffix=None, prefix=None, dir=None, delete=True, *, errors=None)¶
This function operates exactly as TemporaryFile() does, except that the file is guaranteed to have a visible name in the file system (on Unix, the directory entry is not unlinked). That name can be retrieved from the name attribute of the returned file-like object. Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows NT or later). If delete is true (the default), the file is deleted as soon as it is closed. The returned object is always a file-like object whose file attribute is the underlying true file object. This file-like object can be used in a with statement, just like a normal file.
´´´

I agree with Casper about deleting the file.

This shows us that we probably should have some windows environment tests in the CI as well...

@jesper-friis
Copy link
Collaborator

Would it help to add the argument mode='w' to NamedTemporaryFile()? I think I have seen somewhere that it might help on Windows...

@sygout
Copy link
Collaborator Author

sygout commented Dec 3, 2021

According to the reference text copied by Francesca, I don't think it will help to add 'w'.

So I will try to add the file delete.

Otherwise, yes it should be mandatory to test it on Windows, especially for a tool aimed at a larger audience.

@francescalb
Copy link
Collaborator

Would it help to add the argument mode='w' to NamedTemporaryFile()? I think I have seen somewhere that it might help on Windows...

Nope, I tested. It would maybe work with the option ´delete=False´, but then we have to delete the file afterwards as well.

@sygout sygout requested a review from CasperWA April 22, 2022 13:48
@CasperWA CasperWA enabled auto-merge May 5, 2022 09:15
@CasperWA CasperWA merged commit 398b7d6 into master May 5, 2022
@CasperWA CasperWA deleted the permission-denied2 branch May 5, 2022 09:26
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.

permission denied when working with temporary file
4 participants