Skip to content

Commit b35cf3d

Browse files
committed
Use easy_install for distribution
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%401021
1 parent 99cc08b commit b35cf3d

File tree

6 files changed

+63
-19
lines changed

6 files changed

+63
-19
lines changed

setup_base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from distutils.core import setup
1+
from setuptools import setup
22
import os
33

44
long_description="""HTML parser designed to follow the WHATWG HTML5
@@ -34,5 +34,7 @@
3434
for name in os.listdir(os.path.join('src','html5lib'))
3535
if os.path.isdir(os.path.join('src','html5lib',name)) and
3636
not name.startswith('.')],
37-
package_dir = {'html5lib': 'src/html5lib'}
37+
package_dir = {'html5lib': 'src/html5lib'},
38+
test_suite = "tests.buildTestSuite",
39+
tests_require = ['simplejson']
3840
)

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from runtests import buildTestSuite

tests/runtests.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
import glob
44
import unittest
55

6+
#Allow us to import the parent module
7+
os.chdir(os.path.split(os.path.abspath(__file__))[0])
8+
sys.path.insert(0, os.path.abspath(os.curdir))
9+
sys.path.insert(0, os.path.abspath(os.pardir))
10+
11+
612
def buildTestSuite():
713
suite = unittest.TestSuite()
814
for testcase in glob.glob('test_*.py'):
@@ -15,11 +21,4 @@ def main():
1521
if not results.wasSuccessful(): sys.exit(1)
1622

1723
if __name__ == "__main__":
18-
#Allow us to import the parent module
19-
#RELEASE remove
20-
sys.path.insert(0,os.path.abspath(os.path.join(__file__,'../../src')))
21-
#END RELEASE
22-
os.chdir(os.path.split(os.path.abspath(__file__))[0])
23-
sys.path.insert(0, os.path.abspath(os.pardir))
24-
2524
main()

tests/support.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
import html5lib
1010
from html5lib import html5parser, treebuilders
1111

12+
#Define the location of the tests as this changes in release versions
13+
#RELEASE remove
14+
test_dir = os.path.join(os.path.pardir,os.path.pardir,'testdata')
15+
#END RELEASE
16+
#RELEASE add
17+
#test_dir = './testdata'
18+
#END RELEASE
19+
1220
try:
1321
import simplejson
1422
except:
@@ -59,7 +67,7 @@ def load(f):
5967
pass
6068

6169
def html5lib_test_files(subdirectory, files='*.dat'):
62-
return glob.glob(os.path.join(os.path.pardir,os.path.pardir,'testdata',subdirectory,files))
70+
return glob.glob(os.path.join(test_dir,subdirectory,files))
6371

6472
class DefaultDict(dict):
6573
def __init__(self, default, *args, **kwargs):

tests/test_encoding.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import unittest
3-
from support import html5lib_test_files, TestData
3+
from support import html5lib_test_files, TestData, test_dir
44

55
from html5lib import inputstream
66

@@ -23,7 +23,7 @@ def encodingTest(self, data=test['data'], encoding=test['encoding']):
2323
try:
2424
import chardet
2525
def test_chardet(self):
26-
data = open("../../testdata/encoding/chardet/test_big5.txt").read()
26+
data = open(os.path.join(test_dir, "/chardet/test_big5.txt")).read()
2727
encoding = inputstream.HTMLInputStream(data).charEncoding
2828
assert encoding.lower() == "big5"
2929
setattr(Html5EncodingTestCase, 'test_chardet', test_chardet)

utils/package.py

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
class Package(object):
1616

17-
def __init__(self, inDir, outDir, version=0, status=4, installDir="~"):
17+
def __init__(self, inDir, outDir, version="0", status=4, installDir="~"):
1818
#List of files to remove on exit
1919
self.version = str(version)
2020
self.status = str(status)
@@ -28,20 +28,46 @@ def __init__(self, inDir, outDir, version=0, status=4, installDir="~"):
2828

2929
def runall(self):
3030
self.getFileList()
31+
self.copyTestData()
3132
self.copy()
3233
self.makeSetupFile()
3334
self.preprocess()
34-
if self.test():
35-
self.makeZipFile()
36-
self.cleanup()
35+
#if self.test():
36+
self.makeZipFile()
37+
#self.cleanup()
3738

3839

3940
def getExcludeList(self):
4041
rv = []
4142
for item in exclude:
4243
rv.append(item.replace("__basedir__", self.inDir))
4344
return rv
44-
45+
46+
def copyTestData(self):
47+
outDir = "tests/testdata"
48+
try:
49+
os.mkdir(outDir)
50+
except OSError:
51+
#the directory already exists
52+
pass
53+
inBaseDir = os.path.abspath(os.path.join(self.inDir, "../testdata"))
54+
dirWalker = os.walk(inBaseDir)
55+
for (curDir, dirs, files) in dirWalker:
56+
outDir = os.path.join(self.inDir, "tests", "testdata", curDir[len(inBaseDir)+1:])
57+
for dir in dirs[:]:
58+
if self.excludeItem(curDir, dir):
59+
dirs.remove(dir)
60+
else:
61+
try:
62+
os.mkdir(os.path.join(outDir, dir))
63+
except OSError:
64+
#the directory already exists
65+
pass
66+
for fn in files[:]:
67+
if not self.excludeItem(curDir, fn):
68+
newFn = os.path.join(outDir, fn)
69+
shutil.copy(os.path.join(curDir, fn), newFn)
70+
self.cleanupFiles.append(newFn)
4571
def getFileList(self):
4672
"""Get a list of files to copy"""
4773
fileList = []
@@ -95,7 +121,6 @@ def copy(self):
95121
self.outFiles.append(outPath)
96122
if os.path.isdir(inPath):
97123
try:
98-
99124
os.mkdir(outPath)
100125
except OSError:
101126
#File may already exist
@@ -191,4 +216,13 @@ def add(self, line):
191216
def move(self, line):
192217
self.outPath = os.path.abspath(os.path.join(self.inDir,
193218
line[line.find("move")+4:].strip(),
194-
self.outPath[len(self.inDir)+1:]))
219+
self.outPath[len(self.inDir)+1:]))
220+
dirName = os.path.dirname(self.outPath)
221+
if not os.path.exists(dirName):
222+
dirsToCreate = []
223+
while not os.path.exists(dirName):
224+
dirsToCreate.append(dirName)
225+
dirName = os.path.dirname(dirName)
226+
227+
for item in dirsToCreate[::-1]:
228+
os.mkdir(item)

0 commit comments

Comments
 (0)