Skip to content

Commit

Permalink
Merge pull request #1026 from wright-group/fix_windows_copy
Browse files Browse the repository at this point in the history
Fix double opening which causes PermissionError on Windows
  • Loading branch information
kameyer226 committed Oct 21, 2021
2 parents 1fb6eb4 + fb09f5b commit 682b444
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
- `artists.create_figure`: kwarg `margin` allows unique margins on all sides

### Fixed
- PermissionError on windows when copying Data/Collection objects
- Fixed bug in `wt.artists.interact2D` where constants were not handled properly.

## [3.4.0]
Expand Down
8 changes: 3 additions & 5 deletions WrightTools/_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,16 @@ def copy(self, parent=None, name=None, verbose=True):
if name is None:
name = self.natural_name
if parent is None:
from ._open import open as wt_open # circular import

new = Group() # root of new tempfile
# attrs
new.attrs.update(self.attrs)
new.natural_name = name
# children
for k, v in self.items():
super().copy(v, new, name=v.natural_name)
new.flush()
p = new.filepath
new = wt_open(p)
# Converts to appropriate Data/Collection object
new = new["/"]
new.natural_name = name
else:
# copy
self.file.copy(self.name, parent, name=name)
Expand Down
2 changes: 2 additions & 0 deletions tests/group/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ def test_simple_copy():
new = original.copy()
assert original.fullpath != new.fullpath
for k, v in original.attrs.items():
print(k)
assert_equal(new.attrs[k], v)
for k, v in original.items():
print(k)
assert_equal(new[k], v)
original.close()
new.close()
Expand Down

0 comments on commit 682b444

Please sign in to comment.