asp-chef-cli 0.4.20__tar.gz → 0.4.22__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: asp-chef-cli
3
- Version: 0.4.20
3
+ Version: 0.4.22
4
4
  Summary: A simple CLI to run ASP Chef recipes
5
5
  Author: Mario Alviano
6
6
  Author-email: mario.alviano@gmail.com
@@ -158,6 +158,7 @@ async def _(json):
158
158
  cmd.append("--enumerate")
159
159
  pyqasp_process[uuid] = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
160
160
  out, err = pyqasp_process[uuid].communicate(program.encode())
161
+ timeout_reached: Final = pyqasp_process[uuid].returncode == 124
161
162
  pyqasp_process[uuid] = None
162
163
 
163
164
  # report errors
@@ -165,6 +166,8 @@ async def _(json):
165
166
  lines = output.split('\n')
166
167
  if any(line.startswith("Error") for line in lines):
167
168
  raise ValueError(output)
169
+ if timeout_reached:
170
+ lines = [line for line in lines if not line.startswith("Sig term")]
168
171
 
169
172
  # return models
170
173
  models = [
@@ -174,6 +177,52 @@ async def _(json):
174
177
  return {"models": models}
175
178
 
176
179
 
180
+ casper_process: Final[Dict[str, Optional[subprocess.Popen]]] = defaultdict(lambda: None)
181
+ casper_path: Final[str | None] = shutil.which("casper")
182
+
183
+
184
+ def casper_terminate(uuid):
185
+ if casper_process[uuid] is not None:
186
+ casper_process[uuid].kill()
187
+
188
+
189
+ @endpoint(router, "/casper/")
190
+ async def _(json):
191
+ global casper_process
192
+
193
+ uuid = json["uuid"]
194
+ program = json["program"]
195
+ enumerate = json["enumerate"]
196
+ timeout = json["timeout"]
197
+ if type(timeout) is not int or timeout < 1 or timeout >= 24 * 60 * 60:
198
+ timeout = 5
199
+
200
+ casper_terminate(uuid)
201
+
202
+ cmd = ["/bin/timeout", str(timeout), casper_path, "--problem", "/dev/stdin", "--json"]
203
+ if enumerate:
204
+ cmd.append("-n0")
205
+ casper_process[uuid] = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
206
+ out, err = casper_process[uuid].communicate(program.encode())
207
+ timeout_reached: Final = pyqasp_process[uuid].returncode == 124
208
+ casper_process[uuid] = None
209
+
210
+ # report errors
211
+ output = out.decode()
212
+ lines = output.split('\n')
213
+ if any(line.startswith("Error") for line in lines):
214
+ raise ValueError(output)
215
+ if timeout_reached:
216
+ lines = [line for line in lines if not line.startswith("Sig term")]
217
+
218
+ # return models
219
+ models = [
220
+ [lit for lit in json_module.loads(line)['literals'] if not lit.startswith('not ')]
221
+ for line in lines if line
222
+ ]
223
+ return {"models": models}
224
+
225
+
177
226
  @endpoint(router, "/template/core-template/")
178
227
  async def _(json):
179
228
  if not json:
@@ -215,4 +264,4 @@ async def _(json):
215
264
  "program": str(templates[key].program)
216
265
  })
217
266
 
218
- return res
267
+ return res
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "asp-chef-cli"
3
- version = "0.4.20"
3
+ version = "0.4.22"
4
4
  description = "A simple CLI to run ASP Chef recipes"
5
5
  authors = ["Mario Alviano <mario.alviano@gmail.com>"]
6
6
  readme = "README.md"
File without changes
File without changes