diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 278f7bcfb29854394a81cb3c886f3da2ceb3e1cd..58c76a8d88c23f0e6fd227d64bfd38a0d8d5d6d4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,26 +1,14 @@ image: python:3.10 stages: - - dependencies - lint -download_dependencies: - stage: dependencies - before_script: - - python -m venv .venv - - source .venv/bin/activate - script: - - pip install -r requirements.txt - artifacts: - paths: - - .venv - pylint: stage: lint - dependencies: - - download_dependencies - before_script: - - source .venv/bin/activate script: + - python -m venv .venv + - source .venv/bin/activate + - pip install -r requirements.txt # C'est à ton tour de coder un script qui lance pylint sur ton projet - - + - pip install pylint + - pylint calculator --fail-on=warning diff --git a/calculator/expression.py b/calculator/expression.py index 1a27f0c5c27494a971e1479b48bd5c6da9f3ae59..d7967228ba74d0aa1e5d5d85c7c9a1b705657d07 100644 --- a/calculator/expression.py +++ b/calculator/expression.py @@ -1,8 +1,9 @@ """ Expression module defines the structure of an expression. """ -from calculator.operators import Operator from typing import Union +from calculator.operators import Operator + Term: type = int Token: type = Union[Operator, Term] @@ -12,6 +13,7 @@ class OperatorExpression: """ OperatorExpression class is an expression that contains an operator and two sub-expressions. """ + def __init__(self, operator: Operator, left, right): self.operator = operator self.left = left @@ -28,6 +30,7 @@ class TermExpression: """ TermExpression class is an expression that contains a single term. """ + def __init__(self, value: Term): self.value = value diff --git a/calculator/operators.py b/calculator/operators.py index f855332c2cbd379592f4dba51d8c8c66e8c1593d..c12928727c431407a31dcd5aa692080c0b6e3a09 100644 --- a/calculator/operators.py +++ b/calculator/operators.py @@ -1,14 +1,17 @@ """ Operator module contains the Operator class and a list of standard operators. """ + + class Operator: """ Operator class is a binary operator with a symbol, a precedence and an evaluation function. """ + def __init__(self, symbol, precedence, evaluate_function): - self.symbol = symbol - self.precedence = precedence - self.evaluate_function = evaluate_function + self.symbol = symbol + self.precedence = precedence + self.evaluate_function = evaluate_function def __repr__(self): return self.symbol @@ -17,4 +20,9 @@ class Operator: return self.evaluate_function(left, right) -STANDARD_OPERATORS = { '+': Operator('+', 1, lambda a, b: a + b),'-': Operator('-', 1, lambda a, b: a - b),'*': Operator('×', 2, lambda a, b: a * b),'/': Operator('/', 2, lambda a, b: a / b)} +STANDARD_OPERATORS = { + '+': Operator('+', 1, lambda a, b: a + b), + '-': Operator('-', 1, lambda a, b: a - b), + '*': Operator('×', 2, lambda a, b: a * b), + '/': Operator('/', 2, lambda a, b: a / b) +} diff --git a/calculator/server.py b/calculator/server.py index e0dc49ae37812a16bb365a45c95771af16f114b5..feb6402806be44b40a05baa730cf7caac4aba032 100644 --- a/calculator/server.py +++ b/calculator/server.py @@ -1,12 +1,16 @@ -from calculator.calculator import Calculator +""" +C'est le module qui s'occupe du web server +""" from fastapi import FastAPI from fastapi.requests import Request from fastapi.templating import Jinja2Templates +from calculator.calculator import Calculator app = FastAPI() templates = Jinja2Templates(directory="calculator/templates") calc = Calculator() + @app.get("/") async def root(request: Request): """