Skip to content

Commit

Permalink
Switch to 99 character line length
Browse files Browse the repository at this point in the history
  • Loading branch information
gwax committed Oct 25, 2023
1 parent 5b9bbbe commit e9d6e45
Show file tree
Hide file tree
Showing 20 changed files with 43 additions and 120 deletions.
4 changes: 1 addition & 3 deletions mtg_ssm/containers/counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ def merge_card_counts(*card_counts_args: ScryfallCardCount) -> ScryfallCardCount
return dict(merged_counts)


def diff_card_counts(
left: ScryfallCardCount, right: ScryfallCardCount
) -> ScryfallCardCount:
def diff_card_counts(left: ScryfallCardCount, right: ScryfallCardCount) -> ScryfallCardCount:
"""Subtract right print counts from left print counts."""
diffed_counts: ScryfallCardCount = collections.defaultdict(dict)
for card_id in left.keys() | right.keys():
Expand Down
4 changes: 1 addition & 3 deletions mtg_ssm/containers/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ def load_data(self, scrydata: ScryfallDataSet) -> None:

self.snnma_to_id = collections.defaultdict(set)

name_to_unsorted_cards: Dict[str, List[ScryCard]] = collections.defaultdict(
list
)
name_to_unsorted_cards: Dict[str, List[ScryCard]] = collections.defaultdict(list)
setcode_to_unsorted_cards: Dict[str, List[ScryCard]] = {}

