Skip to content

Commit

Permalink
attempting to refactor and clean up imports
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoli committed Aug 24, 2020
1 parent ef6c95a commit d510bb4
Show file tree
Hide file tree
Showing 10 changed files with 320 additions and 178 deletions.
24 changes: 11 additions & 13 deletions pysces/PyscesJWSParse.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
pass

import os, copy
import pysces.lib.lex
import pysces.lib.yacc
from .lib import lex
from .lib import yacc
from getpass import getuser
from time import sleep, strftime
from scipy import MachAr
Expand Down Expand Up @@ -218,9 +218,9 @@ def Show(self, name, tok):
def p_error(self, t):
self.ParseErrors.append(('Syntax error ', t.lineno, t.value, t.type))
print('Syntax error, Line ' + str(t.lineno) + ' : ' + str(t.value))
tok = pysces.lib.yacc.token()
tok = yacc.token()
while tok and tok.type != 'REACTION_ID':
tok = pysces.lib.yacc.token()
tok = yacc.token()
return tok

def p_model(self, t):
Expand Down Expand Up @@ -500,10 +500,8 @@ def psc2jws(self, File, indir=None, outdir=None, quiet=1, debug=0):

if go == 1:
# clean up the modules
reload(
pysces.lib.lex
) # brett's bugbear code these have to be here ALWAYS!!
reload(pysces.lib.yacc)
reload(lex) # brett's bugbear code these have to be here ALWAYS!!
reload(yacc)
# clean up the instance
self.ReactionIDs = [] # List of reaction names
self.Names = [] # List of all reagent, parameter and function names
Expand Down Expand Up @@ -566,9 +564,9 @@ def psc2jws(self, File, indir=None, outdir=None, quiet=1, debug=0):
print(self.tabmodule)
print(self.debugfile)

pysces.lib.lex.lex(module=self, debug=self.Debug)
pysces.lib.lex.input(Model)
pysces.lib.yacc.yacc(
lex.lex(module=self, debug=self.Debug)
lex.input(Model)
yacc.yacc(
module=self,
debug=self.Debug,
debugfile=self.debugfile,
Expand All @@ -578,14 +576,14 @@ def psc2jws(self, File, indir=None, outdir=None, quiet=1, debug=0):
os.chdir(outdir)

while 1:
tok = pysces.lib.lex.token()
tok = lex.token()
if not tok:
break
if self.LexErrors != []:
print('self.LexErrors = ', self.LexErrors, '\n')

while 1:
p = pysces.lib.yacc.parse(Model)
p = yacc.parse(Model)
if not p:
break

Expand Down
32 changes: 18 additions & 14 deletions pysces/PyscesModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,24 @@

from getpass import getuser

from pysces import model_dir as MODEL_DIR
from pysces import output_dir as OUTPUT_DIR
from pysces import install_dir as INSTALL_DIR
from pysces import nleq2
from pysces import nleq2_switch
from pysces import pitcon
from pysces import plt, gplt
from pysces import PyscesStoich
from pysces import PyscesParse
from pysces import PyscesRandom as random
from pysces import __SILENT_START__
from pysces.PyscesScan import Scanner
from pysces.core2.InfixParser import MyInfixParser
from pysces import SED
from . import model_dir as MODEL_DIR
from . import output_dir as OUTPUT_DIR
from . import install_dir as INSTALL_DIR
from . import PyscesRandom as random
from .PyscesScan import Scanner
from .core2.InfixParser import MyInfixParser

from . import (
nleq2,
nleq2_switch,
pitcon,
plt,
gplt,
PyscesStoich,
PyscesParse,
__SILENT_START__,
SED,
)

interface = None

Expand Down
2 changes: 1 addition & 1 deletion pysces/PyscesModelMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from __future__ import absolute_import
from __future__ import unicode_literals

from pysces.version import __version__
from .version import __version__

__doc__ = '''PySCeS ModelMap module: useful for exploring model component relations'''

Expand Down
18 changes: 9 additions & 9 deletions pysces/PyscesParse.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
from __future__ import absolute_import
from __future__ import unicode_literals

from pysces.version import __version__
from .version import __version__

__doc__ = "PySCeS parser module -- uses PLY 1.5 or newer"


import os, copy
import pysces.lib.lex
import pysces.lib.yacc
from .lib import lex
from .lib import yacc
from getpass import getuser
from time import sleep, strftime

Expand Down Expand Up @@ -667,9 +667,9 @@ def p_error(self, t):
self.ParseErrors.append(t)
except:
print('p_error generated a parsing error')
tok = pysces.lib.yacc.token()
tok = yacc.token()
while tok and tok.type != 'REACTION_ID':
tok = pysces.lib.yacc.token()
tok = yacc.token()
self.ParseOK = False
return tok

Expand Down Expand Up @@ -1332,8 +1332,8 @@ def ParsePSC(self, modelfile, modeldir, modeloutput):
self.ModelUsesNumpyFuncs = False

# 4 hrs of debugging and these two lines solve the problem .... I'm out of here!
reload(pysces.lib.lex)
reload(pysces.lib.yacc)
reload(lex)
reload(yacc)
# fixes the obscure reload <--> garbage collection reference overload bug ... who said scripted lang's were
# easy to use :-) - brett 20040122

Expand Down Expand Up @@ -1379,9 +1379,9 @@ def ParsePSC(self, modelfile, modeldir, modeloutput):
print(self.debugfile)
print('cwd: ', os.getcwd())

self.__lexer = pysces.lib.lex.lex(module=self, debug=self.display_debug)
self.__lexer = lex.lex(module=self, debug=self.display_debug)
self.__lexer.input(self.__Model)
self.__parser = pysces.lib.yacc.yacc(
self.__parser = yacc.yacc(
module=self,
debug=self.display_debug,
debugfile=self.debugfile,
Expand Down
4 changes: 2 additions & 2 deletions pysces/PyscesPlot2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from __future__ import absolute_import
from __future__ import unicode_literals

from pysces.version import __version__
from pysces import __SILENT_START__
from .version import __version__
from . import __SILENT_START__
import subprocess, os, shutil, time, math, itertools, copy
from getpass import getuser
import numpy, scipy
Expand Down
4 changes: 2 additions & 2 deletions pysces/PyscesSBML.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from __future__ import absolute_import
from __future__ import unicode_literals

from pysces.version import __version__
from .version import __version__

__doc__ = '''SBML reading/writing module - now replaced by PySCeS Core2'''

Expand All @@ -34,7 +34,7 @@

if sys.platform == 'win32':
try:
import pysces.libsbml.libsbmlinit as SBML
import libsbml as SBML
except Exception as e:
print('Windows sbml load error', e)
else:
Expand Down
2 changes: 0 additions & 2 deletions pysces/core2/InfixParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# NOTE when you do this PLY adds a module name self. to all tokens
# not sure if this is an unexpected feature or not. It can be worked around
# but for now direct import seems the safest
## import pysces.lib.lex as lex
## import pysces.lib.yacc as yacc
from . import lex
from . import yacc
import os
Expand Down
8 changes: 0 additions & 8 deletions pysces/kraken/KrakenServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@
# end header

__psyco_active__ = 0
## try:
## import psyco
## psyco.profile()
## __psyco_active__ = 1
## print 'PySCeS Module is now PsycoActive!'
## except:
## __psyco_active__ = 0
## __psyco_active__ = 0

from pysces import TimerBox

Expand Down
Loading

0 comments on commit d510bb4

Please sign in to comment.