Skip to content

Commit

Permalink
Linting improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexeh committed Nov 27, 2023
1 parent 7eaa4d7 commit e3fe479
Show file tree
Hide file tree
Showing 23 changed files with 120 additions and 155 deletions.
6 changes: 3 additions & 3 deletions joystick_diagrams/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from PyQt5 import QtWidgets, QtGui, QtCore
from joystick_diagrams import config
from joystick_diagrams.ui import ui
from joystick_diagrams.adaptors.dcs_world import DCSWorldParser
from joystick_diagrams.adaptors.joystick_gremlin import JoystickGremlin
from joystick_diagrams.adaptors.star_citizen import StarCitizen
from joystick_diagrams.adaptors.dcs.dcs_world import DCSWorldParser
from joystick_diagrams.adaptors.joystick_gremlin.joystick_gremlin import JoystickGremlin
from joystick_diagrams.adaptors.star_citizen.star_citizen import StarCitizen
from joystick_diagrams.classes import export
from joystick_diagrams.classes.version import version

Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""DCS World Lua Config Parser for use with Joystick Diagrams"""
import logging
import os
import re
from pathlib import Path
import logging

from ply import lex, yacc # type: ignore
import joystick_diagrams.adaptors.dcs_world_lex # pylint: disable=unused-import
import joystick_diagrams.adaptors.dcs_world_yacc # pylint: disable=unused-import

import joystick_diagrams.adaptors.dcs.dcs_world_lex # pylint: disable=unused-import
import joystick_diagrams.adaptors.dcs.dcs_world_yacc # pylint: disable=unused-import
import joystick_diagrams.adaptors.joystick_diagram_interface as jdi

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -128,7 +130,8 @@ def process_profiles(self, profile_list: list | None = None) -> dict:

except FileNotFoundError as err:
_logger.error(
f"DCS: File {joystick_file} no longer found - It has been moved/deleted from directory. {err}"
f"DCS: File {joystick_file} no longer found - \
It has been moved/deleted from directory. {err}"
)
raise

Expand Down
File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Joystick Gremlin (Version ~13) XML Parser for use with Joystick Diagrams"""
from xml.dom import minidom
import logging
from xml.dom import minidom

import joystick_diagrams.adaptors.joystick_diagram_interface as jdi

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -65,17 +66,17 @@ def parse_xml_file(self, xml_file) -> minidom.Document:
def create_dictionary(self, profiles=None) -> dict:
self.profiles = profiles
self.devices = self.get_devices()
_logger.debug("Number of Devices: {}".format(str(self.devices.length)))
_logger.debug(f"Number of Devices: {self.devices.length}")

for self.device in self.devices:
self.current_device = self.get_single_device()
self.modes = self.get_device_modes()
_logger.debug("All Modes: {}".format(self.modes))
_logger.debug(f"All Modes: {self.modes}")
for self.mode in self.modes:
self.current_inherit = self.has_inheritance()
self.button_array = {}
self.current_mode = self.get_single_mode()
_logger.debug("Selected Mode: {}".format(self.current_mode))
_logger.debug(f"Selected Mode: {self.current_mode}")
self.buttons = self.get_mode_buttons()
self.hats = self.get_mode_hats()
self.extract_buttons()
Expand Down Expand Up @@ -141,25 +142,25 @@ def extract_buttons(self):
def extract_hats(self) -> None:
for i in self.hats:
hat_id = i.getAttribute("id")
_logger.debug("Hat ID: {}".format(hat_id))
_logger.debug("Hat ID: {hat_id}")

if i.getAttribute("description"):
hat_description = i.getAttribute("description")
_logger.debug("Hat has description: {}".format(hat_description))
_logger.debug("Hat has description: {hat_description}")
else:
hat_description = ""

hat_containers = i.getElementsByTagName("container")

if hat_containers:
_logger.debug("Has containers: {}".format(hat_containers.length))
_logger.debug("Has containers: {hat_containers.length}")

for container in hat_containers:
hat_positions = container.getElementsByTagName("action-set")
hat_count = hat_positions.length
increment = 8 / hat_count
pos = 1
_logger.debug("We have {} hat positions".format(hat_count))
_logger.debug(f"We have {hat_count} hat positions")

for position in hat_positions:
if position.getElementsByTagName("description"):
Expand All @@ -170,19 +171,15 @@ def extract_hats(self) -> None:
else:
hat_direction_description = hat_description

_logger.debug("POV Position: {}".format(self.position_map[pos]))
_logger.debug(f"POV Position: {self.position_map[pos]}")

