Commit 44b941e8 authored by Thanassis Tsiodras's avatar Thanassis Tsiodras

Revert to absolute imports for generated Python2 code.

Maxime's opengeode and GUI code depend on the old way
of code generation. There appears to be no way to generate
python2 code that does relative imports, and doesn't
"infect" code that uses it to MIGRATE to relative imports.

Until we find the resources to move opengeode and the GUIs
from Python2 to Python2/relativeImports/andorPython3,
all the changes done to address relative imports have
to be reverted.

I hope I am wrong in this and there's some magic way to
mix and match relative-non-relative imports. But I don't
believe so - new code can of course be created to use
relative imports from the start, but there's 10 years
legacy code (1000s of lines) that use what DMT generates.

For people (like Konrad) that need Python2 relative imports
and/or write in Python3, I created a branch that has the
appropriate code:

    generatedCodeWithRelativeImportsForPy2andPy3

Sigh.
parent e853ee4e
......@@ -23,7 +23,7 @@ from __future__ import absolute_import
import os
import re
import copy
from . import DV_Types # pylint: disable=import-error
import DV_Types # pylint: disable=import-error
from ctypes import (
cdll, c_void_p, c_ubyte, c_double, c_uint,
c_longlong, c_bool, c_int, c_long
......
......@@ -75,10 +75,9 @@ def OnStartup(unused_modelingLanguage: str, asnFile: str, outputDir: str, badTyp
inform("Python_A_mapper: Creating file '%s'...", outputFilename)
global g_outputFile
g_outputFile = open(outputDir + outputFilename, 'w')
g_outputFile.write("from __future__ import absolute_import\n\n")
g_outputFile.write("from functools import partial\n\n")
g_outputFile.write("from . import DV\n\n")
g_outputFile.write("from .Stubs import (\n")
g_outputFile.write("import DV\n\n")
g_outputFile.write("from Stubs import (\n")
g_outputFile.write(
" myassert, Clean, DataStream, COMMON)\n\n")
global g_outputGetSetH
......
......@@ -545,7 +545,6 @@ def OnShutdown(badTypes: SetOfBadTypenames) -> None:
g_sqlalchemyOutput.write('''
# SQLAlchemy models for types used in "{d}"
from __future__ import absolute_import
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
......@@ -554,11 +553,11 @@ from sqlalchemy import (Column, Integer, String, Boolean, Float,
ForeignKey, CheckConstraint, UniqueConstraint)
from sqlalchemy.orm import relationship
from .{d_cleaned} import (
from {d_cleaned} import (
{types}
)
from . import DV
import DV
'''.format(d=d, d_cleaned=CleanName(d),
types=", ".join(
......
......@@ -74,7 +74,7 @@ def OnStartup(modelingLanguage: str,
g_headerPython.append("from __future__ import absolute_import\n\n")
g_headerPython.append("import threading, time, sys, os, ctypes\n")
# g_headerPython.append("from PythonAccess import *")
g_headerPython.append("from . import DV")
g_headerPython.append("import DV")
g_headerPython.append('try:')
g_headerPython.append(' PythonAccess = ctypes.cdll.LoadLibrary("./PythonAccess.so")')
g_headerPython.append('except OSError:')
......
......@@ -12,20 +12,19 @@ cleanDB:
rm -f test.db
clean:
rm -rf verifier/asn2dataModel verifier/lotsofdatatypes_model.* */*.pyc verifier/LotsOfDataTypes.asn .coverage
rm -rf asn2dataModel lotsofdatatypes_model.* */*.pyc .coverage
$(MAKE) cleanDB
build:
cd verifier/ ; if [ ! -d asn2dataModel ] ; then mkdir -p asn2dataModel ; [ ! -h LotsOfDataTypes.asn ] && ln -s ../LotsOfDataTypes.asn ; LC_ALL=C asn2dataModel -o asn2dataModel -toPython LotsOfDataTypes.asn ; fi
cd verifier/asn2dataModel || exit 1 && make -f Makefile.python
cd verifier ; LC_ALL=C asn2dataModel -toSqlalchemy -o asn2dataModel/ LotsOfDataTypes.asn
touch verifier/asn2dataModel/__init__.py
if [ ! -d asn2dataModel ] ; then mkdir -p asn2dataModel ; LC_ALL=C asn2dataModel -o asn2dataModel -toPython LotsOfDataTypes.asn ; fi
cd asn2dataModel || exit 1 && make -f Makefile.python
LC_ALL=C asn2dataModel -toSqlalchemy -o asn2dataModel/ LotsOfDataTypes.asn
debug: |build
ipdb -m verifier.testSQLengines.py
ipdb -m ./testSQLengines.py
test: |build
python2 -m verifier.testSQLengines
./testSQLengines.py
print:
@for i in MyInt My2ndInt MySeq MyChoice TypeEnumerated MySuperSeq T_ARR T_ARR_indexes T_ARR_elm ; do \
......
......@@ -3,12 +3,12 @@ import math
from sqlalchemy import exc
# sys.path.append("asn2dataModel")
from .asn2dataModel import DV
from .asn2dataModel.lotsofdatatypes_model import (
sys.path.append("asn2dataModel")
import DV
from lotsofdatatypes_model import (
MyInt_SQL, My2ndInt_SQL, MySeq_SQL, TypeEnumerated_SQL, T_ARR_SQL,
MySuperSeq_SQL, MyChoice_SQL, TypeNested_SQL)
from .asn2dataModel.LotsOfDataTypes_asn import (
from LotsOfDataTypes_asn import (
MyInt, My2ndInt, MySeq, TypeEnumerated, T_ARR, MySuperSeq, MyChoice,
TypeNested
)
......
#!/usr/bin/env python2
import os
import sys
sys.path.append("asn2dataModel")
import logging
import unittest
from sqlalchemy import create_engine
from .commonTests import AllTests
from .asn2dataModel.lotsofdatatypes_model import Base
from commonTests import AllTests
from lotsofdatatypes_model import Base
sys.path.append("asn2dataModel")
from .asn2dataModel.lotsofdatatypes_model import My2ndInt_SQL
from .asn2dataModel.LotsOfDataTypes_asn import My2ndInt
from lotsofdatatypes_model import My2ndInt_SQL
from LotsOfDataTypes_asn import My2ndInt
logging.basicConfig(filename="sql.log")
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
......@@ -27,8 +30,11 @@ class CompleteTestingOfSQLMapperWithSQLite(AllTests, unittest.TestCase):
class CompleteTestingOfSQLMapperWithPostgreSQL(AllTests, unittest.TestCase):
#engine = create_engine('sqlite:///:memory:', echo=True)
engine = create_engine(
'postgresql+psycopg2://ubuntu:@localhost/circle_test', echo=False)
if os.getenv('CIRCLECI') is None:
dburi = 'postgresql+psycopg2://ubuntu:tastedb@localhost/circle_test'
else:
dburi = 'postgresql+psycopg2://ubuntu:@localhost/circle_test'
engine = create_engine(dburi, echo=False)
Base.metadata.create_all(engine)
from sqlalchemy.orm import sessionmaker
......
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