Skip to content

Commit

Permalink
various minor tweaks
Browse files Browse the repository at this point in the history
update linters and fix new issues they found
update requirement links (again)
  • Loading branch information
apple1417 committed Jul 6, 2021
1 parent 50837e8 commit a45fde7
Show file tree
Hide file tree
Showing 24 changed files with 66 additions and 60 deletions.
Binary file modified AltUseVendors/AltUseVendors.zip
Binary file not shown.
6 changes: 3 additions & 3 deletions AltUseVendors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from Mods import AsyncUtil
except ImportError as ex:
import webbrowser
webbrowser.open("https://apple1417.dev/bl2/didntread/?m=Alt%20Use%20Vendors&au")
webbrowser.open("https://bl-sdk.github.io/requirements/?mod=Alt%20Use%20Vendors&all")
raise ex


Expand Down Expand Up @@ -64,7 +64,7 @@ class _AmmoInfo:
AMMO_ICON_NAME: ClassVar[str] = "Icon_RefillAmmo"

def __init__(self) -> None:
self.UpdatingOption = unrealsdk.Options.Boolean(
self.UpdatingOption = Options.Boolean(
"Updating Costs",
"Should the costs of quick buying update live while you're in game. Disabling this"
" won't show the costs of quick buying anymore, but may help reduce lag.",
Expand Down Expand Up @@ -386,7 +386,7 @@ def BuyAmmo(self, pawn: unrealsdk.UObject, vendor: unrealsdk.UObject) -> None:

pool.SetCurrentValue(pool.GetMaxValue())

def ModOptionChanged(self, option: unrealsdk.Options.Boolean, new_value: bool) -> None:
def ModOptionChanged(self, option: Options.Base, new_value: bool) -> None:
if option != self.UpdatingOption:
return

Expand Down
Binary file modified ApplesBorderlandsCheats/ApplesBorderlandsCheats.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion ApplesBorderlandsCheats/Cheats/Shops.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def OnPress(self) -> None:
for obj in unrealsdk.FindAll("WillowVendingMachine"):
if obj.Name == "Default__WillowVendingMachine":
continue
count += 1 # noqa: SIM113
count += 1
obj.ResetInventory()

ShowHUDMessage(
Expand Down
9 changes: 6 additions & 3 deletions ApplesBorderlandsCheats/Presets.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import html
import json
import os
from typing import ClassVar, Dict, List, Optional
from typing import ClassVar, Collection, Dict, List, Optional

from Mods.ModMenu import Options
from Mods.UserFeedback import OptionBox, OptionBoxButton, ShowHUDMessage, TextInputBox

from .Cheats import ABCCheat, ABCCycleableCheat

# This doesn't seem right but it's what mypy reads the var as
PresetData = List[Dict[str, Collection[str]]]


class Preset:
Name: str
Expand Down Expand Up @@ -202,7 +205,7 @@ def _ChangeCheatValue(self, button: OptionBoxButton) -> None:


class PresetManager:
Option: Options.Hidden
Option: Options.Hidden[PresetData]
PresetList: List[Preset]
CheatList: List[ABCCheat]

Expand All @@ -228,7 +231,7 @@ class PresetManager:

_RenameBox: TextInputBox

def __init__(self, Option: Options.Hidden, CheatList: List[ABCCheat]):
def __init__(self, Option: Options.Hidden[PresetData], CheatList: List[ABCCheat]):
self.Option = Option
self.CheatList = CheatList

Expand Down
11 changes: 5 additions & 6 deletions ApplesBorderlandsCheats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@

try:
from Mods import UserFeedback
if UserFeedback.VersionMajor < 1:
raise RuntimeError("UserFeedback version is too old, need at least v1.3!")
if UserFeedback.VersionMajor == 1 and UserFeedback.VersionMinor < 3:

if (UserFeedback.VersionMajor, UserFeedback.VersionMinor) < (1, 3):
raise RuntimeError("UserFeedback version is too old, need at least v1.3!")
# UF 1.0 didn't have version fields, hence the `NameError`
except (ImportError, RuntimeError, NameError) as ex:
import webbrowser
url = "https://apple1417.dev/bl2/didntread/?m=Apple%27s%20Borderlands%20Cheats&uf=v1.3"
url = "https://bl-sdk.github.io/requirements/?mod=Apple%27s%20Borderlands%20Cheats&all"
if isinstance(ex, (RuntimeError, NameError)):
url += "&update"
webbrowser.open(url)
Expand All @@ -36,7 +35,7 @@


from .Cheats import ALL_CHEATS, ALL_HOOKS, ALL_OPTIONS
from .Presets import PresetManager
from .Presets import PresetData, PresetManager


class ApplesBorderlandsCheats(SDKMod):
Expand Down Expand Up @@ -73,7 +72,7 @@ def IsEnabled(self, val: bool) -> None:
SaveModSettings(self)

def __init__(self) -> None:
preset_option = Options.Hidden("Presets", StartingValue=[])
preset_option: Options.Hidden[PresetData] = Options.Hidden("Presets", StartingValue=[])
self.Options = [preset_option] + ALL_OPTIONS # type: ignore

# Load settings once for the set of presets
Expand Down
Binary file modified CommandExtensions/CommandExtensions.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion CommandExtensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def debug_handler(args: argparse.Namespace) -> None:

enable_on_parser = RegisterConsoleCommand(
"CE_EnableOn",
lambda args: unrealsdk.Log("ERROR: 'CE_EnableOn' can only be used in BLCMM files."),
lambda args: unrealsdk.Log("ERROR: 'CE_EnableOn' can only be used in BLCMM files."), # type: ignore
description="""
Can only be used in BLCMM files.
Expand Down
2 changes: 1 addition & 1 deletion CommandExtensions/builtins/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def clone_object(

unrealsdk.KeepAlive(cloned)
cloned.ObjectArchetype = src.ObjectArchetype
# Don't ask me what on earth this means
# Don't ask me what on earth this means, but it lets you reference objects cross package
cloned.ObjectFlags.B |= 4
return cloned

Expand Down
Binary file modified CrowdControl/CrowdControl.zip
Binary file not shown.
14 changes: 6 additions & 8 deletions CrowdControl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
from Mods.UserFeedback import (OptionBox, OptionBoxButton, ShowHUDMessage, TextInputBox,
TrainingBox)

if UserFeedback.VersionMajor < 1:
raise RuntimeError("UserFeedback version is too old, need at least v1.3!")
if UserFeedback.VersionMajor == 1 and UserFeedback.VersionMinor < 3:
if (UserFeedback.VersionMajor, UserFeedback.VersionMinor) < (1, 3):
raise RuntimeError("UserFeedback version is too old, need at least v1.3!")
# UF 1.0 didn't have version fields, hence the `NameError`
except (ImportError, RuntimeError, NameError) as ex:
url = "https://apple1417.dev/bl2/didntread/?m=Borderlands%20Crowd%20Control&au=v1.0&uf=v1.3"
url = "https://bl-sdk.github.io/requirements/?mod=Borderlands%20Crowd%20Control&AsyncUtil=>=1.0&UserFeedback=>=1.3"
if isinstance(ex, (RuntimeError, NameError)):
url += "&update"
webbrowser.open(url)
Expand All @@ -45,8 +43,8 @@
if _native_path not in sys.path:
sys.path.append(_native_path)

from ctypes import GetLastError, WinError, byref, windll # noqa E402
from ctypes.wintypes import BYTE, DWORD # noqa E402
from ctypes import GetLastError, WinError, byref, windll # noqa: E402
from ctypes.wintypes import BYTE, DWORD # noqa: E402

ERROR_BROKEN_PIPE = 109
STARTF_USESHOWWINDOW = 1
Expand Down Expand Up @@ -121,7 +119,7 @@ def __init__(self) -> None:
}

try:
self.Token = open(self.TOKEN_FILE).read().strip()
self.Token = open(self.TOKEN_FILE).read().strip() # noqa: SIM115
except FileNotFoundError:
self.Token = None

Expand Down Expand Up @@ -412,7 +410,7 @@ def GenerateToken(self) -> None:
)

def ReloadToken() -> None:
self.Token = open(self.TOKEN_FILE).read().strip()
self.Token = open(self.TOKEN_FILE).read().strip() # noqa: SIM115

def OnStart(button: OptionBoxButton) -> None:
startfile(self.TOKEN_FILE)
Expand Down
2 changes: 1 addition & 1 deletion CrowdControl/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
webbrowser.open("https://apple1417.dev/bl2/crowdcontrol/")

token = input("Paste the token here:\n")
open(path.join(path.dirname(__file__), "token.txt"), "w").write(token)
open(path.join(path.dirname(__file__), "token.txt"), "w").write(token) # noqa: SIM115

print((
"\nRunning test program."
Expand Down
Binary file modified EquipLocker/EquipLocker.zip
Binary file not shown.
8 changes: 4 additions & 4 deletions EquipLocker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ def CanItemBeEquipped(self, item: unrealsdk.UObject) -> bool:
if item.Class.Name == "WillowVehicleWeapon":
return True

for option, r_set in self.OptionRestrictionMap.items():
if option.CurrentValue and not r_set.CanItemBeEquipped(item):
return False
return True
return not any(
option.CurrentValue and not r_set.CanItemBeEquipped(item)
for option, r_set in self.OptionRestrictionMap.items()
)

def GetEquippedItems(self) -> Iterator[unrealsdk.UObject]:
pawn = unrealsdk.GetEngine().GamePlayers[0].Actor.Pawn
Expand Down
Binary file modified SDKAutorun/SDKAutorun.zip
Binary file not shown.
16 changes: 7 additions & 9 deletions SDKAutorun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
Options, RegisterMod, SaveModSettings, SDKMod)

try:
from Mods import AsyncUtil # noqa F401 # Unused in this file but better to check in one place
from Mods import AsyncUtil # noqa: F401 # Unused in this file but better to check in one place
from Mods import UserFeedback

if UserFeedback.VersionMajor < 1:
raise RuntimeError("UserFeedback version is too old, need at least v1.3!")
if UserFeedback.VersionMajor == 1 and UserFeedback.VersionMinor < 3:
if (UserFeedback.VersionMajor, UserFeedback.VersionMinor) < (1, 3):
raise RuntimeError("UserFeedback version is too old, need at least v1.3!")
# UF 1.0 didn't have version fields, hence the `NameError`
except (ImportError, RuntimeError, NameError) as ex:
import webbrowser
url = "https://apple1417.dev/bl2/didntread/?m=SDK%20Autorun&au=v1.0&uf=v1.3"
url = "https://bl-sdk.github.io/requirements/?mod=SDK%20Autorun&all"
if isinstance(ex, (RuntimeError, NameError)):
url += "&update"
webbrowser.open(url)
Expand Down Expand Up @@ -56,7 +54,7 @@ class SDKAutorun(SDKMod):
"T": "Edit Tasks"
}

TaskOption: Options.Hidden
TaskOption: Options.Hidden[Dict[str, Dict[str, List[Dict[str, Tasks.JSON]]]]]

LaunchTasks: List[Tasks.BaseTask]
MainMenuTasks: List[Tasks.BaseTask]
Expand All @@ -68,9 +66,9 @@ def __init__(self) -> None:
},
"OnLaunch": {
"Comment": [
"Congratulations, you found the secret file where you can setup tasks to run on launch.",
" This is not editable ingame because exec-ing mods before the main menu tends to cause",
" a crash, but if you really want you can edit the `Tasks` array here at your own risk."
"Congratulations, you found the secret file where you can setup tasks to run on launch.", # type: ignore
" This is not editable ingame because exec-ing mods before the main menu tends to cause", # type: ignore
" a crash, but if you really want you can edit the `Tasks` array here at your own risk." # type: ignore
],
"Tasks": []
}
Expand Down
Binary file modified SanitySaver/SanitySaver.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion SanitySaver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SanitySaver(SDKMod):
"C": "Clear Cache"
}

CompressOption: Options.Hidden
CompressOption: Options.Hidden[bool]

def __init__(self) -> None:
self.CompressOption = Options.Hidden("CompressSaves", StartingValue=True)
Expand Down
8 changes: 5 additions & 3 deletions SanitySaver/save_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def update_compression(should_compress: bool) -> None:
suffixes.pop()
base_file = file.parent / (file.stem.split(".")[0] + "".join(suffixes))

with open(base_file.with_suffix(".json"), json_mode) as js:
with open(base_file.with_suffix(".json"), json_mode) as js: # noqa: SIM117
with gzip.open(base_file.with_suffix(".json.gz"), gz_mode) as gz:
if should_compress:
shutil.copyfileobj(js, gz)
Expand Down Expand Up @@ -90,7 +90,7 @@ def load(self) -> None:
if _COMPRESS:
file = gzip.open(self.file_path, "rt", encoding="utf8")
else:
file = open(self.file_path)
file = open(self.file_path) # noqa: SIM115

data = json.load(file)
# JSON doesn't allow int keys, dumping converts them to strings, we need to convert back
Expand All @@ -101,6 +101,7 @@ def load(self) -> None:
int(unique_id): val for unique_id, val in data.get("new_items", {}).items()
}
file.close()

# In this version of python, gzip throws base `OSError`s, which also catches file not founds
except (OSError, json.JSONDecodeError):
self.replacements = {}
Expand All @@ -121,12 +122,13 @@ def write(self) -> None:
if _COMPRESS:
file = gzip.open(self.file_path, "wt", encoding="utf8")
else:
file = open(self.file_path, "w")
file = open(self.file_path, "w") # noqa: SIM115

json.dump({
"replacements": self.replacements,
"new_items": self.new_items
}, file, indent=None if _COMPRESS else 4)

file.close()

def add_item(self, item: unrealsdk.FStruct, is_weapon: bool, existing_save: SaveManager) -> None:
Expand Down
4 changes: 2 additions & 2 deletions UserFeedback/Misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def ShowChatMessage(
ShowTimestamp: bool = True
) -> None:
if Timestamp is None:
Timestamp = datetime.now() # noqa N806
Timestamp = datetime.now() # noqa: N806

is12h = unrealsdk.FindAll("WillowSaveGameManager")[0].TimeFormat == "12"
is12h = unrealsdk.FindAll("WillowSaveGameManager")[-1].TimeFormat == "12"
time_str = Timestamp.strftime(("[%H:%M:%S]", "[%I:%M:%S%p]")[is12h]).lower()

user_str = f"{User} {time_str}" if ShowTimestamp else User
Expand Down
Binary file modified UserFeedback/UserFeedback.zip
Binary file not shown.
18 changes: 9 additions & 9 deletions UserFeedback/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
from Mods.ModMenu import ModPriorities, ModTypes, RegisterMod, SDKMod

# Export everything from the other files
from .GFxMovie import GFxMovie as GFxMovie # noqa F401
from .Misc import ShowChatMessage as ShowChatMessage # noqa F401
from .Misc import ShowHUDMessage as ShowHUDMessage # noqa F401
from .OptionBox import OptionBox as OptionBox # noqa F401
from .OptionBox import OptionBoxButton as OptionBoxButton # noqa F401
from .OptionBox import OptionScrollType as OptionScrollType # noqa F401
from .ReorderBox import ReorderBox as ReorderBox # noqa F401
from .TextInputBox import TextInputBox as TextInputBox # noqa F401
from .TrainingBox import TrainingBox as TrainingBox # noqa F401
from .GFxMovie import GFxMovie as GFxMovie # noqa: F401
from .Misc import ShowChatMessage as ShowChatMessage # noqa: F401
from .Misc import ShowHUDMessage as ShowHUDMessage # noqa: F401
from .OptionBox import OptionBox as OptionBox # noqa: F401
from .OptionBox import OptionBoxButton as OptionBoxButton # noqa: F401
from .OptionBox import OptionScrollType as OptionScrollType # noqa: F401
from .ReorderBox import ReorderBox as ReorderBox # noqa: F401
from .TextInputBox import TextInputBox as TextInputBox # noqa: F401
from .TrainingBox import TrainingBox as TrainingBox # noqa: F401

VersionMajor: int = 1
VersionMinor: int = 5
Expand Down
12 changes: 6 additions & 6 deletions linters.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
flake8-bugbear==20.11.1
flake8-comprehensions==3.3.1
flake8-bugbear==21.4.3
flake8-comprehensions==3.5.0
flake8-isort==4.0.0
flake8-mutable==1.2.0
flake8-noqa==1.1.0
flake8-pyi==20.10.0
flake8-simplify==0.13.0
flake8==3.8.4
isort==5.7.0
mypy==0.800
flake8-simplify==0.14.1
flake8==3.9.2
isort==5.9.1
mypy==0.910
pep8-naming==0.11.1
rope==0.18.0
10 changes: 8 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[mypy]
python_version = 3.7
mypy_path = .stubs
# mypy_path = .stubs
strict = True

[mypy-unrealsdk]
Expand All @@ -18,13 +18,19 @@ ignore_errors = True
[mypy-Mods.MapEditor.*]
ignore_errors = True

[mypy-Mods.ReignOfGiants.*]
ignore_errors = True

[mypy-Mods.TwitchLogin.*]
ignore_errors = True

[flake8]
ignore = Y011, SIM105, SIM106, E501, W503, N802, N803, N813, B901, B950
per-file-ignores =
*.pyi: E302, E704
max-line-length = 100
ignore-names = PC,PCs,PRI,PRIs
exclude = .env, Commander, Constructor, Exodus, MapEditor
exclude = .env, Commander, Constructor, Exodus, MapEditor, ReignOfGiants, TwitchLogin

[isort]
py_version = 37
Expand Down

0 comments on commit a45fde7

Please sign in to comment.