fix import sage in __init__, logging in utility.py
This commit is contained in:
parent
91e4c24413
commit
e125b72ef2
@ -61,7 +61,8 @@ from .utility import import_sage
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
package = __name__.split('.')[0]
|
package = __name__.split('.')[0]
|
||||||
path = os.path.dirname(__file__)
|
dirname = os.path.dirname
|
||||||
|
path = dirname(dirname(__file__))
|
||||||
import_sage('signature', package=package, path=path)
|
import_sage('signature', package=package, path=path)
|
||||||
import_sage('cable_signature', package=package, path=path)
|
import_sage('cable_signature', package=package, path=path)
|
||||||
import_sage('main', package=package, path=path)
|
import_sage('main', package=package, path=path)
|
||||||
|
@ -3,9 +3,11 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
import math
|
import math
|
||||||
|
import logging
|
||||||
|
|
||||||
def mod_one(n):
|
def mod_one(n):
|
||||||
"""
|
r"""calculates the fractional part of the argument
|
||||||
|
|
||||||
Argument:
|
Argument:
|
||||||
a number
|
a number
|
||||||
Return:
|
Return:
|
||||||
@ -22,31 +24,58 @@ def mod_one(n):
|
|||||||
|
|
||||||
|
|
||||||
def import_sage(module_name, package=None, path=''):
|
def import_sage(module_name, package=None, path=''):
|
||||||
"""
|
r"""Import or reload SageMath modules with preparse if the sage file exist.
|
||||||
Import or reload SageMath modules with preparse if the sage file exist.
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
module_name - name of the module (without extension!)
|
||||||
|
package - use only if module is used as a part of a package
|
||||||
|
Return:
|
||||||
|
module
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
from utility import import_sage
|
||||||
|
|
||||||
|
# equivalent to import module_name as my_prefered_shortcut}
|
||||||
|
my_prefered_shortcut = import_sage('module_name')
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
sage_name = module_name + ".sage"
|
sage_name = module_name + ".sage"
|
||||||
python_name = module_name + ".sage.py"
|
python_name = module_name + ".sage.py"
|
||||||
|
|
||||||
|
logging.info("\n\nimport_sage called with arguments:" +
|
||||||
|
"\n\tmodule_name: " + module_name +
|
||||||
|
"\n\tpackage: " + str(package) +
|
||||||
|
"\n\tpath: " + path)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if package is not None:
|
if package is not None:
|
||||||
|
|
||||||
path_from_package_name = re.sub(r'\.', r'\\', package)
|
path_from_package_name = re.sub(r'\.', r'\\', package)
|
||||||
path = os.path.join(path, path_from_package_name)
|
path = os.path.join(path, path_from_package_name)
|
||||||
|
|
||||||
|
logging.info("path with package name: " + str(path))
|
||||||
|
|
||||||
|
|
||||||
sage_path = os.path.join(path, sage_name)
|
sage_path = os.path.join(path, sage_name)
|
||||||
python_path = os.path.join(path, python_name)
|
python_path = os.path.join(path, python_name)
|
||||||
module_path = os.path.join(path, module_name)
|
module_path = os.path.join(path, module_name)
|
||||||
|
|
||||||
if os.path.isfile(sage_path):
|
if os.path.isfile(sage_path):
|
||||||
# print("\nPreparsing sage file " + sage_name + ".")
|
logging.info("\nPreparsing sage file " + sage_name + ".")
|
||||||
os.system('sage --preparse {}'.format(sage_path));
|
os.system('sage --preparse {}'.format(sage_path));
|
||||||
os.system('mv {} {}.py'.format(python_path, module_path))
|
os.system('mv {} {}.py'.format(python_path, module_path))
|
||||||
|
else:
|
||||||
|
logging.info("sage file not found: " + str(sage_path))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if package is not None:
|
if package is not None:
|
||||||
module_name = package + "." + module_name
|
module_name = package + "." + module_name
|
||||||
|
|
||||||
if module_name in sys.modules:
|
if module_name in sys.modules:
|
||||||
|
logging.info("\nmodule " + module_name + " was found.")
|
||||||
return importlib.reload(sys.modules[module_name])
|
return importlib.reload(sys.modules[module_name])
|
||||||
return importlib.import_module(module_name, package=package)
|
return importlib.import_module(module_name, package=package)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user