Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move bundle config to JSON format #126

Merged
merged 4 commits into from
Sep 8, 2021
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
7 changes: 0 additions & 7 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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?
#####################
Expand Down
24 changes: 10 additions & 14 deletions circup.py → circup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import appdirs
import click
import findimports
import pkg_resources
import requests
from semver import VersionInfo

Expand All @@ -30,6 +31,10 @@
#: 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")
Expand All @@ -45,14 +50,6 @@
]
#: 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
Expand Down Expand Up @@ -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


Expand Down
5 changes: 5 additions & 0 deletions circup/config/bundle_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"adafruit": "adafruit/Adafruit_CircuitPython_Bundle",
"circuitpython_community": "adafruit/CircuitPython_Community_Bundle",
"circuitpython_org": "circuitpython/CircuitPython_Org_Bundle"
}
3 changes: 3 additions & 0 deletions circup/config/bundle_config.json.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: 2021 Patrick Walters
#
# SPDX-License-Identifier: MIT
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,6 @@
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 changes: 3 additions & 0 deletions tests/test_bundle_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"test_bundle": "adafruit/Adafruit_CircuitPython_Bundle"
}
3 changes: 3 additions & 0 deletions tests/test_bundle_config.json.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: 2021 Patrick Walters
#
# SPDX-License-Identifier: MIT
9 changes: 6 additions & 3 deletions tests/test_circup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
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():
Expand Down Expand Up @@ -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])
Expand Down