Ajout de la vérification du code Python

This commit is contained in:
Philippe Roy 2022-12-06 03:48:40 +01:00
parent c0a71068e0
commit 21010eca37
13 changed files with 26 additions and 6 deletions

View File

@ -61,14 +61,19 @@ L'environnement de développement est basé sur : la plateforme de modélisation
Le code source, les fichiers blender et les assets sont hébergés sur le dépôt [gitlab](https://gitlab.com/blender-edutech/ropy).
La bibliothèque **serial** utilisée pour la communication sur le port série (jumeau numérique) n'est pas incluse par défaut dans l'environnement UPBGE.
Les bibliothèques suivantes ne sont pas incluses par défaut dans l'environnement UPBGE :
- **pylint** : vérificateur du code Python
- **serial** : communication sur le port série (jumeau numérique)
Il faut donc l'installer localement, les étapes sont :
Il faut donc les installer localement, les étapes sont :
- GNU/Linux : La configuration ici présente est UPBGE installé sur ~ avec Python 3.9 :
- Aller dans le répertoire local de Python de UPBGE: $ cd ~/UPBGE-0.30-linux-x86_64/3.0/python/bin
- Installer localement (UPBGE) le gestionnaire de paquet pip : $ ./python3.9 -m ensurepip --default-pip
- Installer localement (UPBGE) la bibliothèque pylint : $ ./pip install pylint -t ~/UPBGE-0.30-linux-x86_64/3.0/python/lib/python3.9/site-packages
- Installer localement (UPBGE) la bibliothèque serial : $ ./pip install serial -t ~/UPBGE-0.30-linux-x86_64/3.0/python/lib/python3.9/site-packages
- Windows : La configuration ici présente est UPBGE installé sur le bureau utilisateur (philippe.roy) avec la distribution Anaconda installée :
- Avec Anaconda Navigator ouvrir un terminal Powershell
- Avec le terminal installer localement (UPBGE) la bibliothèque pylint : pip install pylint -t C:\Users\philippe.roy\Desktop\UPBGE-0.30-windows-x86_64\3.0\python\lib\site-packages
- Avec le terminal installer localement (UPBGE) la bibliothèque serial : pip install serial -t C:\Users\philippe.roy\Desktop\UPBGE-0.30-windows-x86_64\3.0\python\lib\site-packages

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
ropy-31.blend1 Normal file

Binary file not shown.

1
ropy.bat Normal file
View File

@ -0,0 +1 @@
ropy.exe -con

19
rp.py
View File

@ -11,6 +11,8 @@ import webbrowser # Lien internet
import threading # Multithreading
import xml.etree.ElementTree as ET # Creating/parsing XML file
import runpy # Execution de script Python légère (sans import)
import ast # Parser de code Python
from pylint import epylint as lint # Controle de code Python
import rp_map1 as rp_map # Map definition
import rp_doc # Documentation
@ -218,6 +220,17 @@ def terrain_init (cont):
# Mise en route et pause du cycle
##
def python_validation():
lint.py_run('rp_cmd.py --disable=C --disable=W --disable=R')
with open('rp_cmd.py') as f:
contents = f.read()
try:
ast.parse(contents)
# or compile(contents, fname, 'exec', ast.PyCF_ONLY_AST)
return True
except SyntaxError:
return False
def terrain_run ():
# Pause
@ -252,7 +265,8 @@ def terrain_run ():
scene.objects['Points']['nbligne'] = len(file_txt.split("\n"))-28 # 28 lignes utilisées de base
file.close()
scene.objects['Rover']['stop'] = False
runpy.run_module('rp_cmd', run_name='start') # Execution du script utilisateur
if python_validation():
runpy.run_module('rp_cmd', run_name='start') # Execution du script utilisateur
# Arrêt de la pause
else:
@ -274,7 +288,8 @@ def terrain_stop ():
def terrain_end (cont):
if cont.sensors['End cycle'].positive:
scene.objects['Terrain']['run']=False
runpy.run_module('rp_cmd', run_name='stop') # Fin du script utilisateur
if python_validation():
runpy.run_module('rp_cmd', run_name='stop') # Fin du script utilisateur
# Commandes
scene.objects['Pause'].setVisible(False,False)

View File

@ -1,4 +1,3 @@
import bge # Bibliothèque Blender Game Engine (UPBGE)
import time
from rp_lib import * # Bibliothèque Ropy
@ -29,7 +28,7 @@ from rp_lib import * # Bibliothèque Ropy
def commandes():
# Ecrire votre code ici ...
rp_fin() # A garder
###############################################################################