prefect-client 3.3.7__py3-none-any.whl → 3.3.8.dev1__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.
prefect/_build_info.py CHANGED
@@ -1,5 +1,5 @@
1
1
  # Generated by versioningit
2
- __version__ = "3.3.7"
3
- __build_date__ = "2025-04-28 15:03:08.716974+00:00"
4
- __git_commit__ = "8f86aaeee460bab1184336bf2f9cf62fef73d7bb"
2
+ __version__ = "3.3.8.dev1"
3
+ __build_date__ = "2025-04-29 08:08:59.733773+00:00"
4
+ __git_commit__ = "f517be0bbfa10a7fdd2b715048061f33ed0fbac9"
5
5
  __dirty__ = False
prefect/_versioning.py CHANGED
@@ -6,11 +6,16 @@ from typing import Any, Callable, Coroutine, Dict, Literal, Optional
6
6
  from urllib.parse import urlparse
7
7
 
8
8
  from anyio import run_process
9
- from pydantic import Field, model_validator
9
+ from pydantic import Field
10
10
 
11
11
  from prefect.client.schemas.objects import VersionInfo
12
12
 
13
13
 
14
+ async def get_commit_message_first_line() -> str:
15
+ result = await run_process(["git", "log", "-1", "--pretty=%B"])
16
+ return result.stdout.decode().strip().splitlines()[0]
17
+
18
+
14
19
  class SimpleVersionInfo(VersionInfo):
15
20
  type: Literal["prefect:simple"] = "prefect:simple"
16
21
  version: str = Field(default="")
@@ -21,27 +26,56 @@ class SimpleVersionInfo(VersionInfo):
21
26
  class GithubVersionInfo(VersionInfo):
22
27
  type: Literal["vcs:github"] = "vcs:github"
23
28
  version: str
29
+ commit_sha: str
30
+ message: str
24
31
  branch: str
32
+ repository: str
25
33
  url: str
34
+
35
+
36
+ class GitlabVersionInfo(VersionInfo):
37
+ type: Literal["vcs:gitlab"] = "vcs:gitlab"
38
+ version: str
39
+ commit_sha: str
40
+ message: str
41
+ branch: str
26
42
  repository: str
43
+ url: str
27
44
 
28
- @model_validator(mode="after")
29
- def validate_branch(self):
30
- if not self.branch:
31
- raise ValueError("branch is required when type is 'vcs:github'")
32
- return self
45
+
46
+ class BitbucketVersionInfo(VersionInfo):
47
+ type: Literal["vcs:bitbucket"] = "vcs:bitbucket"
48
+ version: str
49
+ commit_sha: str
50
+ message: str
51
+ branch: str
52
+ repository: str
53
+ url: str
54
+
55
+
56
+ class AzureDevopsVersionInfo(VersionInfo):
57
+ type: Literal["vcs:azuredevops"] = "vcs:azuredevops"
58
+ version: str
59
+ commit_sha: str
60
+ message: str
61
+ branch: str
62
+ repository: str
63
+ url: str
33
64
 
34
65
 
35
66
  class GitVersionInfo(VersionInfo):
36
67
  type: Literal["vcs:git"] = "vcs:git"
37
68
  version: str
69
+ commit_sha: str
70
+ message: str
38
71
  branch: str
39
- url: str
40
72
  repository: str
73
+ url: str
41
74
 
42
75
 
