cook-build 0.7.2__py3-none-any.whl → 0.7.3__py3-none-any.whl

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.
cook/__main__.py CHANGED
@@ -342,12 +342,10 @@ def __main__(cli_args: list[str] | None = None) -> None:
342
342
  ]
343
343
  )
344
344
  if args.module:
345
- # Temporarily add the current working directory to the path.
346
- try:
347
- sys.path.append(os.getcwd())
348
- importlib.import_module(args.module)
349
- finally:
350
- sys.path.pop()
345
+ # Add the current working directory to the path so local modules can be
346
+ # imported.
347
+ sys.path.append(os.getcwd())
348
+ importlib.import_module(args.module)
351
349
  elif args.recipe.is_file():
352
350
  # Parse the recipe.
353
351
  spec = importlib.util.spec_from_file_location("recipe", args.recipe)
cook/actions.py CHANGED
@@ -122,21 +122,22 @@ class SubprocessAction(Action):
122
122
  True
123
123
  """
124
124
 
125
- def __init__(self, *args, **kwargs) -> None:
125
+ def __init__(self, args: str | list[str], **kwargs) -> None:
126
126
  # Validate shell argument early
127
- if kwargs.get("shell", False) and args and not isinstance(args[0], str):
127
+ if kwargs.get("shell", False) and not isinstance(args, str):
128
128
  raise ValueError("shell=True requires string args")
129
129
  self.args = args
130
130
  self.kwargs = kwargs
131
131
 
132
132
  async def execute(self, task: "Task") -> None:
133
133
  # Get the command arguments
134
- (args,) = self.args
134
+ args = self.args
135
135
  shell = self.kwargs.get("shell", False)
136
136
  other_kwargs = {k: v for k, v in self.kwargs.items() if k != "shell"}
137
137
 
138
138
  # Create the subprocess
139
139
  if shell:
140
+ assert isinstance(args, str)
140
141
  process = await asyncio.create_subprocess_shell(args, **other_kwargs)
141
142
  else:
142
143
  # Exec mode: args can be a string (single command) or list
@@ -167,7 +168,7 @@ class SubprocessAction(Action):
167
168
  @property
168
169
  def hexdigest(self) -> str:
169
170
  hasher = hashlib.sha1()
170
- (args,) = self.args
171
+ args = self.args
171
172
  if isinstance(args, str):
172
173
  hasher.update(args.encode())
173
174
  else:
@@ -176,7 +177,7 @@ class SubprocessAction(Action):
176
177
  return hasher.hexdigest()
177
178
 
178
179
  def __repr__(self) -> str:
179
- args, *_ = self.args
180
+ args = self.args
180
181
  if not isinstance(args, str):
181
182
  args = " ".join(map(shlex.quote, args))
182
183
  return f"{self.__class__.__name__}({repr(args)})"
@@ -199,13 +200,13 @@ class CompositeAction(Action):
199
200
 
200
201
  @property
201
202
  def hexdigest(self) -> str | None:
202
- parts = []
203
+ hasher = hashlib.sha1()
203
204
  for action in self.actions:
204
205
  hexdigest = action.hexdigest
205
206
  if hexdigest is None:
206
207
  return None
207
- parts.append(hexdigest)
208
- return "".join(parts)
208
+ hasher.update(bytearray.fromhex(hexdigest))
209
+ return hasher.hexdigest()
209
210
 
210
211
 
211
212
  class ModuleAction(SubprocessAction):
cook/controller.py CHANGED
@@ -39,11 +39,6 @@ QUERIES = {
39
39
  "last_digested" TIMESTAMP NOT NULL
40
40
  );
41
41
  """,
