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 mkdtemp in _create_tmp_config_dir #4597

Closed
tacaswell opened this issue Jul 7, 2015 · 2 comments
Closed

use mkdtemp in _create_tmp_config_dir #4597

tacaswell opened this issue Jul 7, 2015 · 2 comments
Labels
Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues mentored: hackathon
Milestone

Comments

@tacaswell
Copy link
Member

See https://docs.python.org/2/library/tempfile.html#tempfile.mkdtemp

Noted while reviewing #4591

Python now has a function in tempfile which will ensure we get a usable directory in 'the most secure way possible' which seems better than rolling our own.

@tacaswell tacaswell added mentored: hackathon Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues labels Jul 7, 2015
@tacaswell tacaswell modified the milestones: next point release, proposed next point release Jul 7, 2015
@souravsingh
Copy link
Contributor

I would like to work on it.How do I go with it? Do I have to change the entire function to use mkdtemp()?

@KanwarGill
Copy link
Contributor

@tacaswell We are working on this and we have a question. So what we understand from the code is that:

  • It first gets the tempdir of the system matplotlib is being run on.
  • Then it gets the login name username of the user.
  • Then it uses os.path.join to create a directory address like tempdir/matplotlib-username.
  • Afterwards it sets the environment variable "MPLCONFIGDIR" to the newly created temp directory.
  • Then it creates the tempdir/matplotlib-username directory using the mkdirs() function from book.

Our question is, when we use mkdtemp, do we use the same directory naming format as the current version or do we use the built-in naming convention that mkdtemp() provides–that is, creating a random string as the name for the directory?

For example, currently the way it's done is that inside the TEMPDIR a folder with the name matplotlib-username is created and the environment variable set to that path. However, because mkdtemp creates a temp folder inside the TEMPDIR it would create another folder, for example tmpbfd2wzbl inside matplotlib-username.

What we are thinking is to modify the naming convention by removing the string matplotlib-username that is added to the tempdir and instead use the name supplied by mkdtemp. It would look something like this:
os.environ['MPLCONFIGDIR'] = tempfile.mkdtemp(dir=tempdir)

Let us know if this is desirable or prohibited. Also, because here we are changing the implementation of a function by using another (mkdtemp) method, how would we go about testing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues mentored: hackathon
Projects
None yet
Development

No branches or pull requests

3 participants