move bundle config to JSON format (#126)
* move bundle config to JSON format * correct docstring, change print back to logging * remove make reference from contributing * change layout and install for config file
This commit is contained in:
parent
a9f9cf5e77
commit
d467d2545b
8 changed files with 32 additions and 25 deletions
|
|
@ -39,13 +39,6 @@ Run the test suite::
|
|||
|
||||
pytest --random-order --cov-config .coveragerc --cov-report term-missing --cov=circup
|
||||
|
||||
.. warning::
|
||||
|
||||
Whenever you run ``make check``, to ensure the test suite starts from a
|
||||
known clean state, all auto-generated assets are deleted. This includes
|
||||
assets generated by running ``pip install -e ".[dev]"``, including the
|
||||
``circup`` command itself. Simply re-run ``pip`` to re-generate the
|
||||
assets.
|
||||
|
||||
How Does Circup Work?
|
||||
#####################
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import zipfile
|
|||
import appdirs
|
||||
import click
|
||||
import findimports
|
||||
import pkg_resources
|
||||
import requests
|
||||
from semver import VersionInfo
|
||||
|
||||
|
|
@ -30,6 +31,10 @@ VERBOSE = False
|
|||
#: The location of data files used by circup (following OS conventions).
|
||||
DATA_DIR = appdirs.user_data_dir(appname="circup", appauthor="adafruit")
|
||||
#: The path to the JSON file containing the metadata about the bundles.
|
||||
BUNDLE_CONFIG_FILE = pkg_resources.resource_filename(
|
||||
"circup", "config/bundle_config.json"
|
||||
)
|
||||
#: The path to the JSON file containing the metadata about the bundles.
|
||||
BUNDLE_DATA = os.path.join(DATA_DIR, "circup.json")
|
||||
#: The directory containing the utility's log file.
|
||||
LOG_DIR = appdirs.user_log_dir(appname="circup", appauthor="adafruit")
|
||||
|
|
@ -45,14 +50,6 @@ NOT_MCU_LIBRARIES = [
|
|||
]
|
||||
#: The version of CircuitPython found on the connected device.
|
||||
CPY_VERSION = ""
|
||||
#: Adafruit bundle repository
|
||||
BUNDLE_ADAFRUIT = "adafruit/Adafruit_CircuitPython_Bundle"
|
||||
#: Community bundle repository
|
||||
BUNDLE_COMMUNITY = "adafruit/CircuitPython_Community_Bundle"
|
||||
#: CircuitPython Organization bundle repository
|
||||
BUNDLE_CIRCUITPYTHON_ORG = "circuitpython/CircuitPython_Org_Bundle"
|
||||
#: Default bundle repository list
|
||||
BUNDLES_DEFAULT_LIST = [BUNDLE_ADAFRUIT, BUNDLE_COMMUNITY, BUNDLE_CIRCUITPYTHON_ORG]
|
||||
#: Module formats list (and the other form used in github files)
|
||||
PLATFORMS = {"py": "py", "6mpy": "6.x-mpy", "7mpy": "7.x-mpy"}
|
||||
#: Commands that do not require an attached board
|
||||
|
|
@ -707,15 +704,14 @@ def get_bundle_versions(bundles_list, avoid_download=False):
|
|||
|
||||
def get_bundles_list():
|
||||
"""
|
||||
Retrieve the list of bundles. Currently uses the fixed list.
|
||||
The goal is to implement reading from a configuration file.
|
||||
https://github.com/adafruit/circup/issues/82#issuecomment-843368130
|
||||
Retrieve the list of bundles as listed BUNDLE_CONFIG_FILE (JSON)
|
||||
|
||||
:return: List of supported bundles as Bundle objects.
|
||||
"""
|
||||
bundles_list = [Bundle(b) for b in BUNDLES_DEFAULT_LIST]
|
||||
logger.info("Using bundles: %s", ", ".join([b.key for b in bundles_list]))
|
||||
# TODO: this is were we retrieve the bundles list from json
|
||||
with open(BUNDLE_CONFIG_FILE) as bundle_config_json:
|
||||
bundle_config = json.load(bundle_config_json)
|
||||
bundles_list = [Bundle(bundle_config[b]) for b in bundle_config]
|
||||
logger.info("Using bundles: %s", ", ".join(b.key for b in bundles_list))
|
||||
return bundles_list
|
||||
|
||||
|
||||
5
circup/config/bundle_config.json
Normal file
5
circup/config/bundle_config.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"adafruit": "adafruit/Adafruit_CircuitPython_Bundle",
|
||||
"circuitpython_community": "adafruit/CircuitPython_Community_Bundle",
|
||||
"circuitpython_org": "circuitpython/CircuitPython_Org_Bundle"
|
||||
}
|
||||
3
circup/config/bundle_config.json.license
Normal file
3
circup/config/bundle_config.json.license
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# SPDX-FileCopyrightText: 2021 Patrick Walters
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
3
setup.py
3
setup.py
|
|
@ -95,5 +95,6 @@ setup(
|
|||
keywords="adafruit, blinka, circuitpython, micropython, libraries",
|
||||
# You can just specify the packages manually here if your project is
|
||||
# simple. Or you can use find_packages().
|
||||
py_modules=["circup"],
|
||||
packages=["circup"],
|
||||
package_data={"circup": ["config/bundle_config.json"]},
|
||||
)
|
||||
|
|
|
|||
3
tests/test_bundle_config.json
Normal file
3
tests/test_bundle_config.json
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"test_bundle": "adafruit/Adafruit_CircuitPython_Bundle"
|
||||
}
|
||||
3
tests/test_bundle_config.json.license
Normal file
3
tests/test_bundle_config.json.license
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# SPDX-FileCopyrightText: 2021 Patrick Walters
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
|
@ -38,7 +38,10 @@ import requests
|
|||
import circup
|
||||
|
||||
|
||||
TEST_BUNDLE_NAME = "adafruit/Adafruit_CircuitPython_Bundle"
|
||||
TEST_BUNDLE_CONFIG_JSON = "tests/test_bundle_config.json"
|
||||
with open(TEST_BUNDLE_CONFIG_JSON) as tbc:
|
||||
test_bundle_data = json.load(tbc)
|
||||
TEST_BUNDLE_NAME = test_bundle_data["test_bundle"]
|
||||
|
||||
|
||||
def test_Bundle_init():
|
||||
|
|
@ -119,9 +122,9 @@ def test_Bundle_latest_tag():
|
|||
|
||||
def test_get_bundles_list():
|
||||
"""
|
||||
Check we are getting the bundles list from BUNDLES_DEFAULT_LIST.
|
||||
Check we are getting the bundles list from BUNDLE_CONFIG_FILE.
|
||||
"""
|
||||
with mock.patch("circup.BUNDLES_DEFAULT_LIST", [TEST_BUNDLE_NAME]):
|
||||
with mock.patch("circup.BUNDLE_CONFIG_FILE", TEST_BUNDLE_CONFIG_JSON):
|
||||
bundles_list = circup.get_bundles_list()
|
||||
bundle = circup.Bundle(TEST_BUNDLE_NAME)
|
||||
assert repr(bundles_list) == repr([bundle])
|
||||
|
|
|
|||
Loading…
Reference in a new issue