Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ name: Tests

on:
push:
branches: [master]
branches: [main]
pull_request:
branches: [master]
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.12", "3.13", "3.14"]

steps:
- uses: actions/checkout@v4
Expand Down
61 changes: 54 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*.py[codz]
*$py.class

# C extensions
Expand Down Expand Up @@ -46,7 +46,7 @@ htmlcov/
nosetests.xml
coverage.xml
*.cover
*.py,cover
*.py.cover
.hypothesis/
.pytest_cache/
cover/
Expand Down Expand Up @@ -94,20 +94,35 @@ ipython_config.py
# install all needed dependencies.
#Pipfile.lock

# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
#uv.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
#poetry.toml

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
#pdm.toml
.pdm-python
.pdm-build/

# pixi
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
#pixi.lock
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
# in the .venv directory. It is recommended not to include this directory in version control.
.pixi

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
Expand All @@ -121,6 +136,7 @@ celerybeat.pid

# Environments
.env
.envrc
.venv
env/
venv/
Expand Down Expand Up @@ -157,4 +173,35 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
#.idea/

# Abstra
# Abstra is an AI-powered process automation framework.
# Ignore directories containing user credentials, local state, and settings.
# Learn more at https://abstra.io/docs
.abstra/

# Visual Studio Code
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
# and can be added to the global gitignore or merged into this file. However, if you prefer,
# you could uncomment the following to ignore the entire vscode folder
# .vscode/

# Ruff stuff:
.ruff_cache/

# PyPI configuration file
.pypirc

# Cursor
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
# refer to https://docs.cursor.com/context/ignore-files
.cursorignore
.cursorindexingignore

# Marimo
marimo/_static/
marimo/_lsp/
__marimo__/
62 changes: 27 additions & 35 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,50 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: check-added-large-files
- id: check-merge-conflict
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: end-of-file-fixer
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.1
hooks:
- id: pyupgrade
args:
- "--py39-plus"
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- id: ruff-check
- id: ruff-format
- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
rev: 7.3.0
hooks:
- id: flake8
additional_dependencies:
- flake8-absolute-import
- flake8-annotations
- flake8-builtins
- flake8-comprehensions
- flake8-docstrings
- flake8-future-annotations
- flake8-no-implicit-concat
- flake8-print
- flake8-pyproject
- flake8-requirements
- flake8-simplify
- flake8-use-fstring
- flake8-use-pathlib
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
# - repo: https://github.com/nbQA-dev/nbQA
# rev: 1.9.1
# hooks:
# - id: nbqa-flake8
# additional_dependencies:
# - flake8-pyproject
# - flake8-requirements
# - repo: https://github.com/kynan/nbstripout
# rev: 0.8.2
# hooks:
# - id: nbstripout
# args:
# - "--extra-keys=metadata.kernelspec metadata.language_info"
# - "--drop-empty-cells"
- repo: https://github.com/rbubley/mirrors-prettier
rev: v3.8.1
hooks:
- id: prettier
args:
- "--tab-width"
- "2"
- "--tab-width=2"
- repo: https://github.com/shssoichiro/oxipng
rev: v9.1.3
rev: v10.0.0
hooks:
- id: oxipng
args:
- "-o"
- "max"
- "--strip"
- "safe"
- "-o=max"
- "--strip=safe"
- "--alpha"
7 changes: 3 additions & 4 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"ms-python.black-formatter",
"ms-python.flake8",
"ms-python.isort",
"charliermarsh.ruff",
"ms-python.python",
"ms-python.vscode-pylance"
"ms-python.vscode-pylance",
"tamasfe.even-better-toml"
]
}
10 changes: 7 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
"python.testing.pytestEnabled": true,
"git.rebaseWhenSync": true,
"notebook.formatOnSave.enabled": true,
"notebook.codeActionsOnSave": {
"notebook.source.organizeImports.ruff": "explicit"
},
"files.eol": "\n",
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
"source.organizeImports.ruff": "explicit"
}
},
"window.title": "${dirty}${rootName}${separator}${activeEditorShort}"
"window.title": "${dirty}${rootName}${separator}${activeEditorShort}",
"evenBetterToml.formatter.arrayAutoCollapse": false
}
1 change: 1 addition & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mode: Mainline
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ git clone https://github.com/DiddiZ/mtg-proxies.git
cd mtg-proxies
```

2. Install requirements. Requires at least [Python 3.9](https://www.python.org/downloads/).
2. Install requirements. Requires at least [Python 3.12](https://www.python.org/downloads/).

```bash
# On Linux, use `python3` instead of `python`
Expand Down
109 changes: 55 additions & 54 deletions deck_value.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,55 @@
import argparse

import matplotlib.pyplot as plt

