pystacker 1.0.3__py3.10.egg → 1.1.0__py3.10.egg

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
EGG-INFO/PKG-INFO CHANGED
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pystacker
3
- Version: 1.0.3
3
+ Version: 1.1.0
4
4
  Summary: Stacker: RPN Calculator in Python
5
5
  Home-page: https://github.com/remokasu/stacker
6
6
  Author: remokasu
@@ -42,44 +42,22 @@ License-File: LICENSE
42
42
  ~~~
43
43
 
44
44
 
45
- # Download & Install
45
+ # Install
46
46
 
47
47
  If you don't have Python 3 installed, please install it beforehand.
48
48
  Here are the installation instructions for `stacker`:
49
49
 
50
- 1. Download
50
+ 1. Install
51
51
  ~~~ bash
52
- > git clone git@github.com:remokasu/stacker.git
53
- ~~~
54
-
55
- 2. Install dependencies
56
- ~~~
57
- pip install setuptools
58
- ~~~
59
-
60
- * For Windows users only
61
- ~~~ bash
62
- > pip install pyreadline
52
+ > pip install pystacker
63
53
  ~~~
64
54
 
65
- 3. Run the program without installation
66
- ~~~ bash
67
- > cd stacker/stacker
68
- > python stacker.py
55
+ 2. Run the program
69
56
  ~~~
70
-
71
- 4. (Or) Install and run the program
72
- ~~~ bash
73
- cd stacker
74
- > python setup.py install
75
57
  > stacker
76
58
  ~~~
77
59
 
78
- * When you're done playing with it, uninstall
79
- ~~~ bash
80
- > pip uninstall stacker
81
- ~~~
82
-
60
+ # Usage
83
61
 
84
62
  | Operator | Description | Example | Result |
85
63
  |----------|-------------------------------------------------------|----------------------------|--------------------------|
@@ -133,8 +111,13 @@ cd stacker
133
111
  | random | Generate a random floating-point number between 0 and 1| `random` | random.random() |
134
112
  | randint | Generate a random integer within a specified range | `1 6 randint` | random.randint(1, 6) |
135
113
  | uniform | Generate a random floating-point number within a specified range | `1 2 uniform` | random.uniform(1, 2) |
136
- | d | Roll dice (e.g., 3d6) | `3 6 d` | sum(random.randint(1, 6) for _ in range(3)) |
137
-
114
+ | dice | Roll dice (e.g., 3d6) | `3 6 dice` | sum(random.randint(1, 6) for _ in range(3)) |
115
+ | delete | Remove the element at the specified index | `2 delete` | Remove the element at index 2 from the stack |
116
+ | pluck | Remove the element at the specified index and move it to the top of the stack | `2 pluck` | Remove the element at index 2 and move it to the top of the stack |
117
+ | pick | Copy the element at the specified index to the top of the stack | `2 pick` | Copy the element at index 2 to the top of the stack |
118
+ | pop | Remove the top element from the stack | `pop` | Remove the top element from the stack |
119
+ | exec | Execute the specified Python code | `'print(1+1)' exec` | Execute 1+1 and print 2 |
120
+ | eval | Evaluate the specified Python expression | `'1+1' eval` | Add 2 to the stack |
138
121
 
139
122
  <hr>
140
123
 
@@ -190,6 +173,22 @@ Display usage instructions with `help`
190
173
  stacker:0> help
191
174
  ~~~
192
175
 
176
+ # Acknowledgments
177
+ Stacker makes use of the features provided by the Python Prompt Toolkit. We would like to express our gratitude to the developers and contributors of the Python Prompt Toolkit for their excellent work.
178
+
179
+ ## License for Python Prompt Toolkit:
180
+
181
+ The Python Prompt Toolkit is released under the BSD-3-Clause License. The full license text can be found in the LICENSE file of the Python Prompt Toolkit repository, or at the following URL: https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/LICENSE
182
+
183
+ Below is a summary of the main terms of the BSD-3-Clause License:
184
+
185
+ Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
186
+
187
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution.
188
+
189
+ Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
190
+
191
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
193
192
 
194
193
  <br>
195
194
  <hr>
@@ -271,20 +270,16 @@ python3が無ければ事前にインストールしてください。
271
270
  ~~~
272
271
 
273
272
  2. 起動
274
- ~~~
273
+ ~~~bash
275
274
  > stacker
