Skip to content

Commit

Permalink
Resolve long tree string problem on Windows #258
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhwyllie committed May 23, 2019
1 parent 6f3d59c commit 1752154
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
17 changes: 15 additions & 2 deletions ete3/parser/newick.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,20 @@ class as the root(This allows to work with custom TreeNode
from ..coretype.tree import TreeNode
root_node = TreeNode()

if isinstance(newick, six.string_types):
if os.path.exists(newick):
if isinstance(newick, six.string_types):

# try to determine whether the file exists.
# For very large trees, if newick contains the content of the tree, rather than a file name,
# this may fail, at least on Windows, because the os fails to stat the file content, deeming it
# too long for testing with os.path.exists. This raises a ValueError with description
# "stat: path too long for Windows". This is described in issue #258
try:
file_exists = os.path.exists(newick)
except ValueError: # failed to stat
file_exists = False

# if newick refers to a file, read it from file; otherwise, regard it as a Newick content string.
if file_exists:
if newick.endswith('.gz'):
import gzip
nw = gzip.open(newick).read()
Expand All @@ -240,6 +252,7 @@ class as the root(This allows to work with custom TreeNode
else:
nw = newick


matcher = compile_matchers(formatcode=format)
nw = nw.strip()
if not nw.startswith('(') and nw.endswith(';'):
Expand Down
44 changes: 44 additions & 0 deletions ete3/test/test_issue258/issue258.py

Large diffs are not rendered by default.

0 comments on commit 1752154

Please sign in to comment.