for set_ in scrydata.sets:
Expand Down
8 changes: 2 additions & 6 deletions mtg_ssm/containers/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,8 @@ def find_scryfall_id(card_row: Dict[str, str], oracle: Oracle) -> UUID:
mvid = int(card_row.get("multiverseid") or -1)
artist = card_row.get("artist") or None
artist = PSUDONYM_TO_ARTIST.get(artist, artist)
print(
f"Searching => Set: {set_code}; Name: {name}; Number: {collector_number}; MVID: {mvid}"
)
snnma_keys: List[
Tuple[Optional[str], str, Optional[str], Optional[int], Optional[str]]
] = []
print(f"Searching => Set: {set_code}; Name: {name}; Number: {collector_number}; MVID: {mvid}")
snnma_keys: List[Tuple[Optional[str], str, Optional[str], Optional[int], Optional[str]]] = []
for set_ in set_codes:
snnma_keys += [
(set_, name, collector_number, None, None),
Expand Down
8 changes: 2 additions & 6 deletions mtg_ssm/scryfall/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ def scryfetch() -> ScryfallDataSet:
sets_data += sets_list.data

scrylistmigration_decoder = msgspec.json.Decoder(ScryList[ScryMigration])
migrations_list = scrylistmigration_decoder.decode(
_fetch_endpoint(MIGRATIONS_ENDPOINT)
)
migrations_list = scrylistmigration_decoder.decode(_fetch_endpoint(MIGRATIONS_ENDPOINT))
migrations_data = migrations_list.data
while migrations_list.has_more and migrations_list.next_page is not None:
migrations_list = scrylistmigration_decoder.decode(
Expand All @@ -77,8 +75,6 @@ def scryfetch() -> ScryfallDataSet:
migrations_data += migrations_list.data

[cards_endpoint] = [bd.download_uri for bd in bulk_data if bd.type == BULK_TYPE]
cards_data = msgspec.json.decode(
_fetch_endpoint(cards_endpoint), type=List[ScryCard]
)
cards_data = msgspec.json.decode(_fetch_endpoint(cards_endpoint), type=List[ScryCard])

return ScryfallDataSet(sets=sets_data, cards=cards_data, migrations=migrations_data)
8 changes: 2 additions & 6 deletions mtg_ssm/serialization/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
from mtg_ssm.scryfall.models import ScryCard
from mtg_ssm.serialization import interface

CSV_HEADER = ["set", "name", "collector_number", "scryfall_id"] + [
ct.value for ct in CountType
]
CSV_HEADER = ["set", "name", "collector_number", "scryfall_id"] + [ct.value for ct in CountType]


def row_for_card(card: ScryCard, card_count: Mapping[CountType, int]) -> Dict[str, Any]:
Expand All @@ -28,9 +26,7 @@ def row_for_card(card: ScryCard, card_count: Mapping[CountType, int]) -> Dict[st
}


def rows_for_cards(
collection: MagicCollection, verbose: bool
) -> Iterable[Dict[str, Any]]:
def rows_for_cards(collection: MagicCollection, verbose: bool) -> Iterable[Dict[str, Any]]:
"""Yield csv rows from a collection."""
for card_set in sorted(
collection.oracle.index.setcode_to_set.values(),
Expand Down
12 changes: 3 additions & 9 deletions mtg_ssm/serialization/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,15 @@ class SerializationDialect(metaclass=abc.ABCMeta):
"""Abstract interface for mtg ssm serialization dialect."""

_EXT_DIALECT_DOC: ClassVar[Set[Tuple[str, str, str]]] = set()
_EXT_DIALECT_TO_IMPL: ClassVar[
Dict[Tuple[str, str], Type["SerializationDialect"]]
] = {}
_EXT_DIALECT_TO_IMPL: ClassVar[Dict[Tuple[str, str], Type["SerializationDialect"]]] = {}

extension: ClassVar[Optional[str]] = None
dialect: ClassVar[Optional[str]] = None

def __init_subclass__(cls: Type["SerializationDialect"]) -> None:
super().__init_subclass__()
if cls.extension is not None and cls.dialect is not None:
cls._EXT_DIALECT_DOC.add(
(cls.extension, cls.dialect, cls.__doc__ or cls.__name__)
)
cls._EXT_DIALECT_DOC.add((cls.extension, cls.dialect, cls.__doc__ or cls.__name__))
cls._EXT_DIALECT_TO_IMPL[(cls.extension, cls.dialect)] = cls

@abc.abstractmethod
Expand All @@ -52,9 +48,7 @@ def dialects(
cls: Type["SerializationDialect"],
) -> List[Tuple[str, Optional[str], Optional[str]]]:
"""List of (extension, dialect, description) of registered dialects."""
return sorted(
(ext, dial or "", doc or "") for ext, dial, doc in cls._EXT_DIALECT_DOC
)
return sorted((ext, dial or "", doc or "") for ext, dial, doc in cls._EXT_DIALECT_DOC)

@classmethod
def by_extension(
Expand Down
8 changes: 2 additions & 6 deletions mtg_ssm/serialization/xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ def style_all_sets(sheet: Worksheet) -> None:
cdim.number_format = number_format


def create_haverefs(
index: ScryfallDataIndex, setcode: str, cards: Sequence[ScryCard]
) -> str:
def create_haverefs(index: ScryfallDataIndex, setcode: str, cards: Sequence[ScryCard]) -> str:
"""Create a reference to or sum of the have cell(s) for printings in a single set."""
setcode = setcode.upper()
rownums = sorted(index.id_to_setindex[card.id] + ROW_OFFSET for card in cards)
Expand Down Expand Up @@ -222,9 +220,7 @@ def _setsheet_col(column_header: str) -> str:
ROW_OFFSET = 2


def create_set_sheet(
sheet: Worksheet, collection: MagicCollection, setcode: str
) -> None:
def create_set_sheet(sheet: Worksheet, collection: MagicCollection, setcode: str) -> None:
"""Populate sheet with card information from a given set."""
index = collection.oracle.index

Expand Down
12 changes: 3 additions & 9 deletions mtg_ssm/ssm.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,15 @@ def get_args(args: Optional[List[str]] = None) -> argparse.Namespace:
help="Update cards in a collection spreadsheet, preserving counts",
)
update.set_defaults(func=update_cmd)
update.add_argument(
"collection", type=Path, help="Filename for the collection to update"
)
update.add_argument("collection", type=Path, help="Filename for the collection to update")

merge = subparsers.add_parser(
"merge",
aliases=["m"],
help="Merge one or more collection spreadsheets into another. May also be used for format conversions.",
)
merge.set_defaults(func=merge_cmd)
merge.add_argument(
"collection", type=Path, help="Filename for the target collection"
)
merge.add_argument("collection", type=Path, help="Filename for the target collection")
merge.add_argument(
"imports",
nargs="+",
Expand All @@ -174,9 +170,7 @@ def get_args(args: Optional[List[str]] = None) -> argparse.Namespace:
type=Path,
help="Filename for second collection to diff (negative counts)",
)
diff.add_argument(
"output", type=Path, help="Filename for result collection of diff"
)
diff.add_argument("output", type=Path, help="Filename for result collection of diff")

parsed_args = parser.parse_args(args=args)
parsed_args.dialect = dict(parsed_args.dialect)
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ disallow_untyped_defs = true
allow_untyped_globals = false

[tool.black]
line-length = 88
line-length = 99
target-version = ["py38"]

[tool.ruff]
target-version = "py38"
line-length = 88
line-length = 99
select = [
"F",
"E",
Expand Down Expand Up @@ -166,6 +166,6 @@ ignore = [
[tool.ruff.isort]
known-first-party = ["mtg_ssm"]

# [tool.ruff.pylint]
# max-args = 7
# max-returns = 8
[tool.ruff.pylint]
max-args = 7
max-returns = 8
4 changes: 1 addition & 3 deletions tests/containers/test_bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ def test_exclude_foreign_only(scryfall_data: bundles.ScryfallDataSet) -> None:
assert "ren" in set_codes
assert UUID("81917a2b-9bf6-4aa6-947d-36b0f45d6fe3") in card_ids

tokens_removed = bundles.filter_cards_and_sets(
scryfall_data, exclude_foreing_only=True
)
tokens_removed = bundles.filter_cards_and_sets(scryfall_data, exclude_foreing_only=True)
set_codes2 = {s.code for s in tokens_removed.sets}
card_ids2 = {c.id for c in tokens_removed.cards}
assert "ren" not in set_codes2
Expand Down
8 changes: 2 additions & 6 deletions tests/containers/test_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,8 @@ def test_diff_card_counts(
{"scryfall_id": "0180d9a8-992c-4d55-8ac4-33a587786993", "nonfoil": "1"},
],
{
UUID("9d26f171-5bb6-463c-8473-53b6cc27ed66"): {
counts.CountType.FOIL: 1
},
UUID("0180d9a8-992c-4d55-8ac4-33a587786993"): {
counts.CountType.NONFOIL: 1
},
UUID("9d26f171-5bb6-463c-8473-53b6cc27ed66"): {counts.CountType.FOIL: 1},
UUID("0180d9a8-992c-4d55-8ac4-33a587786993"): {counts.CountType.NONFOIL: 1},
},
id="multiple",
),
Expand Down
9 changes: 2 additions & 7 deletions tests/containers/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ def test_load_data(scryfall_data: ScryfallDataSet) -> None:
def test_id_to_card(scryfall_data: ScryfallDataSet) -> None:
index = ScryfallDataIndex()
index.load_data(scryfall_data)
assert (
index.id_to_card[UUID("59cf0906-04fa-4b30-a7a6-3d117931154f")].name
== "Abattoir Ghoul"
)
assert index.id_to_card[UUID("59cf0906-04fa-4b30-a7a6-3d117931154f")].name == "Abattoir Ghoul"


def test_name_to_cards(scryfall_data: ScryfallDataSet) -> None:
Expand Down Expand Up @@ -75,9 +72,7 @@ def test_id_to_setindex(scryfall_data: ScryfallDataSet) -> None:
index = ScryfallDataIndex()
index.load_data(scryfall_data)

assert {
c.id: index.id_to_setindex[c.id] for c in index.setcode_to_cards["isd"]
} == {
assert {c.id: index.id_to_setindex[c.id] for c in index.setcode_to_cards["isd"]} == {
UUID("11bf83bb-c95b-4b4f-9a56-ce7a1816307a"): 0,
UUID("59cf0906-04fa-4b30-a7a6-3d117931154f"): 1,
UUID("b606f644-1728-4cb3-90ed-121838875de1"): 2,
Expand Down
8 changes: 2 additions & 6 deletions tests/containers/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ def test_extract_counts(card_row: Dict[str, Any], expected: Dict[str, int]) -> N
),
],
)
def test_find_scryfall_id(
card_row: Dict[str, Any], expected: UUID, oracle: Oracle
) -> None:
def test_find_scryfall_id(card_row: Dict[str, Any], expected: UUID, oracle: Oracle) -> None:
assert legacy.find_scryfall_id(card_row, oracle) == expected


Expand All @@ -103,7 +101,5 @@ def test_find_scryfall_id(
),
],
)
def test_coerce_row(
card_row: Dict[str, Any], expected: Dict[str, Any], oracle: Oracle
) -> None:
def test_coerce_row(card_row: Dict[str, Any], expected: Dict[str, Any], oracle: Oracle) -> None:
assert legacy.coerce_row(card_row, oracle) == expected
8 changes: 2 additions & 6 deletions tests/gen_testdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,12 @@ def main() -> None: # noqa: PLR0915
warnings=None,
)
with TARGET_MIGRATIONS_FILE.open("wb") as migrations_file:
migrations_file.write(
msgspec.json.format(msgspec.json.encode(migrations_list), indent=2)
)
migrations_file.write(msgspec.json.format(msgspec.json.encode(migrations_list), indent=2))
migrations_file.write(b"\n")