276
275
  ~~~
277
276
 
278
- * windowsの場合の場合、追加で実行
279
- ~~~ bash
280
- > pip install pyreadline
281
- ~~~
282
-
283
277
  * 遊び終わったら削除しましょう
284
278
  ~~~ bash
285
279
  > pip uninstall pystacker
286
280
  ~~~
287
281
 
282
+
288
283
  # 使い方
289
284
 
290
285
  | 演算子 | 説明 | 使い方 | 結果 |
@@ -339,9 +334,13 @@ python3が無ければ事前にインストールしてください。
339
334
  | random | 0と1の間の乱数を生成 | random | random.random() |
340
335
  | randint| 指定した範囲内の整数乱数を生成 | 1 6 randint | random.randint(1, 6) |
341
336
  | uniform| 指定した範囲内の浮動小数点数乱数を生成 | 1 2 uniform | random.uniform(1, 2) |
342
- | d | サイコロを振る (例:3d6) | 3 6 d | sum(random.randint(1, 6) for _ in range(3)) |
343
-
344
-
337
+ | dice | サイコロを振る (例:3d6) | 3 6 dice | sum(random.randint(1, 6) for _ in range(3)) |
338
+ | delete | 指定のindexを削除 | `2 delete` | スタックからindex 2の要素を削除 |
339
+ | pluck | 指定のindexを削除し、スタックのトップに移動 | `2 pluck` | index 2の要素を削除し、スタックのトップに移動 |
340
+ | pick | 指定されたインデックスの要素をスタックのトップにコピー | `2 pick` | index 2の要素をスタックのトップにコピー |
341
+ | pop | スタックのトップを削除 | `pop` | スタックのトップを削除 |
342
+ | exec | 指定のPythonコードを実行 | `'print(1+1)' exec` | 1+1を出力し、2をプリント |
343
+ | eval | 指定のPython式を評価 | `'1+1' eval` | スタックに2を追加 |
345
344
  <br>
346
345
  <hr>
347
346
 
@@ -415,7 +414,7 @@ stacker:1>
415
414
  ただし、execはどんな処理でも結果が`None`なので結果はスタックに入らない。
416
415
  結果を表示したければptint文を式中に埋め込もう。
417
416
  文字列に対して`exec`することでPythonの処理として実行できる。
418
- この機能、危険な香りがしますね。
417
+
419
418
  ~~~
420
419
  stacker:0> '
421
420
  stacker:0> def f(x):
@@ -428,7 +427,7 @@ stacker:7> exec
428
427
  []
429
428
  ~~~
430
429
 
431
- ・面倒くさいので以後はこうしましょうね。
430
+ ・面倒くさいので以後はStackerからPythonを起動しましょう。
432
431
  ~~~
433
432
  stacker:10> '
434
433
  stacker:10> from subprocess import run
@@ -440,7 +439,3 @@ Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux
440
439
  Type "help", "copyright", "credits" or "license" for more information.
441
440
  >>>
442
441
  ~~~
443
-
444
- <br>
445
- <hr>
446
-
EGG-INFO/SOURCES.txt CHANGED
@@ -11,5 +11,6 @@ stacker/__init__.py
11
11
  stacker/stacker.py
12
12
  stacker/test.py
13
13
  stacker/data/about.txt
14
+ stacker/data/help-jp.txt
14
15
  stacker/data/help.txt
15
16
  stacker/data/top.txt
