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.
Files changed (24) hide show
  1. {chemql_python-1.0.1 → chemql_python-1.0.2}/PKG-INFO +1 -1
  2. {chemql_python-1.0.1 → chemql_python-1.0.2}/pyproject.toml +1 -1
  3. {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql/__init__.py +48 -33
  4. {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql_python.egg-info/PKG-INFO +1 -1
  5. {chemql_python-1.0.1 → chemql_python-1.0.2}/LICENSE +0 -0
  6. {chemql_python-1.0.1 → chemql_python-1.0.2}/README.md +0 -0
  7. {chemql_python-1.0.1 → chemql_python-1.0.2}/setup.cfg +0 -0
  8. {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql/__main__.py +0 -0
  9. {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql/data/BondEnergies.json +0 -0
  10. {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql/data/MoleculeBonds.json +0 -0
  11. {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql/data/Molecules.json +0 -0
  12. {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql/data/PeriodicTableJSON.json +0 -0
  13. {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql/data/Reactions.json +0 -0
  14. {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql/data/THIRD_PARTY_LICENSES/PeriodicTableJSON.txt +0 -0
  15. {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql/data/THIRD_PARTY_LICENSES/RHEA.txt +0 -0
  16. {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql/html/periodic_table.html +0 -0
  17. {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql_python.egg-info/SOURCES.txt +0 -0
  18. {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql_python.egg-info/dependency_links.txt +0 -0
  19. {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql_python.egg-info/entry_points.txt +0 -0
  20. {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql_python.egg-info/requires.txt +0 -0
  21. {chemql_python-1.0.1 → chemql_python-1.0.2}/src/chemql_python.egg-info/top_level.txt +0 -0
  22. {chemql_python-1.0.1 → chemql_python-1.0.2}/tests/test_external_molecule_lookup.py +0 -0
  23. {chemql_python-1.0.1 → chemql_python-1.0.2}/tests/test_public_api.py +0 -0
  24. {chemql_python-1.0.1 → chemql_python-1.0.2}/tests/test_reactions.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chemql-python
3
- Version: 1.0.1
3
+ Version: 1.0.2
4
4
  Summary: A chemistry-focused query language and REPL
5
5
  Author-email: Mohammad Rakibul Islam <rakibulofficial1017@gmail.com>
6
6
  Requires-Python: >=3.10
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "chemql-python"
7
- version = "1.0.1"
7
+ version = "1.0.2"
8
8
  authors = [
9
9
  { name = "Mohammad Rakibul Islam", email = "rakibulofficial1017@gmail.com" }
10
10
  ]
@@ -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
- _shell_process = subprocess.Popen(
52
- ["bash", "--noprofile", "--norc"],
53
- stdin=subprocess.PIPE,
54
- stdout=subprocess.PIPE,
55
- stderr=subprocess.STDOUT,
56
- text=True,
57
- bufsize=1,
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
- shell.stdin.write(command + "\n") #type:ignore
70
- shell.stdin.write( #type:ignore
71
- f"printf '\\n%s:%s\\n' '{marker}' \"$?\"\n"
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
- break
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 line.startswith(marker + ":"):
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
- result = "\n".join(output)
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="1.0.1",
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()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chemql-python
3
- Version: 1.0.1
3
+ Version: 1.0.2
4
4
  Summary: A chemistry-focused query language and REPL
5
5
  Author-email: Mohammad Rakibul Islam <rakibulofficial1017@gmail.com>
6
6
  Requires-Python: >=3.10
File without changes
File without changes
File without changes