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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

otms61
Copy link
Contributor

@otms61 otms61 commented May 17, 2020

Issue: #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

$

@mbello
Copy link
Owner

mbello commented May 27, 2020

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.

@otms61
Copy link
Contributor Author

otms61 commented May 30, 2020

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.

@WeLikeIke
Copy link

@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]

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.

3 participants