<commit_before>#!/usr/bin/env python

"""Build the documentation, and run the JavaScript tests with phantomjs if
available."""

import sphinx.cmdline

import argparse
import os
import subprocess
import sys
import threading
# Sane name in Python 3
try:
    from http import server
except ImportError:
    import SimpleHTTPServer as server
try:
    from socketserver import TCPServer
except ImportError:
    from SocketServer import TCPServer

parser = argparse.ArgumentParser(description="Build the vcwebedit documention \
and run the JavaScript tests.")
parser.add_argument("-p", "--port",
        default=8080,
        type=int,
        help="Local port to run the web server for testing.")
parser.add_argument("-l", "--linger",
        action='store_true',
        help="Keep the local web server open after the tests run.")
parser.add_argument("-j", "--phantomjs",
        default="phantomjs",
        help="Path to the phantomjs executable.")
options = parser.parse_args()

# Build the documentation for vcwebedit.
source_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'doc')
build_dir = os.path.join(source_dir, '_build')
# Build html, warning treated as errors, output the doctrees to
# build_dir/doctrees.
sphinx_argv = ['sphinx-build',
    '-b', 'html',
    '-W',
    '-d', os.path.join(build_dir, 'doctrees'),
    source_dir, os.path.join(build_dir, 'html')]
print("Building vcwebedit documentation with:\n")
print(' '.join(sphinx_argv))
build_result = sphinx.cmdline.main(sphinx_argv)
if build_result:
    sys.stderr.write("sphinx-build failed.\n")
    sys.exit(build_result)
else:
    print("sphinx-build succeeded!")


print('Starting up the testing web server...')
os.chdir(os.path.join(build_dir, 'html'))

class ServerRunner(object):
    def serve_on_port(self, port):
        handler = server.SimpleHTTPRequestHandler
        self.httpd = TCPServer(("localhost", options.port), handler)
        self.server_thread = threading.Thread(
            target=self.httpd.serve_forever
            )
        self.server_thread.daemon = True
        self.server_thread.start()

    def cleanup(self):<commit_msg>More improvements for the 'Address already in use' error.<commit_after>#!/usr/bin/env python

"""Build the documentation, and run the JavaScript tests with phantomjs if
available."""

import sphinx.cmdline

import argparse
import os
import subprocess
import sys
import threading
# Sane name in Python 3
try:
    from http import server
except ImportError:
    import SimpleHTTPServer as server
try:
    from socketserver import TCPServer
except ImportError:
    from SocketServer import TCPServer

parser = argparse.ArgumentParser(description="Build the vcwebedit documention \
and run the JavaScript tests.")
parser.add_argument("-p", "--port",
        default=8080,
        type=int,
        help="Local port to run the web server for testing.")
parser.add_argument("-l", "--linger",
        action='store_true',
        help="Keep the local web server open after the tests run.")
parser.add_argument("-j", "--phantomjs",
        default="phantomjs",
        help="Path to the phantomjs executable.")
options = parser.parse_args()

# Build the documentation for vcwebedit.
source_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'doc')
build_dir = os.path.join(source_dir, '_build')
# Build html, warning treated as errors, output the doctrees to
# build_dir/doctrees.
sphinx_argv = ['sphinx-build',
    '-b', 'html',
    '-W',
    '-d', os.path.join(build_dir, 'doctrees'),
    source_dir, os.path.join(build_dir, 'html')]
print("Building vcwebedit documentation with:\n")
print(' '.join(sphinx_argv))
build_result = sphinx.cmdline.main(sphinx_argv)
if build_result:
    sys.stderr.write("sphinx-build failed.\n")
    sys.exit(build_result)
else:
    print("sphinx-build succeeded!")


print('Starting up the testing web server...')
os.chdir(os.path.join(build_dir, 'html'))

class ThreadedHTTPServer(TCPServer):
    allow_reuse_address = True

class ServerRunner(object):
    def serve_on_port(self, port):
        handler = server.SimpleHTTPRequestHandler
        self.httpd = ThreadedHTTPServer(("localhost", options.port), handler)
        self.server_thread = threading.Thread(
            target=self.httpd.serve_forever
            )
        self.server_thread.daemon = True
        self.server_thread.start()

    def cleanup(self):
{'fraction_non_alphanumeric': 0.12102633969118982, 'fraction_numerical': 0.002270663033605813, 'mean_word_length': 3.840659340659341, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4393064', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1347, 'n_words': 361}