Skip to content

Commit

Permalink
refactor: use ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
centaurialpha committed Apr 7, 2024
1 parent 0689efc commit 12f31a3
Show file tree
Hide file tree
Showing 43 changed files with 326 additions and 468 deletions.
7 changes: 0 additions & 7 deletions .flake8

This file was deleted.

9 changes: 2 additions & 7 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,10 @@ jobs:
sudo apt-get install -y libgles2-mesa-dev
fi
- name: Check Format
- name: Lint
if: runner.os == 'Linux'
run: |
make format-check
- name: Flake8
if: runner.os == 'Linux'
run: |
make flake8
make check
- name: Unit Tests
run: |
Expand Down
7 changes: 0 additions & 7 deletions .pycodestyle

This file was deleted.

12 changes: 2 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ help:
@echo "test-unit -- run unit tests"
@echo "test-interpreter -- run tests for Scanner, Lexer, Parser and Interpreter"
@echo "test-integration -- run integration tests"
@echo "flake8 -- run flake8"
@echo "deb -- build a .deb package"

rc:
pyrcc5 pireal/resources/resources.qrc -o pireal/resources.py
Expand All @@ -23,14 +21,8 @@ clean:
rm -rf pireal.egg-info
rm -rf build/

flake8:
flake8 src/pireal --config=.flake8

format-check:
@black src/ tests/ --check

format:
@black src/ tests/
check:
ruff check

test-unit:
pytest -v tests/unit -m "not interpreter"
Expand Down
10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies = [
]

[project.optional-dependencies]
dev = ["pytest", "pytest-cov"]
dev = ["pytest", "pytest-cov", "ruff"]
extras = ["rich"]

[project.scripts]
Expand All @@ -37,3 +37,11 @@ requires = ["setuptools", "setuptools_scm[toml]>=6.2", "wheel"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]

[tool.ruff]
line-length = 100

[tool.ruff.lint]
select = [ "A", "B", "C90", "D", "E", "EM", "F", "I", "N", "PTH", "RUF", "W",]
ignore = ["D103", "D102", "D101", "D100", "D107", "D104", "D105", "EM101", "N802", "N815", "EM102"]
exclude = ["windows/*", "tests/*"]
3 changes: 1 addition & 2 deletions requirements-dev.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pytest
pytest-cov
flake8
black
rich
ruff
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ pytest==8.1.1
# via pytest-cov
pytest-cov==5.0.0
rich==13.7.1
ruff==0.3.5
2 changes: 1 addition & 1 deletion src/pireal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# This necesary for sphinx
from typing import cast

from pkg_resources import get_distribution, DistributionNotFound
from pkg_resources import DistributionNotFound, get_distribution

try:
__version__ = get_distribution("pireal").version
Expand Down
22 changes: 8 additions & 14 deletions src/pireal/core/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,37 @@
# along with Pireal; If not, see <http://www.gnu.org/licenses/>.

import os
from pathlib import Path


def get_extension(filename):
"""This function returns the extension of filename
"""Return the extension of filename.
:param filename: Filename path
:returns: The extension file
"""

return os.path.splitext(filename)[-1]
return Path(filename).suffix


def get_basename(filename):
"""This function returns the base name of filename
"""Return the base name of filename.
:param filename: Filename, for example: "/home/gabo/file.rpf"
:returns: The base name, for example: "file"
"""

return os.path.splitext(os.path.basename(filename))[0]
return Path(filename).stem


def get_path(filename):
return os.path.dirname(filename)
return Path(filename).parent


def generate_database(relations):
"""This function generates the content of the database
"""Generate the content of the database.
:param relations: Dictionary with relations (Relation Object)
:returns: The content of the database
"""

content = ""
for relation_name, relation in list(relations.items()):
content += "@%s:" % relation_name
Expand All @@ -65,8 +63,4 @@ def generate_database(relations):


def get_files_from_folder(path):
return [
os.path.splitext(f)[0]
for f in os.listdir(path)
if os.path.isfile(os.path.join(path, f))
]
return [f.stem for f in os.listdir(path) if (path / f).is_file()]
5 changes: 3 additions & 2 deletions src/pireal/core/ordered_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#
# You should have received a copy of the GNU General Public License
# along with Pireal; If not, see <http://www.gnu.org/licenses/>.
"""
OrderedSet implementation.
"""OrderedSet implementation.
Based on https://code.activestate.com/recipes/576694/ by Raymond Hettinger
Based on https://github.com/LuminosoInsight/ordered-set
"""
Expand All @@ -25,6 +25,7 @@

class OrderedSet(MutableSet):
"""Custom set that remembers its order.
Yes, it may seem anti-mathematical (?, but this is real life
"""

Expand Down
14 changes: 3 additions & 11 deletions src/pireal/core/pfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,12 @@

import os

from PyQt6.QtCore import QObject
from PyQt6.QtCore import QFile, QIODevice, QObject, QTextStream
from PyQt6.QtCore import pyqtSignal as Signal
from PyQt6.QtCore import QFile
from PyQt6.QtCore import QTextStream

# from PyQt6.QtCore import QTextCodec
from PyQt6.QtCore import QIODevice


class File(QObject):

"""This class represents an object file"""
"""Represents an object file."""

fileSaved = Signal(str)

Expand All @@ -43,8 +37,7 @@ def __init__(self, filename=""):

@property
def display_name(self):
"""Returns only the file name with extension, without the path"""

"""Returns only the file name with extension, without the path."""
return os.path.basename(self.filename)

def save(self, data, path=None):
Expand All @@ -68,6 +61,5 @@ def save(self, data, path=None):

def read(self):
"""Reads the file and returns the content"""

with open(self.filename, encoding="utf-8") as f:
return f.read()
Loading

0 comments on commit 12f31a3

Please sign in to comment.