Peforth

Latest version: v1.31

Safety actively analyzes 681812 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 1 of 3

1.24

[X] setup.py 裡的 copy right 年份要改成 2019
*** 打包上 pypi.org 的方法 setup.bat 可以大簡化了。
[V1.22之後的新版] 打包步驟 2018/12/16 11:02
See my Ynote: "Pack peforth to peforth.whl"
1. 檢查 ~\GitHub\peforth\setup.py 看有沒有漏掉新檔案,有沒有要去掉的檔案。
2. (記得先把 dist , build , peforth.egg-info 等 folder 先殺掉) 跑
c:\Users\hcche\Documents\GitHub\peforth>python setup.py sdist bdist_wheel
得到 peforth.whl in c:\Users\hcche\Documents\GitHub\peforth\dist
3. 執行 c:\Users\hcche\Documents\GitHub\peforth>twine upload dist/*
需要帳號密碼,看這裡 Ynote: "python pypi 研究 -- upload to PyPI ok now.note"
4. pip uninstall peforth 然後再 pip install peforth 試驗看看。
5. 完成!
[X] See (15:55 2019-05-22) 這個 check-list 要耐心好好做完!
[X] 所有 run 法帶 selftest:
[X] 改 GitHub\peforth\quit.f
' <selftest> :: enabled=True
[X] 先通過最基本的 selftest: GitHub\peforth\peforth>python test.py
[X] Run python setup.py install 更新本地 site-package 版本以供測試
[X] 可能要 (Anaconda virtualenv 之下) 從 site-packages\peforth-1.24-py3.7.egg
裡 copy peforth\ 去蓋掉 site-packages\peforth\ 這樣 upgrade 才有生效。
[X] 1. python -i -m peforth [X] with-selftest .s words exit bye
[X] 2. ipython -i -m peforth .' Hello World!!' cr bye
[X] 3. ipython import peforth .s words
[X] selftest peforth.ok() .s words <--- w/parent
[X] 1234 bye check echo %errorlevel% <-- 從 ipython 下直接出來也無誤。
[X] 4. jupyter notebook
kernel > restart and clear outputs
x = 123
%f x .
x . \ ==> 123 (<class 'int'>)
[X] 5. jupyter notebook --> peforth kernel --> .s words
[/] 考慮 README.rst 改良
[/] 若有改過 README.rst 則 wheel 就要重做
--> quit.f selftest=False --> 重來
[X] 所有 run 法不帶 selftest 跑一遍,準備要 release 的版本:
[X] 改 GitHub\peforth\quit.f
' <selftest> :: enabled=False
[X] 同上 python test.py 先試試看
[X] Run python setup.py install 更新本地 site-package 版本以供測試
[X] 可能要 (Anaconda virtualenv 之下) 從 site-packages\peforth-1.24-py3.7.egg
裡 copy peforth\ 去蓋掉 site-packages\peforth\ 這樣 upgrade 才有生效。
[X] 同上 repeat 1) python -m peforth 2) ipython -m peforth
[X] 做出取消 selftest 的 wheel
See my Ynote: "Pack peforth to peforth.whl"
[X] 1. 檢查 ~\GitHub\peforth\setup.py 看有沒有漏掉新檔案,有沒有要去掉的檔案。
test.py hello.py misc.f
[X] 2. 跑 c:\Users\hcche\Documents\GitHub\peforth>python setup.py sdist bdist_wheel
得到 peforth.whl in c:\Users\hcche\Documents\GitHub\peforth\dist
[X] pip uninstall peforth
site-packages 下兩個 peforth folder 刪掉了。
setup.bat 建立的 EGG 檔 peforth-1.24-py3.7.egg 也刪掉,否則 pip install 會
被 skip 過去。
[X] 切 CD 到 c:\Users\hcche\Documents\GitHub\peforth\dist>
pip install peforth-1.23-py3-none-any.whl <== 注意!用剛做好的 wheel 否則會上網抓。
[X] 1. (i)python -i -m peforth [X] no-selftest .s words exit
[X] 2. (i)python -i -m peforth version 12345 bye --> echo %errorlevel%
[X] 3. (i)python import peforth
[X] no selftest, peforth.ok() .s words <--- no parent
[X] 1234 bye check echo %errorlevel%
[X] 4. jupyter notebook --> *debug* ok> .s cd help exit
%f %%f magic command
[/] 5. repeat 以上 in ubuntu <------- Ubuntu 18.04 沒有 pip built-in 不想搞了
[/] pip uninstall peforth 已知 Colab & Azure 都是 Ubuntu 故不必自己多測了
[/] pip install (use /mnt/...the wheel) to WSL ubuntu
[/] ipython -m peforth
[/] ipython , import peforth , magic commands
[X] 直接用測過的 wheel update Pypi
執行 c:\Users\hcche\Documents\GitHub\peforth>twine upload dist/*
需要帳號密碼,看這裡 Ynote: "python pypi 研究 -- upload to PyPI ok now.note"
ID, password search my Ynote with pypi _account_
Note: Anaconda base 沒有 twine, 在 Anaconda Navigator 裡找到 twine 把它勾起來 Apply.
[X] 查看 pypi.org 網頁,若不行,晚點 (過幾分鐘就好) 再看。
[X] Windows DOS 下試
[/] WSL Ubuntu 下試 pip uninstall peforth -> pip install peforth
[/] WSL Ubuntu with and w/o w/o virtualenv --> python -m peforth
[X] Test Online Jupyter Notebooks Google Colab, Microsoft Azure, and Notebooks.ai
!pip install peforth
import peforth
%f version drop
x = 12345
%f x --> \ 查看 unknown 的效果
\ Colab & Azure 都用 Ubuntu 查版本, Notebooks.ai 用 Debian 都可用這行指令
!cat /etc/os-release
%f py> path --> \ 查看 path 發現 Azure 就是用 Anaconda 所以它有 support Ubuntu!
%pwd \ 查看 working directory
[x] Colab https://colab.research.google.com/drive/1nZpybQryEiwYzpMvG1tHg4qbNnd_rMey#scrollTo=yAuF9DZcrFaT
[X] Azure https://peforthplayground-hcchen1471.notebooks.azure.com/j/notebooks/peforth-playground.ipynb
[X] notebooks.ai 也測測看
[X] Make a master release up to GitHub --> 用 GitHub Windows 很簡單。
1. 先 commit 上 develop branch, upload 上網上 Github.
2. 切到 master
3. 用 GitHub for Windows desktop 的 Branch > Merge into current branch 選 develop 把它 merge 過來。
解決 conflicts 之後完成 merge.
4. 再 repeat 2-3 但切到 develop 把 master merge 過去。
Master 上的應該是些 README.md 的修改。
[X] version 改成 1.25 (必須跳過 1.20 直接到 1.21 否則會變成 1.2)
[X] 要不要把 projectk.py sync 回 project-k
(很早以前) projectk.py 改了一點,忘了如何 sync 回 project-k 的?
05:30 2019-11-21 peforth source code 裡的 projectk.py 本身不是從 github 直接下來的, 而是
硬放上去的,因此不會與 project-k github 自動同步 <--- 想想看怎麼辦。

[ ] 15:56 2019/11/25 經常要 (see) 東西都會出這個問題:
Callable in phaseB <function compyle_anonymous at 0x00000232B1164A68>: Circular reference detected
問問看有沒有 workaround ?

[ ] 13:42 2019/11/27 下回 release 要在 README.rst ~.md 裡明列有測過的系統:
1. Windows Anaconda DOSBox pyhon 3.7, DOSBox ipython, JupyterNotebook, JupyterLab
2. Colab (Ubuntu,Anaconda), Azure notebooks (Ubuntu), Notebooks.ai (Debian)

[X] 2020/07/27 08:33 可以把 [obj>keys] 'keys' 定義成 dir | dict>keys 這樣就不會與 dir 重複了。又可以與 jeforth 相容。
[X] 2020/07/27 08:38:15 value constant to 要重新定義,不要再用 vm.forth 存放了,改用 variable 自己 word.
See OneNote2020 > "Jeforth variable 變革" --> 成功了。
[X] 07:49 2020/10/04 參考 KsanaVM 發現我原先對 prompt 的時機有誤解,改好了。
[X] 15:49 2020/10/24 v1.25 好了以後 projectk.py 要 sync 回 projectk
[X] 15:30 2020/10/24 準備 release v1.25 to pypi so as to allow gom to have it easily
[X] 15:54 2020/10/24 先試試看 gom ok? --> Pass, 連 selftest 也都 pass.
[X] setup.py 裡的 copy right 年份要改成 2019
*** 打包上 pypi.org 的方法 setup.bat 可以大簡化了。
[V1.22之後的新版] 打包步驟 2018/12/16 11:02
See my Ynote: "Pack peforth to peforth.whl"
1. 檢查 ~\GitHub\peforth\setup.py 看有沒有漏掉新檔案,有沒有要去掉的檔案。
2. (記得先把 dist , build , peforth.egg-info 等 folder 先殺掉) 跑
c:\Users\hcche\Documents\GitHub\peforth>python setup.py sdist bdist_wheel
得到 peforth.whl in c:\Users\hcche\Documents\GitHub\peforth\dist
3. 若無 twine 則 pip install twine 很快很順
執行 c:\Users\hcche\Documents\GitHub\peforth>twine upload dist/*
需要帳號密碼,看這裡 Ynote or Evernote: "python pypi 研究 -- upload to PyPI ok now.note"
4. pip uninstall peforth 然後再 pip install peforth 試驗看看。
5. 完成!
[X] See (15:55 2019-05-22) 這個 check-list 要耐心好好做完!
... snip .....
[X] 17:01 2020/10/24 v1.25 已經上了 pypi 也測過 Gom 成功,以上測試慢慢做,先上 github 再說。
[X] 14:22 2020/10/29 vm.prompt 是要給 gom port dialog 知道目前 prompt 否則只在 ok() 肚子裡。
[X] 13:52 2020/11/23 把 pypi 的 v1.25 直接換成 local 的 v1.26
--> 直接 copy __init__.py version.txt 蓋過去 c:\Users\8304018\AppData\Roaming\gom\2020\python\peforth
--> 11> <py> ok() </py> --> prompt 變成 ok , exit --> prompt 變回 11> 成功! 這就是 v1.26 無誤。
[X] 10:26 2020/11/26 改良 breakpoint 不需要改 peforth, 從 application 端外掛就可以了。 (see GitHub\peforth\playground\jupyternotebook.py)
Usage of breakpoint:
peforth.bp(22,locals()) drop breakpoint 22 with locals()
for i in [11,22,33]: peforth.bps[i]=0 disable breakpoints 11,22,33
for i in [11,22,33]: peforth.bps[i]=i enable breakpoints 11,22,33
peforth.bps=[i for i in range(1000)] reload and enable all breakpoints
'exit' or ESC leaves the breakpoint and continue running.
'bye' to totally stop the script session.

breakpoint
peforth.bp() drop a breakpoint using default prompt bp>
peforth.bp(11) drop a breakpoint using prompt bp11> w/p passing locals()
peforth.bp(22,locals()) drop a breakpoint using prompt bp22> with locals()
peforth.bps=[] disable all breakpoints
peforth.dictate("peforth :: bps=[]") disable all breakpoints
peforth.dictate("peforth :: bps=[123,345,567]") enable only listed breakpoints
peforth.dictate("peforth :: bps[123]=0") disable the breakpoint 123
peforth.dictate("peforth :: pop(111)") disable the breakpoint 111
for i in [11,22,33]: peforth.bps[i]=0 disable breakpoints 11,22,33
peforth.bps=[i for i in range(1000)] reload and enable all breakpoints

def bp(id=None,locals=None):
if id==None:
id = 0
prompt='bp> '
else:
prompt="bp{}>".format(id)
if id in peforth.bps: peforth.push(locals).ok(prompt, cmd="to _locals_")
peforth.bp = bp
peforth.bps = [i for i in range(1000)]

[X] 17:33 2020/12/07 配合 peforth.bp(22,locals()) 新增 bl be bd be* bd* 等指令
[X] 17:34 2020/12/07 release v1.26 to pypi
[X] 17:37 2020/12/07 先試試看 gom ok? --> Pass, 連 selftest 也都 pass.
[X] setup.py 裡的 copy right 年份要改成 2019
*** 打包上 pypi.org 的方法 setup.bat 可以大簡化了。
[V1.22之後的新版] 打包步驟 2018/12/16 11:02
See my Ynote: "Pack peforth to peforth.whl"
1. 檢查 ~\GitHub\peforth\setup.py 看有沒有漏掉新檔案,有沒有要去掉的檔案。
2. (記得先把 dist , build , peforth.egg-info 等 folder 先殺掉) 跑
c:\Users\hcche\Documents\GitHub\peforth>python setup.py sdist bdist_wheel
得到 peforth.whl in c:\Users\hcche\Documents\GitHub\peforth\dist
3. 若無 twine 則 pip install twine 很快很順
執行 c:\Users\hcche\Documents\GitHub\peforth>twine upload dist/*
需要帳號密碼,看這裡 Ynote or Evernote: "python pypi 研究 -- upload to PyPI ok now.note"
4. pip uninstall peforth 然後再 pip install peforth 試驗看看。
5. 完成!
[/] See (15:55 2019-05-22) 這個 check-list 要耐心好好做完!
[/] 所有 run 法帶 selftest:
[/] 改 GitHub\peforth\quit.f
' <selftest> :: enabled=True
[/] 先通過最基本的 selftest: GitHub\peforth\peforth>python test.py
[/] Local install 後來 (10:06 11/23/2021) 會遇上障礙 permission denied 之類。發現 pip install from github/gitlab 的方法了。
Run python setup.py install 更新本地 site-package 版本以供測試
[/] 要 (Anaconda virtualenv 之下) 從 site-packages\peforth-1.24-py3.7.egg
裡 copy peforth\ 去蓋掉 site-packages\peforth\ 這樣 upgrade 才有生效。
16:27 2020/10/24 不必這樣,因為 python setup.py install 灌好的 peforth v1.25 是
c:\Users\8304018\AppData\Local\Continuum\anaconda3\lib\site-packages\peforth-1.25-py3.7.egg
而 pip install peforth 灌好的是另一個 peforth v1.25
c:\Users\8304018\AppData\Local\Continuum\anaconda3\lib\site-packages\peforth\
兩個可以並存!而且後者優先。只要把後者 directory name 改成 peforth.disabled
就可以讓前者生效,前者是 local install 測試時有其方便性。
[/] 1. python -i -m peforth [X] with-selftest .s words exit bye
[/] 2. ipython -i -m peforth .' Hello World!!' cr bye
[/] 3. ipython import peforth .s words
[/] selftest peforth.ok() .s words <--- w/parent
[/] 1234 bye check echo %errorlevel% <-- 從 ipython 下直接出來也無誤。
[/] 4. jupyter notebook
kernel > restart and clear outputs
x = 123
%f x .
x . \ ==> 123 (<class 'int'>)
[/] 5. jupyter notebook --> peforth kernel --> .s words
[/] 6. Gom 手動移除現有的 peforth directories from:
c:\Users\8304018\AppData\Roaming\gom\2020\python\..
然後從 SCRIPTING > Script Choice > pip install peforth > Tools > Install Python Package 灌 peforth 很快很順
import peforth, peforth_gom_port
執行 peforth.ok() 無誤。
新增 peforth_gom_port.py 放到 peforth repo 的 playground directory 裡。
[/] 考慮 README.rst 改良
[/] 若有改過 README.rst 則 wheel 就要重做
--> quit.f selftest=False --> 重來
[/] 所有 run 法不帶 selftest 跑一遍,準備要 release 的版本:
[/] 改 GitHub\peforth\quit.f
' <selftest> :: enabled=False
[/] 同上 python test.py 先試試看
[/] Run python setup.py install 更新本地 site-package 版本以供測試
[X] 可能要 (Anaconda virtualenv 之下) 從 site-packages\peforth-1.24-py3.7.egg
裡 copy peforth\ 去蓋掉 site-packages\peforth\ 這樣 upgrade 才有生效。
[/] 同上 repeat 1) python -m peforth 2) ipython -m peforth
[/] 做出取消 selftest 的 wheel
See my Ynote: "Pack peforth to peforth.whl"
[/] 1. 檢查 ~\GitHub\peforth\setup.py 看有沒有漏掉新檔案,有沒有要去掉的檔案。
test.py hello.py misc.f
[/] 2. 跑 c:\Users\hcche\Documents\GitHub\peforth>python setup.py sdist bdist_wheel
得到 peforth.whl in c:\Users\hcche\Documents\GitHub\peforth\dist
[/] pip uninstall peforth
site-packages 下兩個 peforth folder 刪掉了。
setup.bat 建立的 EGG 檔 peforth-1.24-py3.7.egg 也刪掉,否則 pip install 會
被 skip 過去。
[/] 切 CD 到 c:\Users\hcche\Documents\GitHub\peforth\dist>
pip install peforth-1.23-py3-none-any.whl <== 注意!用剛做好的 wheel 否則會上網抓。
[/] 1. (i)python -i -m peforth [X] no-selftest .s words exit
[/] 2. (i)python -i -m peforth version 12345 bye --> echo %errorlevel%
[/] 3. (i)python import peforth
[/] no selftest, peforth.ok() .s words <--- no parent
[/] 1234 bye check echo %errorlevel%
[/] 4. jupyter notebook --> *debug* ok> .s cd help exit
%f %%f magic command
[/] 5. repeat 以上 in ubuntu <------- Ubuntu 18.04 沒有 pip built-in 不想搞了
[/] pip uninstall peforth 已知 Colab & Azure 都是 Ubuntu 故不必自己多測了
[/] pip install (use /mnt/...the wheel) to WSL ubuntu
[/] ipython -m peforth
[/] ipython , import peforth , magic commands
[/] 直接用測過的 wheel update Pypi
執行 c:\Users\hcche\Documents\GitHub\peforth>twine upload dist/*
需要帳號密碼,看這裡 Ynote: "python pypi 研究 -- upload to PyPI ok now.note"
ID, password search my Ynote with pypi _account_
Note: Anaconda base 沒有 twine, 在 Anaconda Navigator 裡找到 twine 把它勾起來 Apply.
[/] 查看 pypi.org 網頁,若不行,晚點 (過幾分鐘就好) 再看。
[/] Windows DOS 下試
[/] WSL Ubuntu 下試 pip uninstall peforth -> pip install peforth
[/] WSL Ubuntu with and w/o w/o virtualenv --> python -m peforth
[/] Test Online Jupyter Notebooks Google Colab, Microsoft Azure, and Notebooks.ai
!pip install peforth
import peforth
%f version drop
x = 12345
%f x --> \ 查看 unknown 的效果
\ Colab & Azure 都用 Ubuntu 查版本, Notebooks.ai 用 Debian 都可用這行指令
!cat /etc/os-release
%f py> path --> \ 查看 path 發現 Azure 就是用 Anaconda 所以它有 support Ubuntu!
%pwd \ 查看 working directory
[/] Colab https://colab.research.google.com/drive/1nZpybQryEiwYzpMvG1tHg4qbNnd_rMey#scrollTo=yAuF9DZcrFaT
[/] Azure https://peforthplayground-hcchen1471.notebooks.azure.com/j/notebooks/peforth-playground.ipynb
[/] notebooks.ai 也測測看
[/] Make a master release up to GitHub --> 用 GitHub Windows 很簡單。
1. 先 commit 上 develop branch, upload 上網上 Github.
2. 切到 master
3. 用 GitHub for Windows desktop 的 Branch > Merge into current branch 選 develop 把它 merge 過來。
解決 conflicts 之後完成 merge.
4. 再 repeat 2-3 但切到 develop 把 master merge 過去。
Master 上的應該是些 README.md 的修改。
[X] 要不要把 projectk.py sync 回 project-k
(很早以前) projectk.py 改了一點,忘了如何 sync 回 project-k 的?
05:30 2019-11-21 peforth source code 裡的 projectk.py 本身不是從 github 直接下來的, 而是
硬放上去的,因此不會與 project-k github 自動同步 <--- 想想看怎麼辦。
[X] version 改成 1.27 (必須跳過 1.20 直接到 1.21 否則會變成 1.2)
[X] 12:24 2021/03/31 peforth 本來就有 tstack 了,但它是加在 TIB 後面的,故只能放 integer.
[X] 12:25 2021/03/31 弄出個 xstack 來用
-------- xtack 的定義 ---------------------------------------
[] value xstack xstack py: vm.xstack=pop() // ( -- array ) The xstack. 掛進 vm 就可以直接以 py> xstack 取用。
: x xstack :> [-1] ; // ( -- n ) Get TOS of the xstack
: x> // ( -- n ) Pop the xstack
xstack :> pop() ;
: >x // ( n -- ) Push n into the xstack
xstack :: append(pop()) ;
: .x // ( -- ) List xstack
xstack . ;
: xdrop x> drop ; // ( X: ... a -- X: ... ) drop xstack
: xdropall [] to xstack ; // ( X: ... -- X: empty ) clear xstack
-------- xtack 的定義 ---------------------------------------
首先用在研究 Genetic Algorithm 的 jupyternotebook 中。
[/] 12:25 2021/03/31 考慮把 tstack 弄成一般化,不要再用 TIB 這樣的花招了 <== 不對喔 TIB 是 command line 唯一的 resource! tstack 別有意義。

[X] 2021/04/06 10;19:27 jupyternotebook 之下無法 multiple input 的問題有解了。
https://stackoverflow.com/questions/49817934/read-clipboard-not-working-in-jupyter-or-terminal
答案是直接取用 clipboard 給 tib.input 就好了。先定義讀取 clipboard 的 word :
import IPython
: paste py> IPython.lib.clipboard.win32_clipboard_get() tib.insert ;
// ( ... -- ... ) 執行 clipboard 裡的內容,jupyternotebook 進了 peforth prompt 特別需要此功能。

11:29 2021/04/21 clipboard 在 Mars Lander 爬取 data from the web page 時
Documents/GitHub/MarsLander/episode-1/Read the log file2.ipynb
也有用到。
import IPython, peforth
%f : clipboard __main__ :> IPython.lib.clipboard.win32_clipboard_get() ; // ( -- str ) Get string from clipboard.
peforth 看不到 IPython 因它是從 jupyternotebook import IPython 的。簡單用 __main__ :> IPython 即可
解決。

[X] 23:43 2021/04/22 我本來沒啥處理 json 的 words? This is from Codingame > Mars Lander
to save log json from parsed Mars Lander web page after a run.
%%f
: json2file // ( json pathname -- ) Save josn to text file
py> open(pop(),'w') ( json file ) >r ( json )R( file )
py: json.dump(pop(),rtos()) ( does jaosn.dump return anything? )
r> :: close() ;
/// Usage: dictJson char aa.json json2file \ to save file
/// but: "pathname" readTextFile py> eval(pop()) \ eval() is more reliable than txt2json
01:24 2021/11/20 改好這個想要用 peforth 的 setup.bat (Run python setup.py install) 灌進去 site-package 試跑。。。
結果不行因為 Permission denied
(C:\Program Files\Orange) C:\Users\8304018>conda env list
conda environments:

* C:\Program Files\Orange <--------------- 咱正在用的
base C:\ProgramData\Miniconda3
01:43 2021/11/20 但即使切回 (base) venv 再新建 peforth venv 又用 admin preledge 也沒用,因為 Windows App Store
裝起來的 python 在這裡: (see the error message of setup.bat below)
The following error occurred while trying to add or remove files in the
installation directory: [Errno 13] Permission denied: 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\\Lib\\site-packages\\test-easy-install-18740.write-test'
以前研究過 egg 啥的複習一下。。。 Yes, see OneNote "Develop peforth in an Anaconda virtual environment" and (16:27 2020/10/24)
當時 setup.bat 很順。先不管了,用 python -m peforth 在 working directory 試驗即可 。。。 True :-D and it's now v1.27
under developping.

[X] 03:26 2021/11/20 resolve --> and unknown ReDef warning
unknown is a code word, how about to replace its xt? 應該可以
OK ' test :> xt -->
' test :> xt --> <function xt at 0x000001EA1F33F9D0> (<class 'function'>)
But the new one is a colon word --> 把舊的名字改掉 <== 對 unknown 成功了!
' unknown :: name='unknown_deactivated'
--> 單純不該重複出現在 misc.f 裡

[X] 14:42 2021/04/12 peforth breakpoint 外掛如下,考慮加進 master 裡去 why not? (因為大有問題)
15:13 11/22/2021 錯了! peforth.bp 不能放在 projectk.py 裡!因為 kernel 沒有 ok() 也就不會有 bp()
應該要放在定義 ok() 的地方才對。
( 預設有這麼多 Breakpoint ID ) <py> [i for i in range(100)] </pyV> __main__ :: peforth.bps=pop(1)
__main__ :> peforth <py>
peforth = pop()
def bp(id=None,locals=None):
Breakpoint ID 不能超過 peforth.bps 保留,超過的無效。
if id==None:
id = 0
prompt='bp> '
else:
prompt="{}>".format(id)
if id in peforth.bps: peforth.push(locals).ok(prompt, cmd="to _locals_")
push(bp)
</py> __main__ :: peforth.bp=pop(1)
[X] 04:56 2021/11/20 但是 __main__ 很後面才有東西,研究看看。。。。。。。 要過了 __init__.py
之後 __main__ 裡才會有 peforth, 算了改 projectk 吧!
[X] 15:01 11/22/2021 要讓 peforth.bp peforth.bps 直接認得,得把這兩個在 peforth/__init__.py 加進去
tib = vm.tib
tos = vm.tos
words = vm.words
bps = vm.bps <---------- 加進去
bp = vm.bp <---------- 加進去
否則 peforth 不直接認得, projectk 的東西都在 vm 裡面。

[X] 11:34 2021/11/22 為了擴充 peforth.bp for breakpoint GitHub\peforth\peforth\projectk.py 改了,更新 projectk 主流。
[X] 12:55 2021/11/22 d command 改成了 du 避免經常用到 d 撞名。peforth 沒有 i j k 也是一樣道理。因為 jupyternotebook
裡經常有 i j. 插曲,如何在 colon word 裡抓到自己? 它裡面有個 .lastaddress 有參考自己 [ last literal ] 沒錯吧?
沒錯 that's the colon word itself indeed this is the way colon word to get self.
[X] 02:15 2021/11/22 release v1.27 to pypi
pip install 探討 10:12 11/23/2021
1. Local install (16:27 2020/10/24) python setup.py install 最方便,但可能不行。
2. 先 commit 上 GitHub/GitLab 然後 pip install:
pip install git+https://github.com/hcchengithub/peforth.gitdevelop
3. 做成 .whl 來測試
1. 記得先把 dist , build , peforth.egg-info 等 folder 先殺掉
2. 跑 GitHub\peforth>python setup.py sdist bdist_wheel
3. 得到 peforth.whl in GitHub\peforth\dist 可用來 pip install ~.whl
[*] 只要是定義在 __init__.py 裡的東西就必須 import peforth 才有,不能用:
GitHub\peforth>python -m peforth
直接用 source code 跑. 正好 peforth.bp 就是這種, 開發比較麻煩。
[X] Gom port 只測到 v1.26 此 v1.27 我沒 license 測不到了。
[X] setup.py 裡的 copy right 年份要改成 2021
[X] See (15:55 2019-05-22) 這個 check-list 要耐心好好做完!09:29 11/23/2021 真的有發現問題。
[X] 所有 run 法帶 selftest:
[X] 改 GitHub\peforth\quit.f
' <selftest> :: enabled=True
[X] 1. python -i -m peforth [X] with-selftest .s words exit bye
[X] 2. ipython -i -m peforth .' Hello World!!' cr bye
[X] 3. ipython import peforth .s words
[X] 1234 bye check echo %errorlevel% <-- 從 ipython 下直接出來也無誤。
[X] 4. jupyter notebook
kernel > restart and clear outputs
def test():
x = 234
y = 'abc'
peforth.bp(11,locals())
test()
11>x --> 123 (<class 'int'>)
[/] 5. Gom 手動移除現有的 peforth directories from:
c:\Users\8304018\AppData\Roaming\gom\2020\python\..
然後從 SCRIPTING > Script Choice > pip install peforth > Tools > Install Python Package 灌 peforth 很快很順
import peforth, peforth_gom_port
執行 peforth.ok() 無誤。
新增 peforth_gom_port.py 放到 peforth repo 的 playground directory 裡。
[/] 考慮 README.rst 改良
[/] 若有改過 README.rst 則 wheel 就要重做
--> quit.f selftest=False --> 重來
[X] 所有 run 法不帶 selftest 跑一遍,準備要 release 的版本:
[X] 改 GitHub\peforth\quit.f
' <selftest> :: enabled=False
[X] Run [python setup.py install] pip install peforth-1.27-py3-none-any.whl
[X] 同上 repeat 1) python -m peforth 2) ipython -m peforth
[X] 做出取消 selftest 的 wheel
See my Ynote: "Pack peforth to peforth.whl"
[X] 1. 檢查 ~\GitHub\peforth\setup.py 看有沒有漏掉新檔案,有沒有要去掉的檔案。
[X] 2. 跑 c:\Users\hcche\Documents\GitHub\peforth>python setup.py sdist bdist_wheel
得到 peforth.whl in c:\Users\hcche\Documents\GitHub\peforth\dist
[X] pip uninstall peforth
site-packages 下兩個 peforth folder 刪掉了。
setup.bat 建立的 EGG 檔 peforth-1.24-py3.7.egg 也刪掉,否則 pip install 會
被 skip 過去。
[X] 切 CD 到 c:\Users\hcche\Documents\GitHub\peforth\dist>
pip install peforth-1.23-py3-none-any.whl <== 注意!用剛做好的 wheel 否則會上網抓。
[X] 1. (i)python -i -m peforth [/] no-selftest .s words exit
[X] 2. (i)python -i -m peforth version 12345 bye --> echo %errorlevel%
[X] 3. (i)python import peforth
[X] no selftest, peforth.ok() .s words <--- no parent
[X] 1234 bye check echo %errorlevel%
[X] 4. jupyter notebook --> *debug* ok> .s cd help exit
%f %%f magic command
[/] 5. repeat 以上 in ubuntu <------- Ubuntu 18.04 沒有 pip built-in 不想搞了
[/] pip uninstall peforth 已知 Colab & Azure 都是 Ubuntu 故不必自己多測了
[/] pip install (use /mnt/...the wheel) to WSL ubuntu
[/] ipython -m peforth
[/] ipython , import peforth , magic commands
[X] 直接用測過的 wheel update Pypi
執行 c:\Users\hcche\Documents\GitHub\peforth>twine upload dist/*
需要帳號密碼,看這裡 Ynote: "python pypi 研究 -- upload to PyPI ok now.note"
ID, password search my Ynote with pypi _account_
Note: Anaconda base 沒有 twine, 在 Anaconda Navigator 裡找到 twine 把它勾起來 Apply.
或者 pip install twine
或者 conda install twine
[x] 17:01 11/22/2021 結果因為 Orange3 的關係,用 conda install 失敗, pip 倒好了。但執行不到,
找到了 path C:\Users\8304018\AppData\Roaming\Python\Python38\Scripts
GitHub\peforth>C:\Users\8304018\AppData\Roaming\Python\Python38\Scripts\twine upload dist/*
終於成功了。
[X] 17:08 11/22/2021 v1.27 上 Pypi 了今天先到這。。。。。。 08:19 11/23/2021 確定有上 pypi 了。
[/] 08:30 11/23/2021 注意了,本地 repo 還是 develop branch 都好了要 merge to main branch <--- 下面有 check box.
[X] 查看 pypi.org 網頁,若不行,晚點 (過幾分鐘就好) 再看。
[X] Windows DOS 下試
[/] (Google colab 就是 ubuntu 了) WSL Ubuntu 下試 pip uninstall peforth -> pip install peforth
[/] WSL Ubuntu with and w/o w/o virtualenv --> python -m peforth
[X] Test Online Jupyter Notebooks Google Colab, Microsoft Azure, and Notebooks.ai
!pip install peforth
import peforth
%f version drop
x = 12345
%f x --> \ 查看 unknown 的效果
\ Colab & Azure 都用 Ubuntu 查版本, Notebooks.ai 用 Debian 都可用這行指令
!cat /etc/os-release
%f py> path --> \ 查看 path 發現 Azure 就是用 Anaconda 所以它有 support Ubuntu!
%pwd \ 查看 working directory
[X] Colab https://colab.research.google.com/drive/1nZpybQryEiwYzpMvG1tHg4qbNnd_rMey#scrollTo=yAuF9DZcrFaT
[/] Azure https://peforthplayground-hcchen1471.notebooks.azure.com obseleted I guess
[/] notebooks.ai obseleted
[X] Make a master release up to GitHub --> 用 GitHub Windows 很簡單。
1. 先 commit 上 develop branch, upload 上網上 Github.
2. 切到 master
3. 用 GitHub for Windows desktop 的 Branch > Merge into current branch 選 develop 把它 merge 過來。
解決 conflicts 之後完成 merge.
4. 再 repeat 2-3 但切到 develop 把 master merge 過去。
Master 上的應該是些 README.md 的修改。
[X] 要不要把 projectk.py sync 回 project-k
(很早以前) projectk.py 改了一點,忘了如何 sync 回 project-k 的?
05:30 2019-11-21 peforth source code 裡的 projectk.py 本身不是從 github 直接下來的, 而是
硬放上去的,因此不會與 project-k github 自動同步 <--- 想想看怎麼辦,先手動作吧!
09:38 11/23/2021 v1.27 的 projectk.py 有經過 GOM port 的考驗有些改進。
[X] version 改成 1.28 (必須跳過 1.20 直接到 1.21 否則會變成 1.2)
[X] 02:24 2021/11/22 GitHub\peforth\forth.py 可以刪掉很多已經進 v1.27 的東西,考慮改名成 jupyter-extension.py
[x] it's now: GitHub\peforth\playground\jupyter-extension.py.py
[/] 02:36 2021/11/22 jupyter-extension 做出 paste command 的方法可以 apply to DOS box too.
算了,目前 dos box 之下用 ^D Ctrl-D 的方法 suppport multiple lines 的 input 很好了。
[X] 17:52 12/4/2021 受到 icecream 啟發,原本只存在於 selftest 期間的 display-off display-on
等於是咱的 disable/enable 可讓 peforth 與 PROD 版並存無須來回 加上/刪除。
[X] 1.28 版 built-in 了, 1.27 之前用 forth.py 加上。
[X] 16:21 12/8/2021 need an init --> no it's a bug that has been fixed.
[ ] 16:55 12/8/2021 怪事 in jupyternotebook. display-off in a cell, then in another cell display-on and print something that
goes to the output of the previous display-off cell !! behavior of jupyternotebook.
[X] 18:41 12/4/2021 peforth greeting 不該主動 print! 自找麻煩。version command
與 greeting command 分開,保持安靜!這事兒 v1.28 該搞定了。
[X] 15:45 12/8/2021 引進 icecream 的功能,不是跟它重複 e.g. display-off is our existing feature, also the ic.disable() is
needed too, thus we can use %f more flexibly. Simply make dictate to skip all tib, move ntib to the end is a
possible idea.
09:10 12/9/2021 vm.magic switch to on/off %f in __init__.py

[X] 10:35 12/9/2021 __init__.py 裡面取得 path 方法很勉強,有待改進。
當前的問題是開發中這樣測試 ipython -m peforth (其實應該這樣測 GitHub\peforth> python peforth)
半路就 error FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\8304018\\.ipythonversion.txt'
因為 path 錯了!
ipdb> os.path.isfile(path + deli + 'peforth' + deli + 'version.txt') --> False
ipdb> os.path.isfile(path + deli + 'version.txt') --> False
ipdb> for i in sys.path:
print(i)
C:\Program Files\Orange\Scripts
C:\Program Files\Orange\python38.zip
C:\Program Files\Orange\DLLs
C:\Program Files\Orange\lib
C:\Program Files\Orange
C:\Users\8304018\AppData\Roaming\Python\Python38\site-packages
C:\Program Files\Orange\lib\site-packages
C:\Program Files\Orange\lib\site-packages\win32
C:\Program Files\Orange\lib\site-packages\win32\lib
C:\Program Files\Orange\lib\site-packages\Pythonwin
C:\Program Files\Orange\lib\site-packages\IPython\extensions
C:\Users\8304018\.ipython <------------------------------------- 全部都沒有
ipdb> path --> 'C:\\Users\\8304018\\.ipython' <---- 結果 path 大錯!
ipdb> path='.\\peforth' <---------- 直接改成這樣
ipdb> os.path.isfile(path + deli + 'version.txt') --> True 結果可以!
10:39 12/9/2021 所以可以用 path='.\\peforth\\' 當 default 值試試看 --> 有效! v1.28
[X] 18:45 12/4/2021 啟動 %%skip magic 不能靠 %run forth.py 必須靠之後的:
%f get_ipython init_skip_magic :: (pop()) 命令下達
--> 16:47 12/8/2021 還是用 %load_ext skip_kernel_extension 最好,那就與 peforth 無關了嗎?
不然,考慮用 %load_ext 來安裝 peforth ...
See https://stackoverflow.com/questions/26494747/simple-way-to-choose-which-cells-to-run-in-ipython-notebook-during-run-all
[X] jupyter-extension.py ok
[X] https://stackoverflow.com/questions/24816237/ipython-notebook-clear-cell-output-in-code
: cls // ( -- ) Clear output of this cell in Jupyternotebook
py: IPython.display.clear_output() ;
15:24 2022-06-15 測了一下, this solution works on Google Colab too.
[X] jupyter-extension.py ok
[X] Google colab jupyternotebook cell output wraparound
Evernote : 跑一下讓 Google Colab cell output 能 wrap long lines.
OneNote2022: Google Colab tips

[X] 13:39 2022/9/7 peforth 配合 jupyterlab 的 scratchpad debug 超好用,但是最好能斷在 function
裡面利用 peforth 取得 _locals_ 結束程式,回到 console 來,把 peforth _locals_ 帶出來變成 globals.
然後就可以用 jupyterlab 的 scratchpad 來 debug 了,大成功!

How to stop executing the program in a function - Python peforth DevTools debug
從 function 裡面可以把程式停掉來檢查 context,甚至在 peforth.bp() 裡面也可以做得到,命令是

raise SystemExit("Stop right there!")

配合 magic %tb and %debug 很方便查看當時的現況。peforth 的 _locals_ 也可以整個帶出來到 globals() 方法是:

for k,v in peforth.execute("_locals_").pop().items():
globals()[k] = v

因此配合 DevTools.py 可以很方便地做各種實驗。以下 sample code :

__file__ = "DevTools.py"
import pandas as pd 故意看看 df 能不能 SystemExit 之後藉由 peforth 從 function 內部被帶出來到 globals()?
def thefunction():
a = 123
b = 456
print(a+b)
df = pd.read_feather(r"c:\Users\8304018\Downloads\hubble2\2021-6-1.feather")
peforth.bp(11,locals()) raise SystemExit("Stop right there!")

執行之後被 peforth 中斷,在斷點中除了 peforth 的功能之外還可以 raise SystemExit 把程式停掉。
thefunction()

raise SystemExit 停掉程式之後可以把當時的 context 帶到 globals() 來查看,甚至用 DevTools.py 來做更複雜的實驗。
%tb
for k,v in peforth.execute("_locals_").pop().items():
globals()[k] = v
[X] 11:47 2023/2/15 把以上技巧加進 constant debug 的 help 裡去,方便查詢。
[ ] 考慮 projectk.py 本身也上 pypi , 可以 pip install projectk 更有意義!
[ ] 8:53 AM 1/28/2022 unknown (Ûnknôwn) should be ... as a formal solution.
[ ] 15:21 2022-06-15 其實沒有 peforth Python 自己就可以變出 repl
https://dev.to/amal/building-the-python-repl-3468
def repl() -> None:
try:
while True:
try:
_in = input(">> ")
try:
print(eval(_in))
except:
out = exec(_in)
if out != None:
print(out)
except Exception as e:
print(f"Error: {e}")
except KeyboardInterrupt as e:
print("\nExiting...")
[ ] 13:48 2022/9/7 看怎麼放進 forth.py 裡去好用點。

[ ] 11:07 2022/10/11 發現問題! callback 中 ipython I/O 無效了 peforth.bp() 也跟著無效。
http://localhost:8888/notebooks/OneDrive/Documents/Jupyter%20Notebooks/ipywidgets%20-%20Using%20Interact.ipynb

[ ] 2024-01-25 10:41:56 咱的 words 發生衝突了!
1.
peforth 有 str 意思是 TOS casting 成 str
ChatLKK 有 str, str: 意思是從 tib 取 string
2.
peforth 的 help 不能用 \ 只能用 //。 我覺得這個反而比 jeforth/ChatLKK 更自然。

[ ] 10:46 2024/06/20 new Jupyter notebook magic %ai %%ai to call user: command
if llm.invoke("hi") is how AI is called where llm = columbus.get_llm_for_LangChain()
then %f user: talk to ai
%%f
llm constant llm // ( -- llm ) AI LLM object for LangChain
: user: ( <message> -- "AIMessage" ) \ Talk to AI
char _user:_ word ( msg ) llm :> invoke(pop()) ( AIMessage )
:> content ( "AIMessage" ) . ;
Thus %ai ... is equvalent of %f user: ...
[X] 10:46 2024/06/20 new Jupyter notebook magics
%ai %%ai to call ai: command, also
%chat %%chat to call chat: command.
if llm.invoke("hi") is how AI is called where llm = columbus.get_llm_for_LangChain()
then %f user: talk to ai
%%f
llm constant llm // ( -- llm ) AI LLM object for LangChain
: user: ( <message> -- "AIMessage" ) \ Talk to AI
char _user:_ word ( msg ) llm :> invoke(pop()) ( AIMessage )
:> content ( "AIMessage" ) . ;
Thus %ai ... is equvalent of %f user: ...
--> version 1.31 同時把很多 forth.py 裡的 new words 都加進 peforth 了,
e.g. Timer, py2ipynb, clear.
[ ] (13:22 2024/06/22) release v1.31 to pypi
[X] setup.py 裡的 copy right 年份要改成 2024
[ ] version.txt 裡的 __version__ = "1.31-beta" <-- Pypi.org 沒有 public 開關,AI 教我用這 beta 法。
結果真的 upload 好了之後在 Pypi.org 上顯示的是 1.31b0 而且得用 pip install peforth==1.31b0 才 install 得到。
但 peforth.__version__ is '1.31-beta' 一切完美!
*** 打包上 pypi.org 的方法 setup.bat 可以大簡化了。
[V1.22之後的新版] 打包步驟 2018/12/16 11:02
See my Ynote: "Pack peforth to peforth.whl"
[x] 1. 檢查 ~\GitHub\peforth\setup.py 看有沒有漏掉新檔案,有沒有要去掉的檔案, 更新年份。
[x] 2. (記得先把 dist , build , peforth.egg-info 等 folder 先殺掉)
[X] 3. activate MyMLenv 隨便切個 VENV 來用,
c:\Users\hcche\Documents\GitHub\peforth>python setup.py sdist bdist_wheel
得到 peforth.whl in c:\Users\hcche\Documents\GitHub\peforth\dist
[X] 4. 若無 twine 則 pip install twine 很快很順
執行 c:\Users\hcche\Documents\GitHub\peforth>twine upload dist/*
! 需要帳號密碼,看這裡 Ynote or Evernote: "python pypi 研究 -- upload to PyPI ok now.note"
! Ynote web log in: hcchen5600gmail.com/2y0o1u9dao
! Enter your username: hcchen5600
! Enter your password:
15:26 2024/06/22 結果它現在跟我要的不是帳號密碼而是只用一次的 API token!
(MyMLenv) C:\Users\8304018\Documents\GitHub\peforth>twine upload dist/*
Uploading distributions to https://upload.pypi.org/legacy/
Enter your API token: pypi-AgEIcHlw...... 會 commit 上 GitHub 不能留在這裡,算了,需要時都上網頁去要。
從 Pypi.org 網頁上去要。
[X] 5. pip uninstall peforth 然後再 pip install peforth 試驗看看。
[X] 6. 完成!
[X] 所有 run 法帶 selftest:
[X] 用 peforth 查出 c:\\...\\MyMLenv\\lib\\site-packages\\peforth
改 quit.f
' <selftest> :: enabled=True
[X] 先通過最基本的 selftest: GitHub\peforth\peforth>python test.py
萬一 v1.31-beta 無法轉成 float 出錯,直接改 site-packages\peforth\version.txt 即可。
[X] 1. python -i -m peforth [ ] with-selftest .s words exit bye
[X] 2. ipython -i -m peforth .' Hello World!!' cr bye
[X] 3. ipython import peforth .s words
[x] selftest peforth.ok() .s words <--- w/parent
[x] 1234 bye check echo %errorlevel% <-- 從 ipython 下直接出來也無誤。
[X] 4. jupyter notebook
kernel > restart and clear outputs
x = 123
%f x .
x . \ ==> 123 (<class 'int'>)
[x] 5. jupyter notebook --> peforth kernel --> .s words
[ ] 考慮 README.rst 改良
[ ] 若有改過 README.rst 則 wheel 就要重做
--> quit.f selftest=False --> 重來
[ ] 21:04 2024/06/22 刪掉了好多,有興趣可回頭參考 v1.25 的 (15:30 2020/10/24)
例如:從 pip install ..\peforth\dist\peforth-1.31b0-py3-none-any.whl
[ ] 查看 pypi.org 網頁,若不行,晚點 (過幾分鐘就好) 再看。
[ ] Windows DOS 下試
[ ] WSL Ubuntu 下試 pip uninstall peforth -> pip install peforth
[ ] WSL Ubuntu with and w/o w/o virtualenv --> python -m peforth
[ ] Test Online Jupyter Notebooks Google Colab, Microsoft Azure, and Notebooks.ai
!pip install peforth
import peforth
%f version drop
x = 12345
%f x --> \ 查看 unknown 的效果
\ Colab & Azure 都用 Ubuntu 查版本, Notebooks.ai 用 Debian 都可用這行指令
!cat /etc/os-release
%f py> path --> \ 查看 path 發現 Azure 就是用 Anaconda 所以它有 support Ubuntu!
%pwd \ 查看 working directory
[ ] Colab https://colab.research.google.com/drive/1nZpybQryEiwYzpMvG1tHg4qbNnd_rMey#scrollTo=yAuF9DZcrFaT
[ ] Azure https://peforthplayground-hcchen1471.notebooks.azure.com/j/notebooks/peforth-playground.ipynb
[ ] notebooks.ai 也測測看
[X] 21:21 2024/06/22 git push v1.31-beta to branch 'develop'
[ ] Make a master release up to GitHub --> 用 GitHub Windows 很簡單。
1. 先 commit 上 develop branch, upload 上網上 Github.
2. 切到 master
3. 用 GitHub for Windows desktop 的 Branch > Merge into current branch 選 develop 把它 merge 過來。
解決 conflicts 之後完成 merge.
4. 再 repeat 2-3 但切到 develop 把 master merge 過去。
Master 上的應該是些 README.md 的修改。
[ ] 要不要把 projectk.py sync 回 project-k
(很早以前) projectk.py 改了一點,忘了如何 sync 回 project-k 的?
05:30 2019-11-21 peforth source code 裡的 projectk.py 本身不是從 github 直接下來的, 而是
硬放上去的,因此不會與 project-k github 自動同步 <--- 想想看怎麼辦。
[X] version 改成 1.27 (必須跳過 1.20 直接到 1.21 否則會變成 1.2)

1.23

[X] setup.py 裡的 copy right 年份要改成 2019
*** 打包上 pypi.org 的方法 setup.bat 可以大簡化了。
[V1.22之後的新版] 打包步驟 2018/12/16 11:02
See my Ynote: "Pack peforth to peforth.whl"
1. 檢查 ~\GitHub\peforth\setup.py 看有沒有漏掉新檔案,有沒有要去掉的檔案。
2. 跑 c:\Users\hcche\Documents\GitHub\peforth>python setup.py sdist bdist_wheel
得到 peforth.whl in c:\Users\hcche\Documents\GitHub\peforth\dist
3. 執行 c:\Users\hcche\Documents\GitHub\peforth>twine upload dist/*
需要帳號密碼,看這裡 Ynote: "python pypi 研究 -- upload to PyPI ok now.note"
4. pip uninstall peforth 然後再 pip install peforth 試驗看看。
5. 完成!
[X] See (15:55 2019-05-22) 這個 check-list 要耐心好好做完!
[X] 所有 run 法帶 selftest:
[X] 改 GitHub\peforth\quit.f
' <selftest> :: enabled=True
[X] Run python setup.py install 更新本地 site-package 版本以供測試
[X] 1. python -i -m peforth [/] with-selftest .s words exit bye
[X] 2. ipython -i -m peforth .' Hello World!!' cr bye
[X] 3. ipython import peforth .s words
[x] selftest peforth.ok() .s words <--- w/parent
[x] 1234 bye check echo %errorlevel% <-- 從 ipython 下直接出來也無誤。
[X] 4. jupyter notebook
kernel > restart and clear outputs
x = 123
%f x .
x . \ ==> 123 (<class 'int'>)
[/] 5. jupyter notebook --> peforth kernel --> .s words
[/] 考慮 README.rst 改良
[X] 若有改過 README.rst 則 wheel 就要重做
--> quit.f selftest=False --> 重來
[X] 所有 run 法不帶 selftest 跑一遍,準備要 release 的版本:
[X] 改 GitHub\peforth\quit.f
' <selftest> :: enabled=False
[X] 做出取消 selftest 的 wheel
See my Ynote: "Pack peforth to peforth.whl"
[x] 1. 檢查 ~\GitHub\peforth\setup.py 看有沒有漏掉新檔案,有沒有要去掉的檔案。
test.py hello.py misc.f
[X] 2. 跑 c:\Users\hcche\Documents\GitHub\peforth>python setup.py sdist bdist_wheel
得到 peforth.whl in c:\Users\hcche\Documents\GitHub\peforth\dist
[X] pip uninstall peforth
[X] 切 CD 到 c:\Users\hcche\Documents\GitHub\peforth\dist>
pip install peforth-1.23-py3-none-any.whl <== 注意!用剛做好的 wheel 否則會上網抓。
[X] 1. (i)python -i -m peforth [/] no-selftest .s words exit
[X] 2. (i)python -i -m peforth version 12345 bye --> echo %errorlevel%
[X] 3. (i)python import peforth
[X] no selftest, peforth.ok() .s words <--- no parent
[X] 1234 bye check echo %errorlevel%
[X] 4. jupyter notebook --> *debug* ok> .s cd help exit
%f %%f magic command
[/] 5. repeat 以上 in ubuntu <------- Ubuntu 18.04 沒有 pip built-in 不想搞了
[/] pip uninstall peforth
[/] pip install (use /mnt/...the wheel) to WSL ubuntu
[/] ipython -m peforth
[/] ipython , import peforth , magic commands
[X] 直接用測過的 wheel update Pypi
執行 c:\Users\hcche\Documents\GitHub\peforth>twine upload dist/*
需要帳號密碼,看這裡 Ynote: "python pypi 研究 -- upload to PyPI ok now.note"
ID, password search my Ynote with pypi _account_
[X] 查看 pypi.org 網頁,若不行,晚點 (過幾分鐘就好) 再看。
[/] WSL Ubuntu 下試 pip uninstall peforth -> pip install peforth
[/] WSL Ubuntu with and w/o w/o virtualenv --> python -m peforth
[X] Windows DOS 下試
[X] Test Azure Online Jupyter Notebooks
https://peforthplayground-hcchen1471.notebooks.azure.com/j/notebooks/peforth-playground.ipynb
!pip install peforth
import peforth
%f version drop
x = 12345
%f x --> \ 查看 unknown 的效果
[X] Make a master release up to GitHub --> 用 GitHub Windows 很簡單。
1. 先 commit 上 develop branch, upload 上網上 Github.
2. 切到 master
3. 用 GitHub for Windows desktop 的 Branch > Merge into current branch 選 develop 把它 merge 過來。
解決 conflicts 之後完成 merge.
4. 再 repeat 2-3 但切到 develop 把 master merge 過去。
Master 上的應該是些 README.md 的修改。
[X] version 改成 1.24 (必須跳過 1.20 直接到 1.21 否則會變成 1.2)
[X] 11:28 2019-05-26 make a master merge for the article of Febenacci and Decorator
[X] rename the article to 'peforth helps to understand python Decorator'
[/] 11:35 2019-05-26 write an article to introduce 'unknown'
--> forget this, covered already.
[/] 11:35 2019-05-26 find the video I introduce 'unknown' and the other thing
--> forget this, covered already.

[X] 09:11 2019-11-21 本來跑 GitHub\peforth\setup.bat 讓改好的新版生效,在 anaconda 之下還行嗎?
1. 跑 anaconda's prompt make sure python runable
2. peforth runable too, check path
3. cd to GitHub\peforth run setup
4. check peforth
OneNote 筆記:
"Develop peforth in an Anaconda virtual environment"
https://onedrive.live.com/view.aspx?resid=A796EA18AC8C1DA9%2112289&id=documents&wd=target%28Anaconda.one%7CB4E0DFAB-84F7-43D2-A5AB-515B43314252%2FDevelop%20peforth%20in%20an%20Anaconda%20virtual%20environment%7C99DE5C5F-B36D-4949-9471-BC7A857E3C2B%2F%29

[X] 09:52 11/23/2021 從這裡 https://stackoverflow.com/questions/20101834/pip-install-from-git-repo-branch 讀到
不用上 pypi 了,有從 github repo 上直接 pip install 的方法:
pip install git+https://github.com/hcchengithub/peforth.gitdevelop
成功了!
[ ] GitHub 有開始做 package hosting (與 pypi, npm 競爭?) 了:
https://help.github.com/en/github/managing-packages-with-github-packages/about-github-packages#supported-clients-and-formats
[ ] 13:35 12/16/2021 python poetry init 某個 folder 時,暗示有更多種方法灌 python package:
(playground) C:\Users\8304018\Downloads\playground>poetry init

This command will guide you through creating your pyproject.toml config.

Package name [playground]:
Version [0.1.0]:
Description []: try to poetry init on an exising folder with existing .toml and .lock renamed to ~.disabled
Author [H.C. Chen <hcchen5600gmail.com>, n to skip]:
License []: MIT
Compatible Python versions [^3.9]:

Would you like to define your main dependencies interactively? (yes/no) [yes]
You can specify a package in the following forms:
- A single name (requests)
- A name and a constraint (requests^2.23.0)
- A git url (git+https://github.com/python-poetry/poetry.git)
- A git url with a revision (git+https://github.com/python-poetry/poetry.git#develop)
- A file path (../my-package/my-package.whl)
- A directory (../my-package/)
- A url (https://example.com/packages/my-package-0.1.0.tar.gz)

Search for package to add (or leave blank to continue):

Would you like to define your development dependencies interactively? (yes/no) [yes]
[X] 2019/11/24 06:10:22 projectk.py 裡 import 好多它本身不用的 modules (它自己只
用到 re regular expression 一個) 我的註解說:
import re import whatever we want, don't rely on parent module e.g. peforth __init__.py
也是有理,因為 projectk.py kernel 有自己的 space. 然而 modules 應該是 global
的, 不是嗎?從 forth code 裡 import 不行嗎? --> 試了就知道,把 projectk.py 裡
多餘的 imports comment 掉 --> 出問題的時候很晚,只要是 native modules 有機會解決.....
來自 help import 的 hints
\ import os __main__ :: peforth.projectk.os=pop(1) \ peforth global , does not work when run by 'python test.py'
import os py> vm :: os=pop(1) \ this works! when run by 'python test.py'
import inspect py> vm :: inspect=pop(1)
import dis py> vm :: dis=pop(1)
import json py> vm :: json=pop(1)
但是 sys 太根本了必須要在 projectk.py 裡 import 好。
[X] setup.py 裡的 copy right 年份要改成 2019
[/] 2019/11/24 05:20 用 Anaconda 之後似乎 kernel.json 也有問題?
裡面描述的 peforthkernel.py path 是寫死的,在我 OA、Anaconda 上就不對了。
好像只要無意把 peforth 加進 JupyterNotebook 的 kernel 就沒問題。
[X] 05:29 2019-11-21 projectk.py 裡面的 local, Comment, debug 這三個 global token 好像是多
餘的, 有空檢討看看.
[X] local 可能是 ok(prompt='OK ', loc={}, glo={}, cmd="") 或 redefined unknown 用的 <--- 不是
13:47 2019/11/25 delete all suspected things from projectk.py --> dos ok, jupyternotebook ok.
* 注意!setup.bat 不會更新 site-packages 的 peforth\ folder 要手動從 peforth-1.24-py3.7.egg <== 2020.7.28 解了! see OneNote2020 > "Develop peforth in an Anaconda virtual environment"
copy peforth\ 來蓋過 site-packages 裡的 peforth\ folder.
refer to https://onedrive.live.com/view.aspx?resid=A796EA18AC8C1DA9%2112289&id=documents&wd=target%28Anaconda.one%7CB4E0DFAB-84F7-43D2-A5AB-515B43314252%2FDevelop%20peforth%20in%20an%20Anaconda%20virtual%20environment%7C99DE5C5F-B36D-4949-9471-BC7A857E3C2B%2F%29
[X] 14:41 2019/11/25 quit.f 裡這種東西應該要改良,太笨了:
import os py> vm :: os=pop(1) \ 太笨
import os \ 應該改良成這樣
[X] 15:21 2019/11/25 整理 peforth.f quit.f peforth.selftest 的關係,更有系統了。
__init__.py 只 load 進基本的 peforth.f quit.f 其他的都由 quit.f 負責,使 quit.f
成為 eforth 系統的 main program, 統籌者。
[X] 16:07 2019/11/25 一舉搞懂 pop(1) pop(0) in function argument 的順序
code test print(pop(),pop()) end-code // ( 1 0 -- ) 實驗搞清 pop() 順序 1 0 func :: (pop(1),pop(0)) 得 (1,0); 若 1 0 func :: (pop(),pop()) 則得 (0,1)
1 0 test .s \ --> 0 1

1.18

See my Ynote: "mybinder.org FileNotFoundErErrorno 2 No such file or directory"
--> 我猜是 setup.py 的檔案結構,在 Desktop\peforth-master\ 處多用了一個 peforth
folder 如此一來, 從 project 本身的 setup.py 所在之處來看 version.txt 就不在
peforth/version.txt 而直接在 version.txt 才對。 v1.16 先直接修改
Desktop\peforth-master\setup.py
做一版 wheel 在 local 看成不成功, 若成功就證明研究生的檔案結構多一個 peforth
是沒必要的了,改掉就有機會了。
--> 真的做成了, 把 peforth/ 裡的東西都移上來, setup.py 改掉,不要 peforth/,
如下從 working directory 執行, 成功了!
c:\Users\hcche\Desktop\peforth-master>pip wheel --wheel-dir=dist .
Processing c:\users\hcche\desktop\peforth-master
Building wheels for collected packages: peforth
Running setup.py bdist_wheel for peforth ... done
Stored in directory: c:\users\hcche\desktop\peforth-master\dist
Successfully built peforth
c:\Users\hcche\Desktop\peforth-master>
--> 這表示根本不必搞到 Desktop\peforth-master 直接用 local GitHub repo 就可以
了 --> 錯錯錯! Desktop\peforth-master\peforth folder 是必須的
--> peforth/version.txt file not found 應該還是 _the_path_issue_
[x] 做成 1.17 release 以便查看 mybinder.org 解了沒? --> failed !!
see also : Ynote : "研究 peforth 的 path 到底正確該如何"
[x] setup.py 是研究生為了做出 peforth 的 whl 而設。既然 mybinder.org 也要來
看,就一定要更講究一點,我想就是這個原因....
--> 可能要兩個 setup.py, 一個 at peforth folder, the other is for building .whl.
when building .whl, the setup.py is at parent folder and is that a must ?
--> anywhere>pip wheel --wheel-dir=dist c:\Users\hcche\Desktop\peforth-master
c:\Users\hcche\Desktop\peforth-master>pip wheel --wheel-dir=dist peforth
以上都可以 build 出 peforthxxxxx.whl
--> peforth/setup.py 被 mybinder.org 看到了才出的問題, 把它改名成 setup.py.disabled 看看...
RI: 把 setup.py 名字改掉就好了!!! 不要讓 mybinder.org 看到 setup.py 即可。
--> 如前述,我們的 setup.py 是用來做 .whl 的,要給 pip 看的,不是要給 mybinder.org
看的。
[x] Merge 到 master 但可以不必急著 release, 純粹是 setup.py 的問題,跟程式無關。
只要讓 mybinder.org 能跑,改 github 上的 setup.py 成 setup.py.whl 即可。
--> expecting v1.18
[x] Tests before a Release v1.18 <--- on pypi.org already
[x] 所有 run 法帶 selftest:
[x] 改 %USERPROFILE%\Documents\GitHub\peforth\quit.f
' <selftest> :: enabled=True
[取消] 直接從 GitHub folder 執行 python peforth --> 等於是 -m peforth
[x] Run setup.bat 更新本地 pip installed 版本以供測試
[x] 1. python -i -m peforth [x] with-selftest .s words exit bye
[x] 2. ipython -i -m peforth .' Hello World!!' cr bye
[x] 3. ipython import peforth .s words
[x] selftest peforth.ok() .s words <--- w/parent
[x] 1234 bye check echo %errorlevel% <-- 從 ipython 下直接出來也無誤。
[x] 4. jupyter notebook
kernel > restart and clear outputs
import peforth
%%f 擴充、修訂一下 peforth 的行為模式,讓它認得 jupyter notebook 下的 globals. Dot . 也改寫了,適合 jupyter notebook 學習環境使用。
: unknown ( token -- thing Y|N) // Try to find the unknown token in __main__
py> getattr(sys.modules['__main__'],pop(),"Ûnknôwn")
py> str(tos())=="Ûnknôwn" if drop false else true then ;
/// here after, when FORTH come accross an unknown token, instead of alerting
/// it try to find the token in python __main__ module name space.
: . tib. ; // ( tos -- ) A better dot that also prints the entire command line
/// For experiments that need to show both question and result.
/// "" . prints the command line only, w/o the TOS.
: path-to-find-modules ( <path> -- ) // Add path to sys.path so "import module-name" can find the module
CR word trim ( "path" ) py: sys.path.append(pop()) ;
code \ print(nexttoken('\n')) end-code // Redefine \ command to print the comment line
x = 123
%f x .
x . \ ==> 123 (<class 'int'>)
[x] 5. jupyter notebook --> peforth kernel
[/] 考慮 README.rst 改良
[/] 若有改過 README.rst 則 wheel 就要重做
--> quit.f selftest=False --> 重來
[x] 所有 run 法不帶 selftest 跑一遍,準備要 release 的版本:
[x] 改 %USERPROFILE%\Documents\GitHub\peforth\quit.f
' <selftest> :: enabled=False
[x] Run setup.bat 做出取消 selftest 的 wheel
[x] pip uninstall peforth
[x] pip install peforth-xxxx.whl <== 注意!用剛做好的 wheel 否則會上網抓。
[x] 1. python -i -m peforth [x] no-selftest .s words exit
[/] 2. python -i -m peforth version 12345 bye --> echo %errorlevel%
[/] 3. python import peforth
[/] no selftest, peforth.ok() .s words <--- no parent
[/] 1234 bye check echo %errorlevel%
[x] 4. jupyter notebook --> *debug* ok> .s cd help exit
%f %%f magic command
[x] 5. repeat 以上 in ubuntu
[x] pip uninstall peforth
[x] pip install (/mnt/...the wheel) to WSL ubuntu
[x] ipython -m peforth
[x] ipython , import peforth , magic commands
[x] 直接用測過的 wheel update Pypi
繼續剛才的 setup.bat 即可,必要時: twine upload dist/*
ID, password search my Ynote with pypi _account_
[x] test mybinder.org [http://github.com/hcchengithub/peforth][develop][notebook]
這個跟 pypi.org 無關,只要 github 有 push 上去馬上生效。
[x] pypi.org 網頁上已經 upgraded 到 1.18 版了, WSL Ubuntu 下試過
pip uninstall peforth -> pip install peforth 也到 1.17 版了,就是
Windows DOS 下怎麼試都還是 1.16 ! 不管了,晚點再看 --> 真的過幾分鐘就好了!!
[x] WSL Ubuntu w/o virtualenv --> python -m peforth ... ok
[x] WSL Ubuntu with virtualenv --> python -m peforth ... ok
[/] test colab --> v1.18 還是 failed 還是 path 的問題 :-(
[x] version 改成 1.19 (必須跳過 1.10 會變成 1.1)
[x] Make a master release up to GitHub --> 用 GitHub Windows 很簡單。

[x] test colab --> v1.18 還是 failed 還是 path 的問題 :-(
v1.18 is failed on colab, the chance is that v1.16 works fine on colab.
[x] use v1.16 (pip install peforth==1.16 on colab) to check sys.path & site.getsitepackages()
---- from collab with peforth v1.16 ----
import site
site.getsitepackages()
['/usr/local/lib/python3.6/dist-packages',
'/usr/lib/python3/dist-packages',
'/usr/lib/python3.6/dist-packages']
import sys
sys.path
['',
'/env/python',
'/usr/lib/python36.zip',
'/usr/lib/python3.6',
'/usr/lib/python3.6/lib-dynload',
'/usr/local/lib/python3.6/dist-packages',
'/usr/lib/python3/dist-packages',
'/usr/local/lib/python3.6/dist-packages/IPython/extensions',
'/content/.ipython']
-------- actual peforth path on Google colab ---------------
!ls /usr/local/lib/python3.6/dist-packages/peforth
__init__.py __main__.py peforthkernel.py projectk.py __pycache__ setup.py
!ls /usr/local/lib/site-packages/peforth
kernel.json peforthkernel.py __pycache__ version.txt
peforth.f peforth.selftest quit.f
[/] So, the answer is clear here . . . try all possible directories with some
guess to find /peforth/version.txt that's doable
[x] can be setup.py's problem. I don't think all modules are facing the same
annoying problem. --> try to simplify setup.py.whl
--> RTFD : https://packaging.python.org/guides/distributing-packages-using-setuptools/?highlight=data_files#data-files
[x] testing c:\Users\hcche\Desktop\peforth-master\setup.py.improved that uses
package_data={...} instead of data_files=[...] in sety.py
--> 用改過的 setup.py 重作 wheel
很奇怪,必須用 github\peforth\setup.bat 做否則 pip wheel 根本不 build 總之有個辦法可行做出了 v1.19
See Ynote: "Pack peforth to peforth.whl" > "2018/07/02 13:06" 的討論。
--> 直接看 ~.whl (zip檔)就知道成功了!
[x] v1.18 用 sys.path 的加工不對了 --> 改掉
[x] path="" 只有 setup.bat 要看才出錯,真的不行嗎?
--> 真的不行,讀 version.txt 時的 os.getcwd() 真的就是當時的 working directory,這樣不行。
--> 所以用 sys.path 的方法還是要用 --> windows 本來就沒錯了呀!
[x] 改掉 setup.py 的好處是 data files 與 .py 都在一起了,但是 path 如何取得
還是個問題 -- Ubuntu and colab 不能兩全 --> 用 sys.path 去 serch peforth/version.txt
還是唯一的辦法 ... 不難:

path = "something wrong peforth path not found"
for p in (pp for pp in sys.path if pp.endswith("site-packages")):
if os.path.isfile(p + deli + 'peforth' + deli + 'version.txt'):
path = p + deli + 'peforth' + deli
break
vm.path = path
pdb.set_trace() *debug*
[x] windows (none anaconda virtualenv), WSL Ubuntu w/o virtualenv, with virtualenv
--> all pass!

[x] Tests before a Release v1.19 --> v1.21 actually
[x] 所有 run 法帶 selftest:
[x] 改 GitHub\peforth\quit.f
' <selftest> :: enabled=True
[x] Run setup.bat 更新本地 pip installed 版本以供測試
[x] 1. python -i -m peforth [x] with-selftest .s words exit bye
[x] 2. ipython -i -m peforth .' Hello World!!' cr bye
[x] 3. ipython import peforth .s words
[x] selftest peforth.ok() .s words <--- w/parent
[x] 1234 bye check echo %errorlevel% <-- 從 ipython 下直接出來也無誤。
[x] 4. jupyter notebook
kernel > restart and clear outputs
import peforth
%%f 擴充、修訂一下 peforth 的行為模式,讓它認得 jupyter notebook 下的 globals. Dot . 也改寫了,適合 jupyter notebook 學習環境使用。
: unknown ( token -- thing Y|N) // Try to find the unknown token in __main__
py> getattr(sys.modules['__main__'],pop(),"Ûnknôwn")
py> str(tos())=="Ûnknôwn" if drop false else true then ;
/// here after, when FORTH come accross an unknown token, instead of alerting
/// it try to find the token in python __main__ module name space.
: . tib. ; // ( tos -- ) A better dot that also prints the entire command line
/// For experiments that need to show both question and result.
/// "" . prints the command line only, w/o the TOS.
: path-to-find-modules ( <path> -- ) // Add path to sys.path so "import module-name" can find the module
CR word trim ( "path" ) py: sys.path.append(pop()) ;
code \ print(nexttoken('\n')) end-code // Redefine \ command to print the comment line
x = 123
%f x .
x . \ ==> 123 (<class 'int'>)
[x] 5. jupyter notebook --> peforth kernel --> .s words
[/] 考慮 README.rst 改良
[/] 若有改過 README.rst 則 wheel 就要重做
--> quit.f selftest=False --> 重來
[x] 所有 run 法不帶 selftest 跑一遍,準備要 release 的版本:
[x] 改 GitHub\peforth\quit.f
' <selftest> :: enabled=False
[x] Run setup.bat 做出取消 selftest 的 wheel
[x] pip uninstall peforth
[x] pip install peforth-xxxx.whl <== 注意!用剛做好的 wheel 否則會上網抓。
[x] 1. python -i -m peforth [x] no-selftest .s words exit
[x] 2. python -i -m peforth version 12345 bye --> echo %errorlevel%
[x] 3. python import peforth
[x] no selftest, peforth.ok() .s words <--- no parent
[x] 1234 bye check echo %errorlevel%
[x] 4. jupyter notebook --> *debug* ok> .s cd help exit
%f %%f magic command
[x] 5. repeat 以上 in ubuntu
[x] pip uninstall peforth
[x] pip install (/mnt/...the wheel) to WSL ubuntu
[/] ipython -m peforth
[/] ipython , import peforth , magic commands
[x] 直接用測過的 wheel update Pypi
繼續剛才的 setup.bat 即可,必要時: twine upload dist/*
ID, password search my Ynote with pypi _account_
[x] pypi.org 網頁上已經 upgraded 到 1.19 版了,
若不行,晚點再看,過幾分鐘就好。
[x] WSL Ubuntu 下試 pip uninstall peforth -> pip install peforth
[x] WSL Ubuntu with and w/o w/o virtualenv --> python -m peforth
[x] Windows DOS 下試
[x] test mybinder.org [http://github.com/hcchengithub/peforth][develop][notebook]
這個跟 pypi.org 無關,只要 github 有 push 上去馬上生效。
[x] test colab --> v1.19 --> shit, 又錯了! 不能限定要 site-packages, dist-packages 也要接受
deli = '\\' if os.name == 'nt' else '/'
path = "wrong"
for p in sys.path:
if os.path.isfile(p + deli + 'peforth' + deli + 'version.txt'):
path = p + deli + 'peforth' + deli
break
以上這改就對了,出 v1.21 版吧! Shit shit . . .
[x] __init__.py
[x] rebuild setup.bat
[x] release v1.21 to pypi.org
[x] test colab ... !pip install peforth==1.21 要等一等。。。 v1.21 成功了! 嗚嗚嗚
[x] Make a master release up to GitHub --> 用 GitHub Windows 很簡單。
[x] version 改成 1.22 (必須跳過 1.20 會變成 1.2)
[x] 14:48 2018-12-09 python object (attributes -> values) and hash table or
dictionary (keys --> values) are confusing me especially when JavaScript sees
both the samething. The python 'dir' function lists an object's attributes (攤平了,看不見結構) and
JSON can stringify a hash table to a readable string. 有 obj.__dict__ 最好,但不一定有。
Let's make an experient:

\ o1 is a dict
py> {'a':11,'b':22} constant o1
OK o1 tib. --> {'a': 11, 'b': 22} \ it's a dict so it's shown as a dict
OK o1 :> keys() . cr --> dict_keys(['a', 'b']) \ dict has keys
OK o1 :> values() . cr --> dict_values([11, 22]) \ dict has values
\ it's also an ojbect
OK o1 dir . cr \ so it has attributes
--> ['clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']
OK o1 stringify . cr
{
"a": 11,
"b": 22
}
OK
這樣看來,dict 與 object 的混淆是 JavaScript user 的問題。 任何東西都是 object 而只有 dict 才有 hash table.
a. 用 (see) dir _dir_ .members pprint obj.__dict__ 查看 object 的 attributes,
b. 用 (see) keys values stringify 查看 dict.
c. 用 stringify 查看 dict'fy 之後的任何東西。
--> 結論是在 help (see) 裡講清楚就好了。 來自 jeforth 的 obj>keys 與 dir 或 keys 重複所以很少用了。
o C:\Users\8304018\OneDrive\文件\Jupyter Notebooks\I study python dir and __dict__.ipynb
o https://stackoverflow.com/questions/14361256/whats-the-biggest-difference-between-dir-and-dict-in-python

[x] Install peforth from source
---- 2018.12.15 懂得用 python setup.py install 需要修改 ----
[x] Ynote: "研究 install peforth from source 的方法" 已經成功。
[x] 結論是: peforth/ 目錄結構要遷就研究生的安排,改變原先其實不太自然的執行方式:
C:\Users\hcche\Documents\GitHub\>python peforth
變成從 peforth 目錄裡面執行,這很好哇! [X] v1.22 1.23 __main__.py 還是用 import peforth 的,沒意思 --> 有 support test.py 取代 __main__.py 供 developing debugging 用
[x] pywinio repo 裡面也是又有一個 pywinio/ folder, 將來 peforth 也是這樣。
[x] 照研究生的目錄結構改 GitHub/peforth
c:\Users\hcche\Documents\GitHub\peforth\..
Directories Files
-------------------- ---------------------------
.git\ .gitattributes
.ipynb_checkpoints\ LICENCE
__pycache__\ admin.bat
notebook\ requirements.txt
peforth\ LICENSE
peforth.egg-info\ README.md
playground\ README.rst
setup.bat
setup.py
setup.py.whl
log.txt
.gitignore
c:\Users\hcche\Documents\GitHub\peforth\peforth\..
Directories Files
-------------------- ---------------------------
__main__.py
kernel.json
peforthkernel.py
projectk.py
peforth.selftest
version.txt
__init__.py
quit.f
peforth.f
[x] remove existing peforth so aso to try setup.py install
Python on my computer at home is anaconda, so though that I have to remove it
by "conda uninstall" command. That was wrong. Do it by pip as usual works fine.
see Ynote:"研究 install peforth from source 的方法" for the log.
[x] now try "python setup.py install"
it works !!!!
如何查看 setup.py 的 help: c:\Users\hcche\Documents\GitHub\peforth>python setup.py --help
[x] setup.bat 可以大簡化了。
[V1.22之後的新版] 打包步驟 2018/12/16 11:02
See my Ynote: "Pack peforth to peforth.whl"
1. 檢查 ~\GitHub\peforth\setup.py 看有沒有漏掉新檔案,有沒有要去掉的檔案。
2. 跑 c:\Users\hcche\Documents\GitHub\peforth>python setup.py sdist bdist_wheel
得到 peforth.whl in c:\Users\hcche\Documents\GitHub\peforth\dist
3. 執行 c:\Users\hcche\Documents\GitHub\peforth>twine upload dist/*
需要帳號密碼,看這裡 Ynote: "python pypi 研究 -- upload to PyPI ok now.note"
4. pip uninstall peforth 然後再 pip install peforth 試驗看看。
5. 完成!

[x] 13:27 2019-03-06 code ... end-code 可以取 xt.__doc__ 2nd line 當作 help
code txt2json ( txt -- dict ) Convert given string to dictionary
push(json.loads("".join([ c if c != "'" else '"' for c in pop()])))
end-code
' txt2json :> xt :> __doc__ --> def xt(_me=None): txt2json
( txt -- dict ) Convert given string to dictionary
push(json.loads("".join([ c if c != "'" else '"' for c in pop()]))) (<class 'str'>)
18:04 2019-05-09 寫好了:
projectk.py 裡面
The basic FORTH word 'end-code's run time.
def doendcode(_me=None):
global compiling
if compiling!="code":
panic("Error! 'end-code' a none code word.")
current_word_list().append(Word(newname,newxt))
last().vid = current;
last().wid = len(current_word_list())-1;
last().type = 'code';
---------
mm = re.match(r"^.*?\s*(.*)$", last().xt.__doc__.split('\n')[1])
last().help = mm.groups()[0] if mm and mm.groups()[0] else ""
---------
wordhash[last().name] = last();
compiling = False;
--> py> doendcode .source <---- 看到對的 source code 了
[x] 試驗定義一個 code word 查看他的 help 果然第一行的 foo bar 有被抓進去當 help 了。

[X] unkown debug locals() 的說明 copy 過來
older unsync'ed notes on my LRV2
v1.22 既然 peforth 主要都是用來配合 jupyter notebook trace code, set breakpoints, ... etc.
unknown and ... and should be added into the built-in words, plus the ability to
view local variables.
[x] I remember that I have done making 'unknown' predefined . . . no.
16:51 2019-01-12 I am now working on making 'unknown' to try locals. __main__ is
an object so global variables are accessed by getattr() however locals and globals
are dictionary that should be accessed by dict.get(key,default) instead.
see https://stackoverflow.com/questions/3089186/python-getattr-equivalent-for-dictionaries
[x] done an example
http://localhost:8888/notebooks/OneDrive/%E6%96%87%E4%BB%B6/Jupyter%20Notebooks/Siraj%20make_a_neural_net_live_demo.ipynb

Source Code
===========
none value _locals_ // ( -- dict ) locals passed down from ok()
false value debug // ( -- flag ) enable/disable the ok() breakpoint
: unknown ( token -- thing Y|N) // Try to find the unknown token in __main__ or _locals_
_locals_ if \ in a function
( token ) _locals_ :> get(tos(),"Ûnknôwn") ( token, local )
py> str(tos())!="Ûnknôwn" ( token, local, unknown? )
if ( token, local ) nip true exit ( return local Y ) else drop ( token ) then
then
( token ) py> getattr(sys.modules['__main__'],pop(),"Ûnknôwn") ( thing )
py> str(tos())=="Ûnknôwn" if ( thing ) drop false else true then ;
/// Example: Set a breakpoint in python code like this:
/// if peforth.execute('debug').pop() : peforth.push(locals()).ok("bp>",cmd='to _locals_')
/// Example: Save locals for investigations:
/// if peforth.execute('debug').pop() : peforth.push(locals()).dictate('to _locals_')
/// That enters peforth that knows variables in __main__ and locals at the breakpoint.
/// 'exit' to leave the breakpoint and forget locals.
: exit ( -- ) // ( -- ) Exit the breakpoint forget locals and continue the process
none to _locals_ py: vm.exit=True ;
code print(nexttoken('\n')+'\n') end-code // print the comment line after
: --> ( result -- ) // Print the result with the command line.
py> tib[:ntib].rfind("\n") py> tib[max(pop(),0):ntib].strip() ( result cmd-line )
s" {} {} ({})" :> format(pop(),tos(),type(pop())) . cr ;
/// Good for experiments that need to show command line and the result.

[X] 10:48 2019-05-11 older note
開發中,不要動到 pip'ed peforth 出錯很麻煩,所以想要從 working folder 執行
不要每次都得先 pip install 改入 site-packages
[x] __main__.py 當初為何他媽 import peforth 有屁用?就是要跑本地版本試驗改過的東西才有意義呀!
--> 15:48 2019-05-11 應該是 path 搞不定,簡化問題 (Since commit c3d7677 on Oct 8, 2017)。
__main__.py 是用 python -m peforth 執行時的 entry,必須照顧。
11:26 2019-05-11 while __init.py__ is 'import peforth' entry point.
--> 11:24 2019-05-11 __main__.py 就是 run
c:\Users\hcche\Documents\GitHub\peforth>python peforth
and
c:\Users\hcche\Documents>python -m peforth
時被執行的入口
see https://www.tuicool.com/articles/iYRfe2
https://stackoverflow.com/questions/44977227/how-to-configure-main-py-init-py-and-setup-py-for-a-basic-package
--> 11:51 2019-05-11 how about to have test.py that does what __main__.py is supposed to do when
running ~GitHub\peforth>python peforth?
--> this is a good idea, but the path in __init__.py will be wrong, deal with it!!
--> 從 __init__.py 裡面處理 path 處添加可能找到 version.txt 的地方即可。 成功。
--> 成功了,能直接執行就好,不一定要堅持像早期一樣執行 peforth 目錄。
執行方法: c:\Users\hcche\Documents\GitHub\peforth\peforth>python test.py
__run__.py --> 最終命名為 test.py 最自然
各種方法都試過,最後還是用 exec(open().read()) 最像 include
from . import __init__
from __init__ import ok
import subprocess; subprocess.call("__init__.py", shell=True)
exec(open("__init__.py").read()) this is like: include __init__.py
ok('\n')
[X] __main__.py 還是要用 import peforth 的,若不然一開始 open("__init__.py") 就 file not found 了。
而 test.py 當然是在對的 directory 之下才能執行,所以叫做 test.py ;-D
[x] 若要餵進 "python test.py foo bar" 執行 command line 則 test.py 就要用來分辨
是否「從 ipython, jupyternotebook 執行」 (參見 quit.f) 所以 test.py 檔名
就不能改了,要改連 quit.f 也要一起改。或者改進 quit.f 裡分辨 ipython 的方法。
\ ~~~~~~ quit.f ~~~~~~
\ When in ipython or jupyter notebook the command line is used by
\ ipython already. In jupyter notebook, it looks like:
\
\ vm.commandline ----------------------------------------------------------------------------------.
\ sys.argv[0] --------. |
\ | |
\ V V
\ --------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------
\ c:\users\hcche\appdata\local\programs\python\python36\lib\site-packages\ipykernel_launcher.py -f C:\Users\hcche\AppData\Roaming\jupyter\runtime\kernel-4be53345-1ddd-47c2-bef2-5e9801688f3f.json
\ So peforth can't support command line statements for ipython and jupyter notebook.
\ For none ipython cases, I have no better idea than to check sys.argv[0] for '.py'
\ and the likes so far 2019-05-15. See the following code, the filename 'test.py' is
\ fixed-coded here therefore.
\
[X] command line 也是跑 site-package 之外的 .f 檔的方法,例如:
c:\Users\hcche\Documents\GitHub\peforth\peforth>python test.py include ..\playground\misc.f
c:\Users\hcche\Documents\>python -m peforth include GitHub\peforth\playground\misc.f
這兩行都可以。

[x] 從 source code working directory 用 setup.py 直接 install
=========================================================
18:35 2019-05-09 我忘了 peforth 要怎麼 maintain 了!!!! 以上程式要改到哪裡去?
--> 直接在 github working directory 修改
--> 這樣 run 到的還是 installed 到 site-packages 的版本,因為 __main__.py 其實是 import peforth
c:\Users\hcche\Documents\GitHub\peforth>python peforth
16:48 2019-05-11 這個早期的 run 法如今 改成
c:\Users\hcche\Documents\GitHub\peforth\peforth> python test.py
--> 16:48 2019-05-10 奇怪 LRV2 OA 上 pip list 看到的 peforth 是 1.21!!
但是 python -m peforth 跑到的是 1.22,經過 pip uninstall peforth 之後
馬上 pip list 卻看到了 peforth 1.23 (對了)
[x] 16:38 2019-05-22 release v1.23 時在 T550 又看到類似現象: pip uninstall peforth
之後有把 python setup.py install 灌上的 v1.23 uninstall 掉,但是 site-packages 裡面一查,
仍有 v1.22 的 egg 存在 --> 直接再 pip uninstall peforth 一次,才把它 uninstall 掉。
--> pip install peforth 下來的在 site-packages 裡面就沒有 egg 字樣,如此可供分辨。同時
也證實 pip uninstall 不會 remove egg 版的 (python setup.py install上去的) 要下
多次 pip uninstall peforth 才輪得到舊版。
--> 我猜: 剛才改好程式之後用 ~\GitHub\peforth>python setup.py install 安裝進 site-package
的 1.23 並沒有蓋掉原來的, 因為這時裝上的是 egg, path 與用 whl 裝上的不同!
[X] 經過 c:\Users\hcche\Documents\GitHub\peforth>python setup.py install
之後,確實會直接有類似 pip install 的效果 --> 可以 python -m peforth 執行了,但是 path 不同
pip install 的 c:\Users\hcche\AppData\Local\Programs\Python\Python36\lib\site-packages\peforth\version.txt
setup.py 的 c:\Users\hcche\AppData\Local\Programs\Python\Python36\lib\site-packages\peforth-1.23-py3.6.egg\peforth\version.txt
[X] 用 ~\GitHub\peforth>python setup.py install 安裝進 site-package 雖然 path 不同,jupyter notebook
完全沒問題,頂多 Kernel > Restart 一下,馬上生效。完全符合我 「從 source 直接 install」 的期待,免去 pip install
或先前暴力 setup.bat 的麻煩。
結論:
1. 直接修改 GitHub source code (善用 GitHub 保障各版本安全)
2. pip uninstall peforth 把舊的清乾淨
3. c:\Users\hcche\Documents\GitHub\peforth>python setup.py install 從 source code 安裝
4. 有兩種方式執行、測試
a. 用 Jupyter Notebook 試驗,只要 Kernel > Restart 新版就生效了。
b. 執行 c:\Users\hcche\Documents\GitHub\peforth\peforth>python test.py
5. repeat
[X] 10:59 2022/10/17 新發現 https://hyp.is/lwAoFE3HEe2UxFN9MY2KjA/github.com/jupyterlab/extension-examples
install in editable mode 就是直接從 working directory install 的方法
python -m pip install -e .
Editable mode 意思 is run from the working directory directly 可以隨時改來改去生效!Try pip list and observe:

peforth 1.28 d:\github\peforth
^^^^^^^^^^^^^^^^^ <--- Wow !! this is the perfect dream come true.

[X] 2023-12-21 14:26:40 讀 https://github.com/cpacker/MemGPT?tab=readme-ov-file 又看到這個方法,成功!以下是完整的 screen dump ...

Windows PowerShell
Copyright (C) Microsoft Corporation. 著作權所有,並保留一切權利。

請嘗試新的跨平台 PowerShell https://aka.ms/pscore6

PS D:\GitHub\insightbridge\notebooks> cmd
Microsoft Windows [版本 10.0.19044.3693]
(c) Microsoft Corporation. 著作權所有,並保留一切權利。

(InsightBridge) D:\GitHub\insightbridge\notebooks>pip list | find /i "peforth"
peforth 1.27

(InsightBridge) D:\GitHub\insightbridge\notebooks>cd d:\GitHub\peforth

(InsightBridge) d:\GitHub\peforth>pip install -e .
Obtaining file:///D:/GitHub/peforth
Preparing metadata (setup.py) ... done
Installing collected packages: peforth
Attempting uninstall: peforth
Found existing installation: peforth 1.27
Uninstalling peforth-1.27:
Successfully uninstalled peforth-1.27
Running setup.py develop for peforth
Successfully installed peforth-1.28

(InsightBridge) d:\GitHub\peforth>pip list | find /i "peforth"
peforth 1.28 d:\github\peforth

(InsightBridge) d:\GitHub\peforth>

[X] 19:07 2019-05-13 這段 code 在 peforth.f 裡面本應處裡 alias 的新 // help, 但是又有問題
\
\ Redefine // to "replace" alias' help message instead of "append".
\
\ Append if last().help has stack diagram but no help message, otherewise replace.
\ Stack diagram might be unexpectedly given again. That can be resolved by putting
\ complete help message to the original word or use the trick of // dummy and then
\ // again or simply don't give it again in the alias' help message.
\
<py>
'''
m = re.match("(?P<before>.*?)(?P<stackdiagram>\(.*\))(?P<after>.*)", last().help)
if m and (m.groupdict()['before'] + m.groupdict()['after']).strip()=="":
last().help += nexttoken('\\n|\\r');
else:
last().help = nexttoken('\\n|\\r');
'''
</pyV> -indent ' // py: pop().xt=genxt("//",pop(1))

問題如下,有些東西 help 裡面的 stack diagram 不見了!!
[r Prepare an array of data to compare with rstack in selftest.
Example: [r 1,2,3 r] [d True d] [p 'word1','word2' p]
[r...r] section is optional, [d...d] section is the judge.
--> 點掉也沒用! --> 13:34 2019-05-15 misc.f 裡面的新 ( comment ) 造成的。
--> 19:15 2019-05-15 已經乾脆放棄讓 (comment) 自動進 help 了,要 help 用 // 就好了。
(comment) 直接改成 nested 的,更好。 v1.23

[X] 14:06 2019-05-15 現在覺得原來的 (comment) 沒有我 gist words4jupyter.py 的 nested (comment) 好。
何必搞個這麼難懂的 (comment) 就會了讓 stack diagram 進 last.help 而已,有 // 就夠了!
[X] 16:39 2019-05-16 本來的 // 一直想著前面有 (comment) 已經進 help 了!所以他是用 += 的,
難怪有這個問題,不要了,直接用 last().help = nexttoken('\n|\r'); 就好了。 v1.23

\ to be
code ( ( <str> -- ) // Comment down to ')' which can be nested if balanced
nextstring('\(|\)')['str'] skip TIB to the next delimiter
cc = tib[ntib] cc must be delimiter '(', ')', or '\n'
vm.ntib+=1 skip any of them
if cc=='(':
execute(_me) recursion of (
execute(_me) recursion of )
end-code immediate
\ was
code ( ( <stack diagram> -- ) Get stack diagram to the last's help.
a = nexttoken('\\)')
b = nexttoken() the ')'
if compiling and last().help=="": skip if help alreay exists
last().help = '( ' + a + b + ' '
end-code immediate
/// Nested not allowed yet.


[X] 經 marker 刪除的 value & constant 留在 vm[context] 裡面的 garbage
沒有回收! marker 還要再加強,forget 也要注意。
--> 123 value x char abc value ss vm.forth dict>keys -->
dict_keys(['CRLF', 'obj2dict', '_locals_', 'debug', 'screen-buffer',
'description', 'expected_rstack', 'expected_stack', 'test-result',
'[all-pass]', 'xxx', 'x', 'y', 'ss'])
^^^ ^^^^ 有在 vm.forth 裡面
--> 執行 marker --> words 裡沒有 x, ss 了, 當然 --> 但是 vm.forth 裡還是存在,造成堆積!!
v1.23 還是有這個問題,不知道該怎麼做。。。。
FP, see below 2020/07/27 08:38:15 value constant to 要重新定義. . . . .

[X] 改寫所有的 code words 把彆扭的 help 用新的 功能改自然點。
done! v1.23

1.17

[x] 所有 run 法帶 selftest:
[x] 改 %USERPROFILE%\Documents\GitHub\peforth\quit.f
' <selftest> :: enabled=True
[x] 直接從 GitHub folder 執行 python peforth --> .s cd help exit
[x] Run setup.bat 更新本地 pip installed 版本以供測試
[x] 1. python -i -m peforth [x] with-selftest .s words exit bye
[x] 2. ipython -i -m peforth .' Hello World!!' cr bye
[x] 3. ipython import peforth .s words
[x] selftest peforth.ok() .s words <--- w/parent
[x] 1234 bye check echo %errorlevel% <-- 從 ipython 下直接出來也無誤。
[x] 4. jupyter notebook
kernel > restart and clear outputs
import peforth
%%f 擴充、修訂一下 peforth 的行為模式,讓它認得 jupyter notebook 下的 globals. Dot . 也改寫了,適合 jupyter notebook 學習環境使用。
: unknown ( token -- thing Y|N) // Try to find the unknown token in __main__
py> getattr(sys.modules['__main__'],pop(),"Ûnknôwn")
py> str(tos())=="Ûnknôwn" if drop false else true then ;
/// here after, when FORTH come accross an unknown token, instead of alerting
/// it try to find the token in python __main__ module name space.
: . tib. ; // ( tos -- ) A better dot that also prints the entire command line
/// For experiments that need to show both question and result.
/// "" . prints the command line only, w/o the TOS.
: path-to-find-modules ( <path> -- ) // Add path to sys.path so "import module-name" can find the module
CR word trim ( "path" ) py: sys.path.append(pop()) ;
code \ print(nexttoken('\n')) end-code // Redefine \ command to print the comment line
x = 123
%f x .
x . \ ==> 123 (<class 'int'>)
[/] 考慮 README.rst 改良
[/] 若有改過 README.rst 則 wheel 就要重做
--> quit.f selftest=False --> 重來
[x] 所有 run 法不帶 selftest 跑一遍,準備要 release 的版本:
[x] 改 %USERPROFILE%\Documents\GitHub\peforth\quit.f
' <selftest> :: enabled=False
[x] Run setup.bat 直接從 GitHub folder 執行 python peforth 先確定一把 --> .s cd help exit
[x] Run setup.bat 做出取消 selftest 的 wheel
[x] pip uninstall peforth
[x] pip install peforth-xxxx.whl <== 注意!用剛做好的 wheel 否則會上網抓。
[x] 1. python -i -m peforth [x] no-selftest .s words exit
[x] 2. python -i -m peforth version 12345 bye --> echo %errorlevel%
[x] 3. python import peforth
[x] no selftest, peforth.ok() .s words <--- no parent
[x] 1234 bye check echo %errorlevel%
[x] 4. jupyter notebook --> *debug* ok> .s cd help exit
%f %%f magic command
[x] 5. repeat 以上 in ubuntu
[x] pip uninstall peforth
[x] pip install (/mnt/...the wheel) to WSL ubuntu
[x] ipython -m peforth
[x] ipython , import peforth , magic commands
[x] 直接用測過的 wheel update Pypi
繼續剛才的 setup.bat 即可,必要時: twine upload dist/*
ID, password search my Ynote with pypi _account_
--> 出錯! GFW?
HTTPError: 403 Client Error: Invalid or non-existent authentication information. for url: https://upload.pypi.org/legacy/
--> retry 看看 ... 這次就成功了!
c:\Users\hcche\Desktop\peforth-master>twine upload dist/*
Uploading distributions to https://upload.pypi.org/legacy/
Enter your username: hcchen5600
Enter your password:
Uploading peforth-1.17-py3-none-any.whl
12%|...snip....
c:\Users\hcche\Desktop\peforth-master>
--> 很奇怪,pypi.org 網頁上已經 upgraded 到 1.17 版了, WSL Ubuntu 下試過
pip uninstall peforth -> pip install peforth 也到 1.17 版了,就是
Windows DOS 下怎麼試都還是 1.16 ! 不管了,晚點再看 --> 真的過幾分鐘就好了!!
[x] version 改成 1.18 (必須跳過 1.10 會變成 1.1)
[x] test mybinder.org
[http://github.com/hcchengithub/peforth][master][notebook]
不行, 看來是 setup.py 的問題 --> see Ynote: "mybinder.org FileNotFoundErErrorno 2 No such file or directory"
--> RI: 不是 bug, setup.py 改名不要讓 mybinder.org 看到即可。
2018.12.15 這可能是為何名為 setup.py.whl 的原因,我正在研究 command line:
python setup.py install
也許就是 peforth 的 install from source 的正解。
[x] Make a master release up to GitHub --> 用 GitHub Windows 很簡單。

1.16

[x] 所有 run 法帶 selftest:
[x] 改 %USERPROFILE%\Documents\GitHub\peforth\quit.f
' <selftest> :: enabled=True
[x] 直接從 GitHub folder 執行 python peforth --> .s cd help exit
[x] Run setup.bat 更新本地 pip installed 版本以供測試
[x] 1. python -i -m peforth [x] with-selftest .s words exit bye
[/] 2. ipython -i -m peforth .' Hello World!!' cr bye --> 目前有問題
[x] 3. ipython import peforth .s words
[x] selftest peforth.ok() .s words <--- w/parent
[x] 1234 bye check echo %errorlevel% <-- 從 ipython 下直接出來也無誤。
[x] 4. jupyter notebook
import peforth
%f ." Hello FORTH!"
%%f Now we redefine the 'unknown' command that was doing nothing
: unknown ( token -- thing Y|N) // Try to find the unknown token in __main__
py> getattr(sys.modules['__main__'],pop(),"Ûnknôwn")
py> str(tos())=="Ûnknôwn" if drop false else true then ;

\ here after, when FORTH come accross an unknown token, instead of an error
\ message, it try to find the token in python __main__ module name space.
y = 'abc'
%f y . cr
%f yy . cr
[x] 考慮 README.rst 改良
[x] 若有改過 README.rst 則 wheel 就要重做
--> quit.f selftest=False --> 重來
[x] 所有 run 法不帶 selftest 跑一遍,準備要 release 的版本:
[x] 改 %USERPROFILE%\Documents\GitHub\peforth\quit.f
' <selftest> :: enabled=False
[x] Run setup.bat 直接從 GitHub folder 執行 python peforth 先確定一把 --> .s cd help exit
[x] Run setup.bat 做出取消 selftest 的 wheel
[x] pip uninstall peforth
[x] pip install peforth-xxxx.whl <== 注意!用剛做好的 wheel 否則會上網抓。
[x] 1. python -i -m peforth [x] no-selftest .s words exit
[x] 2. python -i -m peforth version 12345 bye --> echo %errorlevel%
[x] 3. python import peforth
[x] selftest peforth.ok() .s words <--- no parent
[x] 1234 bye check echo %errorlevel%
[x] 4. jupyter notebook --> .s cd help exit
%f %%f magic command
[/] 5. repeat 以上 in ubuntu
--> pip3 install (/mnt/...the wheel) to WSL ubuntu
--> use virtualenv is fine
[/] 考慮 README.rst 改良
[/] 若有改過 README.rst 則 wheel 就要重做
--> quit.f selftest=False --> 重來
[x] 直接用測過的 wheel update Pypi
twine upload dist/*
ID, password search my Ynote with pypi _account_
[x] version 改成 1.17 (必須跳過 1.10 會變成 1.1)
[x] test mybinder.org to view peforth > notebook > *.ipynb
不行, 猜測還是 _the_path_issue_ 的問題 <--- no, setup.py issue, see below.
[x] Make a master release up to GitHub --> 用 GitHub Windows 很簡單。
[x] v1.16 released

[x] (create) in peforth.f 認為當有 command line 時就不要有 reDef 警告,讓畫面清爽
且 reDef 是常態。但是到了 jupyter notebook 底下, 他一定有 command line

jupyter notebook 下
%f py> commandline.strip() tib. ==> -f C:\Users\hcche\AppData\Roaming\jupyter\runtime\kernel-17e1c697-6363-49d3-b3af-81708a468835.json (<class 'str'>)

因此 reDef 警告就都消失了也不對。因為 jupyter notebook 之下 command line 完全
無用,因此原來的判斷方法可以保持,但是要排除 jupyter notebook 的場合。

結論是 --> ('jupyter' in str(sys.modules) or not commandline.strip())

1.15

%f __main__ :> census_train['age'].head(2) . cr \ 奇怪,它怎知這 dtype 是 int64?
13:34 18/05/22 複製不出來, 上面這法都忘了怎來的了。

[x] 不認得的 words 自動到 __main__ 裡去找找看 <-- 成功了! v1.16
不認得的 words 自動到 locals 裡去找找看
不認得的 words 自動到 globals 裡去找找看
似乎 project-k 或看怎麼外掛一個序列 methods 用來處理 unknown workds
--> 執行一個 word 就叫做 unknown ( 'token' -- thing Y|n)
傳回 True 就表示處理過了,轉回 False 就表示沒處理 (default) 然則顯示
unknown 訊息。
--> 先做 __main__ 的比較簡單
: unknown py> getattr(sys.modules['__main__'],pop(),"Ûnknôwn")
py> str(tos())=='Ûnknôwn' if drop false else true then ;
// ( token -- thing Y|N) Try to find the unknown in __main__

[x] 開始 support jupyter magics 之後冒出問題,直接跑 ipython -m peforth 出 error 如下。
先進 ipython 之後再 import peforth 就沒問題。

c:\Users\hcche\Documents\GitHub>ipython -i -m peforth
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.
p e f o r t h v1.16
source code http://github.com/hcchengithub/peforth
Type 'peforth.ok()' to enter forth interpreter, 'exit' to come back.

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
c:\users\hcche\appdata\local\programs\python\python36\lib\runpy.py in run_module(mod_name, init_globals, run_name, alter_sys)
199 Returns the resulting top level namespace dictionary
200 """"""""
--> 201 mod_name, mod_spec, code = _get_module_details(mod_name)
202 if run_name is None:
203 run_name = mod_name

c:\users\hcche\appdata\local\programs\python\python36\lib\runpy.py in _get_module_details(mod_name, error)
140 try:
141 pkg_main_name = mod_name + ".__main__"
--> 142 return _get_module_details(pkg_main_name, error)
143 except error as e:
144 if mod_name not in sys.modules:

c:\users\hcche\appdata\local\programs\python\python36\lib\runpy.py in _get_module_details(mod_name, error)
107 Try importing the parent to avoid catching initialization errors
108 try:
--> 109 __import__(pkg_name)
110 except ImportError as e:
111 If the parent or higher ancestor package is missing, let the

c:\Users\hcche\Documents\GitHub\peforth\__init__.py in <module>()
166 Define peforth magic command, %f.
167 register_line_cell_magic
--> 168 def f(line, cell=None):
169 if cell is None:
170 vm.dictate(line)

c:\users\hcche\appdata\local\programs\python\python36\lib\site-packages\IPython\core\magic.py in magic_deco(arg)
227 break
228 else:
--> 229 raise NameError('Decorator can only run in context where '
230 '`get_ipython` exists')
231

NameError: Decorator can only run in context where `get_ipython` exists
c:\users\hcche\appdata\local\programs\python\python36\lib\site-packages\IPython\core\interactiveshell.py:2598: UserWarning: Unknown failure executing module: <peforth>
warn('Unknown failure executing module: <%s>' % mod_name)

[x] ipython -m peforth 會出問題,可能是因為 get_ipython 當時還沒有 ready <-- 對
NameError: Decorator can only run in context where `get_ipython` exists
c:\users\hcche\appdata\local\programs\python\python36\lib\site-packages\IPython\core\interactiveshell.py:2598: UserWarning: Unknown failure executing module: <peforth>
warn('Unknown failure executing module: <%s>' % mod_name)
只要進了 ipython command prompt or jupyter notebook 都沒問題
In [2]: 'get_ipython' in globals()
Out[2]: True
--> 用對的方法檢查 ipython magic 存不存在即可,以上 error message 提供了線索
查看 python token 是否 defined 必須用 try-except:
try:
flag = "InteractiveShell" in str(get_ipython)
except:
flag = False

if flag:
from IPython.core.magic import register_line_cell_magic
... snip ....

注意, 解掉問題之後,如今:
1. jupyter notebook 完全沒問題。
2. 用 ipython -i -m peforth 跑起來的,exit 到 ipython 不認得 magic commands:
In [1]: %f
UsageError: Line magic function `%f` not found.
3. 先進 ipython 然後 import peforth 的才認得 magic commands.

Page 1 of 3

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.