import scryfall
from mtgproxies.cli import parse_decklist_spec

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Show deck value decomposition.")
parser.add_argument(
"decklist",
metavar="decklist_spec",
help="path to a decklist in text/arena format, or manastack:{manastack_id}, or archidekt:{archidekt_id}",
)
parser.add_argument(
"--lump-threshold",
help="lump together cards with lesser proportional value",
type=float,
default=0.03,
metavar="FLOAT",
)

args = parser.parse_args()

# Parse decklist
decklist = parse_decklist_spec(args.decklist, warn_levels=["ERROR", "WARNING"])

# Fetch prices
card_prices = []
for card in decklist.cards:
price = scryfall.get_price(card["oracle_id"])
if price is not None:
card_prices.append((card["name"], card.count * price))
else:
print(f"WARNING: Unable to find price for {card['name']}")

card_prices.sort(key=lambda x: x[1], reverse=True)
price_total = sum(p for _, p in card_prices)

# Partition cards in named and bulk
cards_named = [(card, price) for card, price in card_prices if price >= args.lump_threshold * price_total]
cards_lump = [(card, price) for card, price in card_prices if price < args.lump_threshold * price_total]

# Plot
plt.pie(
[price for _, price in cards_named] + [sum(p for _, p in cards_lump)],
labels=[name for name, _ in cards_named] + ["other"],
autopct=lambda pct: f"{pct / 100. * price_total:0.2f}€",
shadow=True,
startangle=90,
)
plt.title(f"{decklist.name} ({price_total:0.2f}€)")
plt.tight_layout()
plt.show()
import argparse
from operator import itemgetter

import matplotlib.pyplot as plt

import scryfall
from mtgproxies.cli import parse_decklist_spec

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Show deck value decomposition.")
parser.add_argument(
"decklist",
metavar="decklist_spec",
help="path to a decklist in text/arena format, or manastack:{manastack_id}, or archidekt:{archidekt_id}",
)
parser.add_argument(
"--lump-threshold",
help="lump together cards with lesser proportional value",
type=float,
default=0.03,
metavar="FLOAT",
)

args = parser.parse_args()

# Parse decklist
decklist = parse_decklist_spec(args.decklist, warn_levels=["ERROR", "WARNING"])

# Fetch prices
card_prices = []
for card in decklist.cards:
price = scryfall.get_price(card["oracle_id"])
if price is not None:
card_prices.append((card["name"], card.count * price))
else:
print(f"WARNING: Unable to find price for {card['name']}")

card_prices.sort(key=itemgetter(1), reverse=True)
price_total = sum(p for _, p in card_prices)

# Partition cards in named and bulk
cards_named = [(card, price) for card, price in card_prices if price >= args.lump_threshold * price_total]
cards_lump = [(card, price) for card, price in card_prices if price < args.lump_threshold * price_total]

# Plot
plt.pie(
[price for _, price in cards_named] + [sum(p for _, p in cards_lump)],
labels=[name for name, _ in cards_named] + ["other"],
autopct=lambda pct: f"{pct / 100.0 * price_total:0.2f}€",
shadow=True,
startangle=90,
)
plt.title(f"{decklist.name} ({price_total:0.2f}€)")
plt.tight_layout()
plt.show()
Binary file modified examples/decklist.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion mtgproxies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

__all__ = [
"fetch_scans_scryfall",
"print_cards_matplotlib",
"print_cards_fpdf",
"print_cards_matplotlib",
]
7 changes: 4 additions & 3 deletions mtgproxies/cli.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from collections.abc import Container
from pathlib import Path

from mtgproxies.decklists import archidekt, manastack, parse_decklist
from mtgproxies.decklists.decklist import Decklist


def parse_decklist_spec(decklist_spec: str, warn_levels=("ERROR", "WARNING", "COSMETIC")) -> Decklist:
def parse_decklist_spec(decklist_spec: str, warn_levels: Container[str] = ("ERROR", "WARNING", "COSMETIC")) -> Decklist:
"""Attempt to parse a decklist from different locations.

Args:
Expand All @@ -20,8 +21,8 @@ def parse_decklist_spec(decklist_spec: str, warn_levels=("ERROR", "WARNING", "CO
decklist, ok, warnings = manastack.parse_decklist(manastack_id)
elif decklist_spec.lower().startswith("archidekt:") and decklist_spec.split(":")[-1].isdigit():
# Decklist on Archidekt
manastack_id = decklist_spec.split(":")[-1]
decklist, ok, warnings = archidekt.parse_decklist(manastack_id)
archidekt_id = decklist_spec.split(":")[-1]
decklist, ok, warnings = archidekt.parse_decklist(archidekt_id)
else:
print(f"Cant find decklist '{decklist_spec}'")
quit()
Expand Down
Loading