Repository: adafruit/circup (language: python)

Issue:
list bundle urls in json rather than in code
so we can dynamically add more bundles!
also bundlefly can reference it


Discussion / hints:
@makermelissa this is a pretty small todo if you wanna pick it up

Fix patch:
diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index ee3ae3c..b3a851a 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -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?
 #####################
diff --git a/circup.py b/circup/__init__.py
similarity index 98%
rename from circup.py
rename to circup/__init__.py
index efaba58..837dbe1 100644
--- a/circup.py
+++ b/circup/__init__.py
@@ -20,6 +20,7 @@
 import appdirs
 import click
 import findimports
+import pkg_resources
 import requests
 from semver import VersionInfo
 
@@ -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")
@@ -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
@@ -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
 
 
diff --git a/circup/config/bundle_config.json b/circup/config/bundle_config.json
new file mode 100644
index 0000000..eb38930
--- /dev/null
+++ b/circup/config/bundle_config.json
@@ -0,0 +1,5 @@
+{
+    "adafruit": "adafruit/Adafruit_CircuitPython_Bundle",
+    "circuitpython_community": "adafruit/CircuitPython_Community_Bundle",
+    "circuitpython_org": "circuitpython/CircuitPython_Org_Bundle"
+}
diff --git a/circup/config/bundle_config.json.license b/circup/config/bundle_config.json.license
new file mode 100644
index 0000000..56a8808
--- /dev/null
+++ b/circup/config/bundle_config.json.license
@@ -0,0 +1,3 @@
+# SPDX-FileCopyrightText: 2021 Patrick Walters
+#
+# SPDX-License-Identifier: MIT
diff --git a/setup.py b/setup.py
index 3381f35..2e84e89 100644
--- a/setup.py
+++ b/setup.py
@@ -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"]},
 )


Test patch:
diff --git a/tests/test_bundle_config.json b/tests/test_bundle_config.json
new file mode 100644
index 0000000..ee90090
--- /dev/null
+++ b/tests/test_bundle_config.json
@@ -0,0 +1,3 @@
+{
+    "test_bundle": "adafruit/Adafruit_CircuitPython_Bundle"
+}
diff --git a/tests/test_bundle_config.json.license b/tests/test_bundle_config.json.license
new file mode 100644
index 0000000..56a8808
--- /dev/null
+++ b/tests/test_bundle_config.json.license
@@ -0,0 +1,3 @@
+# SPDX-FileCopyrightText: 2021 Patrick Walters
+#
+# SPDX-License-Identifier: MIT
diff --git a/tests/test_circup.py b/tests/test_circup.py
index e3c89cb..7a85417 100644
--- a/tests/test_circup.py
+++ b/tests/test_circup.py
@@ -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():
@@ -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])