circup 3.1.0__tar.gz → 3.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {circup-3.1.0/circup.egg-info → circup-3.2.0}/PKG-INFO +42 -19
- {circup-3.1.0 → circup-3.2.0}/README.rst +41 -18
- {circup-3.1.0 → circup-3.2.0}/circup/backends.py +219 -53
- {circup-3.1.0 → circup-3.2.0}/circup/bundle.py +4 -2
- {circup-3.1.0 → circup-3.2.0}/circup/command_utils.py +58 -48
- {circup-3.1.0 → circup-3.2.0}/circup/commands.py +58 -25
- {circup-3.1.0 → circup-3.2.0}/circup/module.py +4 -3
- {circup-3.1.0 → circup-3.2.0}/circup/shared.py +62 -3
- {circup-3.1.0 → circup-3.2.0}/circup/wwshell/commands.py +4 -4
- {circup-3.1.0 → circup-3.2.0/circup.egg-info}/PKG-INFO +42 -19
- {circup-3.1.0 → circup-3.2.0}/circup.egg-info/SOURCES.txt +1 -0
- {circup-3.1.0 → circup-3.2.0}/circup.egg-info/scm_file_list.json +1 -0
- circup-3.2.0/circup.egg-info/scm_version.json +8 -0
- {circup-3.1.0 → circup-3.2.0}/tests/test_circup.py +327 -1
- circup-3.2.0/tests/test_dotfile_skip.py +104 -0
- circup-3.1.0/circup.egg-info/scm_version.json +0 -8
- {circup-3.1.0 → circup-3.2.0}/.github/ISSUE_TEMPLATE.md +0 -0
- {circup-3.1.0 → circup-3.2.0}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
- {circup-3.1.0 → circup-3.2.0}/.github/workflows/build.yml +0 -0
- {circup-3.1.0 → circup-3.2.0}/.github/workflows/release.yml +0 -0
- {circup-3.1.0 → circup-3.2.0}/.gitignore +0 -0
- {circup-3.1.0 → circup-3.2.0}/.isort.cfg +0 -0
- {circup-3.1.0 → circup-3.2.0}/.pre-commit-config.yaml +0 -0
- {circup-3.1.0 → circup-3.2.0}/.pylintrc +0 -0
- {circup-3.1.0 → circup-3.2.0}/CODE_OF_CONDUCT.rst +0 -0
- {circup-3.1.0 → circup-3.2.0}/CODE_OF_CONDUCT.rst.license +0 -0
- {circup-3.1.0 → circup-3.2.0}/CONTRIBUTING.rst +0 -0
- {circup-3.1.0 → circup-3.2.0}/CONTRIBUTING.rst.license +0 -0
- {circup-3.1.0 → circup-3.2.0}/LICENSE +0 -0
- {circup-3.1.0 → circup-3.2.0}/LICENSES/CC-BY-4.0.txt +0 -0
- {circup-3.1.0 → circup-3.2.0}/LICENSES/MIT.txt +0 -0
- {circup-3.1.0 → circup-3.2.0}/LICENSES/Unlicense.txt +0 -0
- {circup-3.1.0 → circup-3.2.0}/README.rst.license +0 -0
- {circup-3.1.0 → circup-3.2.0}/circup/__init__.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/circup/config/bundle_config.json +0 -0
- {circup-3.1.0 → circup-3.2.0}/circup/config/bundle_config.json.license +0 -0
- {circup-3.1.0 → circup-3.2.0}/circup/lazy_metadata.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/circup/logging.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/circup/wwshell/README.rst +0 -0
- {circup-3.1.0 → circup-3.2.0}/circup/wwshell/README.rst.license +0 -0
- {circup-3.1.0 → circup-3.2.0}/circup/wwshell/__init__.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/circup.egg-info/dependency_links.txt +0 -0
- {circup-3.1.0 → circup-3.2.0}/circup.egg-info/entry_points.txt +0 -0
- {circup-3.1.0 → circup-3.2.0}/circup.egg-info/requires.txt +0 -0
- {circup-3.1.0 → circup-3.2.0}/circup.egg-info/top_level.txt +0 -0
- {circup-3.1.0 → circup-3.2.0}/docs/_static/favicon.ico +0 -0
- {circup-3.1.0 → circup-3.2.0}/docs/_static/favicon.ico.license +0 -0
- {circup-3.1.0 → circup-3.2.0}/docs/conf.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/docs/index.rst +0 -0
- {circup-3.1.0 → circup-3.2.0}/docs/index.rst.license +0 -0
- {circup-3.1.0 → circup-3.2.0}/docs/logo.png +0 -0
- {circup-3.1.0 → circup-3.2.0}/docs/logo.png.license +0 -0
- {circup-3.1.0 → circup-3.2.0}/docs/requirements.txt +0 -0
- {circup-3.1.0 → circup-3.2.0}/optional_requirements.txt +0 -0
- {circup-3.1.0 → circup-3.2.0}/optional_requirements.txt.license +0 -0
- {circup-3.1.0 → circup-3.2.0}/pyproject.toml +0 -0
- {circup-3.1.0 → circup-3.2.0}/readthedocs.yml +0 -0
- {circup-3.1.0 → circup-3.2.0}/requirements.txt +0 -0
- {circup-3.1.0 → circup-3.2.0}/requirements.txt.license +0 -0
- {circup-3.1.0 → circup-3.2.0}/setup.cfg +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/__init__.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/bad_module/__init__.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/bad_module/my_module.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/bad_python.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/bundle.json +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/bundle.json.license +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/device.json +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/device.json.license +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/dir_module/__init__.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/dir_module/my_module.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/import_styles.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/local_module.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/local_module_cp7.mpy +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/local_module_cp7.mpy.license +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/mock_device/apps/test_app/import_styles.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/mock_device/apps/test_app/import_styles_sub.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/mock_device/boot_out.txt +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/mock_device/boot_out.txt.license +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/mock_device/import_styles.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/mock_device/import_styles_sub.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/mock_device/lib/adafruit_waveform/.gitkeep +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/mock_device_2/.gitignore +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/mock_device_2/boot_out.txt +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/mock_device_2/boot_out.txt.license +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/mock_device_2/code.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/mock_device_2/import_styles_sub.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/mock_device_2/package/__init__.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/mock_device_2/package/other.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/mount_exists.txt +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/mount_exists.txt.license +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/mount_missing.txt +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/mount_missing.txt.license +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/remote_module.py +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/test_bundle_config.json +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/test_bundle_config.json.license +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/test_bundle_config_local.json +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/test_bundle_config_local.json.license +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/test_module.mpy +0 -0
- {circup-3.1.0 → circup-3.2.0}/tests/test_module.mpy.license +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: circup
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.2.0
|
|
4
4
|
Summary: A tool to manage/update libraries on CircuitPython devices.
|
|
5
5
|
Author-email: Adafruit Industries <circuitpython@adafruit.com>
|
|
6
6
|
License: MIT License
|
|
@@ -146,35 +146,58 @@ To get help, just type the command::
|
|
|
146
146
|
A tool to manage and update libraries on a CircuitPython device.
|
|
147
147
|
|
|
148
148
|
Options:
|
|
149
|
-
--verbose
|
|
150
|
-
--path DIRECTORY
|
|
151
|
-
|
|
152
|
-
--host TEXT
|
|
153
|
-
|
|
154
|
-
--
|
|
155
|
-
--
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
149
|
+
--verbose Comprehensive logging is sent to stdout.
|
|
150
|
+
--path DIRECTORY Path to CircuitPython directory. Overrides automatic
|
|
151
|
+
path detection.
|
|
152
|
+
--host TEXT Hostname or IP address of a device. Overrides automatic
|
|
153
|
+
path detection.
|
|
154
|
+
--port INTEGER Port to contact. Overrides automatic path detection.
|
|
155
|
+
--password TEXT Password to use for authentication when --host is used.
|
|
156
|
+
You can optionally set an environment variable
|
|
157
|
+
CIRCUP_WEBWORKFLOW_PASSWORD instead of passing this
|
|
158
|
+
argument. If both exist the CLI arg takes precedent.
|
|
159
|
+
--offline Prevents Circup from accessing the internet for any
|
|
160
|
+
reason. Without this flag, Circup will fail with an
|
|
161
|
+
error if it needs to access the network and the network
|
|
162
|
+
is not available. With this flag, Circup will attempt
|
|
163
|
+
to proceed without the network if possible. Circup will
|
|
164
|
+
only use bundles downloaded locally even if there might
|
|
165
|
+
be newer versions available.
|
|
166
|
+
--timeout INTEGER Specify the timeout in seconds for any network
|
|
167
|
+
operations.
|
|
168
|
+
--board-id TEXT Manual Board ID of the CircuitPython device. If
|
|
169
|
+
provided in combination with --cpy-version, it
|
|
170
|
+
overrides the detected board ID.
|
|
171
|
+
--cpy-version TEXT Manual CircuitPython version. If provided in
|
|
172
|
+
combination with --board-id, it overrides the detected
|
|
173
|
+
CPy version.
|
|
174
|
+
--bundle-version TEXT Specify the version to use for a bundle. Include the
|
|
175
|
+
bundle name and the version separated by '=', similar
|
|
176
|
+
to the format of requirements.txt. This option can be
|
|
177
|
+
used multiple times for different bundles. Bundle
|
|
178
|
+
version values provided here will override any pinned
|
|
179
|
+
values from the pyproject.toml.
|
|
180
|
+
--allow-unsupported Allow using a device with a version of CircuitPython
|
|
181
|
+
that is no longer supported. Using an unsupported
|
|
182
|
+
version of CircuitPython is generally not recommended
|
|
183
|
+
because libraries may not work with it.
|
|
184
|
+
--version Show the version and exit.
|
|
185
|
+
--help Show this message and exit.
|
|
164
186
|
|
|
165
187
|
Commands:
|
|
166
188
|
bundle-add Add bundles to the local bundles list, by "user/repo"...
|
|
189
|
+
bundle-freeze Output details of all the bundles for modules found on the...
|
|
167
190
|
bundle-remove Remove one or more bundles from the local bundles list.
|
|
168
191
|
bundle-show Show the list of bundles, default and local, with URL,...
|
|
192
|
+
clear-cache Remove downloaded bundles and locally saved Circup data.
|
|
169
193
|
example Copy named example(s) from a bundle onto the device.
|
|
170
194
|
freeze Output details of all the modules found on the connected...
|
|
171
195
|
install Install a named module(s) onto the device.
|
|
172
196
|
list Lists all out of date modules found on the connected...
|
|
173
197
|
show Show a list of available modules in the bundle.
|
|
174
198
|
uninstall Uninstall a named module(s) from the connected device.
|
|
175
|
-
update Update modules on the device. Use --all to automatically
|
|
176
|
-
|
|
177
|
-
|
|
199
|
+
update Update modules on the device. Use --all to automatically update
|
|
200
|
+
all modules without Major Version warnings.
|
|
178
201
|
|
|
179
202
|
|
|
180
203
|
To automatically install all modules imported by ``code.py``,
|
|
@@ -89,35 +89,58 @@ To get help, just type the command::
|
|
|
89
89
|
A tool to manage and update libraries on a CircuitPython device.
|
|
90
90
|
|
|
91
91
|
Options:
|
|
92
|
-
--verbose
|
|
93
|
-
--path DIRECTORY
|
|
94
|
-
|
|
95
|
-
--host TEXT
|
|
96
|
-
|
|
97
|
-
--
|
|
98
|
-
--
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
92
|
+
--verbose Comprehensive logging is sent to stdout.
|
|
93
|
+
--path DIRECTORY Path to CircuitPython directory. Overrides automatic
|
|
94
|
+
path detection.
|
|
95
|
+
--host TEXT Hostname or IP address of a device. Overrides automatic
|
|
96
|
+
path detection.
|
|
97
|
+
--port INTEGER Port to contact. Overrides automatic path detection.
|
|
98
|
+
--password TEXT Password to use for authentication when --host is used.
|
|
99
|
+
You can optionally set an environment variable
|
|
100
|
+
CIRCUP_WEBWORKFLOW_PASSWORD instead of passing this
|
|
101
|
+
argument. If both exist the CLI arg takes precedent.
|
|
102
|
+
--offline Prevents Circup from accessing the internet for any
|
|
103
|
+
reason. Without this flag, Circup will fail with an
|
|
104
|
+
error if it needs to access the network and the network
|
|
105
|
+
is not available. With this flag, Circup will attempt
|
|
106
|
+
to proceed without the network if possible. Circup will
|
|
107
|
+
only use bundles downloaded locally even if there might
|
|
108
|
+
be newer versions available.
|
|
109
|
+
--timeout INTEGER Specify the timeout in seconds for any network
|
|
110
|
+
operations.
|
|
111
|
+
--board-id TEXT Manual Board ID of the CircuitPython device. If
|
|
112
|
+
provided in combination with --cpy-version, it
|
|
113
|
+
overrides the detected board ID.
|
|
114
|
+
--cpy-version TEXT Manual CircuitPython version. If provided in
|
|
115
|
+
combination with --board-id, it overrides the detected
|
|
116
|
+
CPy version.
|
|
117
|
+
--bundle-version TEXT Specify the version to use for a bundle. Include the
|
|
118
|
+
bundle name and the version separated by '=', similar
|
|
119
|
+
to the format of requirements.txt. This option can be
|
|
120
|
+
used multiple times for different bundles. Bundle
|
|
121
|
+
version values provided here will override any pinned
|
|
122
|
+
values from the pyproject.toml.
|
|
123
|
+
--allow-unsupported Allow using a device with a version of CircuitPython
|
|
124
|
+
that is no longer supported. Using an unsupported
|
|
125
|
+
version of CircuitPython is generally not recommended
|
|
126
|
+
because libraries may not work with it.
|
|
127
|
+
--version Show the version and exit.
|
|
128
|
+
--help Show this message and exit.
|
|
107
129
|
|
|
108
130
|
Commands:
|
|
109
131
|
bundle-add Add bundles to the local bundles list, by "user/repo"...
|
|
132
|
+
bundle-freeze Output details of all the bundles for modules found on the...
|
|
110
133
|
bundle-remove Remove one or more bundles from the local bundles list.
|
|
111
134
|
bundle-show Show the list of bundles, default and local, with URL,...
|
|
135
|
+
clear-cache Remove downloaded bundles and locally saved Circup data.
|
|
112
136
|
example Copy named example(s) from a bundle onto the device.
|
|
113
137
|
freeze Output details of all the modules found on the connected...
|
|
114
138
|
install Install a named module(s) onto the device.
|
|
115
139
|
list Lists all out of date modules found on the connected...
|
|
116
140
|
show Show a list of available modules in the bundle.
|
|
117
141
|
uninstall Uninstall a named module(s) from the connected device.
|
|
118
|
-
update Update modules on the device. Use --all to automatically
|
|
119
|
-
|
|
120
|
-
|
|
142
|
+
update Update modules on the device. Use --all to automatically update
|
|
143
|
+
all modules without Major Version warnings.
|
|
121
144
|
|
|
122
145
|
|
|
123
146
|
To automatically install all modules imported by ``code.py``,
|
|
@@ -10,19 +10,33 @@ import shutil
|
|
|
10
10
|
import sys
|
|
11
11
|
import socket
|
|
12
12
|
import tempfile
|
|
13
|
+
from functools import cached_property
|
|
13
14
|
from urllib.parse import urlparse, urljoin
|
|
14
15
|
import click
|
|
15
16
|
import requests
|
|
16
17
|
from requests.adapters import HTTPAdapter
|
|
17
18
|
from requests.auth import HTTPBasicAuth
|
|
18
19
|
|
|
19
|
-
from circup.shared import
|
|
20
|
+
from circup.shared import (
|
|
21
|
+
DATA_DIR,
|
|
22
|
+
BAD_FILE_FORMAT,
|
|
23
|
+
NATIVE_ARCHITECTURES,
|
|
24
|
+
drop_shadowed_native_files,
|
|
25
|
+
extract_metadata,
|
|
26
|
+
native_files,
|
|
27
|
+
split_architecture,
|
|
28
|
+
_get_modules_file,
|
|
29
|
+
)
|
|
20
30
|
|
|
21
31
|
#: The location to store a local copy of code.py for use with --auto and
|
|
22
32
|
# web workflow
|
|
23
33
|
LOCAL_CODE_PY_COPY = os.path.join(DATA_DIR, "code.tmp.py")
|
|
24
34
|
|
|
25
35
|
|
|
36
|
+
class NativeOnlyError(OSError):
|
|
37
|
+
"""The module is only available as native code, and the chosen board can't load it."""
|
|
38
|
+
|
|
39
|
+
|
|
26
40
|
class Backend:
|
|
27
41
|
"""
|
|
28
42
|
Backend parent class to be extended for workflow specific
|
|
@@ -47,6 +61,88 @@ class Backend:
|
|
|
47
61
|
"""
|
|
48
62
|
raise NotImplementedError
|
|
49
63
|
|
|
64
|
+
@property
|
|
65
|
+
def device_architecture(self):
|
|
66
|
+
"""The board's native .mpy architecture, like ``armv7emsp``, or None."""
|
|
67
|
+
raise NotImplementedError
|
|
68
|
+
|
|
69
|
+
def _compiled_module_files(self, bundle_path):
|
|
70
|
+
"""
|
|
71
|
+
The bundle files to install for ``foo.mpy``: ``foo.mpy`` itself and this
|
|
72
|
+
board's native ``foo.<arch>.mpy`` file.
|
|
73
|
+
"""
|
|
74
|
+
stem = bundle_path[: -len(".mpy")]
|
|
75
|
+
files = [bundle_path] if os.path.isfile(bundle_path) else []
|
|
76
|
+
native_path = f"{stem}.{self.device_architecture}.mpy"
|
|
77
|
+
if self.device_architecture and os.path.isfile(native_path):
|
|
78
|
+
files.append(native_path)
|
|
79
|
+
if files:
|
|
80
|
+
return files
|
|
81
|
+
if any(
|
|
82
|
+
os.path.isfile(f"{stem}.{architecture}.mpy")
|
|
83
|
+
for architecture in NATIVE_ARCHITECTURES
|
|
84
|
+
):
|
|
85
|
+
raise NativeOnlyError(
|
|
86
|
+
"This module only comes as native code, which this board can't load."
|
|
87
|
+
)
|
|
88
|
+
raise OSError("Cannot find compiled version of module.")
|
|
89
|
+
|
|
90
|
+
@staticmethod
|
|
91
|
+
def _compiled_bundle_path(bundle, metadata):
|
|
92
|
+
"""
|
|
93
|
+
The path of the module in the compiled bundle: ``foo.mpy`` or the
|
|
94
|
+
package directory.
|
|
95
|
+
"""
|
|
96
|
+
module_name = os.path.basename(metadata["path"]).replace(".py", ".mpy")
|
|
97
|
+
if not module_name:
|
|
98
|
+
# Must be a directory based module.
|
|
99
|
+
module_name = os.path.basename(os.path.dirname(metadata["path"]))
|
|
100
|
+
return os.path.join(bundle.lib_dir(), module_name)
|
|
101
|
+
|
|
102
|
+
def _can_install_compiled(self, name, bundle, metadata):
|
|
103
|
+
"""Check that the board can load the module before anything on it changes."""
|
|
104
|
+
bundle_path = self._compiled_bundle_path(bundle, metadata)
|
|
105
|
+
if not os.path.isdir(bundle_path):
|
|
106
|
+
try:
|
|
107
|
+
self._compiled_module_files(bundle_path)
|
|
108
|
+
except NativeOnlyError as ex:
|
|
109
|
+
click.secho(f"Could not install '{name}': {ex}", fg="bright_red")
|
|
110
|
+
return False
|
|
111
|
+
elif not self.device_architecture:
|
|
112
|
+
for _, _, files in os.walk(bundle_path):
|
|
113
|
+
if any(
|
|
114
|
+
split_architecture(os.path.splitext(f)[0])[1]
|
|
115
|
+
for f in drop_shadowed_native_files(files)
|
|
116
|
+
):
|
|
117
|
+
click.secho(
|
|
118
|
+
f"Parts of '{name}' only come as native code, "
|
|
119
|
+
"which this board can't load.",
|
|
120
|
+
fg="yellow",
|
|
121
|
+
)
|
|
122
|
+
break
|
|
123
|
+
return True
|
|
124
|
+
|
|
125
|
+
def _files_for_update(self, module):
|
|
126
|
+
"""The bundle files that replace the single file module ``module``."""
|
|
127
|
+
if not module.mpy:
|
|
128
|
+
return [module.bundle_path]
|
|
129
|
+
return self._compiled_module_files(
|
|
130
|
+
os.path.join(os.path.dirname(module.bundle_path), module.name + ".mpy")
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
def _skip_other_architectures(self, _directory, names):
|
|
134
|
+
"""
|
|
135
|
+
A ``shutil.copytree`` ignore function that skips the native files for
|
|
136
|
+
other architectures.
|
|
137
|
+
"""
|
|
138
|
+
return [
|
|
139
|
+
name
|
|
140
|
+
for name in names
|
|
141
|
+
if name.endswith(".mpy")
|
|
142
|
+
and split_architecture(name[: -len(".mpy")])[1]
|
|
143
|
+
not in (None, self.device_architecture)
|
|
144
|
+
]
|
|
145
|
+
|
|
50
146
|
def _get_modules(self, device_lib_path):
|
|
51
147
|
"""
|
|
52
148
|
To be overridden by subclass
|
|
@@ -134,6 +230,15 @@ class Backend:
|
|
|
134
230
|
click.echo("No module name(s) provided.")
|
|
135
231
|
return
|
|
136
232
|
if name in mod_names or local_path is not None:
|
|
233
|
+
if (
|
|
234
|
+
local_path is None
|
|
235
|
+
and not pyext
|
|
236
|
+
and mod_names[name]["bundle"].platform is not None
|
|
237
|
+
and not self._can_install_compiled(
|
|
238
|
+
name, mod_names[name]["bundle"], mod_names[name]
|
|
239
|
+
)
|
|
240
|
+
):
|
|
241
|
+
return
|
|
137
242
|
|
|
138
243
|
# Grab device modules to check if module already installed
|
|
139
244
|
if name in device_modules:
|
|
@@ -190,7 +295,7 @@ class Backend:
|
|
|
190
295
|
click.secho(
|
|
191
296
|
f"Aborted installing module {name} - it needs {new_module_size} bytes "
|
|
192
297
|
f"but only {self.get_free_space()} bytes of storage is available",
|
|
193
|
-
fg="
|
|
298
|
+
fg="bright_red",
|
|
194
299
|
)
|
|
195
300
|
return
|
|
196
301
|
|
|
@@ -269,6 +374,14 @@ class Backend:
|
|
|
269
374
|
board_id = ""
|
|
270
375
|
return circuit_python, board_id
|
|
271
376
|
|
|
377
|
+
@staticmethod
|
|
378
|
+
def parse_boot_out_architecture(boot_out_contents):
|
|
379
|
+
"""The architecture from boot_out.txt's ``architecture:`` line, or None."""
|
|
380
|
+
for line in boot_out_contents.split("\n"):
|
|
381
|
+
if line.startswith("architecture:"):
|
|
382
|
+
return line[len("architecture:") :].strip()
|
|
383
|
+
return None
|
|
384
|
+
|
|
272
385
|
def file_exists(self, filepath):
|
|
273
386
|
"""
|
|
274
387
|
To be overriden by subclass
|
|
@@ -280,7 +393,7 @@ def _writeable_error():
|
|
|
280
393
|
click.secho(
|
|
281
394
|
"CircuitPython Web Workflow Device not writable\n - "
|
|
282
395
|
"Remount storage as writable to device (not PC)",
|
|
283
|
-
fg="
|
|
396
|
+
fg="bright_red",
|
|
284
397
|
)
|
|
285
398
|
sys.exit(1)
|
|
286
399
|
|
|
@@ -350,12 +463,15 @@ class WebBackend(Backend):
|
|
|
350
463
|
_writeable_error()
|
|
351
464
|
r.raise_for_status()
|
|
352
465
|
|
|
353
|
-
def install_dir_http(self, source, location=None):
|
|
466
|
+
def install_dir_http(self, source, location=None, ignore=None):
|
|
467
|
+
# pylint: disable=too-many-locals
|
|
354
468
|
"""
|
|
355
469
|
Install directory to device using web workflow.
|
|
356
470
|
:param source source directory.
|
|
357
471
|
:param location the location on the device to copy the source
|
|
358
472
|
directory in to. If omitted is CIRCUITPY/lib/ used.
|
|
473
|
+
:param ignore optional function that returns the file names to skip,
|
|
474
|
+
like the ``ignore`` argument of ``shutil.copytree``.
|
|
359
475
|
"""
|
|
360
476
|
mod_name = source.split(os.path.sep)
|
|
361
477
|
mod_name = mod_name[-2] if mod_name[-1] == "" else mod_name[-1]
|
|
@@ -400,7 +516,10 @@ class WebBackend(Backend):
|
|
|
400
516
|
if r.status_code == 409:
|
|
401
517
|
_writeable_error()
|
|
402
518
|
r.raise_for_status()
|
|
519
|
+
skipped = ignore(root, files) if ignore else ()
|
|
403
520
|
for name in files:
|
|
521
|
+
if name in skipped:
|
|
522
|
+
continue
|
|
404
523
|
with open(os.path.join(root, name), "rb") as fp:
|
|
405
524
|
path_to_create = (
|
|
406
525
|
urljoin(
|
|
@@ -437,13 +556,25 @@ class WebBackend(Backend):
|
|
|
437
556
|
if r.status_code != requests.codes.ok:
|
|
438
557
|
click.secho(
|
|
439
558
|
f" Unable to get version from {self.device_location}: {r.status_code}",
|
|
440
|
-
fg="
|
|
559
|
+
fg="bright_red",
|
|
441
560
|
)
|
|
442
561
|
sys.exit(1)
|
|
443
562
|
# pylint: enable=no-member
|
|
444
563
|
ver_json = r.json()
|
|
445
564
|
return ver_json.get("version"), ver_json.get("board_id")
|
|
446
565
|
|
|
566
|
+
@cached_property
|
|
567
|
+
def device_architecture(self):
|
|
568
|
+
"""The board's native .mpy architecture from /cp/version.json, or None."""
|
|
569
|
+
with self.session.get(
|
|
570
|
+
self.device_location + "/cp/version.json", timeout=self.timeout
|
|
571
|
+
) as r:
|
|
572
|
+
# pylint: disable=no-member
|
|
573
|
+
if r.status_code != requests.codes.ok:
|
|
574
|
+
return None
|
|
575
|
+
# pylint: enable=no-member
|
|
576
|
+
return r.json().get("architecture")
|
|
577
|
+
|
|
447
578
|
def _get_modules(self, device_lib_path):
|
|
448
579
|
return self._get_modules_http(device_lib_path)
|
|
449
580
|
|
|
@@ -469,12 +600,16 @@ class WebBackend(Backend):
|
|
|
469
600
|
for entry in r.json()["files"]:
|
|
470
601
|
|
|
471
602
|
entry_name = entry.get("name")
|
|
603
|
+
# Skip dotfiles matching the disk backend
|
|
604
|
+
if entry_name.startswith("."):
|
|
605
|
+
continue
|
|
472
606
|
if entry.get("directory"):
|
|
473
607
|
directory_mods.append(entry_name)
|
|
474
608
|
else:
|
|
475
609
|
if entry_name.endswith(".py") or entry_name.endswith(".mpy"):
|
|
476
610
|
single_file_mods.append(entry_name)
|
|
477
611
|
|
|
612
|
+
single_file_mods = drop_shadowed_native_files(single_file_mods)
|
|
478
613
|
self._get_modules_http_single_mods(auth, result, single_file_mods, url)
|
|
479
614
|
self._get_modules_http_dir_mods(auth, directory_mods, result, url)
|
|
480
615
|
|
|
@@ -508,6 +643,9 @@ class WebBackend(Backend):
|
|
|
508
643
|
|
|
509
644
|
for entry in r.json()["files"]:
|
|
510
645
|
entry_name = entry.get("name")
|
|
646
|
+
# Skip dotfiles as the disk backend does
|
|
647
|
+
if entry_name.startswith("."):
|
|
648
|
+
continue
|
|
511
649
|
if not entry.get("directory") and (
|
|
512
650
|
entry_name.endswith(".py") or entry_name.endswith(".mpy")
|
|
513
651
|
):
|
|
@@ -561,7 +699,7 @@ class WebBackend(Backend):
|
|
|
561
699
|
metadata = extract_metadata(tmp_name, self.logger)
|
|
562
700
|
os.remove(tmp_name)
|
|
563
701
|
metadata["path"] = sfm_url
|
|
564
|
-
result[sfm[:idx]] = metadata
|
|
702
|
+
result[split_architecture(sfm[:idx])[0]] = metadata
|
|
565
703
|
|
|
566
704
|
def create_directory(self, device_path, directory):
|
|
567
705
|
auth = HTTPBasicAuth("", self.password)
|
|
@@ -610,7 +748,9 @@ class WebBackend(Backend):
|
|
|
610
748
|
self.FS_URL + target_file, timeout=self.timeout, auth=auth
|
|
611
749
|
) as r:
|
|
612
750
|
if r.status_code == 404:
|
|
613
|
-
click.secho(
|
|
751
|
+
click.secho(
|
|
752
|
+
f"{target_file} was not found on the device", fg="bright_red"
|
|
753
|
+
)
|
|
614
754
|
|
|
615
755
|
file_name = target_file.split("/")[-1]
|
|
616
756
|
if location_to_paste is None:
|
|
@@ -646,20 +786,12 @@ class WebBackend(Backend):
|
|
|
646
786
|
:param library_path library path
|
|
647
787
|
:param metadata dictionary.
|
|
648
788
|
"""
|
|
649
|
-
|
|
650
|
-
if not module_name:
|
|
651
|
-
# Must be a directory based module.
|
|
652
|
-
module_name = os.path.basename(os.path.dirname(metadata["path"]))
|
|
653
|
-
bundle_path = os.path.join(bundle.lib_dir(), module_name)
|
|
789
|
+
bundle_path = self._compiled_bundle_path(bundle, metadata)
|
|
654
790
|
if os.path.isdir(bundle_path):
|
|
655
|
-
|
|
656
|
-
self.install_dir_http(bundle_path)
|
|
657
|
-
|
|
658
|
-
elif os.path.isfile(bundle_path):
|
|
659
|
-
self.install_file_http(bundle_path)
|
|
660
|
-
|
|
791
|
+
self.install_dir_http(bundle_path, ignore=self._skip_other_architectures)
|
|
661
792
|
else:
|
|
662
|
-
|
|
793
|
+
for path in self._compiled_module_files(bundle_path):
|
|
794
|
+
self.install_file_http(path)
|
|
663
795
|
|
|
664
796
|
# pylint: enable=too-many-locals,too-many-branches
|
|
665
797
|
def install_module_py(self, metadata, location=None):
|
|
@@ -681,10 +813,21 @@ class WebBackend(Backend):
|
|
|
681
813
|
"""
|
|
682
814
|
url = urlparse(device_path)
|
|
683
815
|
auth = HTTPBasicAuth("", url.password)
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
816
|
+
module_paths = [module_path]
|
|
817
|
+
if not module_path.endswith("/"):
|
|
818
|
+
# A single file module can also have native files, foo.<arch>.mpy.
|
|
819
|
+
names = [f["name"] for f in self.list_dir("lib/")]
|
|
820
|
+
module_name = os.path.basename(urlparse(module_path).path)
|
|
821
|
+
module_paths += [
|
|
822
|
+
urljoin(module_path, name)
|
|
823
|
+
for name in native_files(names, module_name)
|
|
824
|
+
if name != module_name
|
|
825
|
+
]
|
|
826
|
+
for path in module_paths:
|
|
827
|
+
with self.session.delete(path, auth=auth, timeout=self.timeout) as r:
|
|
828
|
+
if r.status_code == 409:
|
|
829
|
+
_writeable_error()
|
|
830
|
+
r.raise_for_status()
|
|
688
831
|
|
|
689
832
|
def update(self, module):
|
|
690
833
|
"""
|
|
@@ -712,8 +855,10 @@ class WebBackend(Backend):
|
|
|
712
855
|
Update the module using web workflow.
|
|
713
856
|
"""
|
|
714
857
|
if module.file:
|
|
715
|
-
|
|
716
|
-
self.
|
|
858
|
+
files = self._files_for_update(module)
|
|
859
|
+
self.uninstall(self.device_location, module.path)
|
|
860
|
+
for path in files:
|
|
861
|
+
self.install_file_http(path)
|
|
717
862
|
else:
|
|
718
863
|
# Delete the directory (recursive) first.
|
|
719
864
|
url = urlparse(module.path)
|
|
@@ -722,7 +867,9 @@ class WebBackend(Backend):
|
|
|
722
867
|
if r.status_code == 409:
|
|
723
868
|
_writeable_error()
|
|
724
869
|
r.raise_for_status()
|
|
725
|
-
self.install_dir_http(
|
|
870
|
+
self.install_dir_http(
|
|
871
|
+
module.bundle_path, ignore=self._skip_other_architectures
|
|
872
|
+
)
|
|
726
873
|
|
|
727
874
|
def get_file_path(self, filename):
|
|
728
875
|
"""
|
|
@@ -740,7 +887,9 @@ class WebBackend(Backend):
|
|
|
740
887
|
web_api_version = r.json().get("web_api_version")
|
|
741
888
|
if web_api_version is None:
|
|
742
889
|
self.logger.error("Unable to get web API version from device.")
|
|
743
|
-
click.secho(
|
|
890
|
+
click.secho(
|
|
891
|
+
"Unable to get web API version from device.", fg="bright_red"
|
|
892
|
+
)
|
|
744
893
|
return False
|
|
745
894
|
|
|
746
895
|
if web_api_version < 4:
|
|
@@ -749,7 +898,7 @@ class WebBackend(Backend):
|
|
|
749
898
|
)
|
|
750
899
|
click.secho(
|
|
751
900
|
f"Device running unsupported web API version {web_api_version} < 4.",
|
|
752
|
-
fg="
|
|
901
|
+
fg="bright_red",
|
|
753
902
|
)
|
|
754
903
|
return False
|
|
755
904
|
except requests.exceptions.ConnectionError:
|
|
@@ -781,10 +930,12 @@ class WebBackend(Backend):
|
|
|
781
930
|
r.raise_for_status()
|
|
782
931
|
if r.json().get("free") is None:
|
|
783
932
|
self.logger.error("Unable to get free block count from device.")
|
|
784
|
-
click.secho(
|
|
933
|
+
click.secho(
|
|
934
|
+
"Unable to get free block count from device.", fg="bright_red"
|
|
935
|
+
)
|
|
785
936
|
elif r.json().get("block_size") is None:
|
|
786
937
|
self.logger.error("Unable to get block size from device.")
|
|
787
|
-
click.secho("Unable to get block size from device.", fg="
|
|
938
|
+
click.secho("Unable to get block size from device.", fg="bright_red")
|
|
788
939
|
elif r.json().get("writable") is None or r.json().get("writable") is False:
|
|
789
940
|
self.logger.error(
|
|
790
941
|
"CircuitPython Web Workflow Device not writable\n - "
|
|
@@ -793,7 +944,7 @@ class WebBackend(Backend):
|
|
|
793
944
|
click.secho(
|
|
794
945
|
"CircuitPython Web Workflow Device not writable\n - "
|
|
795
946
|
"Remount storage as writable to device (not PC)",
|
|
796
|
-
fg="
|
|
947
|
+
fg="bright_red",
|
|
797
948
|
)
|
|
798
949
|
else:
|
|
799
950
|
return r.json()["free"] * r.json()["block_size"] # bytes
|
|
@@ -855,6 +1006,7 @@ class DiskBackend(Backend):
|
|
|
855
1006
|
self.device_location = device_location
|
|
856
1007
|
self.library_path = os.path.join(self.device_location, self.LIB_DIR_PATH)
|
|
857
1008
|
self.version_info = None
|
|
1009
|
+
self.boot_out = boot_out
|
|
858
1010
|
if boot_out is not None:
|
|
859
1011
|
self.version_info = self.parse_boot_out_file(boot_out)
|
|
860
1012
|
self.version_override = version_override
|
|
@@ -890,7 +1042,7 @@ class DiskBackend(Backend):
|
|
|
890
1042
|
except FileNotFoundError:
|
|
891
1043
|
click.secho(
|
|
892
1044
|
"Missing file boot_out.txt on the device: wrong path or drive corrupted.",
|
|
893
|
-
fg="
|
|
1045
|
+
fg="bright_red",
|
|
894
1046
|
)
|
|
895
1047
|
self.logger.error("boot_out.txt not found.")
|
|
896
1048
|
sys.exit(1)
|
|
@@ -898,6 +1050,21 @@ class DiskBackend(Backend):
|
|
|
898
1050
|
|
|
899
1051
|
return self.version_info
|
|
900
1052
|
|
|
1053
|
+
@cached_property
|
|
1054
|
+
def device_architecture(self):
|
|
1055
|
+
"""The board's native .mpy architecture from boot_out.txt, or None."""
|
|
1056
|
+
boot_out_contents = self.boot_out
|
|
1057
|
+
if boot_out_contents is None:
|
|
1058
|
+
try:
|
|
1059
|
+
with open(
|
|
1060
|
+
os.path.join(self.device_location, "boot_out.txt"),
|
|
1061
|
+
encoding="utf-8",
|
|
1062
|
+
) as boot:
|
|
1063
|
+
boot_out_contents = boot.read()
|
|
1064
|
+
except FileNotFoundError:
|
|
1065
|
+
return None
|
|
1066
|
+
return self.parse_boot_out_architecture(boot_out_contents)
|
|
1067
|
+
|
|
901
1068
|
def _get_modules(self, device_lib_path):
|
|
902
1069
|
"""
|
|
903
1070
|
Get a dictionary containing metadata about all the Python modules found in
|
|
@@ -933,26 +1100,17 @@ class DiskBackend(Backend):
|
|
|
933
1100
|
:param bundle library bundle.
|
|
934
1101
|
:param metadata dictionary.
|
|
935
1102
|
"""
|
|
936
|
-
|
|
937
|
-
if not module_name:
|
|
938
|
-
# Must be a directory based module.
|
|
939
|
-
module_name = os.path.basename(os.path.dirname(metadata["path"]))
|
|
940
|
-
|
|
941
|
-
bundle_path = os.path.join(bundle.lib_dir(), module_name)
|
|
1103
|
+
bundle_path = self._compiled_bundle_path(bundle, metadata)
|
|
942
1104
|
if os.path.isdir(bundle_path):
|
|
943
|
-
target_path = os.path.join(self.library_path,
|
|
1105
|
+
target_path = os.path.join(self.library_path, os.path.basename(bundle_path))
|
|
944
1106
|
# Copy the directory.
|
|
945
|
-
shutil.copytree(
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
target = os.path.basename(bundle_path)
|
|
949
|
-
|
|
950
|
-
target_path = os.path.join(self.library_path, target)
|
|
951
|
-
|
|
952
|
-
# Copy file.
|
|
953
|
-
shutil.copyfile(bundle_path, target_path)
|
|
1107
|
+
shutil.copytree(
|
|
1108
|
+
bundle_path, target_path, ignore=self._skip_other_architectures
|
|
1109
|
+
)
|
|
954
1110
|
else:
|
|
955
|
-
|
|
1111
|
+
for path in self._compiled_module_files(bundle_path):
|
|
1112
|
+
target_path = os.path.join(self.library_path, os.path.basename(path))
|
|
1113
|
+
shutil.copyfile(path, target_path)
|
|
956
1114
|
|
|
957
1115
|
# pylint: enable=too-many-locals,too-many-branches
|
|
958
1116
|
def install_module_py(self, metadata, location=None):
|
|
@@ -996,6 +1154,9 @@ class DiskBackend(Backend):
|
|
|
996
1154
|
target_path = os.path.join(library_path, target)
|
|
997
1155
|
# Remove file
|
|
998
1156
|
os.remove(target_path)
|
|
1157
|
+
# A single file module can also have native files, foo.<arch>.mpy.
|
|
1158
|
+
for name in native_files(os.listdir(library_path), target):
|
|
1159
|
+
os.remove(os.path.join(library_path, name))
|
|
999
1160
|
|
|
1000
1161
|
def update(self, module):
|
|
1001
1162
|
"""
|
|
@@ -1013,11 +1174,16 @@ class DiskBackend(Backend):
|
|
|
1013
1174
|
if os.path.isdir(module.path):
|
|
1014
1175
|
# Delete and copy the directory.
|
|
1015
1176
|
shutil.rmtree(module.path, ignore_errors=True)
|
|
1016
|
-
shutil.copytree(
|
|
1177
|
+
shutil.copytree(
|
|
1178
|
+
module.bundle_path, module.path, ignore=self._skip_other_architectures
|
|
1179
|
+
)
|
|
1017
1180
|
else:
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1181
|
+
files = self._files_for_update(module)
|
|
1182
|
+
self.uninstall(self.device_location, module.path)
|
|
1183
|
+
for path in files:
|
|
1184
|
+
shutil.copyfile(
|
|
1185
|
+
path, os.path.join(self.library_path, os.path.basename(path))
|
|
1186
|
+
)
|
|
1021
1187
|
|
|
1022
1188
|
def file_exists(self, filepath):
|
|
1023
1189
|
"""
|