chemql-python 1.0.1__tar.gz → 1.0.2__tar.gz
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.
- {chemql_python-1.0.1 → chemql_python-1.0.2}/PKG-INFO +1 -1
- {chemql_python-1.0.1 → chemql_python-1.0.2}/pyproject.toml +1 -1
- {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql/__init__.py +48 -33
- {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql_python.egg-info/PKG-INFO +1 -1
- {chemql_python-1.0.1 → chemql_python-1.0.2}/LICENSE +0 -0
- {chemql_python-1.0.1 → chemql_python-1.0.2}/README.md +0 -0
- {chemql_python-1.0.1 → chemql_python-1.0.2}/setup.cfg +0 -0
- {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql/__main__.py +0 -0
- {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql/data/BondEnergies.json +0 -0
- {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql/data/MoleculeBonds.json +0 -0
- {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql/data/Molecules.json +0 -0
- {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql/data/PeriodicTableJSON.json +0 -0
- {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql/data/Reactions.json +0 -0
- {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql/data/THIRD_PARTY_LICENSES/PeriodicTableJSON.txt +0 -0
- {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql/data/THIRD_PARTY_LICENSES/RHEA.txt +0 -0
- {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql/html/periodic_table.html +0 -0
- {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql_python.egg-info/SOURCES.txt +0 -0
- {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql_python.egg-info/dependency_links.txt +0 -0
- {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql_python.egg-info/entry_points.txt +0 -0
- {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql_python.egg-info/requires.txt +0 -0
- {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql_python.egg-info/top_level.txt +0 -0
- {chemql_python-1.0.1 → chemql_python-1.0.2}/tests/test_external_molecule_lookup.py +0 -0
- {chemql_python-1.0.1 → chemql_python-1.0.2}/tests/test_public_api.py +0 -0
- {chemql_python-1.0.1 → chemql_python-1.0.2}/tests/test_reactions.py +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import math
|
|
3
3
|
import shlex
|
|
4
|
+
import os
|
|
4
5
|
import re
|
|
5
6
|
import ast
|
|
6
7
|
import argparse
|
|
@@ -36,73 +37,82 @@ __all__ = [
|
|
|
36
37
|
"search",
|
|
37
38
|
"union",
|
|
38
39
|
"intersection",
|
|
40
|
+
"__version__"
|
|
39
41
|
]
|
|
40
42
|
|
|
43
|
+
__version__ = "1.0.2"
|
|
41
44
|
|
|
42
45
|
|
|
43
46
|
_shell_process = None
|
|
44
47
|
|
|
45
48
|
|
|
46
49
|
def get_shell():
|
|
47
|
-
"""Start Bash once and reuse the same session."""
|
|
48
50
|
global _shell_process
|
|
49
51
|
|
|
50
52
|
if _shell_process is None or _shell_process.poll() is not None:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
if os.name == "nt":
|
|
54
|
+
_shell_process = subprocess.Popen(
|
|
55
|
+
["cmd.exe", "/D", "/Q", "/K", "prompt $S"],
|
|
56
|
+
stdin=subprocess.PIPE,
|
|
57
|
+
stdout=subprocess.PIPE,
|
|
58
|
+
stderr=subprocess.STDOUT,
|
|
59
|
+
text=True,
|
|
60
|
+
bufsize=1,
|
|
61
|
+
)
|
|
62
|
+
else:
|
|
63
|
+
_shell_process = subprocess.Popen(
|
|
64
|
+
["bash", "--noprofile", "--norc"],
|
|
65
|
+
stdin=subprocess.PIPE,
|
|
66
|
+
stdout=subprocess.PIPE,
|
|
67
|
+
stderr=subprocess.STDOUT,
|
|
68
|
+
text=True,
|
|
69
|
+
bufsize=1,
|
|
70
|
+
)
|
|
59
71
|
|
|
60
72
|
return _shell_process
|
|
61
73
|
|
|
62
74
|
|
|
63
75
|
def run_shell_command(command):
|
|
64
|
-
"""Run a command in the persistent Bash session."""
|
|
65
76
|
shell = get_shell()
|
|
77
|
+
|
|
78
|
+
command = command.replace("\r\n", "\n").replace("\r", "\n").rstrip("\n")
|
|
66
79
|
marker = f"__CHEMQL_END_{uuid.uuid4().hex}__"
|
|
67
80
|
|
|
68
81
|
try:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
82
|
+
if os.name == "nt":
|
|
83
|
+
# Run the command, then print a unique completion marker.
|
|
84
|
+
shell.stdin.write(
|
|
85
|
+
f"{command}\r\n"
|
|
86
|
+
f"echo {marker}\r\n"
|
|
87
|
+
)
|
|
88
|
+
else:
|
|
89
|
+
shell.stdin.write( #type:ignore
|
|
90
|
+
f"{command}\n"
|
|
91
|
+
f"printf '\\n%s\\n' '{marker}'\n"
|
|
92
|
+
)
|
|
93
|
+
|
|
73
94
|
shell.stdin.flush() #type:ignore
|
|
74
95
|
|
|
75
96
|
output = []
|
|
76
|
-
exit_code = None
|
|
77
97
|
|
|
78
98
|
while True:
|
|
79
99
|
line = shell.stdout.readline() #type:ignore
|
|
80
100
|
|
|
81
101
|
if not line:
|
|
82
|
-
|
|
102
|
+
return "\n".join(output) or "Shell session terminated."
|
|
83
103
|
|
|
84
|
-
line = line.rstrip("\n")
|
|
104
|
+
line = line.rstrip("\r\n")
|
|
85
105
|
|
|
86
|
-
if
|
|
87
|
-
exit_code = int(line[len(marker) + 1:])
|
|
106
|
+
if marker in line:
|
|
88
107
|
break
|
|
89
108
|
|
|
90
109
|
output.append(line)
|
|
91
110
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if exit_code is None:
|
|
95
|
-
return result or "Shell session terminated."
|
|
96
|
-
|
|
97
|
-
if exit_code != 0 and not result:
|
|
98
|
-
return f"Command exited with status {exit_code}"
|
|
99
|
-
|
|
100
|
-
return result
|
|
111
|
+
return "\n".join(output).strip()
|
|
101
112
|
|
|
102
113
|
except (BrokenPipeError, OSError) as exc:
|
|
103
114
|
return f"Shell error: {exc}"
|
|
104
115
|
|
|
105
|
-
|
|
106
116
|
def close_shell():
|
|
107
117
|
"""Clean up the persistent shell on exit."""
|
|
108
118
|
global _shell_process
|
|
@@ -2533,6 +2543,9 @@ def execute(arguments, query_text=None, positions=None):
|
|
|
2533
2543
|
if arguments[0].lower() == "sorry":
|
|
2534
2544
|
return "\033[34mIt's ok, everybody makes mistakes👌\033[0m"
|
|
2535
2545
|
|
|
2546
|
+
if arguments[0].lower() == "version":
|
|
2547
|
+
return __version__
|
|
2548
|
+
|
|
2536
2549
|
if arguments[0] == "conditions":
|
|
2537
2550
|
if len(arguments) != 1:
|
|
2538
2551
|
return "Usage: conditions"
|
|
@@ -3117,7 +3130,7 @@ class ChemqlLexer(Lexer):
|
|
|
3117
3130
|
first_word = words[0] if words else ""
|
|
3118
3131
|
|
|
3119
3132
|
# search / source / list / return / clear / exit
|
|
3120
|
-
if first_word in {"search", "source", "list", "clear", "exit", "findel", "findmol", "findre", "set", "add", "remove", "react", "balance", "conditions", "view", "help", "dump"}:
|
|
3133
|
+
if first_word in {"search", "source", "list", "clear", "exit", "findel", "findmol", "findre", "set", "add", "remove", "react", "balance", "conditions", "view", "help", "dump", "version"}:
|
|
3121
3134
|
command_start = line.find(first_word)
|
|
3122
3135
|
command_end = command_start + len(first_word)
|
|
3123
3136
|
|
|
@@ -3365,7 +3378,7 @@ class ChemqlCompleter(Completer):
|
|
|
3365
3378
|
commands = (
|
|
3366
3379
|
"search", "source", "list", "clear", "return", "exit",
|
|
3367
3380
|
"findel", "findmol", "findre", "set", "add", "remove",
|
|
3368
|
-
"react", "balance", "conditions",
|
|
3381
|
+
"react", "balance", "conditions", "version", "help", "view"
|
|
3369
3382
|
)
|
|
3370
3383
|
|
|
3371
3384
|
if not command_words:
|
|
@@ -3582,7 +3595,7 @@ def main():
|
|
|
3582
3595
|
"-v",
|
|
3583
3596
|
"--version",
|
|
3584
3597
|
action="version",
|
|
3585
|
-
version=
|
|
3598
|
+
version=__version__,
|
|
3586
3599
|
)
|
|
3587
3600
|
|
|
3588
3601
|
|
|
@@ -3604,7 +3617,9 @@ def main():
|
|
|
3604
3617
|
)
|
|
3605
3618
|
sys.exit(upgrade_package(version_target))
|
|
3606
3619
|
|
|
3607
|
-
|
|
3620
|
+
if args.command is not None:
|
|
3621
|
+
process_lines(args.command.splitlines())
|
|
3622
|
+
return
|
|
3608
3623
|
elif args.file:
|
|
3609
3624
|
with open(args.file) as f:
|
|
3610
3625
|
code = f.read()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|