primitive 0.1.13__tar.gz → 0.1.14__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 (55) hide show
  1. {primitive-0.1.13 → primitive-0.1.14}/PKG-INFO +1 -1
  2. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/__about__.py +1 -1
  3. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/agent/actions.py +4 -4
  4. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/cli.py +6 -0
  5. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/client.py +4 -0
  6. {primitive-0.1.13/src/primitive/projects → primitive-0.1.14/src/primitive/jobs}/actions.py +133 -5
  7. primitive-0.1.14/src/primitive/jobs/commands.py +41 -0
  8. primitive-0.1.14/src/primitive/organizations/actions.py +84 -0
  9. primitive-0.1.14/src/primitive/organizations/commands.py +24 -0
  10. primitive-0.1.14/src/primitive/projects/actions.py +79 -0
  11. primitive-0.1.14/src/primitive/projects/commands.py +24 -0
  12. {primitive-0.1.13 → primitive-0.1.14}/.git-hooks/pre-commit +0 -0
  13. {primitive-0.1.13 → primitive-0.1.14}/.gitattributes +0 -0
  14. {primitive-0.1.13 → primitive-0.1.14}/.github/workflows/lint.yml +0 -0
  15. {primitive-0.1.13 → primitive-0.1.14}/.github/workflows/publish.yml +0 -0
  16. {primitive-0.1.13 → primitive-0.1.14}/.gitignore +0 -0
  17. {primitive-0.1.13 → primitive-0.1.14}/.vscode/settings.json +0 -0
  18. {primitive-0.1.13 → primitive-0.1.14}/LICENSE.txt +0 -0
  19. {primitive-0.1.13 → primitive-0.1.14}/Makefile +0 -0
  20. {primitive-0.1.13 → primitive-0.1.14}/README.md +0 -0
  21. {primitive-0.1.13 → primitive-0.1.14}/linux setup.md +0 -0
  22. {primitive-0.1.13 → primitive-0.1.14}/pyproject.toml +0 -0
  23. {primitive-0.1.13 → primitive-0.1.14}/requirements.txt +0 -0
  24. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/__init__.py +0 -0
  25. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/agent/commands.py +0 -0
  26. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/auth/__init__.py +0 -0
  27. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/auth/actions.py +0 -0
  28. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/auth/commands.py +0 -0
  29. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/daemons/actions.py +0 -0
  30. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/daemons/commands.py +0 -0
  31. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/daemons/launch_agents.py +0 -0
  32. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/daemons/launch_service.py +0 -0
  33. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/files/actions.py +0 -0
  34. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/files/commands.py +0 -0
  35. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/git/__init__.py +0 -0
  36. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/git/actions.py +0 -0
  37. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/git/commands.py +0 -0
  38. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/graphql/__init__.py +0 -0
  39. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/graphql/sdk.py +0 -0
  40. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/hardware/actions.py +0 -0
  41. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/hardware/commands.py +0 -0
  42. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/lint/actions.py +0 -0
  43. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/lint/commands.py +0 -0
  44. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/projects/__init__.py +0 -0
  45. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/simulations/__init__.py +0 -0
  46. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/simulations/actions.py +0 -0
  47. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/utils/actions.py +0 -0
  48. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/utils/config.py +0 -0
  49. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/utils/files.py +0 -0
  50. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/utils/git.py +0 -0
  51. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/utils/memory_size.py +0 -0
  52. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/utils/printer.py +0 -0
  53. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/utils/shell.py +0 -0
  54. {primitive-0.1.13 → primitive-0.1.14}/src/primitive/utils/verible.py +0 -0
  55. {primitive-0.1.13 → primitive-0.1.14}/tests/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: primitive
3
- Version: 0.1.13
3
+ Version: 0.1.14
4
4
  Project-URL: Documentation, https://github.com//primitivecorp/primitive-cli#readme
5
5
  Project-URL: Issues, https://github.com//primitivecorp/primitive-cli/issues
6
6
  Project-URL: Source, https://github.com//primitivecorp/primitive-cli
@@ -1,4 +1,4 @@
1
1
  # SPDX-FileCopyrightText: 2024-present Dylan Stein <dylan@steins.studio>
2
2
  #
3
3
  # SPDX-License-Identifier: MIT
4
- __version__ = "0.1.13"
4
+ __version__ = "0.1.14"
@@ -32,7 +32,7 @@ class Agent(BaseAction):
32
32
  sleep(5)
33
33
  continue
34
34
 
35
- job_runs_data = self.primitive.projects.get_job_runs(
35
+ job_runs_data = self.primitive.jobs.get_job_runs(
36
36
  status="pending", first=1, reservation_id=active_reservation_id
37
37
  )
38
38
 
@@ -52,7 +52,7 @@ class Agent(BaseAction):
52
52
  )
53
53
 
