Commit 6a8bdd27 authored by eckhart's avatar eckhart
Browse files

- DHParser/server.py - bug: failure to run unter Python 3.6 and PyPy3 fixed

parent c035690f
......@@ -560,6 +560,7 @@ class Server:
await writer.drain()
if self.exit_connection or self.kill_switch:
writer.write_eof()
await writer.drain()
writer.close()
self.exit_connection = False # reset flag
......@@ -570,7 +571,7 @@ class Server:
# TODO: terminate processes and threads! Is this needed??
self.stage.value = SERVER_TERMINATE
self.server.close()
if sys.version_info < (3, 6) and self.loop is not None:
if sys.version_info < (3, 7) and self.loop is not None:
self.loop.stop()
self.kill_switch = False # reset flag
# print('END DHParser.server.connection()')
......@@ -655,7 +656,7 @@ class Server:
print("Server logging is on.")
try:
if sys.version_info >= (3, 7):
asyncio.run(self.serve(host, port))
asyncio_run(self.serve(host, port))
else:
self.serve_py35(host, port, loop)
except KeyboardInterrupt:
......@@ -699,6 +700,8 @@ class Server:
while self.stage.value != SERVER_OFFLINE \
and self.server_messages.get() != SERVER_OFFLINE:
pass
writer.write_eof()
await writer.drain()
writer.close()
except ConnectionRefusedError:
pass
......
......@@ -8,7 +8,7 @@ import sys
LOGGING = ''
scriptpath = os.path.dirname(__file__)
scriptpath = os.path.dirname(__file__) or '.'
for path in (os.path.join('..', '..'), '.'):
fullpath = os.path.abspath(os.path.join(scriptpath, path))
if fullpath not in sys.path:
......
......@@ -8,7 +8,7 @@ import sys
LOGGING = 'LOGS'
scriptpath = os.path.dirname(__file__)
scriptpath = os.path.dirname(__file__) or '.'
for path in (os.path.join('..', '..'), '.'):
fullpath = os.path.abspath(os.path.join(scriptpath, path))
if fullpath not in sys.path:
......
......@@ -8,7 +8,7 @@ import sys
LOGGING = ''
scriptpath = os.path.dirname(__file__)
scriptpath = os.path.dirname(__file__) or '.'
for path in (os.path.join('..', '..'), '.'):
fullpath = os.path.abspath(os.path.join(scriptpath, path))
if fullpath not in sys.path:
......
......@@ -22,7 +22,7 @@ limitations under the License.
import os
import sys
scriptpath = os.path.dirname(__file__)
scriptpath = os.path.dirname(__file__) or '.'
for path in (os.path.join('..', '..'), '.'):
fullpath = os.path.abspath(os.path.join(scriptpath, path))
if fullpath not in sys.path:
......
......@@ -24,7 +24,7 @@ import re
import sys
scriptpath = os.path.dirname(__file__)
scriptpath = os.path.dirname(__file__) or '.'
for path in (os.path.join('..', '..'), '.'): # '../showcases' ?
fullpath = os.path.abspath(os.path.join(scriptpath, path))
if fullpath not in sys.path:
......
......@@ -8,7 +8,7 @@ import sys
LOGGING = ''
scriptpath = os.path.dirname(__file__)
scriptpath = os.path.dirname(__file__) or '.'
for path in (os.path.join('..', '..'), '.'):
fullpath = os.path.abspath(os.path.join(scriptpath, path))
if fullpath not in sys.path:
......
......@@ -22,7 +22,7 @@ limitations under the License.
import os
import sys
scriptpath = os.path.dirname(__file__)
scriptpath = os.path.dirname(__file__) or '.'
for path in (os.path.join('..', '..'), '.'):
fullpath = os.path.abspath(os.path.join(scriptpath, path))
if fullpath not in sys.path:
......
......@@ -6,7 +6,7 @@
import os
import sys
scriptpath = os.path.dirname(__file__)
scriptpath = os.path.dirname(__file__) or '.'
for path in (os.path.join('..', '..'), '.'):
fullpath = os.path.abspath(os.path.join(scriptpath, path))
if fullpath not in sys.path:
......
......@@ -6,7 +6,7 @@
import os
import sys
scriptpath = os.path.dirname(__file__)
scriptpath = os.path.dirname(__file__) or '.'
for path in (os.path.join('..', '..'), '.'):
fullpath = os.path.abspath(os.path.join(scriptpath, path))
if fullpath not in sys.path:
......
......@@ -48,6 +48,7 @@ from DHParser import start_logging, is_filename, load_if_file, \
def jsonPreprocessor(text):
return text, lambda i: i
def get_preprocessor() -> PreprocessorFunc:
return jsonPreprocessor
......@@ -140,8 +141,8 @@ def CreatejsonTransformer() -> TransformationFunc:
def get_transformer() -> TransformationFunc:
"""Returns a thread/process-exclusive transformation function."""
THREAD_LOCALS = access_thread_locals()
try:
THREAD_LOCALS = access_thread_locals()
transformer = THREAD_LOCALS.json_00000001_transformer_singleton
except AttributeError:
THREAD_LOCALS.json_00000001_transformer_singleton = CreatejsonTransformer()
......@@ -190,6 +191,7 @@ class jsonCompiler(Compiler):
def get_compiler() -> jsonCompiler:
"""Returns a thread/process-exclusive jsonCompiler-singleton."""
THREAD_LOCALS = access_thread_locals()
try:
compiler = THREAD_LOCALS.json_00000001_compiler_singleton
except AttributeError:
......
......@@ -24,7 +24,7 @@ import asyncio
import os
import sys
scriptpath = os.path.dirname(__file__)
scriptpath = os.path.dirname(__file__) or '.'
STOP_SERVER_REQUEST = b"__STOP_SERVER__" # hardcoded in order to avoid import from DHParser.server
IDENTIFY_REQUEST = "identify()"
......
......@@ -8,7 +8,7 @@ import sys
LOGGING = ''
scriptpath = os.path.dirname(__file__)
scriptpath = os.path.dirname(__file__) or '.'
for path in (os.path.join('..', '..'), '.'):
fullpath = os.path.abspath(os.path.join(scriptpath, path))
if fullpath not in sys.path:
......
......@@ -8,7 +8,7 @@ import sys
LOGGING = ''
scriptpath = os.path.dirname(__file__)
scriptpath = os.path.dirname(__file__) or '.'
for path in (os.path.join('..', '..'), '.'):
fullpath = os.path.abspath(os.path.join(scriptpath, path))
if fullpath not in sys.path:
......
......@@ -6,6 +6,7 @@ import concurrent.futures
import doctest
import multiprocessing
import os
import subprocess
import sys
import time
import threading
......@@ -26,11 +27,11 @@ def run_doctests(module):
return result.failed
# def run_unittests(command):
# args = command.split(' ')
# filename = args[1]
# print('\nUNITTEST ' + filename)
# subprocess.run(args)
def run_unittests(command):
args = command.split(' ')
filename = args[1]
print('\nUNITTEST ' + filename)
subprocess.run(args)
if __name__ == "__main__":
......@@ -60,22 +61,16 @@ if __name__ == "__main__":
"__init__.py"):
results.append(pool.submit(run_doctests, filename[:-3]))
concurrent.futures.wait(results)
# unit tests
for interpreter in interpreters:
if os.system(interpreter + '--version') == 0:
# for filename in os.listdir('test'):
# if filename.startswith('test_'):
# command = interpreter + os.path.join('test', filename)
# results.append(pool.submit(run_unittests, command))
os.system(' '.join([interpreter, '-c',
'''"import sys; '''
'''sys.path.extend(['DHParser']);'''
'''import testing; testing.run_path('%s')"''' %
scriptdir.replace('\\', '\\\\'),
os.path.join(os.getcwd(), 'test')]))
# unit tests
for interpreter in interpreters:
if os.system(interpreter + '--version') == 0:
for filename in os.listdir('test'):
if filename.startswith('test_'):
command = interpreter + os.path.join('test', filename)
# run_unittests(command)
results.append(pool.submit(run_unittests, command))
concurrent.futures.wait(results)
elapsed = time.time() - timestamp
print('\n Test-Duration: %.2f seconds' % elapsed)
......
......@@ -19,9 +19,11 @@ See the License for the specific language governing permissions and
limitations under the License.
"""
import os
import sys
sys.path.extend(['../', './'])
scriptpath = os.path.dirname(__file__) or '.'
sys.path.append(os.path.abspath(os.path.join(scriptpath, '..')))
from DHParser import parse_sxpr, Compiler
......
......@@ -21,9 +21,11 @@ limitations under the License.
"""
import multiprocessing
import os
import sys
sys.path.extend(['../', './'])
scriptpath = os.path.dirname(__file__) or '.'
sys.path.append(os.path.abspath(os.path.join(scriptpath, '..')))
from DHParser.configuration import access_presets, finalize_presets
......
......@@ -26,9 +26,8 @@ import shutil
import subprocess
import sys
sys.path.extend(['../', './'])
scriptdir = os.path.dirname(os.path.realpath(__file__))
scriptpath = os.path.dirname(__file__) or '.'
sys.path.append(os.path.abspath(os.path.join(scriptpath, '..')))
def system(s: str) -> int:
# return os.system(s)
......@@ -37,7 +36,7 @@ def system(s: str) -> int:
class TestDHParserCommandLineTool:
def setup(self):
self.cwd = os.getcwd()
os.chdir(scriptdir)
os.chdir(scriptpath)
if not os.path.exists('test_dhparser_data'):
os.mkdir('test_dhparser_data')
self.nulldevice = " >/dev/null" if platform.system() != "Windows" else " > NUL"
......
......@@ -22,7 +22,9 @@ limitations under the License.
import os
import sys
sys.path.extend(['../', './'])
scriptpath = os.path.dirname(__file__) or '.'
sys.path.append(os.path.abspath(os.path.join(scriptpath, '..')))
from DHParser.parse import Grammar
from DHParser import Compiler
......
......@@ -24,9 +24,8 @@ import os
import sys
from multiprocessing import Pool
scriptdir = os.path.dirname(os.path.realpath(__file__))
sys.path.extend(['../', './'])
scriptpath = os.path.dirname(__file__) or '.'
sys.path.append(os.path.abspath(os.path.join(scriptpath, '..')))
from DHParser.configuration import get_config_value, set_config_value
from DHParser.toolkit import compile_python_object, re
......@@ -135,7 +134,7 @@ class TestEBNFParser:
def setup(self):
self.save_dir = os.getcwd()
os.chdir(scriptdir)
os.chdir(scriptpath)
self.EBNF = get_ebnf_grammar()
def teardown(self):
......
Supports Markdown
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