Binary file
@@ -0,0 +1,78 @@
1
+ RPN式を入力し、変数の代入、または関数の定義を行ってください。
2
+ 'exit'と入力すると終了します。
3
+
4
+ 例:
5
+ RPN式: 3 4 +
6
+ 変数の代入: x = 5
7
+ 関数の定義: x y func => x y *
8
+ 関数の呼び出し: 4 5 func
9
+
10
+ サポートされている演算子と関数:
11
+ == 等しい
12
+ != 等しくない
13
+ < より小さい
14
+ <= 以下
15
+ > より大きい
16
+ >= 以上
17
+ and 論理積
18
+ or 論理和
19
+ not 否定
20
+ band ビット毎のAND
21
+ bor ビット毎のOR
22
+ bxor ビット毎のXOR
23
+ + 加算
24
+ - 減算
25
+ * 乗算
26
+ / 除算
27
+ // 整数除算
28
+ % 剰余
29
+ ^ べき乗
30
+ gcd 最大公約数
31
+ lcm 最小公倍数
32
+ neg 符号反転
33
+ abs 絶対値
34
+ exp 指数関数
35
+ log 自然対数
36
+ log10 底が10の対数
37
+ log2 底が2の対数
38
+ sin 正弦関数
39
+ cos 余弦関数
40
+ tan 正接関数
41
+ asin アークサイン
42
+ acos アークコサイン
43
+ atan アークタンジェント
44
+ sinh 双曲線正弦
45
+ cosh 双曲線余弦
46
+ tanh 双曲線正接
47
+ asinh 双曲線正弦の逆関数
48
+ acosh 双曲線余弦の逆関数
49
+ atanh 双曲線正接の逆関数
50
+ sqrt 平方根
51
+ radians 度数からラジアンに変換
52
+ ! 階乗
53
+ cbrt 立方根
54
+ ncr 組み合わせ (nCr)
55
+ npr 順列 (nPr)
56
+ float 整数を浮動小数点数に変換
57
+ int 浮動小数点数を整数に変換
58
+ ceil 切り上げ
59
+ floor 切り捨て
60
+ round 四捨五入
61
+ roundn 任意の桁数で丸める
62
+ random 0から1までの範囲でランダムな浮動小数点数を生成
63
+ randint 指定された範囲でランダムな整数を生成
64
+ uniform 指定された範囲でランダムな浮動小数点数を生成
65
+ dice ダイスロー (例: 3d6)
66
+ delete 指定したインデックスのアイテムをスタックから削除
67
+ pluck 指定したインデックスのアイテムをスタックから削除し、トップに移動
68
+ pick 指定したインデックスのアイテムをスタックからコピーしてトップに配置
69
+ pop スタックからアイテムを取り除く
70
+ exec 指定したPythonコードを実行
71
+ eval 指定したPython式を評価
72
+
73
+ 使い方:
74
+ RPN表記で数字と演算子を入力し、スペースで区切ります。
75
+ Enterキーを押すと、式が評価され、結果が表示されます。
76
+ 結果はスタックにプッシュされます。
77
+ 結果を後続の計算で使用するには、次の式を入力します。
78
+ スタックをクリアするには、'clear'と入力します。
stacker/data/help.txt CHANGED
@@ -8,19 +8,67 @@ Examples:
8
8
  Function call: 4 5 func
9
9
 
10
10
  Supported operators and functions:
11
- Arithmetic: +, -, *, /, //, %, ^, neg, abs
12
- Comparison: ==, !=, <, <=, >, >=
13
- Logical: and, or, not
14
- Bitwise: band, bor, bxor
15
- Math functions:
16
- exp, log, log10, log2, sin, cos, tan, asin, acos, atan,
17
- sinh, cosh, tanh, asinh, acosh, atanh, sqrt, cbrt,
18
- ceil, floor, round, roundn, random, randint, uniform, d,
19
- ncr((nCr)), npr(nPr)
20
-
21
- Type conversion: int2float, float2int
22
- Factorial: !
23
- GCD: gcd
11
+ == Equal
12
+ != Not equal
13
+ < Less than
14
+ <= Less than or equal to
15
+ > Greater than
16
+ >= Greater than or equal to
17
+ and Logical AND
18
+ or Logical OR
19
+ not Logical NOT
20
+ band Bitwise AND
21
+ bor Bitwise OR
22
+ bxor Bitwise XOR
23
+ + Addition
24
+ - Subtraction
25
+ * Multiplication
26
+ / Division
27
+ // Integer division
28
+ % Modulus
29
+ ^ Exponentiation
30
+ gcd Greatest common divisor
31
+ lcm Least common multiple
32
+ neg Negation
33
+ abs Absolute value
34
+ exp Exponential function
35
+ log Natural logarithm
36
+ log10 Base 10 logarithm
37
+ log2 Base 2 logarithm
38
+ sin Sine
39
+ cos Cosine
40
+ tan Tangent
41
+ asin Arcsine
42
+ acos Arccosine
43
+ atan Arctangent
44
+ sinh Hyperbolic sine
45
+ cosh Hyperbolic cosine
46
+ tanh Hyperbolic tangent
47
+ asinh Inverse hyperbolic sine
48
+ acosh Inverse hyperbolic cosine
49
+ atanh Inverse hyperbolic tangent
50
+ sqrt Square root
51
+ radians Convert degrees to radians
52
+ ! Factorial
53
+ cbrt Cube root
54
+ ncr Combinations (nCr)
55
+ npr Permutations (nPr)
56
+ float Convert integer to floating-point number
57
+ int Convert floating-point number to integer
58
+ ceil Ceiling (smallest integer greater than or equal to the number)
59
+ floor Floor (largest integer less than or equal to the number)
60
+ round Round to the nearest integer
61
+ roundn Round to a specified number of decimal places
62
+ random Generate a random floating-point number between 0 and 1
63
+ randint Generate a random integer in the specified range
64
+ uniform Generate a random floating-point number in the specified range
65
+ dice Dice roll (e.g., 3d6)
66
+ delete Remove an item from the stack at the specified index
67
+ pluck Remove an item from the stack at the specified index and move it to the top
68
+ pick Copy an item from the specified index to the top of the stack
69
+ pop Pop an item from the stack
70
+ exec Execute specified Python code
71
+ eval Evaluate specified Python expression
24
72
 
