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 uuid.uuid4 to generate unique names #274

Merged
merged 5 commits into from
Jan 24, 2019
Merged

Use uuid.uuid4 to generate unique names #274

merged 5 commits into from
Jan 24, 2019

Conversation

seisman
Copy link
Member

@seisman seisman commented Jan 23, 2019

Description of proposed changes

Use uuid.uuid4().hex to generate unique names.

Fixes #273

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If adding new functionality, add an example to docstrings or tutorials.

# Use the tempfile module to generate a unique name.
with NamedTemporaryFile(prefix="gmt-python-") as tmpfile:
return os.path.split(tmpfile.name)[-1]
return "gmt-python-" + uuid.uuid4().hex
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure how to deal with the prefix gmt-python. Possible ways:

  1. No prefix at all
  2. Change gmt-python- to pygmt-
  3. Add arguments prefix and suffix to unique_name.

Copy link
Member

Choose a reason for hiding this comment

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

I think we can remove that prefix. Not sure why I added it but it really doesn't make a difference.

@seisman seisman requested a review from leouieda January 23, 2019 18:36
Copy link
Member

@leouieda leouieda left a comment

Choose a reason for hiding this comment

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

Thanks @seisman! Just need a few small changes.

pygmt/helpers/tempfile.py Outdated Show resolved Hide resolved
# Use the tempfile module to generate a unique name.
with NamedTemporaryFile(prefix="gmt-python-") as tmpfile:
return os.path.split(tmpfile.name)[-1]
return "gmt-python-" + uuid.uuid4().hex
Copy link
Member

Choose a reason for hiding this comment

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

I think we can remove that prefix. Not sure why I added it but it really doesn't make a difference.

@leouieda
Copy link
Member

The failure is because of #276. Will rerun the checks after that is fixed.

@leouieda leouieda merged commit 63e8959 into master Jan 24, 2019
@leouieda leouieda deleted the unique-name branch January 24, 2019 15:16
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.

Use the uuid package to generate figure names
2 participants