Commit 91975266 authored by Yori Fournier's avatar Yori Fournier
Browse files

Merge branch '88-cleanning-pep8-compilance' into 'dev'

Almost Resolve "CLEANNING: PEP8 compilance"

See merge request !59
parents 0443382a 1fc7e78e
Pipeline #515 passed with stage
in 12 minutes and 22 seconds
from .myData import MyData
from .mpl_data import MplData
from matplotlib import rcParams
# FORM -----------------------------------------------------------------
......@@ -14,7 +14,7 @@ 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_RAWDATA = MyData() # default raw data
D_RAWDATA = MplData() # default raw data
D_INPUTARG = 'current' # default Input argument
# myIOs
......
from .myData import MyData
from .mpl_data import MplData
from matplotlib import rcParams
# FORM -----------------------------------------------------------------
......@@ -14,7 +14,7 @@ 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_RAWDATA = MyData() # default raw data
D_RAWDATA = MplData() # default raw data
D_INPUTARG = 'current' # default Input argument
# myIOs
......
from .myData import MyData
from .mpl_data import MplData
from matplotlib import rcParams
# FORM -----------------------------------------------------------------
......@@ -14,7 +14,7 @@ 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_RAWDATA = MyData() # default raw data
D_RAWDATA = MplData() # default raw data
D_INPUTARG = 'current' # default Input argument
# myIOs
......
from .myData import MyData
from .mpl_data import MplData
# TECHNICAL ------------------------------------------------------------
D_VERSION='v5'
......@@ -19,7 +19,7 @@ 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_RAWDATA = MyData() # default raw data
D_RAWDATA = MplData() # default raw data
D_INPUTARG = 'current' # default Input argument
# myIOs
......
......@@ -6,6 +6,7 @@ before_script:
- python -m pip --version
- python -m pip install --upgrade pip
- python -m pip install -U matplotlib
- python -m pip install pep8
myplotlib_import_local_latex_tkagg:
script:
......@@ -15,13 +16,14 @@ myplotlib_import_local_latex_tkagg:
- ./setup_test_folder.sh -r latex-tkagg
- python import_test.py
- python -m tests
- python -m tutorials
- ./clean_test_folder.sh
myplotlib_test_mytool:
script:
- git name-rev --name-only HEAD
- ls -l
- cd mytool
- cd mpl_toolbox/
- cp ../.configs/tests/config-local.py ../config.py
- python -m tests
- python -m tutorials
......@@ -35,3 +37,11 @@ myplotlib_import_network_latex_tkagg:
- python test_com_nogl.py
- python -m tests
- ./clean_test_folder.sh
myplotlib_test_pep8:
script:
- git name-rev --name-only HEAD
- ls -l
- cd test
- python -m comp_pep8
allow_failure: true
......@@ -38,24 +38,40 @@ from .config import D_HIERARCHY
import os as os
import numpy as np
np.set_printoptions(threshold='nan')
from signal import Signal, Query, Status, Answer
from mpl_unpickler import MplUnpickler
np.set_printoptions(threshold='nan')
# matplotlib import for client/local -----------------------------------
if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
if D_HIERARCHY in ('CLIENT', 'client'):
print(INFO+'Import '+__package__+' as a client.')
print(INFO + 'Import ' + __package__ + ' as a client.')
else:
print(INFO+'Import '+__package__+' for local use.')
print(INFO + 'Import ' + __package__ + ' for local use.')
# Test mpl version:
from matplotlib import __version__ as mplvers
if int(mplvers.replace('.','')[:3]) < 143 :
print('\n\n' + WARN + 72*'=' + '\n' + SPCE + 'The matplotlib version you are using is not supported.\n' + SPCE + 'Most of myplotlib should work, but some stuff may not.\n' + SPCE + 'ex: expect an error with test203\n' + SPCE + 72*'=' + '\n\n')
if int(mplvers.replace('.', '')[:3]) < 143:
print(
'\n\n' +
WARN +
72 *
'=' +
'\n' +
SPCE +
'The matplotlib version you are using is not supported.\n' +
SPCE +
'Most of myplotlib should work, but some stuff may not.\n' +
SPCE +
'ex: expect an error with test203\n' +
SPCE +
72 *
'=' +
'\n\n')
# matplotlib
from matplotlib.pyplot import figure
......@@ -72,16 +88,17 @@ if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
from socket import socket, AF_INET, SOCK_STREAM
elif D_HIERARCHY in ('SERVER', 'server'):
print(INFO+'Import '+__package__+' as a server.')
if DBUG:
print(INFO + 'Import ' + __package__ + ' as a server.')
from .config import D_HOST, D_PORT
from socket import socket, AF_INET, SOCK_STREAM, SOL_SOCKET, SO_REUSEADDR
else:
print(SEVR+'the value of D_HIERARCHY has to be SERVER or CLIENT')
print(SEVR + 'the value of D_HIERARCHY has to be SERVER or CLIENT')
raise ImportError
# myplotlib
from .myData import MyData
from .mpl_data import MplData
# CONFIGURATION --------------------------------------------------------
from .config import D_FIGNUM, D_FIGSIZE, D_REFORMAT, D_FORMATTED
......@@ -96,58 +113,52 @@ if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
if D_HIERARCHY in ('CLIENT', 'client'):
# MyAxes: Overlay on matplotlib.Axes class
from .myAxes_client import MyAxes_client as MyAxes
# MplAxes: Overlay on matplotlib.Axes class
from .mpl_axes_client import MplAxesClient as MplAxes
from .mpl_grid import Grid, VerticalGrid, HorizontalGrid
# MyFig: Overlay on matplotlib.Figure class
from .myFig_client import MyFig_client as MyFig
# MplFig: Overlay on matplotlib.Figure class
from .mpl_fig_client import MplFigClient as MplFig
from .progressbar import ProgressBar
from .mplClient import MplClient
from .mplClient2 import MplClient2
from .mpl_client import MplClient
elif(D_HIERARCHY in ('SERVER', 'server')):
# MyAxes: Overlay on matplotlib.Axes class
from .myAxes_server import MyAxes_server as MyAxes
# MplAxes: Overlay on matplotlib.Axes class
from .mpl_axes_server import MplAxesServer as MplAxes
# MyFig: Overlay on matplotlib.Figure class
from .myFig_server import MyFig_server as MyFig
from .mpl_grid import Grid, VerticalGrid, HorizontalGrid
# from .test import FigTestServer
# from .test import FigTest
# for testing purpose
# from .test import readStupidData, readStupidData2
# MplFig: Overlay on matplotlib.Figure class
from .mpl_fig_server import MplFigServer as MplFig
SERVER_IOFUNCTIONS = {
# 'readStupidData': readStupidData,
# 'readStupidData2': readStupidData2
# 'readStupidData': readStupidData,
# 'readStupidData2': readStupidData2
}
SERVER_FIGURES = {
#'FigTest': FigTest
}
from .mplServer import MplServer
from .mplServer2 import MplServer2, MplHandler
from .mpl_server import MplServer, MplHandler
elif D_HIERARCHY in ('LOCAL', 'local'):
# MyAxes: Overlay on matplotlib.Axes class
from .myAxes import MyAxes
# MyFig: Overlay on matplotlib.Figure class
from .myFig import MyFig
from .mplGrid import Grid, VerticalGrid, HorizontalGrid
# MplAxes: Overlay on matplotlib.Axes class
from .mpl_axes import MplAxes
# MplFig: Overlay on matplotlib.Figure class
from .mpl_grid import Grid, VerticalGrid, HorizontalGrid
from .mpl_fig import MplFig
from .empty_fig import EmptyFig
from .empty_axes import EmptyAxes
else:
print(SEVR+'the value of D_HIERARCHY has to be SERVER, CLIENT or LOCAL')
print(SEVR + 'the value of D_HIERARCHY has to be SERVER, CLIENT or LOCAL')
raise ImportError
......@@ -167,24 +178,5 @@ if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
elif rcParams['backend'] == u'MacOSX':
from .myWin_MacOSx import MyWin_MacOSx as MyWin
else:
print(SEVR + "The backend you choosed is not supported interactive mode not available")
# myTool.*: interface functions to use myplotlib interactively
#from .mytool import print2file # need to make tools for server ?? or just put them in client/local
#from .mytool import FigOneAxes
#if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
# from .mytool import print2file # need to make tools for server ?? or just put them in client/local
# from .mytool import FigOneAxes
# from .mytool import window_exists, getCurrentWindowIDs
# from .mytool import print2file, print2screen, printListCurrentWindows
# from .mytool import getWindow, getFigOnWindow, drawFigOnWindow, giveDataToWindow
# from .mytool import closeWindow, closeAllWindows
# TESTS ----------------------------------------------------------------
# from .test import myTest
# from .test import testList
# from .test import FigTest
print(SEVR + """The backend you choosed is not
supported interactive mode not available""")
......@@ -35,8 +35,8 @@ from . import D_HIERARCHY
from . import INFO, SPCE, DBUG
if D_HIERARCHY in ('CLIENT', 'client', 'local', 'LOCAL'):
from . import myTest, testList
from .test import __dict__ as availTests
from . import myTest
from .test import __dict__ as avail_tests
else:
from socket import socket, AF_INET, SOCK_STREAM
from . import D_HOST, D_PORT
......@@ -82,8 +82,8 @@ for opt, arg in opts:
tests = arg.split(', ')
testList = []
for test in tests:
if test in availTests.keys():
testList.append(availTests[test])
if test in avail_tests.keys():
testList.append(avail_tests[test])
if len(testList) == 0:
print(" > sevr-: you need to give valid tests to be tested.")
......@@ -104,9 +104,19 @@ for opt, arg in opts:
if run4Test:
if debug:
print(DBUG + '{title:{c}^{n}}'.format(title=' Run for Test ', c='=', n=72))
print(
DBUG +
'{title:{c}^{n}}'.format(
title=' Run for Test ',
c='=',
n=72))
else:
print(INFO + '{title:{c}^{n}}'.format(title=' Run for Test ', c='=', n=72))
print(
INFO +
'{title:{c}^{n}}'.format(
title=' Run for Test ',
c='=',
n=72))
fail = []
status = True
......@@ -114,8 +124,10 @@ if run4Test:
print(INFO + "TESTS: ")
for test in testList:
print('\n')
print(INFO + '{title:{c}^{n}}'.format(title=' ' + str(test.__name__) + ' ', c='=', n=72))
testStatus = myTest(test, True, fail, debug) # function, expected, fail, debug
print(INFO + '{title:{c}^{n}}'.format(title=' ' + \
str(test.__name__) + ' ', c='=', n=72))
# function, expected, fail, debug
testStatus = myTest(test, True, fail, debug)
if testStatus:
print(INFO + 72 * '-' + " [PASSED]")
else:
......@@ -158,5 +170,3 @@ elif run4server:
else:
print(usage)
from .myData import MyData
from .mpl_Data import MplData
from matplotlib import rcParams
# FORM -----------------------------------------------------------------
......@@ -14,7 +14,7 @@ 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_RAWDATA = MyData() # default raw data
D_RAWDATA = MplData() # default raw data
D_INPUTARG = 'current' # default Input argument
# myIOs
......@@ -36,7 +36,7 @@ rcParams['font.family'] = 'serif'
rcParams['font.size'] = '22'
try:
rcParams['text.usetex'] = True # need dvipng, ghostscript, and Agg
except:
except Exception:
print(WARN + "I could not set the LaTeX font sorry...")
# LINES
......@@ -61,7 +61,7 @@ try:
rcParams['ytick.minor.width'] = 1.5
rcParams['xtick.minor.visible'] = False
rcParams['ytick.minor.visible'] = False
except:
except Exception:
pass
# DPI
......
from .myData import MyData
from .mpl_Data import MplData
# TECHNICAL ------------------------------------------------------------
D_VERSION='v5'
D_HIERARCHY='SERVER'
D_HOST='localhost'
D_PORT=50803
D_VERSION = 'v5'
D_HIERARCHY = 'SERVER'
D_HOST = 'localhost'
D_PORT = 50803
# FORM -----------------------------------------------------------------
INFO = " > info-: "
......@@ -19,7 +19,7 @@ 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_RAWDATA = MyData() # default raw data
D_RAWDATA = MplData() # default raw data
D_INPUTARG = 'current' # default Input argument
# myIOs
......
from myplotlib import MyAxes
from myplotlib import MplAxes
class EmptyAxes(MyAxes):
class EmptyAxes(MplAxes):
def plotting(self):
return(True)
def formatRawData(self, rawdata):
def format_rawdata(self, rawdata):
self.data = rawdata.data
return(True)
from myplotlib import MyFig
from myplotlib import MplFig
class EmptyFig(MyFig):
class EmptyFig(MplFig):
def __init__(self, **kwargs):
MyFig.__init__(self, (), **kwargs)
MplFig.__init__(self, (), **kwargs)
def addAxes(self):
pass
from . import socket, AF_INET, SOCK_STREAM
from . import INFO, DBUG, WARN, SEVR, SPCE
SIZE_STATUS_MAX = 1024
from . import ProgressBar
from . import D_DEBUG
DEBUG = D_DEBUG
# CLASS CLIENT ---------------------------------------------------------
class MplClient(object):
# CONSTRUCTOR ------------------------------------------------------
def __init__(self, ip, port):
'''This is a myplotlib client.
It sends instructions to a MplSever at host:port.
'''
self.ip = ip
self.port = port
# just a list of names
#~ self.currentRemoteData = []
# PACK SIGNAL ------------------------------------------------------
def packSignal(self, unpackedSignal):
'''Pack the signal.'''
packedSignal = ''
header, instrucSize = unpackedSignal
header = str(header)
instrucSize = str(instrucSize)
packedSignal = "("+"\""+header+"\""+", "+instrucSize+")"
return(packedSignal)
# PACK INSTRUCTION -------------------------------------------------
def packInstructions(self, instructions):
'''Pack the instructions, a tuple of strings: (header, content).'''
header, packedContent = instructions
packedInstructions = "(\""+header+"\", "+str(packedContent)+")"
return(packedInstructions)
# PACK READDATA CONTENT --------------------------------------------
def packReadDataContent(self, ioFunction, dataName, *args, **kwargs):
'''Pack the content of the instructions for readData.'''
packedContent = "['"+str(dataName)+"', '"+ioFunction.__name__+"', "+str(args)+", "+str(kwargs)+"]"
return(packedContent)
# READ DATA --------------------------------------------------------
def readData(self, ioFunction, dataName, *args, **kwargs):
'''Start the readData procedure.
1. Send ReadData Signal with length of packedInstructions
2. Wait for receipt
3. Send Instructions
4. Wait for status
'''
# Pack instructions and get size
content = self.packReadDataContent(ioFunction, dataName, *args, **kwargs)
packedInstructions = self.packInstructions(('readData', content))
instructionSize = len(packedInstructions)
# Send the signal with size
signal = self.packSignal(('readData', instructionSize))
sock = self.sendSignal(signal)
if(DEBUG):
print(INFO+'Sent Signal, waiting for receipt...')
status = self.waitForReceipt(sock)
# Check status
if not status:
return(False)
if(DEBUG):
print(INFO+'Received the receipt')
print(INFO+'Sent the instructions, waiting for status: ')
# Send Instructions
self.sendInstructions(sock, packedInstructions)
# Check status
status = self.waitForStatus(sock)
if not status:
return(False)
return(True)
# SEND SIGNAL ------------------------------------------------------
def sendSignal(self, packedSignal):
'''Send a signal: readData, newSyncFigure, syncFigFormatRawData'''
sock = socket(AF_INET, SOCK_STREAM)
sock.connect((self.ip, self.port))
sock.sendall(str(packedSignal))
return(sock)
# WAIT FOR RECEIPT -------------------------------------------------
def waitForReceipt(self, sock):
'''Wait for the receipt. return a tuple.'''
answer = sock.recv(SIZE_STATUS_MAX)
status = False
errmsg = ''
header = ''
try:
header, status, errmsg = eval(answer)
except:
print(SEVR+'could not Exctract the receipt.')
print(SEVR+'Received: '+str(answer))
status = eval(status)
if not status:
print(SEVR+"SERVER: "+str(errmsg))
return(status)
# SEND INSTRUCTIONS ------------------------------------------------
def sendInstructions(self, sock, packedInstructions):
'''Send Instructions.'''
sock.sendall(packedInstructions)
return(True)
# SEND ALT INSTRUCTIONS --------------------------------------------
# def sendInstructions(self, packedInstructions):
# '''Send Instructions.'''
# sock = socket(AF_INET, SOCK_STREAM)
# sock.connect((self.ip, self.port))
# sock.sendall(packedInstructions)
#
# return(sock)
# WAIT FOR STATUS --------------------------------------------------
def waitForStatus(self, sock):
'''Wait for the status. return a tuple.'''
answer = sock.recv(SIZE_STATUS_MAX)
status = False
errmsg = ''
header = ''
try:
header, status, errmsg = eval(answer)
except:
print(SEVR+'could not Exctract the status.')
status = eval(status)
if not status:
print(SEVR+"SERVER: "+str(errmsg))
return(status)
# NEW SYNC FIGURE --------------------------------------------------
def newSyncFigure(self, figClass, symbolicRawdata, **kwargs):
'''Start the readData procedure.
1. Send newSyncFigure Signal with length of packedInstructions
2. Wait for receipt
3. Send Instructions
4. Wait for status
'''
# create temporary syncFigure
syncFigure = figClass(symbolicRawdata, **kwargs)
# Pack instructions and get size
content = self.packNewSyncFigureContent(figClass, symbolicRawdata, **kwargs)
packedInstructions = self.packInstructions(('newSyncFigure', content))
instructionSize = len(packedInstructions)
# Send the signal with size
signal = self.packSignal(('newSyncFigure', instructionSize))
sock = self.sendSignal(signal)
if(DEBUG):
print(INFO+'Sent Signal, waiting for receipt...')
# Wait for the receipt
status = self.waitForReceipt(sock)
# Check status
if not status:
del(syncFigure)
return(None)
if(DEBUG):
print(INFO+'Received the receipt')
print(INFO+'Sent the instructions, waiting for status: ')
# Send Instructions
self.sendInstructions(sock, packedInstructions)
# Check status
ID = self.waitForStatus(sock)
# If failed
if not ID:
del(syncFigure)
return(None)
# If created