Skip to content

Commit 5513f41

Browse files
committed
add posix shell string split and update license date
1 parent 32f0537 commit 5513f41

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2022~2023 yodeng <[email protected]>
3+
Copyright (c) 2023~2024 yodeng <[email protected]>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

src/dag.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,13 @@ def reset_graph(self):
124124
def ind_nodes(self, graph=None):
125125
if graph is None:
126126
graph = self.graph
127-
dependent_nodes = set(
128-
node for dependents in graph.values() for node in dependents
129-
)
130-
return [node for node in graph.keys() if node not in dependent_nodes]
127+
nodes2 = set(n2 for n2s in graph.values() for n2 in n2s)
128+
return [n1 for n1 in graph.keys() if n1 not in nodes2]
129+
130+
def end_nodes(self, graph=None):
131+
if graph is None:
132+
graph = self.graph
133+
return [n1 for n1, n2 in graph.items() if not n2]
131134

132135
def validate(self, graph=None):
133136
graph = graph if graph is not None else self.graph
@@ -197,3 +200,5 @@ def dot(self):
197200

198201
def __str__(self):
199202
return self.dot()
203+
204+
__repr__ = __str__

src/job.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import re
66
import sys
7+
import shlex
78
import getpass
89
import tempfile
910

@@ -282,7 +283,7 @@ def from_cmd(self, sgefile, linenum=None, cmd=None):
282283
if re.search("\s+//", cmd) or re.search("//\s+", cmd):
283284
self.rawstring = cmd.rsplit("//", 1)[0].strip()
284285
try:
285-
argstring = cmd.rsplit("//", 1)[1].strip().split()
286+
argstring = shlex.split(cmd.rsplit("//", 1)[1].strip())
286287
args = shell_job_parser(argstring)
287288
for i in ['force', 'local', 'max_timeout_retry', 'workdir', 'jobname',
288289
'groups', 'mode', 'queue', 'memory', 'cpu', 'out_maping']:
@@ -320,7 +321,7 @@ def from_cmd(self, sgefile, linenum=None, cmd=None):
320321
"_", 1)[0] + "_%d_%05d" % (os.getpid(), self.linenum)
321322
return self
322323

323-
def forceToLocal(self, jobname="", removelog=False):
324+
def to_local(self, jobname="", removelog=False):
324325
self.host = "localhost"
325326
self.name = self.jobname = jobname
326327
self.logfile = join(self.logdir, basename(

src/run.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def init_callback(self):
202202
continue
203203
job = Job(self.conf)
204204
job = job.from_cmd(self.jfile, linenum=-1, cmd=cmd)
205-
job.forceToLocal(jobname=name, removelog=False)
205+
job.to_local(jobname=name, removelog=False)
206206
self.totaljobdict[name] = job
207207
if name == "init":
208208
self.jobs.insert(0, job)
@@ -212,7 +212,7 @@ def init_callback(self):
212212
self.jobsgraph.add_edge(name, j)
213213
else:
214214
self.jobs.append(job)
215-
f = [i for i, j in self.jobsgraph.graph.items() if not len(j)]
215+
f = self.jobsgraph.end_nodes()
216216
self.jobsgraph.add_node_if_not_exists(job.jobname)
217217
for j in f:
218218
self.jobsgraph.add_edge(j, name)

0 commit comments

Comments
 (0)