Skip to content

Commit

Permalink
Merge pull request #473 from Almenon/remove_saved
Browse files Browse the repository at this point in the history
Remove saved
  • Loading branch information
Almenon authored Nov 18, 2024
2 parents 497fbe5 + 95f1aca commit dc6c013
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 72 deletions.
8 changes: 8 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ tsconfig.json
personal/**
.travis.yml
dependencygraph.svg
.hypothesis
.env
.vscode-test.js
areplDemoGif2.gif
copy_backend.bat
notes.txt
*.code-workspace
tslint.json
#pycharm dir
.idea/**
# coverage output
Expand Down
32 changes: 0 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,38 +145,6 @@ I have [overridden the display](https://github.com/Almenon/AREPL-backend/blob/ma
If you want a type to be displayed in a particular manner just [file an issue](https://github.com/Almenon/AREPL-vscode/issues)


### #$save

*This is buggy and I would suggest using the [arepl_store variable](https://github.com/Almenon/AREPL-vscode/wiki/Caching-data-between-runs) instead*

If you want to avoid a section of code being executed in real-time (due to it being slow or calling external resources) you can use \#\$save. For example:

```python
def largest_prime_factor(n):
i = 2
while i * i <= n:
if n % i:
i += 1
else:
n //= i
return n

# this takes a looonnggg time to execute
result = largest_prime_factor(8008514751439999)

#$save
print("but now that i saved i am back to real-time execution")
```

```python
import random
x = random.random()
#$save
print(x) # this number will not change when editing below the #$save line
```

Please note that \#\$save [does not work](https://github.com/Almenon/AREPL-vscode/issues/53) with certain types, like generators. If #$save fails in pickling the code state [file an issue](https://github.com/Almenon/AREPL-vscode/issues) so I can look into it.

### More Stuff

Check out the [wiki](https://github.com/Almenon/AREPL-vscode/wiki)!
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
🐛 As a consequence of above, AREPL will no longer crash when there is a infinite loop
🐛 As a consequence of above, pandas now works better
🐛 As a consequence of above, boto3 now works better
🔧 `#$save` feature has been removed
🔧 Removed `keepPreviousVars` setting
🔧 `arepl_store` variable has been removed.

## v2.0.5 (3/5/2023) 🐛🚀
🐛 [Fixed inconsistent variable display in certain cases](https://github.com/Almenon/AREPL-vscode/issues/3716)
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,6 @@
"type": "boolean",
"default": false,
"description": "Whether to automatically load django models. This setting doesn't actually do anything yet. See https://github.com/Almenon/AREPL-vscode/issues/279"
},
"AREPL.keepPreviousVars": {
"type": "boolean",
"default": false,
"description": "If set to true AREPL will add onto the local state each run instead of clearing it and starting fresh."
}
}
},
Expand Down Expand Up @@ -292,7 +287,7 @@
},
"dependencies": {
"@vscode/extension-telemetry": "^0.9.7",
"arepl-backend": "^3.0.3"
"arepl-backend": "^3.0.5"
},
"bugs": {
"url": "https://github.com/almenon/arepl-vscode-wordcount/issues",
Expand Down
1 change: 0 additions & 1 deletion src/PreviewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ export default class PreviewManager {
const data: ExecArgs = {
evalCode: codeLines,
filePath,
savedCode: '',
usePreviousVariables: true,
show_global_vars: settingsCached.get<boolean>('showGlobalVars'),
default_filter_vars: settingsCached.get<string[]>('defaultFilterVars'),
Expand Down
22 changes: 11 additions & 11 deletions src/pythonPanelPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,22 @@ export default class PythonPanelPreview {
<ul>
<li>🦋 <a href="https://github.com/Almenon/AREPL-vscode/issues/439">AREPL now restarts the python backend each run. This eliminates many bugs, although you may see more CPU utilization.</a></li>
<li>🐛 AREPL will no longer crash when there is a infinite loop</li>
<li>🔧 #$save feature has been removed</li>
<li>🔧 Removed keepPreviousVars setting</li>
<li>🔧 arepl_store variable has been removed. If you still use this please <a href="https://github.com/Almenon/AREPL-vscode/issues">file an issue</a> and I might be able to add it back in.</li>
</ul>
<br>
<h3>Examples</h3>
<h4>Simple List</h4>
<code style="white-space:pre-wrap">
x = [1,2,3]
<code style="white-space:pre-wrap">x = [1,2,3]
y = [num*2 for num in x]
print(y)
</code>
<h4>Dumping</h4>
<code style="white-space:pre-wrap">
from arepl_dump import dump
<code style="white-space:pre-wrap">from arepl_dump import dump
def milesToKilometers(miles):
kilometers = miles*1.60934
Expand All @@ -66,8 +67,7 @@ a=2
</code>
<h4>Turtle</h4>
<code style="white-space:pre-wrap">
import turtle
<code style="white-space:pre-wrap">import turtle
# window in right hand side of screen
turtle.setup(500,500,-1,0)
Expand All @@ -80,15 +80,15 @@ turtle.left(90)
</code>
<h4>Web call</h4>
<code style="white-space:pre-wrap">
import requests
<code style="white-space:pre-wrap">import requests
import datetime as dt
# We don't want to spam an API with calls every time we stop typing
# so we use #$end to deactivate real-time mode for everything afterwords
# then we can run blocks of code as desired with command-enter or control-enter
#$end
r = requests.get("https://api.github.com")
#$save
# #$save saves state so request is not re-executed when modifying below
now = dt.datetime.now()
if r.status_code == 200:
print("API up at " + str(now))
Expand Down
18 changes: 3 additions & 15 deletions src/toAREPLLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {settings} from "./settings"
*/
export class ToAREPLLogic{

lastSavedSection = ""
lastCodeSection = ""
lastEndSection = ""

Expand All @@ -33,21 +32,15 @@ export class ToAREPLLogic{

let codeLines = text.split(eol)

let savedLines: string[] = []
let startLineNum = 0
let endLineNum = codeLines.length

codeLines.forEach((line, i) => {
if(line.trimRight().endsWith("#$save")){
savedLines = codeLines.slice(0, i + 1)
startLineNum = i+1
}
if(line.trimRight().endsWith("#$end")){
if(line.trimEnd().endsWith("#$end")){
endLineNum = i+1
return
}
});
const endSection = codeLines.slice(endLineNum).join(eol)
codeLines = codeLines.slice(startLineNum, endLineNum)

const unsafeKeywords = settingsCached.get<string[]>('unsafeKeywords')
Expand All @@ -60,22 +53,17 @@ export class ToAREPLLogic{
const data: ExecArgs = {
evalCode: codeLines.join(eol),
filePath,
savedCode: savedLines.join(eol),
usePreviousVariables: settingsCached.get<boolean>('keepPreviousVars'),
show_global_vars: showGlobalVars,
default_filter_vars: settingsCached.get<string[]>('defaultFilterVars'),
default_filter_types: settingsCached.get<string[]>('defaultFilterTypes')
}

// user should be able to rerun code without changing anything
// only scenario where we dont re-run is if just end section is changed
if(endSection != this.lastEndSection && data.savedCode == this.lastSavedSection && data.evalCode == this.lastCodeSection){
if(data.evalCode == this.lastCodeSection){
// nothing changed, no point in rerunning
return false
}

this.lastCodeSection = data.evalCode
this.lastSavedSection = data.savedCode
this.lastEndSection = endSection

this.PythonExecutor.execCode(data)

Expand Down

0 comments on commit dc6c013

Please sign in to comment.