diff --git a/.github/workflows/linting.yaml b/.github/workflows/linting.yaml new file mode 100644 index 0000000..23e5f90 --- /dev/null +++ b/.github/workflows/linting.yaml @@ -0,0 +1,30 @@ +name: Linting + +on: + push: + branches: [ "main", "master" ] + pull_request: + branches: [ "main", "master" ] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.13" + + - name: Install Ruff + run: | + python -m pip install --upgrade pip + pip install ruff + + - name: Run Ruff Lint + run: ruff check . + + - name: Run Ruff Format Check + run: ruff format --check . \ No newline at end of file diff --git a/Canvas.py b/Canvas.py index 4cb155c..3d199fe 100644 --- a/Canvas.py +++ b/Canvas.py @@ -3,7 +3,6 @@ class MplCanvas(FigureCanvasQTAgg): - def __init__(self, parent=None, width=6, height=6, dpi=100): fig = Figure(figsize=(width, height), dpi=dpi) self.axes = fig.add_subplot(111) diff --git a/CanvasThreeD.py b/CanvasThreeD.py index ab762a3..7536363 100644 --- a/CanvasThreeD.py +++ b/CanvasThreeD.py @@ -3,7 +3,6 @@ class MplCanvas(FigureCanvasQTAgg): - def __init__(self, parent=None, width=6, height=6, dpi=100): fig = Figure(figsize=(width, height), dpi=dpi) self.axes = fig.add_subplot(projection="3d") diff --git a/CheckCreateDirectory.py b/CheckCreateDirectory.py index ea2ef0b..082e467 100644 --- a/CheckCreateDirectory.py +++ b/CheckCreateDirectory.py @@ -7,7 +7,6 @@ def check_create_dir(path): isExist = os.path.exists(path) if not isExist: - # Create a new directory because it does not exist os.makedirs(path) print("The new directory is created!") diff --git a/Circle.py b/Circle.py index d4955da..2518a2d 100644 --- a/Circle.py +++ b/Circle.py @@ -27,7 +27,7 @@ import CircleCalc import Canvas import SaveFig -from Shape import * +from Shape import ShapeFunctionality # Get the absolute path to the directory where this script is located SCRIPT_DIR = Path(__file__).resolve().parent diff --git a/Cube.py b/Cube.py index 19c1263..b675dcf 100644 --- a/Cube.py +++ b/Cube.py @@ -27,7 +27,7 @@ import CubeCalc import CanvasThreeD import SaveFig -from Shape import * +from Shape import ShapeFunctionality # Get the absolute path to the directory where this script is located SCRIPT_DIR = Path(__file__).resolve().parent diff --git a/Ellipse.py b/Ellipse.py index 44ce08f..512bbed 100644 --- a/Ellipse.py +++ b/Ellipse.py @@ -27,7 +27,7 @@ import EllipseCalc import Canvas import SaveFig -from Shape import * +from Shape import ShapeFunctionality # Get the absolute path to the directory where this script is located SCRIPT_DIR = Path(__file__).resolve().parent diff --git a/Ellipsoid.py b/Ellipsoid.py index d221b52..37349c9 100644 --- a/Ellipsoid.py +++ b/Ellipsoid.py @@ -27,7 +27,7 @@ import EllipsoidCalc import CanvasThreeD import SaveFig -from Shape import * +from Shape import ShapeFunctionality # Get the absolute path to the directory where this script is located SCRIPT_DIR = Path(__file__).resolve().parent diff --git a/MathApp.py b/MathApp.py index ca721c4..c069495 100644 --- a/MathApp.py +++ b/MathApp.py @@ -1,5 +1,8 @@ import sys from pathlib import Path +import matplotlib + +matplotlib.use("Qt5Agg") from PyQt5.QtWidgets import ( QApplication, @@ -22,26 +25,21 @@ from PyQt5 import QtCore -# Get the absolute path to the directory where this script is located -SCRIPT_DIR = Path(__file__).resolve().parent - -from Circle import * -from Sphere import * -from Ellipse import * -from Ellipsoid import * -from Square import * -from Cube import * - -import matplotlib - -matplotlib.use("Qt5Agg") +from Circle import WindowCircle +from Sphere import WindowSphere +from Ellipse import WindowEllipse +from Ellipsoid import WindowEllipsoid +from Square import WindowSquare +from Cube import WindowCube from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg from matplotlib.figure import Figure +# Get the absolute path to the directory where this script is located +SCRIPT_DIR = Path(__file__).resolve().parent -class MplCanvas(FigureCanvasQTAgg): +class MplCanvas(FigureCanvasQTAgg): def __init__(self, parent=None, width=5, height=5, dpi=100): fig = Figure(figsize=(width, height), dpi=dpi) self.axes = fig.add_subplot(111) @@ -50,7 +48,6 @@ def __init__(self, parent=None, width=5, height=5, dpi=100): class MainWindow(QMainWindow): - def __init__(self): super().__init__() @@ -75,9 +72,9 @@ def __init__(self): buttonClose = QPushButton("Close") buttonClose.clicked.connect(app.closeAllWindows) - l = QHBoxLayout() - l.addStretch(1) - l.addWidget(buttonClose) + layout = QHBoxLayout() + layout.addStretch(1) + layout.addWidget(buttonClose) l2 = QVBoxLayout() @@ -122,7 +119,7 @@ def __init__(self): button6.clicked.connect(lambda checked: self.toggle_window(self.window6)) l3.addWidget(button6, 3, 1) - l2.addLayout(l) + l2.addLayout(layout) w = QWidget() w.setLayout(l2) @@ -198,7 +195,7 @@ def _createMenuBar(self): geometryMenu.addAction(self.squareAction) geometryMenu.addAction(self.cubeAction) - helpMenu = menuBar.addMenu("&Help") + menuBar.addMenu("&Help") app = QApplication(sys.argv) diff --git a/Shape.py b/Shape.py index 772c84a..45de15b 100644 --- a/Shape.py +++ b/Shape.py @@ -18,7 +18,6 @@ class ShapeFunctionality: - def custom_messagebox(self, text="Error!"): """ Displays a custom message box with an error icon. diff --git a/Sphere.py b/Sphere.py index 3aa6d9d..b65eeec 100644 --- a/Sphere.py +++ b/Sphere.py @@ -23,7 +23,7 @@ import SphereCalc import CanvasThreeD import SaveFig -from Shape import * +from Shape import ShapeFunctionality # Get the absolute path to the directory where this script is located SCRIPT_DIR = Path(__file__).resolve().parent diff --git a/Square.py b/Square.py index e0c94e0..55d5409 100644 --- a/Square.py +++ b/Square.py @@ -27,7 +27,7 @@ import SquareCalc import Canvas import SaveFig -from Shape import * +from Shape import ShapeFunctionality # Get the absolute path to the directory where this script is located SCRIPT_DIR = Path(__file__).resolve().parent diff --git a/Tests/test_circle.py b/Tests/test_circle.py index 62b4dbd..3699292 100644 --- a/Tests/test_circle.py +++ b/Tests/test_circle.py @@ -4,11 +4,10 @@ # setting path sys.path.append("../PyQtMathApp") -from CircleCalc import * +from CircleCalc import Circle class CircleTest(unittest.TestCase): - def test_init_valid_radius(self): """Tests initialization with a valid positive radius.""" circle = Circle(5.0) diff --git a/Tests/test_cube.py b/Tests/test_cube.py index f3c9aa5..fc82f68 100644 --- a/Tests/test_cube.py +++ b/Tests/test_cube.py @@ -3,11 +3,10 @@ # setting path sys.path.append("../PyQtMathApp") -from CubeCalc import * +from CubeCalc import Cube class TestSquare(unittest.TestCase): - def test_init_valid_side_length(self): """Tests initialization with a valid positive side length.""" cube = Cube(5.526) diff --git a/Tests/test_ellipse.py b/Tests/test_ellipse.py index 8cba2cc..cb789bb 100644 --- a/Tests/test_ellipse.py +++ b/Tests/test_ellipse.py @@ -1,14 +1,13 @@ import unittest import sys -from math import pi +import math # setting path sys.path.append("../PyQtMathApp") -from EllipseCalc import * +from EllipseCalc import Ellipse class EllipseTest(unittest.TestCase): - def test_init_valid_axes(self): """Tests initialization with valid positive axis lengths.""" ellipse = Ellipse(5.0, 3.0) @@ -68,7 +67,7 @@ def test_init_very_small_positive_major_axis(self): ellipse = Ellipse(0.000001, 3.0) self.assertAlmostEqual( ellipse.circumference(), - round(pi * math.sqrt(2 * (0.000001**2 + 3.0**2)), 5), + round(math.pi * math.sqrt(2 * (0.000001**2 + 3.0**2)), 5), ) def test_init_very_large_major_axis(self): @@ -76,7 +75,7 @@ def test_init_very_large_major_axis(self): ellipse = Ellipse(1000000.0, 3.0) self.assertAlmostEqual( ellipse.circumference(), - round(pi * math.sqrt(2 * (1000000.0**2 + 3.0**2)), 5), + round(math.pi * math.sqrt(2 * (1000000.0**2 + 3.0**2)), 5), ) def test_init_empty_string_major_axis(self): @@ -98,21 +97,21 @@ def test_init_empty_string_minor_axis(self): def test_circumference(self): """Tests circumference calculation for various axis lengths.""" ellipse = Ellipse(3.0, 1.0) - expected_circumference = round(pi * math.sqrt(2 * (3.0**2 + 1.0**2)), 5) + expected_circumference = round(math.pi * math.sqrt(2 * (3.0**2 + 1.0**2)), 5) self.assertEqual(ellipse.circumference(), expected_circumference) ellipse = Ellipse(8.0, 4.0) - expected_circumference = round(pi * math.sqrt(2 * (8.0**2 + 4.0**2)), 5) + expected_circumference = round(math.pi * math.sqrt(2 * (8.0**2 + 4.0**2)), 5) self.assertEqual(ellipse.circumference(), expected_circumference) def test_area(self): """Tests area calculation for various axis lengths.""" ellipse = Ellipse(2.0, 1.5) - expected_area = round(pi * 2.0 * 1.5, 5) + expected_area = round(math.pi * 2.0 * 1.5, 5) self.assertEqual(ellipse.area(), expected_area) ellipse = Ellipse(7.0, 3.0) - expected_area = round(pi * 7.0 * 3.0, 5) + expected_area = round(math.pi * 7.0 * 3.0, 5) self.assertEqual(ellipse.area(), expected_area) def test_get_description(self): diff --git a/Tests/test_ellipsoid.py b/Tests/test_ellipsoid.py index e17665a..fa248c9 100644 --- a/Tests/test_ellipsoid.py +++ b/Tests/test_ellipsoid.py @@ -4,11 +4,10 @@ # setting path sys.path.append("../PyQtMathApp") -from EllipsoidCalc import * +from EllipsoidCalc import Ellipsoid class EllipsoidTest(unittest.TestCase): - def test_init_valid_dimensions(self): """Tests initialization with valid positive semi-axes.""" ellipsoid = Ellipsoid(5.0, 3.0, 2.0) diff --git a/Tests/test_sphere.py b/Tests/test_sphere.py index 1aca86e..52c7ae8 100644 --- a/Tests/test_sphere.py +++ b/Tests/test_sphere.py @@ -1,17 +1,14 @@ import unittest import sys -from math import pi # setting path sys.path.append("../PyQtMathApp") -from SphereCalc import * +from SphereCalc import Sphere -import unittest import math class SphereTest(unittest.TestCase): - def test_init_valid_radius(self): """Tests initialization with a valid positive radius.""" sphere = Sphere(5.0) diff --git a/Tests/test_square.py b/Tests/test_square.py index 618e333..b78d3c0 100644 --- a/Tests/test_square.py +++ b/Tests/test_square.py @@ -3,11 +3,10 @@ # setting path sys.path.append("../PyQtMathApp") -from SquareCalc import * +from SquareCalc import Square class TestSquare(unittest.TestCase): - def test_init_valid_side_length(self): """Tests initialization with a valid positive side length.""" square = Square(5.0)