Commit 9c705474 by Steven Bird

* code to detect python version in util.py

  (py25, py26, py27)
* call this in __init__.py (deciding whether to import align, which requires 2.6+)
* call this in corpus/reader/util.py (deciding whether to use followlinks flag)
parent f77d83bd
......@@ -113,8 +113,7 @@ from util import *
from yamltags import *
# Modules that require Python 2.6
from sys import version_info as vi
if vi[0] == 2 and vi[1] >= 6:
if py26() or py27():
from align import *
# don't import contents into top-level namespace:
......
......@@ -24,7 +24,7 @@ from nltk.internals import slice_bounds
from nltk.data import PathPointer, FileSystemPathPointer, ZipFilePathPointer
from nltk.data import SeekableUnicodeStreamReader
from nltk.sourcedstring import SourcedStringStream
from nltk.util import AbstractLazySequence, LazySubsequence, LazyConcatenation
from nltk.util import AbstractLazySequence, LazySubsequence, LazyConcatenation, py25
######################################################################
#{ Corpus View
......@@ -760,7 +760,11 @@ def find_corpus_fileids(root, regexp):
# or symlinked) subdirectories, and match paths against the regexp.
elif isinstance(root, FileSystemPathPointer):
items = []
for dirname, subdirs, fileids in os.walk(root.path, followlinks=True):
# workaround for py25 which doesn't support followlinks
kwargs = {}
if not py25():
kwargs = {'followlinks': True}
for dirname, subdirs, fileids in os.walk(root.path, **kwargs):
prefix = ''.join('%s/' % p for p in _path_from(root.path, dirname))
items += [prefix+fileid for fileid in fileids
if re.match(regexp, prefix+fileid)]
......
......@@ -16,6 +16,7 @@ import os
from itertools import islice, chain
from pprint import pprint
from collections import defaultdict, deque
from sys import version_info
from nltk.internals import slice_bounds
......@@ -108,6 +109,18 @@ def tokenwrap(tokens, separator=" ", width=70):
##########################################################################
# Python version
##########################################################################
def py25():
return version_info[0] == 2 and version_info[1] == 5
def py26():
return version_info[0] == 2 and version_info[1] == 6
def py27():
return version_info[0] == 2 and version_info[1] == 7
##########################################################################
# Indexing
##########################################################################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment