Skip to content

Conversation

@mattwthompson
Copy link
Member

Fixes #503

Arguably instead of just removing the functions, they could be replaced with some sort of DeprecationWarning. But downstream users are probably not importing these functions directly. Open to suggestions here

@lgtm-com
Copy link

lgtm-com bot commented May 12, 2020

This pull request introduces 1 alert when merging dd4af89 into 5abd8d9 - view on LGTM.com

new alerts:

  • 1 for Unused import

Copy link
Member

@j-wags j-wags left a comment

Choose a reason for hiding this comment

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

This looks good to me. I tried to think of cases where making and entering a temporary directory in separate steps would be essential, but nothing comes to mind. This is great, and I'm happy to be removing unneeded code.

@mattwthompson mattwthompson merged commit 33a6130 into master May 14, 2020
@SimonBoothroyd
Copy link
Contributor

@mattwthompson (cc @j-wags ) I don't think the TemporaryDirectory context manager also cd's into the temporary directory, so I think the changes you've made where you now remove the temporary cd will just create files in the cwd.

Also snippets like

        with tempfile.TemporaryDirectory() as tmpdir:
            outfile = 'temp_molecule.' + file_format
            self.to_file(molecule, outfile, file_format)
            file_data = open(outfile).read()

would likely be better to just use a NamedTemporaryFile.

import re
import subprocess
import textwrap
import tempfile
Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, thought I fixed this typo

@mattwthompson
Copy link
Member Author

>>> with tempfile.TemporaryDirectory() as tmpdir:
...     Molecule.from_smiles('CCO').to_file('tmp.sdf', file_format='sdf')
... 
>>> os.listdir()
['foo.txt', 'tmp.sdf', 'bar.txt']

That's right. I was fairly surprised the tests passed but that shouldn't have been the criteria anyway. I'll fix this tomorrow.

@mattwthompson mattwthompson mentioned this pull request Jun 3, 2020
4 tasks
@j-wags
Copy link
Member

j-wags commented Jun 4, 2020

Ahhh, simon is correct above, just saw this and came to say the same thing -- There are still some places where we need to cd into the temporary directory. I'm adding temporary_cd back in in #471

@SimonBoothroyd
Copy link
Contributor

@j-wags https://github.com/SimonBoothroyd/nonbonded/blob/621151c747925aefeb368d0a2bc99c4305de6dd7/nonbonded/library/utilities/utilities.py#L34 may be helpful - it optionally temporarily cd's into a temporary directory.

j-wags added a commit that referenced this pull request Jun 4, 2020
@j-wags j-wags mentioned this pull request Jun 4, 2020
14 tasks
@j-wags
Copy link
Member

j-wags commented Jun 4, 2020

Ah, that's really helpful. For now I'm going to revert it to two nested contexts (first make directory, then enter it), since that's more explicit about what's happening. I think this will continue to be a tricky area of the codebase, so "more explicit" will be good here.

@mattwthompson mattwthompson deleted the tempdir branch May 25, 2021 19:40
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.

[LINT] 'temporary_directory' duplicates 'tempfile.TemporaryDirectory'

4 participants