print("Writing cards")
with TARGET_CARDS_FILE.open("wb") as cards_file:
cards_file.write(
msgspec.json.format(msgspec.json.encode(accepted_cards), indent=2)
)
cards_file.write(msgspec.json.format(msgspec.json.encode(accepted_cards), indent=2))
cards_file.write(b"\n")

print("Writing bulk data")
Expand Down
8 changes: 2 additions & 6 deletions tests/mtg/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ def test_is_strict_basic(name: str, expected: bool) -> None:
("name", "card_id", "number", "variant"),
[
pytest.param("Thallid", UUID("4caaf31b-86a9-485b-8da7-d5b526ed1233"), 74, "a"),
pytest.param(
"Dark Ritual", UUID("ebb6664d-23ca-456e-9916-afcd6f26aa7f"), 98, None
),
pytest.param(
"Stairs to Infinity", UUID("57f25ead-b3ec-4c40-972d-d750ed2f5319"), 1, "P"
),
pytest.param("Dark Ritual", UUID("ebb6664d-23ca-456e-9916-afcd6f26aa7f"), 98, None),
pytest.param("Stairs to Infinity", UUID("57f25ead-b3ec-4c40-972d-d750ed2f5319"), 1, "P"),
pytest.param(
"Ertai, the Corrupted",
UUID("66b950d9-8fef-4deb-b51b-26edb90abc56"),
Expand Down
8 changes: 2 additions & 6 deletions tests/scryfall/test_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
from mtg_ssm.scryfall.models import ScryCard, ScryMigration, ScrySet
from tests import gen_testdata

BULK_CARDS_REGEX = (
r"https://data\.scryfall\.io/default-cards/default-cards-\d{14}\.json"
)
BULK_CARDS_REGEX = r"https://data\.scryfall\.io/default-cards/default-cards-\d{14}\.json"

ENDPOINT_TO_FILE: Dict[Union[str, Pattern[str]], Path] = {
fetcher.BULK_DATA_ENDPOINT: gen_testdata.TARGET_BULK_FILE,
Expand Down Expand Up @@ -47,9 +45,7 @@ def test_scryfetch() -> None:
assert scrydata1 == scrydata2
assert {s.code for s in scrydata1.sets} == gen_testdata.TEST_SETS_TO_CARDS.keys()
assert {(c.set, c.name) for c in scrydata1.cards} == {
(key, card)
for key, value in gen_testdata.TEST_SETS_TO_CARDS.items()
for card in value
(key, card) for key, value in gen_testdata.TEST_SETS_TO_CARDS.items() for card in value
}


Expand Down
16 changes: 4 additions & 12 deletions tests/serialization/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ def test_rows_for_cards_verbose(oracle: Oracle) -> None:


def test_rows_for_cards_terse(oracle: Oracle) -> None:
card_counts: counts.ScryfallCardCount = {
TEST_CARD_ID: {counts.CountType.NONFOIL: 3}
}
card_counts: counts.ScryfallCardCount = {TEST_CARD_ID: {counts.CountType.NONFOIL: 3}}
collection = MagicCollection(oracle=oracle, counts=card_counts)
rows = csv.rows_for_cards(collection, False)
assert list(rows) == [
Expand All @@ -106,9 +104,7 @@ def test_rows_for_cards_terse(oracle: Oracle) -> None:
]


def test_write_verbose(
snapshot: SnapshotAssertion, oracle: Oracle, tmp_path: Path
) -> None:
def test_write_verbose(snapshot: SnapshotAssertion, oracle: Oracle, tmp_path: Path) -> None:
csv_path = tmp_path / "outfile.csv"
card_counts: ScryfallCardCount = {
TEST_CARD_ID: {counts.CountType.NONFOIL: 3, counts.CountType.FOIL: 7}
Expand All @@ -120,13 +116,9 @@ def test_write_verbose(
assert csv_file.read() == snapshot


def test_write_terse(
snapshot: SnapshotAssertion, oracle: Oracle, tmp_path: Path
) -> None:
def test_write_terse(snapshot: SnapshotAssertion, oracle: Oracle, tmp_path: Path) -> None:
csv_path = tmp_path / "outfile.csv"
card_counts: counts.ScryfallCardCount = {
TEST_CARD_ID: {counts.CountType.NONFOIL: 3}
}
card_counts: counts.ScryfallCardCount = {TEST_CARD_ID: {counts.CountType.NONFOIL: 3}}
collection = MagicCollection(oracle=oracle, counts=card_counts)

serializer = csv.CsvTerseDialect()
Expand Down
4 changes: 1 addition & 3 deletions tests/serialization/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ def test_all_dialects() -> None:
def test_extension_lookup(
extension: str, dialect_mapping: Dict[str, str], dialect_name: str
) -> None:
serialization_class = interface.SerializationDialect.by_extension(
extension, dialect_mapping
)
serialization_class = interface.SerializationDialect.by_extension(extension, dialect_mapping)
assert isinstance(serialization_class, type)
assert issubclass(serialization_class, interface.SerializationDialect)
assert serialization_class.__name__ == dialect_name
12 changes: 3 additions & 9 deletions tests/serialization/test_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def test_create_all_sets(snapshot: SnapshotAssertion, oracle: Oracle) -> None:
book = openpyxl.Workbook()
sheet = book.create_sheet()
xlsx.create_all_sets(sheet, oracle.index)
assert [[cell.value for cell in row] for row in sheet.rows] == snapshot(
name=str(sheet.title)
)
assert [[cell.value for cell in row] for row in sheet.rows] == snapshot(name=str(sheet.title))


def test_create_haverefs(oracle: Oracle) -> None:
Expand Down Expand Up @@ -86,9 +84,7 @@ def test_create_all_cards_sheet(snapshot: SnapshotAssertion, oracle: Oracle) ->
book = openpyxl.Workbook()
sheet = book.create_sheet()
xlsx.create_all_cards(sheet, oracle.index)
assert [[cell.value for cell in row] for row in sheet.rows] == snapshot(
name=str(sheet.title)
)
assert [[cell.value for cell in row] for row in sheet.rows] == snapshot(name=str(sheet.title))


def test_create_set_sheet(snapshot: SnapshotAssertion, oracle: Oracle) -> None:
Expand All @@ -104,9 +100,7 @@ def test_create_set_sheet(snapshot: SnapshotAssertion, oracle: Oracle) -> None:
book = openpyxl.Workbook()
sheet = book.create_sheet()
xlsx.create_set_sheet(sheet, collection, "ice")
assert [[cell.value for cell in row] for row in sheet.rows] == snapshot(
name=str(sheet.title)
)
assert [[cell.value for cell in row] for row in sheet.rows] == snapshot(name=str(sheet.title))


def test_write(snapshot: SnapshotAssertion, oracle: Oracle, tmp_path: Path) -> None:
Expand Down
Loading

0 comments on commit e9d6e45

Please sign in to comment.