memory-tempfile icon indicating copy to clipboard operation
memory-tempfile copied to clipboard

Make it possible not to raise AttributeError when running on macOS.

Open otms61 opened this issue 5 years ago • 3 comments

Issue: https://github.com/mbello/memory-tempfile/issues/5

Initialize the attribute that caused the attribute error even in the non-Linux environment.

It was necessary to pay attention to the execution environment when calling found_mem_tempdir().

tempfile = MemoryTempfile()
if platform.system() == "Linux":
    if tempfile.found_mem_tempdir():
        pass

This PR make it possible to control it with the fallback option, even if it's a non-Linux environment.

tempfile = MemoryTempfile(fallback=True)
if tempfile.found_mem_tempdir():
    pass

I've confirmed the following.

Even on macOS, RuntimeError is raised if fallback is not specified. This makes it easier to investigate from an error message than an AttributeError.

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.15.4
BuildVersion:   19E287

$ cat x.py
from memory_tempfile import MemoryTempfile

tempfile = MemoryTempfile()
if tempfile.found_mem_tempdir():
    pass

$ python x.py
Traceback (most recent call last):
  File "x.py", line 3, in <module>
    tempfile = MemoryTempfile()
  File "/Users/otms61/.ghq/github.com/otms61/memory-tempfile/memory_tempfile/memory_tempfile.py", line 68, in __init__
    raise RuntimeError('No memory temporary dir found and fallback is disabled.')
RuntimeError: No memory temporary dir found and fallback is disabled.

Also, if you specify "fallback=True", you can use a default tempdir.

$ cat x.py
from memory_tempfile import MemoryTempfile

tempfile = MemoryTempfile(fallback=True)
if tempfile.found_mem_tempdir():
    pass

$ python x.py

$

otms61 avatar May 17 '20 02:05 otms61

Thanks for reporting this issue and sorry for the delay responding.

I think that it is not ideal to have to change code so that your devs on Mac can test their code. You may not want to have fallback=true in production.

What if when not Linux we just use "tempfile.gettempdir()" as temporary dir (or a fallback if supplied)? This way it will be like bypassing the functionality of this package in other platforms and using vanilla tempfile.

Let me know your opinion.

mbello avatar May 27 '20 23:05 mbello

Thank you for replying!

I think that it is not ideal to have to change code so that your devs on Mac can test their code. You may not want to have fallback=true in production.

I agree with your thoughts. And we decided that we would just skip the tests if it is running on non-Linux instead of changing application codes.

The purpose of this pull request is to focus on the problem of the difficulty of identifying the cause from the error message AttributeError. This pull request solves this issue by raising RuntimeErrors, as noted in my first comment.

otms61 avatar May 30 '20 12:05 otms61

@mbello I am sorry for using a comment in a repository just to get a hold of you.

I would like to send you an email regarding your pyhton 'pdflatex' repo which is now not accessible anymore.

Please hit me up at [email protected]

WeLikeIke avatar Oct 19 '22 12:10 WeLikeIke