Skip to content

Use uuid.uuid4 to generate unique names - #274

Merged
leouieda merged 5 commits into
masterfrom
unique-name
Jan 24, 2019
Merged

leouieda merged 5 commits into
masterfrom
unique-name

Conversation

@seisman

@seisman seisman commented Jan 23, 2019 •

Copy link
Copy Markdown
Member

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.

Comment thread pygmt/helpers/tempfile.py Outdated
# 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
Copy Markdown
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
Copy Markdown
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

@leouieda leouieda left a comment

Copy link
Copy Markdown
Member

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.

Comment thread pygmt/helpers/tempfile.py Resolved
Comment thread pygmt/helpers/tempfile.py Outdated
# 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
Copy Markdown
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
Copy Markdown
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