43
76
  async def get_github_version_info(
44
- version: Optional[str] = None,
77
+ commit_sha: Optional[str] = None,
78
+ message: Optional[str] = None,
45
79
  branch: Optional[str] = None,
46
80
  repository: Optional[str] = None,
47
81
  url: Optional[str] = None,
@@ -49,10 +83,11 @@ async def get_github_version_info(
49
83
  """Create a GithubVersionInfo object from provided values or environment variables.
50
84
 
51
85
  Args:
52
- version: The commit SHA, falls back to GITHUB_SHA env var
86
+ commit_sha: The commit SHA, falls back to GITHUB_SHA env var
87
+ message: The commit message, falls back to git log -1 --pretty=%B
53
88
  branch: The git branch, falls back to GITHUB_REF_NAME env var
54
89
  repository: The repository name, falls back to GITHUB_REPOSITORY env var
55
- url: The repository URL, constructed from GITHUB_SERVER_URL/GITHUB_REPOSITORY if not provided
90
+ url: The repository URL, constructed from GITHUB_SERVER_URL/GITHUB_REPOSITORY/tree/GITHUB_SHA if not provided
56
91
 
57
92
  Returns:
58
93
  A GithubVersionInfo
@@ -60,25 +95,230 @@ async def get_github_version_info(
60
95
  Raises:
61
96
  ValueError: If any required fields cannot be determined
62
97
  """
63
- version = version or os.getenv("GITHUB_SHA")
64
- branch = branch or os.getenv("GITHUB_REF_NAME")
65
- repository = repository or os.getenv("GITHUB_REPOSITORY")
66
- url = url or f"{os.getenv('GITHUB_SERVER_URL')}/{repository}"
67
-
68
- if not version:
69
- raise ValueError("version is required - must be provided or set in GITHUB_SHA")
70
- if not branch:
71
- raise ValueError(
72
- "branch is required - must be provided or set in GITHUB_REF_NAME"
73
- )
74
- if not repository:
98
+ try:
99
+ commit_sha = commit_sha or os.getenv("GITHUB_SHA")
100
+ branch = branch or os.getenv("GITHUB_REF_NAME")
101
+ repository = repository or os.getenv("GITHUB_REPOSITORY")
102
+ url = url or f"{os.getenv('GITHUB_SERVER_URL')}/{repository}/tree/{commit_sha}"
103
+
104
+ if not message:
105
+ message = await get_commit_message_first_line()
106
+
107
+ if not commit_sha:
108
+ raise ValueError(
109
+ "commit_sha is required - must be provided or set in GITHUB_SHA"
110
+ )
111
+ if not branch:
112
+ raise ValueError(
113
+ "branch is required - must be provided or set in GITHUB_REF_NAME"
114
+ )
115
+ if not repository:
116
+ raise ValueError(
117
+ "repository is required - must be provided or set in GITHUB_REPOSITORY"
118
+ )
119
+
120
+ except Exception as e:
75
121
  raise ValueError(
76
- "repository is required - must be provided or set in GITHUB_REPOSITORY"
122
+ f"Error getting git version info: {e}. You may not be in a Github repository."
77
123
  )
78
124
 
79
125
  return GithubVersionInfo(
80
126
  type="vcs:github",
81
- version=version,
127
+ version=commit_sha[:8],
128
+ commit_sha=commit_sha,
129
+ message=message,
130
+ branch=branch,
131
+ repository=repository,
132
+ url=url,
133
+ )
134
+
135
+
136
+ async def get_gitlab_version_info(
137
+ commit_sha: Optional[str] = None,
138
+ message: Optional[str] = None,
139
+ branch: Optional[str] = None,
140
+ repository: Optional[str] = None,
141
+ url: Optional[str] = None,
142
+ ) -> GitlabVersionInfo:
143
+ """Create a GitlabVersionInfo object from provided values or environment variables.
144
+
145
+ Args:
146
+ commit_sha: The commit SHA, falls back to CI_COMMIT_SHA env var
147
+ message: The commit message, falls back to git log -1 --pretty=%B
148
+ branch: The git branch, falls back to CI_COMMIT_REF_NAME env var
149
+ repository: The repository name, falls back to CI_PROJECT_NAME env var
150
+ url: The repository URL, constructed from CI_PROJECT_URL/-/tree/CI_COMMIT_SHA if not provided
151
+
152
+ Returns:
153
+ A GitlabVersionInfo
154
+
155
+ Raises:
156
+ ValueError: If any required fields cannot be determined
157
+ """
158
+ try:
159
+ commit_sha = commit_sha or os.getenv("CI_COMMIT_SHA")
160
+ branch = branch or os.getenv("CI_COMMIT_REF_NAME")
161
+ repository = repository or os.getenv("CI_PROJECT_NAME")
162
+ url = url or f"{os.getenv('CI_PROJECT_URL')}/-/tree/{commit_sha}"
163
+
164
+ if not message:
165
+ message = await get_commit_message_first_line()
166
+
167
+ if not commit_sha:
168
+ raise ValueError(
169
+ "commit_sha is required - must be provided or set in CI_COMMIT_SHA"
170
+ )
171
+ if not branch:
172
+ raise ValueError(
173
+ "branch is required - must be provided or set in CI_COMMIT_REF_NAME"
174
+ )
175
+ if not repository:
176
+ raise ValueError(
177
+ "repository is required - must be provided or set in CI_PROJECT_NAME"
178
+ )
179
+ if not url:
180
+ raise ValueError(
181
+ "url is required - must be provided or set in CI_PROJECT_URL"
182
+ )
183
+
184
+ except Exception as e:
185
+ raise ValueError(
186
+ f"Error getting git version info: {e}. You may not be in a Gitlab repository."
187
+ )
188
+
189
+ return GitlabVersionInfo(
190
+ type="vcs:gitlab",
191
+ version=commit_sha[:8],
192
+ commit_sha=commit_sha,
193
+ message=message,
194
+ branch=branch,
195
+ repository=repository,
196
+ url=url,
197
+ )
198
+
199
+
200
+ async def get_bitbucket_version_info(
201
+ commit_sha: Optional[str] = None,
202
+ message: Optional[str] = None,
203
+ branch: Optional[str] = None,
204
+ repository: Optional[str] = None,
205
+ url: Optional[str] = None,
206
+ ) -> BitbucketVersionInfo:
207
+ """Create a BitbucketVersionInfo object from provided values or environment variables.
208
+
209
+ Args:
210
+ commit_sha: The commit SHA, falls back to BITBUCKET_COMMIT env var
211
+ message: The commit message, falls back to git log -1 --pretty=%B
212
+ branch: The git branch, falls back to BITBUCKET_BRANCH env var
213
+ repository: The repository name, falls back to BITBUCKET_REPO_SLUG env var
214
+ url: The repository URL, constructed from BITBUCKET_GIT_HTTP_ORIGIN/BITBUCKET_REPO_SLUG/src/BITBUCKET_COMMIT if not provided
215
+
216
+ Returns:
217
+ A BitbucketVersionInfo
218
+
219
+ Raises:
220
+ ValueError: If any required fields cannot be determined
221
+ """
222
+ try:
223
+ commit_sha = commit_sha or os.getenv("BITBUCKET_COMMIT")
224
+ branch = branch or os.getenv("BITBUCKET_BRANCH")
225
+ repository = repository or os.getenv("BITBUCKET_REPO_SLUG")
226
+ url = url or f"{os.getenv('BITBUCKET_GIT_HTTP_ORIGIN')}/src/{commit_sha}"
227
+
228
+ if not message:
229
+ message = await get_commit_message_first_line()
230
+
231
+ if not commit_sha:
232
+ raise ValueError(
233
+ "commit_sha is required - must be provided or set in BITBUCKET_COMMIT"
234
+ )
235
+ if not branch:
236
+ raise ValueError(
237
+ "branch is required - must be provided or set in BITBUCKET_BRANCH"
238
+ )
239
+ if not repository:
240
+ raise ValueError(
241
+ "repository is required - must be provided or set in BITBUCKET_REPO_SLUG"
242
+ )
243
+ if not url:
244
+ raise ValueError(
245
+ "url is required - must be provided or set in BITBUCKET_GIT_HTTP_ORIGIN"
246
+ )
247
+
248
+ except Exception as e:
249
+ raise ValueError(
250
+ f"Error getting git version info: {e}. You may not be in a Bitbucket repository."
251
+ )
252
+
253
+ return BitbucketVersionInfo(
254
+ type="vcs:bitbucket",
255
+ version=commit_sha[:8],
256
+ commit_sha=commit_sha,
257
+ message=message,
258
+ branch=branch,
259
+ repository=repository,
260
+ url=url,
261
+ )
262
+
263
+
264
+ async def get_azuredevops_version_info(
265
+ commit_sha: Optional[str] = None,
266
+ message: Optional[str] = None,
267
+ branch: Optional[str] = None,
268
+ repository: Optional[str] = None,
269
+ url: Optional[str] = None,
270
+ ) -> AzureDevopsVersionInfo:
271
+ """Create an AzureDevopsVersionInfo object from provided values or environment variables.
272
+
273
+ Args:
274
+ commit_sha: The commit SHA, falls back to BUILD_SOURCEVERSION env var
275
+ message: The commit message, falls back to git log -1 --pretty=%B
276
+ branch: The git branch, falls back to BUILD_SOURCEBRANCHNAME env var
277
+ repository: The repository name, falls back to BUILD_REPOSITORY_NAME env var
278
+ url: The repository URL, constructed from BUILD_REPOSITORY_URI?version=GCBUILD_SOURCEVERSION if not provided
279
+
280
+ Returns:
281
+ An AzureDevopsVersionInfo
282
+
283
+ Raises:
284
+ ValueError: If any required fields cannot be determined
285
+ """
286
+ try:
287
+ commit_sha = commit_sha or os.getenv("BUILD_SOURCEVERSION")
288
+ branch = branch or os.getenv("BUILD_SOURCEBRANCHNAME")
289
+ repository = repository or os.getenv("BUILD_REPOSITORY_NAME")
290
+ url = url or f"{os.getenv('BUILD_REPOSITORY_URI')}?version=GC{commit_sha}"
291
+
292
+ if not message:
293
+ message = await get_commit_message_first_line()
294
+
295
+ if not commit_sha:
296
+ raise ValueError(
297
+ "commit_sha is required - must be provided or set in BUILD_SOURCEVERSION"
298
+ )
299
+ if not branch:
300
+ raise ValueError(
301
+ "branch is required - must be provided or set in BUILD_SOURCEBRANCHNAME"
302
+ )
303
+ if not repository:
304
+ raise ValueError(
305
+ "repository is required - must be provided or set in BUILD_REPOSITORY_NAME"
306
+ )
307
+ if not url:
308
+ raise ValueError(
309
+ "url is required - must be provided or set in BUILD_REPOSITORY_URI"
310
+ )
311
+
312
+ except Exception as e:
313
+ raise ValueError(
314
+ f"Error getting git version info: {e}. You may not be in an Azure DevOps repository."
315
+ )
316
+
317
+ return AzureDevopsVersionInfo(
318
+ type="vcs:azuredevops",
319
+ version=commit_sha[:8],
320
+ commit_sha=commit_sha,
321
+ message=message,
82
322
  branch=branch,
83
323
  repository=repository,
84
324
  url=url,
@@ -86,17 +326,18 @@ async def get_github_version_info(
86
326
 
87
327
 
88
328
  async def get_git_version_info(
89
- version: Optional[str] = None,
329
+ commit_sha: Optional[str] = None,
330
+ message: Optional[str] = None,
90
331
  branch: Optional[str] = None,
91
332
  url: Optional[str] = None,
92
333
  repository: Optional[str] = None,
93
334
  ) -> GitVersionInfo:
94
335
  try:
95
- if not version:
336
+ if not commit_sha:
96
337
  # Run git command and get stdout
97
338
  result = await run_process(["git", "rev-parse", "HEAD"])
98
339
  # Decode bytes to string and strip whitespace
99
- version = result.stdout.decode().strip()
340
+ commit_sha = result.stdout.decode().strip()
100
341
 
101
342
  if not branch:
102
343
  result = await run_process(["git", "rev-parse", "--abbrev-ref", "HEAD"])
@@ -112,6 +353,9 @@ async def get_git_version_info(
112
353
  if repository.endswith(".git"):
113
354
  repository = repository[:-4]
114
355
 
356
+ if not message:
357
+ message = await get_commit_message_first_line()
358
+
115
359
  if not url and repository:
116
360
  # Use the full remote URL as the URL
117
361
  result = await run_process(["git", "config", "--get", "remote.origin.url"])
@@ -125,15 +369,23 @@ async def get_git_version_info(
125
369
  raise ValueError("Could not determine git repository URL")
126
370
 
127
371
  return GitVersionInfo(
128
- type="vcs:git", version=version, branch=branch, url=url, repository=repository
372
+ type="vcs:git",
373
+ version=commit_sha[:8],
374
+ branch=branch,
375
+ url=url,
376
+ repository=repository,
377
+ commit_sha=commit_sha,
378
+ message=message,
129
379
  )
130
380
 
131
381
 
132
382
  class VersionType(str, Enum):
133
383
  SIMPLE = "prefect:simple"
134
384
  GITHUB = "vcs:github"
385
+ GITLAB = "vcs:gitlab"
386
+ BITBUCKET = "vcs:bitbucket"
387
+ AZUREDEVOPS = "vcs:azuredevops"
135
388
  GIT = "vcs:git"
136
- DOCKER = "container:docker"
137
389
 
138
390
 
139
391
  async def get_inferred_version_info(
@@ -155,12 +407,18 @@ async def get_inferred_version_info(
155
407
  # Map version types to their getter functions
156
408
  type_to_getter: Dict[str, Callable[..., Coroutine[Any, Any, Any]]] = {
157
409
  VersionType.GITHUB: get_github_version_info,
410
+ VersionType.GITLAB: get_gitlab_version_info,
411
+ VersionType.BITBUCKET: get_bitbucket_version_info,
412
+ VersionType.AZUREDEVOPS: get_azuredevops_version_info,
158
413
  VersionType.GIT: get_git_version_info,
159
414
  }
160
415
 
161
416
  # Default order of getters to try
162
417
  default_getters = [
163
418
  get_github_version_info,
419
+ get_gitlab_version_info,
420
+ get_bitbucket_version_info,
421
+ get_azuredevops_version_info,
164
422
  get_git_version_info,
165
423
  ]
166
424
 
prefect/flow_runs.py CHANGED
@@ -141,7 +141,10 @@ async def wait_for_flow_run(
141
141
  return flow_run
142
142
 
143
143
  async for event in subscriber:
144
- state_type = StateType(event.resource["prefect.state-type"])
144
+ if not (state_type := event.resource.get("prefect.state-type")):
145
+ logger.debug(f"Received {event.event!r} event")
146
+ continue
147
+ state_type = StateType(state_type)
145
148
  state = State(type=state_type)
146
149
 
147
150
  if log_states:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: prefect-client
3
- Version: 3.3.7
3
+ Version: 3.3.8.dev1
4
4
  Summary: Workflow orchestration and management.
5
5
  Project-URL: Changelog, https://github.com/PrefectHQ/prefect/releases
6
6
  Project-URL: Documentation, https://docs.prefect.io
@@ -1,9 +1,9 @@
1
1
  prefect/.prefectignore,sha256=awSprvKT0vI8a64mEOLrMxhxqcO-b0ERQeYpA2rNKVQ,390
2
2
  prefect/__init__.py,sha256=iCdcC5ZmeewikCdnPEP6YBAjPNV5dvfxpYCTpw30Hkw,3685
3
3
  prefect/__main__.py,sha256=WFjw3kaYJY6pOTA7WDOgqjsz8zUEUZHCcj3P5wyVa-g,66
4
- prefect/_build_info.py,sha256=yFQx2GfGnZezTWU1rGjrvTOpehcZtB9Gm3FIGU3w33k,180
4
+ prefect/_build_info.py,sha256=NBARPtakQcbgZhytfkEjryqyuM23Ah1-de8sfRoP7eA,185
5
5
  prefect/_result_records.py,sha256=S6QmsODkehGVSzbMm6ig022PYbI6gNKz671p_8kBYx4,7789
6
- prefect/_versioning.py,sha256=Bm2EwEODvMe_kLkeVXy32BaTA_4ijBZl9eFbdtXEV4w,5498
6
+ prefect/_versioning.py,sha256=nRawjhBY2XpAzS5dHm4ajj8GlSNCr_YOjg2Zbez69j0,14069
7
7
  prefect/_waiters.py,sha256=Ia2ITaXdHzevtyWIgJoOg95lrEXQqNEOquHvw3T33UQ,9026
8
8
  prefect/agent.py,sha256=dPvG1jDGD5HSH7aM2utwtk6RaJ9qg13XjkA0lAIgQmY,287
9
9
  prefect/artifacts.py,sha256=dMBUOAWnUamzjb5HSqwB5-GR2Qb-Gxee26XG5NDCUuw,22720
@@ -14,7 +14,7 @@ prefect/engine.py,sha256=uB5JN4l045i5JTlRQNT1x7MwlSiGQ5Bop2Q6jHHOgxY,3699
14
14
  prefect/exceptions.py,sha256=wZLQQMRB_DyiYkeEdIC5OKwbba5A94Dlnics-lrWI7A,11581
15
15
  prefect/filesystems.py,sha256=v5YqGB4uXf9Ew2VuB9VCSkawvYMMVvEtZf7w1VmAmr8,18036
16
16
  prefect/flow_engine.py,sha256=hZpTYEtwTPMtwVoTCrfD93igN7rlKeG_0kyCvdU4aYE,58876
17
- prefect/flow_runs.py,sha256=dbHcXsOq1UsNM7vyJV9gboCTylmdUwQ_-W4NQt4R4ds,17267
17
+ prefect/flow_runs.py,sha256=d3jfmrIPP3C19IJREvpkuN6fxksX3Lzo-LlHOB-_E2I,17419
18
18
  prefect/flows.py,sha256=UCBwsb99wtPTGPu2PneKCfAMlMBA2GhXJb5rzMBxw1s,118041
19
19
  prefect/futures.py,sha256=F4eplqRcqw5-aMNKu6-lOFOWdDNr0RGrPso4C4G02bU,24248
20
20
  prefect/main.py,sha256=8V-qLB4GjEVCkGRgGXeaIk-JIXY8Z9FozcNluj4Sm9E,2589
@@ -319,7 +319,7 @@ prefect/workers/cloud.py,sha256=dPvG1jDGD5HSH7aM2utwtk6RaJ9qg13XjkA0lAIgQmY,287
319
319
  prefect/workers/process.py,sha256=Yi5D0U5AQ51wHT86GdwtImXSefe0gJf3LGq4r4z9zwM,11090
320
320
  prefect/workers/server.py,sha256=2pmVeJZiVbEK02SO6BEZaBIvHMsn6G8LzjW8BXyiTtk,1952
321
321
  prefect/workers/utilities.py,sha256=VfPfAlGtTuDj0-Kb8WlMgAuOfgXCdrGAnKMapPSBrwc,2483
322
- prefect_client-3.3.7.dist-info/METADATA,sha256=YBJhkMhcGJYgPdGEvAUr6sKNdBQOcX6-tSiShqqj2H0,7466
323
- prefect_client-3.3.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
324
- prefect_client-3.3.7.dist-info/licenses/LICENSE,sha256=MCxsn8osAkzfxKC4CC_dLcUkU8DZLkyihZ8mGs3Ah3Q,11357
325
- prefect_client-3.3.7.dist-info/RECORD,,
322
+ prefect_client-3.3.8.dev1.dist-info/METADATA,sha256=gFKUyJDQYtjrukaMaj8xfLVZusjBrro8KRhwVj35sVw,7471
323
+ prefect_client-3.3.8.dev1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
324
+ prefect_client-3.3.8.dev1.dist-info/licenses/LICENSE,sha256=MCxsn8osAkzfxKC4CC_dLcUkU8DZLkyihZ8mGs3Ah3Q,11357
325
+ prefect_client-3.3.8.dev1.dist-info/RECORD,,