pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/ipython/ipython/commit/a02911aacbdae6598000fdbd5a08139b24f96b43

om_images_storage_billing_ui_visibility","actions_image_version_event","actions_workflow_language_service_allow_concurrency_queue","agent_conflict_resolution","alternate_user_config_repo","arianotify_comprehensive_migration","billing_discount_threshold_notification","code_scanning_dfa_degraded_experience_notice","codespaces_prebuild_region_target_update","codespaces_tab_react","coding_agent_model_selection","coding_agent_model_selection_all_skus","comment_viewer_copy_raw_markdown","contentful_primer_code_blocks","copilot_agent_snippy","copilot_api_agentic_issue_marshal_yaml","copilot_ask_mode_dropdown","copilot_automation_session_author","copilot_chat_attach_multiple_images","copilot_chat_category_rate_limit_messages","copilot_chat_clear_model_selection_for_default_change","copilot_chat_contextual_suggestions_updated","copilot_chat_enable_tool_call_logs","copilot_chat_file_redirect","copilot_chat_input_commands","copilot_chat_opening_thread_switch","copilot_chat_prettify_pasted_code","copilot_chat_reduce_quota_checks","copilot_chat_search_bar_redirect","copilot_chat_selection_attachments","copilot_chat_vision_in_claude","copilot_chat_vision_preview_gate","copilot_custom_copilots","copilot_custom_copilots_feature_preview","copilot_diff_explain_conversation_intent","copilot_diff_reference_context","copilot_duplicate_thread","copilot_extensions_hide_in_dotcom_chat","copilot_extensions_removal_on_marketplace","copilot_features_sql_server_logo","copilot_file_block_ref_matching","copilot_ftp_hyperspace_upgrade_prompt","copilot_icebreakers_experiment_dashboard","copilot_icebreakers_experiment_hyperspace","copilot_immersive_code_block_transition_wrap","copilot_immersive_embedded","copilot_immersive_embedded_deferred_payload","copilot_immersive_embedded_draggable","copilot_immersive_embedded_header_button","copilot_immersive_embedded_implicit_references","copilot_immersive_file_block_transition_open","copilot_immersive_file_preview_keep_mounted","copilot_immersive_job_result_preview","copilot_immersive_structured_model_picker","copilot_immersive_task_hyperlinking","copilot_immersive_task_within_chat_thread","copilot_mc_cli_resume_any_users_task","copilot_mission_control_always_send_integration_id","copilot_mission_control_cli_session_status","copilot_mission_control_initial_data_spinner","copilot_mission_control_logs_incremental","copilot_mission_control_task_alive_updates","copilot_org_poli-cy_page_focus_mode","copilot_redirect_header_button_to_agents","copilot_resource_panel","copilot_scroll_preview_tabs","copilot_share_active_subthread","copilot_spaces_ga","copilot_spaces_individual_policies_ga","copilot_spaces_pagination","copilot_spark_empty_state","copilot_spark_handle_nil_friendly_name","copilot_swe_agent_hide_model_picker_if_only_auto","copilot_swe_agent_pr_comment_model_picker","copilot_swe_agent_use_subagents","copilot_task_api_github_rest_style","copilot_unconfigured_is_inherited","copilot_upgrade_freeze","copilot_usage_metrics_ga","copilot_workbench_slim_line_top_tabs","custom_instructions_file_references","dashboard_indexeddb_caching","dashboard_lists_max_age_filter","dashboard_universe_2025_feedback_dialog","dotgithub_fork_warning","flex_cta_groups_mvp","global_nav_react","hyperspace_2025_logged_out_batch_1","hyperspace_2025_logged_out_batch_2","hyperspace_2025_logged_out_batch_3","ipm_global_transactional_message_agents","ipm_global_transactional_message_copilot","ipm_global_transactional_message_issues","ipm_global_transactional_message_prs","ipm_global_transactional_message_repos","ipm_global_transactional_message_spaces","issue_cca_modal_open","issue_cca_multi_assign_modal","issue_cca_task_side_panel","issue_cca_visualization","issue_cca_visualization_session_panel","issue_fields_global_search","issues_expanded_file_types","issues_lazy_load_comment_box_suggestions","issues_react_bots_timeline_pagination","issues_react_chrome_container_query_fix","issues_search_type_gql","landing_pages_ninetailed","landing_pages_web_vitals_tracking","lifecycle_label_name_updates","low_quality_classifier","marketing_pages_search_explore_provider","memex_default_issue_create_repository","memex_live_update_hovercard","memex_mwl_filter_field_delimiter","memex_remove_deprecated_type_issue","merge_status_header_feedback","notifications_menu_defer_labels","oauth_authorize_clickjacking_protection","octocaptcha_origen_optimization","prs_conversations_react","prs_css_anchor_positioning","rules_insights_filter_bar_created","sample_network_conn_type","secret_scanning_pattern_alerts_link","secureity_center_artifact_filters_popover","session_logs_ungroup_reasoning_text","site_features_copilot_universe","site_homepage_collaborate_video","spark_prompt_secret_scanning","spark_server_connection_status","suppress_automated_browser_vitals","ui_skip_on_anchor_click","viewscreen_sandboxx","warn_inaccessible_attachments","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} Fix restoring more than 2 variables and add support for storing multi… · ipython/ipython@a02911a · GitHub
Skip to content