25
73
  Usage:
26
74
  Input numbers and operators in RPN notation, separated by spaces.
stacker/stacker.py CHANGED
@@ -77,6 +77,12 @@ def show_help():
77
77
  print(message)
78
78
 
79
79
 
80
+ def show_help_jp():
81
+ with pkg_resources.resource_stream(__name__, "data/help-jp.txt") as f:
82
+ message = f.read().decode('utf-8')
83
+ print(message)
84
+
85
+
80
86
  def delete_history():
81
87
  if history_file_path.exists():
82
88
  history_file_path.unlink()
@@ -198,7 +204,7 @@ class Stacker:
198
204
  "random": (lambda: random.random()), # 0から1までの範囲でランダムな浮動小数点数を生成
199
205
  "randint": (lambda x1, x2: random.randint(int(x1), int(x2))), # 指定された範囲でランダムな整数を生成
200
206
  "uniform": (lambda x1, x2: random.uniform(x1, x2)), # 指定された範囲でランダムな浮動小数点数を生成
201
- "d": (lambda num_dice, num_faces: sum(random.randint(1, int(num_faces)) for _ in range(int(num_dice)))), # ダイスロール(例 3d6)
207
+ "dice": (lambda num_dice, num_faces: sum(random.randint(1, int(num_faces)) for _ in range(int(num_dice)))), # ダイスロール(例 3d6)
202
208
  "delete": (lambda index: self.stack.pop(index)), # 指定のindexを削除
203
209
  "pluck": (lambda index: self.stack.pop(index)), # 指定のindexを削除し、スタックのトップに移動
204
210
  "pick": (lambda index: self.stack.append((self.stack[index]))), # 指定されたインデックスの要素をスタックのトップにコピー
@@ -216,7 +222,7 @@ class Stacker:
216
222
  "nan": math.nan,
217
223
  }
218
224
  self.functions = {}
219
- self.reserved_word = ["help", "about", "exit", "delete_history"]
225
+ self.reserved_word = ["help", "help-jp", "about", "exit", "delete_history", "last_pop"]
220
226
 
221
227
  # def get_operators_with_n_args(self, n: int):
222
228
  # # 任意の引数の数に対応する演算子の一覧を取得
@@ -429,7 +435,11 @@ class InteractiveMode(ExecutionMode):
429
435
  (expression.startswith('"') and expression.count('"') % 2 != 0) or
430
436
  (expression.startswith("'") and expression.count("'") % 2 != 0)
431
437
  ):
432
- next_line = input(f"stacker:{line_count}> ")
438
+ next_line = prompt(
439
+ f"stacker:{line_count}> ",
440
+ history=FileHistory(history_file_path),
441
+ completer=self.completer,
442
+ )
433
443
  expression += "\n" + next_line
434
444
 
435
445
  if expression.lower() == "exit":
@@ -437,6 +447,9 @@ class InteractiveMode(ExecutionMode):
437
447
  if expression.lower() == "help":
438
448
  show_help()
439
449
  continue
450
+ if expression.lower() == "help-jp":
451
+ show_help_jp()
452
+ continue
440
453
  if expression.lower() == "about":
441
454
  show_about()
442
455
  continue