Commit 684ddc82 authored by Yori Fournier's avatar Yori Fournier
Browse files

Merge branch '103-MODIF-installing-with-setup' into 'dev'

Resolve "MODIF: load config dynamically"

Closes #107

See merge request !75
parents 4ded1528 17fbfec1
Pipeline #723 failed with stage
{
"D_VERSION": "v5",
"CONTEXT": "client",
"D_HOST": "localhost",
"D_PORT": 50803,
"INFO": " > info-: ",
"WARN": " > warn-: ",
"SEVR": " > sevr-: ",
"DBUG": " > dbug-: ",
"SPCE": " > -----: ",
"D_FIGNUM": 0,
"D_FIGSIZE":[8.0, 6.0],
"D_REFORMAT": true,
"D_FORMATTED": false,
"D_INPUTARG": "current",
"D_IPATH": "../",
"D_OPATH": "myplotlib/img",
"D_OFORMAT": "png",
"D_DEBUG": true
}
from .mpl_data import MplData
# TECHNICAL ------------------------------------------------------------
D_VERSION='v5'
CONTEXT='CLIENT'
D_HOST='localhost'
D_PORT=50803
# FORM -----------------------------------------------------------------
INFO = " > info-: "
WARN = " > warn-: "
SEVR = " > sevr-: "
DBUG = " > dbug-: "
SPCE = " > -----: "
# CONFIGURATION --------------------------------------------------------
# myFig
D_FIGNUM = 0 # default figure number
D_FIGSIZE = (8., 6.) # default figure size
D_REFORMAT = True # default reformat value
D_FORMATTED = False # default formatted value
D_INPUTARG = 'current' # default Input argument
# myIOs
D_IPATH = '../' # default path to project
# print2file
D_OPATH = 'myplotlib/img/' # default path to ouput
D_OFORMAT = 'png' # default format for ouput
# Debug
D_DEBUG = True # default debug value
from .mpl_data import MplData
# TECHNICAL ------------------------------------------------------------
D_VERSION='v5'
CONTEXT='LOCAL'
D_HOST='localhost'
D_PORT=50803
# FORM -----------------------------------------------------------------
INFO = " > info-: "
WARN = " > warn-: "
SEVR = " > sevr-: "
DBUG = " > dbug-: "
SPCE = " > -----: "
# CONFIGURATION --------------------------------------------------------
# myFig
D_FIGNUM = 0 # default figure number
D_FIGSIZE = (8., 6.) # default figure size
D_REFORMAT = True # default reformat value
D_FORMATTED = False # default formatted value
D_INPUTARG = 'current' # default Input argument
# myIOs
D_IPATH = '../' # default path to project
# print2file
D_OPATH = 'myplotlib/img/' # default path to ouput
D_OFORMAT = 'png' # default format for ouput
# Debug
D_DEBUG = True # default debug value
from .mpl_data import MplData
# TECHNICAL ------------------------------------------------------------
D_VERSION='v5'
CONTEXT='server'
D_HOST='localhost'
D_PORT=50803
# FORM -----------------------------------------------------------------
INFO = " > info-: "
WARN = " > warn-: "
SEVR = " > sevr-: "
DBUG = " > dbug-: "
SPCE = " > -----: "
# CONFIGURATION --------------------------------------------------------
# myFig
D_FIGNUM = 0 # default figure number
D_FIGSIZE = (8., 6.) # default figure size
D_REFORMAT = True # default reformat value
D_FORMATTED = False # default formatted value
D_INPUTARG = 'current' # default Input argument
# myIOs
D_IPATH = '../' # default path to project
# print2file
D_OPATH = 'myplotlib/img/' # default path to ouput
D_OFORMAT = 'png' # default format for ouput
# Debug
D_DEBUG = True # default debug value
{
"D_VERSION": "v5",
"CONTEXT": "local",
"D_HOST": "localhost",
"D_PORT": 50803,
"INFO": " > info-: ",
"WARN": " > warn-: ",
"SEVR": " > sevr-: ",
"DBUG": " > dbug-: ",
"SPCE": " > -----: ",
"D_FIGNUM": 0,
"D_FIGSIZE":[8.0, 6.0],
"D_REFORMAT": true,
"D_FORMATTED": false,
"D_INPUTARG": "current",
"D_IPATH": "../",
"D_OPATH": "myplotlib/img",
"D_OFORMAT": "png",
"D_DEBUG": true
}
{
"D_VERSION": "v5",
"CONTEXT": "server",
"D_HOST": "localhost",
"D_PORT": 50803,
"INFO": " > info-: ",
"WARN": " > warn-: ",
"SEVR": " > sevr-: ",
"DBUG": " > dbug-: ",
"SPCE": " > -----: ",
"D_FIGNUM": 0,
"D_FIGSIZE":[8.0, 6.0],
"D_REFORMAT": true,
"D_FORMATTED": false,
"D_INPUTARG": "current",
"D_IPATH": "../",
"D_OPATH": "myplotlib/img",
"D_OFORMAT": "png",
"D_DEBUG": true
}
......@@ -33,8 +33,12 @@
#
#
# IMPORT ---------------------------------------------------------------
from .config import INFO, WARN, SEVR, DBUG, SPCE
from .config import CONTEXT
import sys
# CONFIGURATION
from .mpl_config import load_config
module = sys.modules[__name__]
load_config(module)
import os as os
import numpy as np
......@@ -74,13 +78,11 @@ if CONTEXT.lower() in ('client', 'local'):
from matplotlib import is_interactive
from matplotlib import use
from .config import D_HOST, D_PORT
from socket import socket, AF_INET, SOCK_STREAM
elif CONTEXT.lower() == 'server':
if DBUG:
print(INFO + 'Import ' + __name__ + ' as a server.')
from .config import D_HOST, D_PORT
from socket import socket, AF_INET, SOCK_STREAM, SOL_SOCKET, SO_REUSEADDR
else:
......@@ -91,13 +93,6 @@ else:
# from .mpl_data import MplData
# CONFIGURATION --------------------------------------------------------
from .config import D_FIGNUM, D_FIGSIZE, D_REFORMAT, D_FORMATTED
# from .config import D_RAWDATA, D_INPUTARG
from .config import D_INPUTARG
from .config import D_IPATH
from .config import D_OPATH, D_OFORMAT
from .config import D_DEBUG
if CONTEXT.lower() in ('client', 'local'):
from .rconfig import rcParams
......
{
"D_VERSION": "v5",
"CONTEXT": "local",
"D_HOST": "localhost",
"D_PORT": 50803,
"INFO": " > info-: ",
"WARN": " > warn-: ",
"SEVR": " > sevr-: ",
"DBUG": " > dbug-: ",
"SPCE": " > -----: ",
"D_FIGNUM": 0,
"D_FIGSIZE":[8.0, 6.0],
"D_REFORMAT": true,
"D_FORMATTED": false,
"D_INPUTARG": "current",
"D_IPATH": "../",
"D_OPATH": "myplotlib/img",
"D_OFORMAT": "png",
"D_DEBUG": true
}
import os
import inspect
import json
D_CONFIG_FILENAME='config.json'
def open_config(filename: str):
try:
fd = open(filename, 'r')
except FileNotFoundError:
try:
fd = open('./' + filename, 'r')
except FileNotFoundError:
print("WARNING: No user config file. fallback on default.")
try:
path_to_myplotlib = os.path.dirname(inspect.getfile(inspect.currentframe()))
fd = open(path_to_myplotlib + '/default-config.json', 'r')
except FileNotFoundError:
print("ERROR: ``default-config.json`` could not be found. Wrong installation.")
raise
return(fd)
def read_config(fd):
return(json.load(fd))
def import_config(module, config):
for config_item, config_value in config.items():
setattr(module, config_item, config_value)
def load_config(module, filename=D_CONFIG_FILENAME):
fd = open_config(filename)
config = read_config(fd)
import_config(module, config)
......@@ -2,8 +2,10 @@
# On the server side
cd myplotlib
# save the config
mv config.py config.save
find . -maxdepth 1 -name "*.py" -exec unlink {} \;
# recover theconfig
mv config.save config.py
cd mpl_toolbox
find . -maxdepth 1 -name "*.py" -exec unlink {} \;
cd ../
rm -r mpl_toolbox
rm -r __pycache__
{
"D_VERSION": "v5",
"CONTEXT": "local",
"D_HOST": "localhost",
"D_PORT": 50803,
"INFO": " > info-: ",
"WARN": " > warn-: ",
"SEVR": " > sevr-: ",
"DBUG": " > dbug-: ",
"SPCE": " > -----: ",
"D_FIGNUM": 0,
"D_FIGSIZE":[8.0, 6.0],
"D_REFORMAT": true,
"D_FORMATTED": false,
"D_INPUTARG": "current",
"D_IPATH": "../",
"D_OPATH": "myplotlib/img",
"D_OFORMAT": "png",
"D_DEBUG": true
}
*
!.gitignore
!config.py
!default-config.json
from .mpl_data import MplData
# TECHNICAL ------------------------------------------------------------
D_VERSION='v5'
CONTEXT='LOCAL'
D_HOST='localhost'
D_PORT=50803
# FORM -----------------------------------------------------------------
INFO = " > info-: "
WARN = " > warn-: "
SEVR = " > sevr-: "
DBUG = " > dbug-: "
SPCE = " > -----: "
# CONFIGURATION --------------------------------------------------------
# myFig
D_FIGNUM = 0 # default figure number
D_FIGSIZE = (8., 6.) # default figure size
D_REFORMAT = True # default reformat value
D_FORMATTED = False # default formatted value
D_INPUTARG = 'current' # default Input argument
# myIOs
D_IPATH = '../' # default path to project
# print2file
D_OPATH = 'myplotlib/img/' # default path to ouput
D_OFORMAT = 'png' # default format for ouput
# Debug
D_DEBUG = True # default debug value
......@@ -2,7 +2,6 @@
# On the virtual local host
cd myplotlib
#cp ../../../.configs/tests/rconfig-latex-tkagg.py rconfig.py
find ../../../ -maxdepth 1 -name "*.py" -exec ln -s {} . \;
mkdir mpl_toolbox
......
......@@ -3,15 +3,17 @@
# On the server side
cd serverside/myplotlib
# save the config
mv config.py config.save
mv default-config.json config.save
find . -maxdepth 1 -name "*.py" -exec unlink {} \;
rm -r __pycache__
# recover theconfig
mv config.save config.py
mv config.save default-config.json
# On the client side
cd ../../clientside/myplotlib
# save the config
mv config.py config.save
mv default-config.json config.save
find . -maxdepth 1 -name "*.py" -exec unlink {} \;
rm -r __pycache__
# recover theconfig
mv config.save config.py
mv config.save default-config.json
from .mpl_data import MplData
# TECHNICAL ------------------------------------------------------------
D_VERSION='v5'
CONTEXT='CLIENT'
D_HOST='localhost'
D_PORT=50803
# FORM -----------------------------------------------------------------
INFO = " > info-: "
WARN = " > warn-: "
SEVR = " > sevr-: "
DBUG = " > dbug-: "
SPCE = " > -----: "
# CONFIGURATION --------------------------------------------------------
# myFig
D_FIGNUM = 0 # default figure number
D_FIGSIZE = (8., 6.) # default figure size
D_REFORMAT = True # default reformat value
D_FORMATTED = False # default formatted value
D_INPUTARG = 'current' # default Input argument
# myIOs
D_IPATH = '../' # default path to project
# print2file
D_OPATH = 'myplotlib/img/' # default path to ouput
D_OFORMAT = 'png' # default format for ouput
# Debug
D_DEBUG = True # default debug value
{
"D_VERSION": "v5",
"CONTEXT": "client",
"D_HOST": "localhost",
"D_PORT": 50803,
"INFO": " > info-: ",
"WARN": " > warn-: ",
"SEVR": " > sevr-: ",
"DBUG": " > dbug-: ",
"SPCE": " > -----: ",
"D_FIGNUM": 0,
"D_FIGSIZE":[8.0, 6.0],
"D_REFORMAT": true,
"D_FORMATTED": false,
"D_INPUTARG": "current",
"D_IPATH": "../",
"D_OPATH": "myplotlib/img",
"D_OFORMAT": "png",
"D_DEBUG": true
}
from .mpl_data import MplData
# TECHNICAL ------------------------------------------------------------
D_VERSION='v5'
CONTEXT='SERVER'
D_HOST='localhost'
D_PORT=50803
# FORM -----------------------------------------------------------------
INFO = " > info-: "
WARN = " > warn-: "
SEVR = " > sevr-: "
DBUG = " > dbug-: "
SPCE = " > -----: "
# CONFIGURATION --------------------------------------------------------
# myFig
D_FIGNUM = 0 # default figure number
D_FIGSIZE = (8., 6.) # default figure size
D_REFORMAT = True # default reformat value
D_FORMATTED = False # default formatted value
D_INPUTARG = 'current' # default Input argument
# myIOs
D_IPATH = '../' # default path to project
# print2file
D_OPATH = 'myplotlib/img/' # default path to ouput
D_OFORMAT = 'png' # default format for ouput
# Debug
D_DEBUG = True # default debug value
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