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