54
54
  github_access_token = (
55
- self.primitive.projects.github_access_token_for_job_run(
55
+ self.primitive.jobs.github_access_token_for_job_run(
56
56
  job_run["id"]
57
57
  )
58
58
  )
@@ -68,7 +68,7 @@ class Agent(BaseAction):
68
68
  if job_run["job"]["slug"] == "lint":
69
69
  logger.debug("Executing Lint Job")
70
70
 
71
- self.primitive.projects.job_run_update(
71
+ self.primitive.jobs.job_run_update(
72
72
  job_run["id"], status="request_in_progress"
73
73
  )
74
74
 
@@ -79,7 +79,7 @@ class Agent(BaseAction):
79
79
  conclusion = "success"
80
80
  else:
81
81
  conclusion = "failure"
82
- self.primitive.projects.job_run_update(
82
+ self.primitive.jobs.job_run_update(
83
83
  job_run["id"],
84
84
  status="request_completed",
85
85
  conclusion=conclusion,
@@ -10,6 +10,9 @@ from .lint.commands import cli as lint_commands
10
10
  from .agent.commands import cli as agent_commands
11
11
  from .git.commands import cli as git_commands
12
12
  from .daemons.commands import cli as daemons_commands
13
+ from .jobs.commands import cli as jobs_commands
14
+ from .organizations.commands import cli as organizations_commands
15
+ from .projects.commands import cli as projects_commands
13
16
 
14
17
 
15
18
  @click.group()
@@ -61,6 +64,9 @@ cli.add_command(lint_commands, "lint")
61
64
  cli.add_command(agent_commands, "agent")
62
65
  cli.add_command(git_commands, "git")
63
66
  cli.add_command(daemons_commands, "daemons")
67
+ cli.add_command(jobs_commands, "jobs")
68
+ cli.add_command(organizations_commands, "organizations")
69
+ cli.add_command(projects_commands, "projects")
64
70
 
65
71
  if __name__ == "__main__":
66
72
  cli(obj={})
@@ -10,6 +10,8 @@ from .lint.actions import Lint
10
10
  from .agent.actions import Agent
11
11
  from .git.actions import Git
12
12
  from .daemons.actions import Daemons
13
+ from .jobs.actions import Jobs
14
+ from .organizations.actions import Organizations
13
15
 
14
16
  from loguru import logger
15
17
 
@@ -55,7 +57,9 @@ class Primitive:
55
57
  )
56
58
 
57
59
  self.auth: Auth = Auth(self)
60
+ self.organizations: Organizations = Organizations(self)
58
61
  self.projects: Projects = Projects(self)
62
+ self.jobs: Jobs = Jobs(self)
59
63
  self.files: Files = Files(self)
60
64
  self.simulations: Simulations = Simulations(self)
61
65
  self.hardware: Hardware = Hardware(self)
@@ -5,7 +5,88 @@ from gql import gql
5
5
  from primitive.utils.actions import BaseAction
6
6
 
7
7
 
8
- class Projects(BaseAction):
8
+ class Jobs(BaseAction):
9
+ def get_jobs(
10
+ self,
11
+ organization_id: Optional[str] = None,
12
+ project_id: Optional[str] = None,
13
+ job_id: Optional[str] = None,
14
+ slug: Optional[str] = None,
15
+ first: Optional[int] = 1,
16
+ last: Optional[int] = None,
17
+ ):
18
+ query = gql(
19
+ """
20
+ fragment PageInfoFragment on PageInfo {
21
+ hasNextPage
22
+ hasPreviousPage
23
+ startCursor
24
+ endCursor
25
+ }
26
+
27
+ fragment JobFragment on Job {
28
+ id
29
+ pk
30
+ slug
31
+ name
32
+ createdAt
33
+ updatedAt
34
+ }
35
+
36
+ query jobs(
37
+ $before: String
38
+ $after: String
39
+ $first: Int
40
+ $last: Int
41
+ $filters: JobFilters
42
+ ) {
43
+ jobs(
44
+ before: $before
45
+ after: $after
46
+ first: $first
47
+ last: $last
48
+ filters: $filters
49
+ ) {
50
+ totalCount
51
+ pageInfo {
52
+ ...PageInfoFragment
53
+ }
54
+ edges {
55
+ cursor
56
+ node {
57
+ ...JobFragment
58
+ }
59
+ }
60
+ }
61
+ }
62
+ """
63
+ )
64
+
65
+ filters = {}
66
+ if organization_id:
67
+ filters["organization"] = {"id": organization_id}
68
+ if project_id:
69
+ filters["project"] = {"id": project_id}
70
+ if job_id:
71
+ filters["id"] = job_id
72
+ if slug:
73
+ filters["slug"] = {"exact": slug}
74
+
75
+ variables = {
76
+ "first": first,
77
+ "last": last,
78
+ "filters": filters,
79
+ "order": {
80
+ "createdAt": "DESC",
81
+ },
82
+ }
83
+
84
+ result = self.primitive.session.execute(
85
+ query, variable_values=variables, get_execution_result=True
86
+ )
87
+ jobs = [edge["node"] for edge in result.data["jobs"]["edges"]]
88
+ return jobs
89
+
9
90
  def get_job_runs(
10
91
  self,
11
92
  organization_id: Optional[str] = None,
@@ -114,12 +195,34 @@ query jobRuns(
114
195
  def get_job_run(self, id: str):
115
196
  query = gql(
116
197
  """
198
+ fragment JobRunFragment on JobRun {
199
+ id
200
+ pk
201
+ createdAt
202
+ updatedAt
203
+ completedAt
204
+ startedAt
205
+ status
206
+ conclusion
207
+ stdout
208
+ job {
209
+ id
210
+ pk
211
+ slug
212
+ name
213
+ createdAt
214
+ updatedAt
215
+ }
216
+ gitCommit {
217
+ sha
218
+ branch
219
+ repoFullName
220
+ }
221
+ }
222
+
117
223
  query jobRun($id: GlobalID!) {
118
224
  jobRun(id: $id) {
119
- id
120
- organization {
121
- id
122
- }
225
+ ...JobRunFragment
123
226
  }
124
227
  }
125
228
  """
@@ -173,3 +276,28 @@ query ghAppTokenForJobRun($jobRunId: GlobalID!) {
173
276
  variables = {"jobRunId": job_run_id}
174
277
  result = self.primitive.session.execute(query, variable_values=variables)
175
278
  return result["ghAppTokenForJobRun"]
279
+
280
+ def get_latest_job_run_for_job(
281
+ self, job_slug: Optional[str] = None, job_id: Optional[str] = None
282
+ ):
283
+ if not job_slug and not job_id:
284
+ raise ValueError("job_slug or job_id is required")
285
+ jobs_results = self.get_jobs(slug=job_slug)
286
+ jobs = [edge["node"] for edge in jobs_results.data["jobs"]["edges"]]
287
+
288
+ job_id = jobs.id
289
+ job_run_results = self.get_job_runs(job_id=job_id, first=1)
290
+ job_run = [edge["node"] for edge in job_run_results.data["job_runs"]["edges"]][
291
+ 0
292
+ ]
293
+ return job_run
294
+
295
+ def job_run_start(
296
+ self,
297
+ job_slug: str,
298
+ job_id: str,
299
+ ):
300
+ if not job_slug and not job_id:
301
+ raise ValueError("job_slug or job_id is required")
302
+
303
+ self.get_jobs(slug=job_slug)
@@ -0,0 +1,41 @@
1
+ import click
2
+
3
+ from ..utils.printer import print_result
4
+
5
+ import typing
6
+
7
+ if typing.TYPE_CHECKING:
8
+ from ..client import Primitive
9
+
10
+
11
+ @click.group()
12
+ @click.pass_context
13
+ def cli(context):
14
+ """Jobs Commands"""
15
+ pass
16
+
17
+
18
+ @cli.command("list")
19
+ @click.pass_context
20
+ def list(
21
+ context,
22
+ organization_slug: str = None,
23
+ organization_id: str = None,
24
+ ):
25
+ """List Job"""
26
+ primitive: Primitive = context.obj.get("PRIMITIVE")
27
+ message = primitive.jobs.get_jobs()
28
+ print_result(message=message, context=context)
29
+
30
+
31
+ @cli.command("details")
32
+ @click.argument("job_slug")
33
+ @click.pass_context
34
+ def details(
35
+ context,
36
+ job_slug: str = None,
37
+ ):
38
+ """List Job"""
39
+ primitive: Primitive = context.obj.get("PRIMITIVE")
40
+ message = primitive.jobs.get_jobs(slug=job_slug)
41
+ print_result(message=message, context=context)
@@ -0,0 +1,84 @@
1
+ from typing import Optional
2
+ from gql import gql
3
+
4
+
5
+ from primitive.utils.actions import BaseAction
6
+
7
+
8
+ class Organizations(BaseAction):
9
+ def get_organizations(
10
+ self,
11
+ organization_id: Optional[str] = None,
12
+ slug: Optional[str] = None,
13
+ first: Optional[int] = 1,
14
+ last: Optional[int] = None,
15
+ ):
16
+ query = gql(
17
+ """
18
+ fragment PageInfoFragment on PageInfo {
19
+ hasNextPage
20
+ hasPreviousPage
21
+ startCursor
22
+ endCursor
23
+ }
24
+
25
+ fragment OrganizationFragment on Organization {
26
+ id
27
+ pk
28
+ slug
29
+ name
30
+ createdAt
31
+ updatedAt
32
+ }
33
+
34
+ query organizations(
35
+ $before: String
36
+ $after: String
37
+ $first: Int
38
+ $last: Int
39
+ $filters: OrganizationFilters
40
+ $order: OrganizationOrder
41
+ ) {
42
+ organizations(
43
+ before: $before
44
+ after: $after
45
+ first: $first
46
+ last: $last
47
+ filters: $filters
48
+ order: $order
49
+ ) {
50
+ totalCount
51
+ pageInfo {
52
+ ...PageInfoFragment
53
+ }
54
+ edges {
55
+ cursor
56
+ node {
57
+ ...OrganizationFragment
58
+ }
59
+ }
60
+ }
61
+ }
62
+ """
63
+ )
64
+
65
+ filters = {}
66
+ if organization_id:
67
+ filters["organization"] = {"id": organization_id}
68
+ if slug:
69
+ filters["slug"] = {"exact": slug}
70
+
71
+ variables = {
72
+ "first": first,
73
+ "last": last,
74
+ "filters": filters,
75
+ "order": {
76
+ "createdAt": "DESC",
77
+ },
78
+ }
79
+
80
+ result = self.primitive.session.execute(
81
+ query, variable_values=variables, get_execution_result=True
82
+ )
83
+ organizations = [edge["node"] for edge in result.data["organizations"]["edges"]]
84
+ return organizations
@@ -0,0 +1,24 @@
1
+ import click
2
+
3
+ from ..utils.printer import print_result
4
+
5
+ import typing
6
+
7
+ if typing.TYPE_CHECKING:
8
+ from ..client import Primitive
9
+
10
+
11
+ @click.group()
12
+ @click.pass_context
13
+ def cli(context):
14
+ """Organizations Commands"""
15
+ pass
16
+
17
+
18
+ @cli.command("list")
19
+ @click.pass_context
20
+ def details(context):
21
+ """List Organizations"""
22
+ primitive: Primitive = context.obj.get("PRIMITIVE")
23
+ message = primitive.organizations.get_organizations()
24
+ print_result(message=message, context=context)
@@ -0,0 +1,79 @@
1
+ from gql import gql
2
+
3
+ from typing import Optional
4
+ from primitive.utils.actions import BaseAction
5
+
6
+
7
+ class Projects(BaseAction):
8
+
9
+ def get_projects(
10
+ self,
11
+ organization_id: Optional[str] = None,
12
+ slug: Optional[str] = None,
13
+ first: Optional[int] = 1,
14
+ last: Optional[int] = None,
15
+ ):
16
+ query = gql(
17
+ """
18
+ fragment PageInfoFragment on PageInfo {
19
+ hasNextPage
20
+ hasPreviousPage
21
+ startCursor
22
+ endCursor
23
+ }
24
+
25
+ fragment ProjectFragment on Project {
26
+ id
27
+ pk
28
+ slug
29
+ name
30
+ createdAt
31
+ updatedAt
32
+ }
33
+
34
+ query projects(
35
+ $before: String
36
+ $after: String
37
+ $first: Int
38
+ $last: Int
39
+ $filters: ProjectFilters
40
+ ) {
41
+ projects(
42
+ before: $before
43
+ after: $after
44
+ first: $first
45
+ last: $last
46
+ filters: $filters
47
+ ) {
48
+ totalCount
49
+ pageInfo {
50
+ ...PageInfoFragment
51
+ }
52
+ edges {
53
+ cursor
54
+ node {
55
+ ...ProjectFragment
56
+ }
57
+ }
58
+ }
59
+ }
60
+ """
61
+ )
62
+
63
+ filters = {}
64
+ if organization_id:
65
+ filters["organization"] = {"id": organization_id}
66
+ if slug:
67
+ filters["slug"] = {"exact": slug}
68
+
69
+ variables = {
70
+ "first": first,
71
+ "last": last,
72
+ "filters": filters,
73
+ }
74
+
75
+ result = self.primitive.session.execute(
76
+ query, variable_values=variables, get_execution_result=True
77
+ )
78
+ projects = [edge["node"] for edge in result.data["projects"]["edges"]]
79
+ return projects
@@ -0,0 +1,24 @@
1
+ import click
2
+
3
+ from ..utils.printer import print_result
4
+
5
+ import typing
6
+
7
+ if typing.TYPE_CHECKING:
8
+ from ..client import Primitive
9
+
10
+
11
+ @click.group()
12
+ @click.pass_context
13
+ def cli(context):
14
+ """Projects Commands"""
15
+ pass
16
+
17
+
18
+ @cli.command("list")
19
+ @click.pass_context
20
+ def list(context):
21
+ """List Projects"""
22
+ primitive: Primitive = context.obj.get("PRIMITIVE")
23
+ message = primitive.projects.get_projects()
24
+ print_result(message=message, context=context)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes