Skip to content

Commit

Permalink
first rendition of contributing docs & remove format
Browse files Browse the repository at this point in the history
Signed-off-by: ZeldaZach <zahalpern+github@gmail.com>
  • Loading branch information
ZeldaZach committed Oct 9, 2019
1 parent 8e2e7bd commit 531dd73
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 47 deletions.
46 changes: 46 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Contributing to MTGJSON

First off, thanks for taking the time to read this document! It means something to us that you're potentially interested in helping improve our project.

Our goal for MTGJSON was and is to provide free and easily accessible Magic: the Gathering data for those who want and/or need it.

If you're not a software developer, but want to help the project in some way, we are always looking for individuals to audit the content we provide. We also accept financial contributions to the project via [PayPal](https://www.paypal.me/zachhalpern) and [Patreon](https://patreon.com/mtgjson).

## Environment Setup

Here at MTGJSON, we recommend all of our developers check out [PyCharm](https://jetbrains.com/pycharm/). While any IDE or notepad can be used, we found that the JetBrains environment is intuitive and easy to understand.

In addition to PyCharm, you'll need to install Python 3. We develop actively on the latest release of Python, but aim for compatibility with Python 3.6.

- Mac: `brew install python3`
- Linux: `sudo apt-get install python3.7`
- Windows: [Download Python 3](https://www.python.org/downloads/)


## Project Hierarchy
The codebase is split up into different files based on functionality. While not perfect, we aim to segregate components based on their usages and dependencies.

- `provider/` is where we put code for each 3rd party resource we need to contact in order to collate our data. Each source should be given its own folder and should not be dependent on any other provider.
- `resources/` is where we put MTGJSON corrections, fixes, and hard caches. These are data points we want to include, but can't grab from an external entity easily or without causing a circular loop.
- `__main__.py` is where we define our globals for the project. TODO is to re-write them into their own class.
- `compile_mtg.py` is the main functionality of the project, where we handle turning data blobs into MTGJSON cards and sets.
- `compressor.py` is where we compress completed outputs for release.
- `outputter.py` is where all I/O operations should take place. All write to disk calls should be done from here.
- `util.py` are common utilities that may be used across the codebase.

## Code Style & Testing

We follow the [black](https://pypi.org/project/black/) style guides, a stricter version of [PEP-8](https://www.python.org/dev/peps/pep-0008/) styling.

To reformat your code and ensure compatibility with our system, simply run the Tox file found in the repo before you open up a pull request.
- Before running Tox, you'll need to install the requirements
- `python3 install -r requirements_test.txt`
- In PyCharm, simply right click on `tox.ini` and click "Run Tox"

You will need to pass all Tox requirements, including the unit tests, for your pull request to be approved.

## Communication Channels

We communicate almost exclusively through [Discord](https://mtgjson.com/discord). Feel free to join us, whether you're a developer or not. We love chatting with the community!

MTGJSON staff can be identified with a blue name, and our staff listing is found on the [website](https://mtgjson.com/).
43 changes: 0 additions & 43 deletions mtgjson4/format.py

This file was deleted.

3 changes: 1 addition & 2 deletions mtgjson4/outputter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import mtgjson4
from mtgjson4 import SUPPORTED_FORMAT_OUTPUTS, util
from mtgjson4.format import build_format_map
from mtgjson4.mtgjson_card import MTGJSONCard
from mtgjson4.provider import magic_precons, scryfall, wizards

Expand Down Expand Up @@ -397,7 +396,7 @@ def create_set_centric_outputs(sets: Dict[str, Any]) -> None:
:param sets: Dictionary mapping name -> card data. Should be AllSets.
"""
# Compute format map from all_sets
format_map = build_format_map(sets)
format_map = util.build_format_map(sets)
LOGGER.info(f"Format Map: {format_map}")

# Standard.json
Expand Down
41 changes: 40 additions & 1 deletion mtgjson4/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import re
import shutil
import tempfile
from typing import Any, List, Optional
from typing import Any, Dict, List, Optional, Set
import unicodedata

import requests
Expand All @@ -27,6 +27,14 @@

STANDARD_API_URL: str = "https://whatsinstandard.com/api/v5/sets.json"

NORMAL_SETS: Set[str] = {
"expansion",
"core",
"draft_innovation",
"commander",
"masters",
}


def retryable_session(session: requests.Session, retries: int = 8) -> requests.Session:
"""
Expand Down Expand Up @@ -229,3 +237,34 @@ def set_gist_json_file(

LOGGER.info("Removing local CH database")
shutil.rmtree(temp_working_dir)


def build_format_map(
all_sets: Dict[str, Any], regular: bool = True
) -> Dict[str, List[str]]:
"""
For each set in the specified JSON file, determine its legal sets and return a dictionary mapping set code to
a list of legal formats.
:param all_sets: AllSets content
:param regular: If this is True, then unusual sets will be excluded.
:return: Dictionary of the form { format: [codes] }
"""
formats: Dict[str, List[Any]] = {
fmt: [] for fmt in mtgjson4.SUPPORTED_FORMAT_OUTPUTS
}

for code, data in all_sets.items():
if regular and data["type"] not in NORMAL_SETS:
continue

possible_formats = mtgjson4.SUPPORTED_FORMAT_OUTPUTS

for card in data.get("cards"):
# The legalities dictionary only has keys for formats where the card is legal, banned or restricted.
card_formats = set(card.get("legalities").keys())
possible_formats = possible_formats.intersection(card_formats)

for fmt in possible_formats:
formats[fmt].append(code)

return formats
2 changes: 1 addition & 1 deletion tests/mtgjson4/test_format.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from mtgjson4.format import build_format_map
from mtgjson4.util import build_format_map


NULL_OUTPUT = {"standard": [], "modern": [], "legacy": [], "vintage": [], "pauper": []}
Expand Down

0 comments on commit 531dd73

Please sign in to comment.