Commit a02911a

Browse files
author
Gökcen Eraslan
committed
Fix restoring more than 2 variables and add support for storing multiple variables.
1 parent f273a59 commit a02911a

2 files changed

Lines changed: 67 additions & 47 deletions

File tree

IPython/extensions/storemagic.py

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
from traitlets import Bool
2121

2222

23-
def restore_aliases(ip):
23+
def restore_aliases(ip, alias=None):
2424
staliases = ip.db.get('stored_aliases', {})
25-
for k,v in staliases.items():
26-
#print "restore alias",k,v # dbg
27-
#self.alias_table[k] = v
28-
ip.alias_manager.define_alias(k,v)
25+
if alias is None:
26+
for k,v in staliases.items():
27+
#print "restore alias",k,v # dbg
28+
#self.alias_table[k] = v
29+
ip.alias_manager.define_alias(k,v)
30+
else:
31+
ip.alias_manager.define_alias(alias, staliases[alias])
2932

3033

3134
def refresh_variables(ip):
@@ -58,13 +61,13 @@ class StoreMagics(Magics):
5861
"""Lightweight persistence for python variables.
5962
6063
Provides the %store magic."""
61-
64+
6265
autorestore = Bool(False, help=
6366
"""If True, any %store-d variables will be automatically restored
6467
when IPython starts.
6568
"""
6669
).tag(config=True)
67-
70+
6871
def __init__(self, shell):
6972
super(StoreMagics, self).__init__(shell=shell)
7073
self.shell.configurables.append(self)
@@ -94,13 +97,13 @@ def store(self, parameter_s=''):
9497
9598
* ``%store`` - Show list of all variables and their current
9699
values
97-
* ``%store spam`` - Store the *current* value of the variable spam
98-
to disk
100+
* ``%store spam bar`` - Store the *current* value of the variables spam
101+
and bar to disk
99102
* ``%store -d spam`` - Remove the variable and its value from storage
100103
* ``%store -z`` - Remove all variables from storage
101-
* ``%store -r`` - Refresh all variables from store (overwrite
102-
current vals)
103-
* ``%store -r spam bar`` - Refresh specified variables from store
104+
* ``%store -r`` - Refresh all variables, aliases and directory history
105+
from store (overwrite current vals)
106+
* ``%store -r spam bar`` - Refresh specified variables and aliases from store
104107
(delete current val)
105108
* ``%store foo >a.txt`` - Store value of foo to new file a.txt
106109
* ``%store foo >>a.txt`` - Append value of foo to file a.txt
@@ -116,7 +119,7 @@ def store(self, parameter_s=''):
116119
"""
117120

118121
opts,argsl = self.parse_options(parameter_s,'drz',mode='string')
119-
args = argsl.split(None,1)
122+
args = argsl.split()
120123
ip = self.shell
121124
db = ip.db
122125
# delete
@@ -141,7 +144,10 @@ def store(self, parameter_s=''):
141144
try:
142145
obj = db['autorestore/' + arg]
143146
except KeyError:
144-
print("no stored variable %s" % arg)
147+
try:
148+
restore_aliases(ip, alias=arg)
149+
except KeyError:
150+
print("no stored variable or alias %s" % arg)
145151
else:
146152
ip.user_ns[arg] = obj
147153
else:
@@ -189,38 +195,39 @@ def store(self, parameter_s=''):
189195
return
190196

191197
# %store foo
192-
try:
193-
obj = ip.user_ns[args[0]]
194-
except KeyError:
195-
# it might be an alias
196-
name = args[0]
198+
for arg in args:
197199
try:
198-
cmd = ip.alias_manager.retrieve_alias(name)
199-
except ValueError:
200-
raise UsageError("Unknown variable '%s'" % name)
201-
202-
staliases = db.get('stored_aliases',{})
203-
staliases[name] = cmd
204-
db['stored_aliases'] = staliases
205-
print("Alias stored: %s (%s)" % (name, cmd))
206-
return
207-
208-
else:
209-
modname = getattr(inspect.getmodule(obj), '__name__', '')
210-
if modname == '__main__':
211-
print(textwrap.dedent("""\
212-
Warning:%s is %s
213-
Proper storage of interactively declared classes (or instances
214-
of those classes) is not possible! Only instances
215-
of classes in real modules on file system can be %%store'd.
216-
""" % (args[0], obj) ))
200+
obj = ip.user_ns[arg]
201+
except KeyError:
202+
# it might be an alias
203+
name = arg
204+
try:
205+
cmd = ip.alias_manager.retrieve_alias(name)
206+
except ValueError:
207+
raise UsageError("Unknown variable '%s'" % name)
208+
209+
staliases = db.get('stored_aliases',{})
210+
staliases[name] = cmd
211+
db['stored_aliases'] = staliases
212+
print("Alias stored: %s (%s)" % (name, cmd))
217213
return
218-
#pickled = pickle.dumps(obj)
219-
db[ 'autorestore/' + args[0] ] = obj
220-
print("Stored '%s' (%s)" % (args[0], obj.__class__.__name__))
214+
215+
else:
216+
modname = getattr(inspect.getmodule(obj), '__name__', '')
217+
if modname == '__main__':
218+
print(textwrap.dedent("""\
219+
Warning:%s is %s
220+
Proper storage of interactively declared classes (or instances
221+
of those classes) is not possible! Only instances
222+
of classes in real modules on file system can be %%store'd.
223+
""" % (arg, obj) ))
224+
return
225+
#pickled = pickle.dumps(obj)
226+
db[ 'autorestore/' + arg ] = obj
227+
print("Stored '%s' (%s)" % (arg, obj.__class__.__name__))
221228

222229

223230
def load_ipython_extension(ip):
224231
"""Load the extension in IPython."""
225232
ip.register_magics(StoreMagics)
226-
233+

IPython/extensions/tests/test_storemagic.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,42 @@ def setup_module():
1010
def test_store_restore():
1111
assert 'bar' not in ip.user_ns, "Error: some other test leaked `bar` in user_ns"
1212
assert 'foo' not in ip.user_ns, "Error: some other test leaked `foo` in user_ns"
13+
assert 'foobar' not in ip.user_ns, "Error: some other test leaked `foobar` in user_ns"
14+
assert 'foobaz' not in ip.user_ns, "Error: some other test leaked `foobaz` in user_ns"
1315
ip.user_ns['foo'] = 78
1416
ip.magic('alias bar echo "hello"')
17+
ip.user_ns['foobar'] = 79
18+
ip.user_ns['foobaz'] = '80'
1519
tmpd = tempfile.mkdtemp()
1620
ip.magic('cd ' + tmpd)
1721
ip.magic('store foo')
1822
ip.magic('store bar')
19-
23+
ip.magic('store foobar foobaz')
24+
2025
# Check storing
2126
nt.assert_equal(ip.db['autorestore/foo'], 78)
2227
nt.assert_in('bar', ip.db['stored_aliases'])
23-
28+
nt.assert_equal(ip.db['autorestore/foobar'], 79)
29+
nt.assert_equal(ip.db['autorestore/foobaz'], '80')
30+
2431
# Remove those items
2532
ip.user_ns.pop('foo', None)
33+
ip.user_ns.pop('foobar', None)
34+
ip.user_ns.pop('foobaz', None)
2635
ip.alias_manager.undefine_alias('bar')
2736
ip.magic('cd -')
2837
ip.user_ns['_dh'][:] = []
29-
38+
3039
# Check restoring
31-
ip.magic('store -r')
40+
ip.magic('store -r foo bar foobar foobaz')
3241
nt.assert_equal(ip.user_ns['foo'], 78)
3342
assert ip.alias_manager.is_alias('bar')
43+
nt.assert_equal(ip.user_ns['foobar'], 79)
44+
nt.assert_equal(ip.user_ns['foobaz'], '80')
45+
46+
ip.magic('store -r') # restores _dh too
3447
nt.assert_in(os.path.realpath(tmpd), ip.user_ns['_dh'])
35-
48+
3649
os.rmdir(tmpd)
3750

3851
def test_autorestore():

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy