6868 " You can optionally set an environment variable CIRCUP_WEBWORKFLOW_PASSWORD"
6969 " instead of passing this argument. If both exist the CLI arg takes precedent." ,
7070)
71+ @click .option (
72+ "--offline" ,
73+ is_flag = True ,
74+ help = "Prevents Circup from accessing the internet for any reason. "
75+ "Without this flag, Circup will fail with an error if it needs to access "
76+ "the network and the network is not available. With this flag, Circup "
77+ "will attempt to proceed without the network if possible. Circup will "
78+ "only use bundles downloaded locally even if there might be newer "
79+ "versions available." ,
80+ )
7181@click .option (
7282 "--timeout" ,
7383 default = 30 ,
@@ -107,6 +117,7 @@ def main( # pylint: disable=too-many-locals
107117 host ,
108118 port ,
109119 password ,
120+ offline ,
110121 timeout ,
111122 board_id ,
112123 cpy_version ,
@@ -121,6 +132,7 @@ def main( # pylint: disable=too-many-locals
121132 ctx .obj ["BUNDLE_TAGS" ] = (
122133 parse_cli_bundle_tags (bundle_versions ) if len (bundle_versions ) > 0 else None
123134 )
135+ Bundle .offline = offline
124136
125137 if password is None :
126138 password = os .getenv ("CIRCUP_WEBWORKFLOW_PASSWORD" )
@@ -177,20 +189,22 @@ def main( # pylint: disable=too-many-locals
177189
178190 logger .info ("### Started Circup ###" )
179191
180- # If a newer version of circup is available, print a message.
181- logger .info ("Checking for a newer version of circup" )
182- version = get_circup_version ()
183- if version :
184- update_checker .update_check ("circup" , version )
192+ if offline :
193+ logger .info (
194+ "'--offline' flag present, all update checks requiring the network will be skipped."
195+ )
196+ else :
197+ # If a newer version of circup is available, print a message.
198+ logger .info ("Checking for a newer version of circup" )
199+ version = get_circup_version ()
200+ if version :
201+ update_checker .update_check ("circup" , version )
185202
186203 # stop early if the command is boardless
187204 if ctx .invoked_subcommand in BOARDLESS_COMMANDS or "--help" in sys .argv :
188205 return
189206
190207 ctx .obj ["DEVICE_PATH" ] = device_path
191- latest_version = get_latest_release_from_url (
192- "https://github.com/adafruit/circuitpython/releases/latest" , logger
193- )
194208
195209 if device_path is None or not ctx .obj ["backend" ].is_device_present ():
196210 click .secho ("Could not find a connected CircuitPython device." , fg = "red" )
@@ -206,22 +220,27 @@ def main( # pylint: disable=too-many-locals
206220 board_id , device_path , cpy_version
207221 )
208222 )
209- try :
210- if VersionInfo .parse (cpy_version ) < VersionInfo .parse (latest_version ):
211- click .secho (
212- "A newer version of CircuitPython ({}) is available." .format (
213- latest_version
214- ),
215- fg = "green" ,
216- )
217- if board_id :
218- url_download = f"https://circuitpython.org/board/{ board_id } "
219- else :
220- url_download = "https://circuitpython.org/downloads"
221- click .secho ("Get it here: {}" .format (url_download ), fg = "green" )
222- except ValueError as ex :
223- logger .warning ("CircuitPython has incorrect semver value." )
224- logger .warning (ex )
223+
224+ if not offline :
225+ latest_version = get_latest_release_from_url (
226+ "https://github.com/adafruit/circuitpython/releases/latest" , logger
227+ )
228+ try :
229+ if VersionInfo .parse (cpy_version ) < VersionInfo .parse (latest_version ):
230+ click .secho (
231+ "A newer version of CircuitPython ({}) is available." .format (
232+ latest_version
233+ ),
234+ fg = "green" ,
235+ )
236+ if board_id :
237+ url_download = f"https://circuitpython.org/board/{ board_id } "
238+ else :
239+ url_download = "https://circuitpython.org/downloads"
240+ click .secho ("Get it here: {}" .format (url_download ), fg = "green" )
241+ except ValueError as ex :
242+ logger .warning ("CircuitPython has incorrect semver value." )
243+ logger .warning (ex )
225244
226245
227246@main .command ()
@@ -392,7 +411,7 @@ def install(
392411 upgrade ,
393412 )
394413
395- if stubs :
414+ if stubs and not Bundle . offline :
396415 # Check we are in a virtual environment
397416 if not is_virtual_env_active ():
398417 if is_global_install_ok is None :
@@ -728,6 +747,10 @@ def bundle_add(ctx, bundle):
728747 )
729748 return
730749
750+ if Bundle .offline :
751+ click .secho ("Cannot add new bundle when '--offline' flag is present." , fg = "red" )
752+ return
753+
731754 bundles_dict = get_bundles_local_dict ()
732755 modified = False
733756 for bundle_repo in bundle :
0 commit comments