42
- "select_task": """
43
- SELECT "digest"
44
- FROM "files"
45
- WHERE "name" = :name
46
- """,
47
42
  "upsert_task_completed": """
48
43
  INSERT INTO "tasks" ("name", "digest", "last_completed")
49
44
  VALUES (:name, :digest, :last_completed)
@@ -80,7 +75,6 @@ class Controller:
80
75
  def __init__(self, dependencies: nx.DiGraph, connection: Connection) -> None:
81
76
  self.dependencies = dependencies
82
77
  self.connection = connection
83
- self._digest_cache: dict[Path, tuple[float, bytes]] = {}
84
78
 
85
79
  def resolve_stale_tasks(self, tasks: list["Task"] | None = None) -> set["Task"]:
86
80
  self.is_stale(tasks or list(self.dependencies))
@@ -88,7 +82,7 @@ class Controller:
88
82
  node for node, data in self.dependencies.nodes(True) if data.get("is_stale")
89
83
  }
90
84
 
91
- def _evaluate_task_hexdigest(self, task: "Task") -> str | None:
85
+ def _evaluate_task_hexdigest(self, task: "Task") -> str:
92
86
  """
93
87
  Evaluate the digest of a task by combining the digest of all its dependencies.
94
88
  """
@@ -102,8 +96,7 @@ class Controller:
102
96
  )
103
97
  dependency = Path(dependency).resolve()
104
98
  if not dependency.is_file():
105
- LOGGER.debug("dependency %s of %s is missing", dependency, task)
106
- return None
99
+ raise FileNotFoundError(f"dependency {dependency} of {task} is missing")
107
100
  dependencies.append(dependency)
108
101
 
109
102
  hasher = hashlib.sha1()
@@ -198,9 +191,11 @@ class Controller:
198
191
  return True
199
192
 
200
193
  # If one of the dependencies is missing, the task is stale.
201
- current_digest = self._evaluate_task_hexdigest(task)
202
- if current_digest is None:
194
+ try:
195
+ current_digest = self._evaluate_task_hexdigest(task)
196
+ except FileNotFoundError:
203
197
  LOGGER.debug("%s is stale because one of its dependencies is missing", task)
198
+ return True
204
199
 
205
200
  # If the digest has changed, the task is stale.
206
201
  (cached_digest,) = cached_digest
@@ -290,7 +285,9 @@ class Controller:
290
285
  dep_futures = [task_futures[dep] for dep in dep_tasks]
291
286
  await asyncio.gather(*dep_futures)
292
287
 
293
- digest = self._evaluate_task_hexdigest(task)
288
+ digest: str | None = None
289
+ if not dry_run:
290
+ digest = self._evaluate_task_hexdigest(task)
294
291
  start: datetime | None = None
295
292
 
296
293
  try:
@@ -332,6 +329,7 @@ class Controller:
332
329
 
333
330
  # Update DB for completion
334
331
  if not dry_run:
332
+ assert digest is not None
335
333
  params = {
336
334
  "name": task.name,
337
335
  "digest": digest,
cook/manager.py CHANGED
@@ -63,7 +63,7 @@ class Manager:
63
63
  raise ValueError(f"{context} did not return a task")
64
64
  self.tasks[task.name] = task
65
65
  return task
66
- except:
66
+ except Exception:
67
67
  filename, lineno = util.get_location()
68
68
  LOGGER.exception(
69
69
  "failed to create task with name '%s' at %s:%d", name, filename, lineno
cook/util.py CHANGED
@@ -32,6 +32,7 @@ def evaluate_hexdigest(path: PathOrStr, size=2**16, hasher: str = "sha1") -> str
32
32
  class Timer:
33
33
  def __init__(self):
34
34
  self.start = None
35
+ self.end = None
35
36
 
36
37
  def __enter__(self) -> Timer:
37
38
  self.start = time()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cook-build
3
- Version: 0.7.2
3
+ Version: 0.7.3
4
4
  Summary: A task-centric build system with simple declarative recipes specified in Python
5
5
  Author: Till Hoffmann
6
6
  License: BSD-3-Clause
@@ -0,0 +1,14 @@
1
+ cook/__init__.py,sha256=SCa9_i6B84IzSAwq0wnSQqvycyL4dvTO7dRIysJXZj4,179
2
+ cook/__main__.py,sha256=3vnDZOJLTMJGRQzPolqurVzKJ7KCUjosBuuUkW22tKY,13192
3
+ cook/actions.py,sha256=yxo_LQ42iejq0K92OnYs7x2GaTuyNK3ZmqnRikQUgWs,7537
4
+ cook/contexts.py,sha256=-L4o_b_XPNZ_MBuYAgR1LYbptWPankDyj-00Pji7EVg,10710
5
+ cook/controller.py,sha256=vs9wBfvdQzE5RGZxZtKef6hb8rUOKKMp_kuPnmVAf9s,13432
6
+ cook/manager.py,sha256=sLlqPjsi81UTSHNhNj-ZTDilCdVmEF992N94yxWPOlU,6247
7
+ cook/task.py,sha256=-LNMwHdFlTUG45DF_QyWlIHw55_n_u2Xf5beKB7LrdY,2308
8
+ cook/util.py,sha256=Ssk_79cB7tvxEk_I9VAjjzmEp1bJ95ELZHCAx6sybyo,2459
9
+ cook_build-0.7.3.dist-info/licenses/LICENSE,sha256=3Nuj_WTTcz7JDg4-9EzNf6vHlKRWpdLUccg-pvoZ3WE,1500
10
+ cook_build-0.7.3.dist-info/METADATA,sha256=M83L-Uar5tKKLB2OyqQ1IS3wxe-idBZIvH2foLTXxAE,4586
11
+ cook_build-0.7.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
12
+ cook_build-0.7.3.dist-info/entry_points.txt,sha256=5UP0ZmmxSNKevTVISUJxmdXEQsKrI4n54OQYkjrdX2c,48
13
+ cook_build-0.7.3.dist-info/top_level.txt,sha256=ewNQIn2oRSYV98vAsUnw88u2Q8XHKhAz70ed2PEdR2c,5
14
+ cook_build-0.7.3.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- cook/__init__.py,sha256=SCa9_i6B84IzSAwq0wnSQqvycyL4dvTO7dRIysJXZj4,179
2
- cook/__main__.py,sha256=4sO22TsNTt3oirT71dJjZJwmynsRyUGT-CHJNlDgCkk,13242
3
- cook/actions.py,sha256=jHAsj0NzPGeLam9GmFF_mb-tLdHLIIVXWD8XCppU33I,7465
4
- cook/contexts.py,sha256=-L4o_b_XPNZ_MBuYAgR1LYbptWPankDyj-00Pji7EVg,10710
5
- cook/controller.py,sha256=-6KhAMYJn15szTRLR49PO9LFly0sqjHusOpoOutqIIY,13486
6
- cook/manager.py,sha256=dk-erHToyl89Xlq6risgYc9hkVVg2AZZKxui-5QPKF8,6237
7
- cook/task.py,sha256=-LNMwHdFlTUG45DF_QyWlIHw55_n_u2Xf5beKB7LrdY,2308
8
- cook/util.py,sha256=15MMG07CYZZ-YdFE_2jzRRTaqHMsw83UFg0s7e72MhI,2435
9
- cook_build-0.7.2.dist-info/licenses/LICENSE,sha256=3Nuj_WTTcz7JDg4-9EzNf6vHlKRWpdLUccg-pvoZ3WE,1500
10
- cook_build-0.7.2.dist-info/METADATA,sha256=Ok39Muj7dI2nL1SEwOPXd0gxzsn5iYLw0BPbKeKMuq0,4586
11
- cook_build-0.7.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
12
- cook_build-0.7.2.dist-info/entry_points.txt,sha256=5UP0ZmmxSNKevTVISUJxmdXEQsKrI4n54OQYkjrdX2c,48
13
- cook_build-0.7.2.dist-info/top_level.txt,sha256=ewNQIn2oRSYV98vAsUnw88u2Q8XHKhAz70ed2PEdR2c,5
14
- cook_build-0.7.2.dist-info/RECORD,,