self.button_array.update(
{
"POV_{ID}_{DIR}".format(ID=i.getAttribute("id"), DIR=self.position_map[pos]): str(
hat_direction_description
)
}
{f"POV_{i.getAttribute('id')}_{self.position_map[pos]}": str(hat_direction_description)}
)

pos = pos + increment
else:
_logger.error("No container found for hat: {}".format(hat_id))
_logger.error(f"No container found for hat: {hat_id}")

def get_device_count(self):
return self.file.getElementsByTagName("device").length
Empty file.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Star Citizen XML Parser for use with Joystick Diagrams"""
import logging
import os
from pathlib import Path
from xml.dom import minidom
import logging

import joystick_diagrams.adaptors.joystick_diagram_interface as jdi

_logger = logging.getLogger(__name__)
Expand All @@ -17,9 +18,9 @@ def __init__(self, file_path):
self.hat = None
self.devices = {}
self.button_array = {}
self.actionsMapBypass = {"Fire 1", "Fire 2"}
self.action_map_bypass = {"Fire 1", "Fire 2"}
# Force some Labels, this ideally need to be declared elsewhere or from an external file
self.customLabels = {
self.custom_labels = {
"attack1": "z_attack",
"combatheal": "z_combat_heal",
"combathealtarget": "z_heal_target",
Expand Down Expand Up @@ -507,10 +508,10 @@ def __validate_file(self, data) -> bool:

def parse_map(self, bind_map) -> tuple:
segments = bind_map.split("_")
_logger.debug("Bind Information: {}".format(segments))
_logger.debug(f"Bind Information: {segments}")
bind_device = segments[0]
device_object = self.get_stored_device(bind_device)
_logger.debug("Device: {}".format(device_object))
_logger.debug(f"Device: {device_object}")
if device_object is None:
c_map = None
return (device_object, c_map)
Expand All @@ -519,44 +520,44 @@ def parse_map(self, bind_map) -> tuple:
return (device_object, c_map)
elif segments[1][0:6] == "button":
button_id = segments[1][6:]
c_map = "BUTTON_{id}".format(id=button_id)
c_map = f"BUTTON_{button_id}"
return (device_object, c_map)
elif segments[1][0:3] == "hat":
pov_id = segments[1][3:]
pov_dir = self.convert_hat_format(segments[2])
c_map = "POV_{id}_{dir}".format(id=pov_id, dir=pov_dir)
c_map = f"POV_{pov_id}_{pov_dir}"
return (device_object, c_map)
elif segments[1][0] in ("x", "y", "z"):
axis = segments[1][0]
c_map = "AXIS_{axis}".format(axis=axis)
c_map = f"AXIS_{axis}"
return (device_object, c_map)
elif segments[1][0:3] == "rot":
axis = segments[1][3:]
c_map = "AXIS_R{axis}".format(axis=axis)
c_map = f"AXIS_R{axis}"
return (device_object, c_map)
elif segments[1][0:6] == "slider":
slider_id = segments[1][6:]
c_map = "AXIS_SLIDER_{id}".format(id=slider_id)
c_map = f"AXIS_SLIDER_{slider_id}"
return (device_object, c_map)
else:
c_map = None
return (device_object, c_map)

def get_human_readable_name(self, name) -> str:
if name in self.customLabels:
return self.name_format(self.customLabels.get(name))
if name in self.custom_labels:
return self.name_format(self.custom_labels.get(name))

return self.name_format(name)

def name_format(self, name: str) -> str:
name = name.split("_")
if len(name) == 1:
return name[0].capitalize()
name_parts = name.split("_")
if len(name_parts) == 1:
return name_parts[0].capitalize()
else:
return (" ".join(name[1:])).capitalize()
return (" ".join(name_parts[1:])).capitalize()

def convert_hat_format(self, hat) -> str:
_logger.debug("Convert Hat: {}".format(hat))
_logger.debug(f"Convert Hat: {hat}")
return self.hat_formats[hat]

def extract_device_information(self, option) -> dict:
Expand All @@ -580,10 +581,10 @@ def add_device(self, option) -> None:
): self.extract_device_information(option)
}
)
_logger.debug("Device List: {}".format(self.devices))
_logger.debug(f"Device List: {self.devices}")

def process_name(self, name: str) -> str:
_logger.debug("Bind Name: {}".format(name))
_logger.debug(f"Bind Name: {name}")

return self.get_human_readable_name(name)

Expand All @@ -600,7 +601,7 @@ def device_id(self, device_type, instance) -> str:
device_code = "js"
else:
device_code = "mo" ## Catch all for now
return "{type}{instance}".format(type=device_code, instance=instance)
return f"{device_code}{instance}"

def parse(self) -> dict:
parse = minidom.parseString(self.data)
Expand All @@ -610,16 +611,16 @@ def parse(self) -> dict:
actions = parse.getElementsByTagName("actionmap")

for i in actions:
_logger.debug("Bind Category: {}".format(self.process_name(i.getAttribute("name"))))
_logger.debug(f"Bind Category: {self.process_name(i.getAttribute('name'))}")
single_actions = i.getElementsByTagName("action")
for action in single_actions:
name = self.process_name(action.getAttribute("name"))
binds = action.getElementsByTagName("rebind")
_logger.debug("Binds in group: {}".format(binds))
_logger.debug("Binds in group: {binds}")
for bind in binds:
bind = bind.getAttribute("input")
button = self.parse_map(bind)
_logger.debug("Parsed Control: {}".format(button))
bind_input = bind.getAttribute("input")
button = self.parse_map(bind_input)
_logger.debug("Parsed Control: {button}")
if button and button[1] is not None:
_logger.debug("Valid button, adding to map")
# Check if the Device exist is already Mapped
Expand All @@ -630,12 +631,12 @@ def parse(self) -> dict:
self.build_button_map(button[0]["name"], button[1], name)
else:
# Check if the current Binding bypass existing one
if name in self.actionsMapBypass:
if name in self.action_map_bypass:
self.build_button_map(button[0]["name"], button[1], name)
else:
# Add Mapping
self.build_button_map(button[0]["name"], button[1], name)
_logger.debug("Button Map is now: {}".format(self.button_array))
_logger.debug("Button Map is now: {self.button_array}")
else:
_logger.debug("Button not valid, skipping")

Expand Down
30 changes: 0 additions & 30 deletions joystick_diagrams/update.py

This file was deleted.

6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ coveralls = "^3.3.0"
pylint = "^3.0.0"
cx-Freeze = "^6.15.0"
mypy = "^1.7.1"
isort = "^5.12.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down Expand Up @@ -82,6 +83,7 @@ exclude = '''
# the root of the project
)
'''

[tool.pylint.format]
max-line-length = 120

Expand All @@ -95,5 +97,5 @@ disable = ["C0114", "C0115","W1201","W1202","logging-fstring-interpolation","mis
output-format = "colorized"

[tool.mypy]
warn_return_any = "False"
warn_unused_configs = "True"
warn_return_any = false
warn_unused_configs = true
10 changes: 4 additions & 6 deletions tests/dcs_world/test_dcs_parse.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import unittest
import joystick_diagrams.adaptors.dcs_world as dcs
import pprint

import joystick_diagrams.adaptors.dcs.dcs_world as dcs

class TestDCS_Parse_Test(unittest.TestCase):

class TestDCSParseTest(unittest.TestCase):
def setUp(self):
self.dcs_instance = dcs.DCSWorldParser("./tests/data/dcs_world/valid_dcs_world_directory")
self.maxDiff = None

def test_no_profiles_selected_no_easy(self):
"""Test default no selection, with easy modes disabled (excluded)"""
profiles = self.dcs_instance.get_validated_profiles()

expected = {
"Throttle - HOTAS Warthog": {
Expand Down Expand Up @@ -55,7 +53,7 @@ def test_no_profiles_selected_no_easy(self):

def test_no_profiles_selected_including_easy_modes(self):
"""Test default no selection, with easy modes enabled (included)"""
profiles = self.dcs_instance.get_validated_profiles()

expected = {
"Throttle - HOTAS Warthog": {
"CoolPlane-A": {
Expand Down
9 changes: 4 additions & 5 deletions tests/dcs_world/test_dcs_path_tests.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import unittest
import joystick_diagrams.adaptors.dcs_world as dcs
import os
import pytest
import tempfile
import shutil
import unittest

import joystick_diagrams.adaptors.dcs.dcs_world as dcs


class TestDCS_Paths(unittest.TestCase):
class TestDCSPaths(unittest.TestCase):
def setUp(self):
pass

Expand Down
9 changes: 5 additions & 4 deletions tests/exports/test_export_template.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import datetime
import unittest
import joystick_diagrams.classes.export as export
import tempfile
import os
import tempfile
import unittest

from joystick_diagrams.classes import export


class TestExport_Template(unittest.TestCase):
class TestExportTemplate(unittest.TestCase):
data = {
"VPC Throttle MT-50 CM2": {
"A10": {
Expand Down
Loading

0 comments on commit e3fe479

Please sign in to comment.