primitive 0.1.11__py3-none-any.whl → 0.1.12__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.
- primitive/__about__.py +1 -1
- primitive/agent/actions.py +34 -14
- primitive/cli.py +2 -0
- primitive/client.py +2 -0
- primitive/git/__init__.py +0 -0
- primitive/git/actions.py +42 -0
- primitive/git/commands.py +49 -0
- primitive/lint/actions.py +6 -9
- primitive/projects/actions.py +17 -0
- primitive/utils/files.py +9 -2
- {primitive-0.1.11.dist-info → primitive-0.1.12.dist-info}/METADATA +1 -1
- {primitive-0.1.11.dist-info → primitive-0.1.12.dist-info}/RECORD +15 -12
- {primitive-0.1.11.dist-info → primitive-0.1.12.dist-info}/WHEEL +0 -0
- {primitive-0.1.11.dist-info → primitive-0.1.12.dist-info}/entry_points.txt +0 -0
- {primitive-0.1.11.dist-info → primitive-0.1.12.dist-info}/licenses/LICENSE.txt +0 -0
primitive/__about__.py
CHANGED
primitive/agent/actions.py
CHANGED
@@ -45,28 +45,48 @@ class Agent(BaseAction):
|
|
45
45
|
logger.debug(f"Job Run ID: {job_run['id']}")
|
46
46
|
logger.debug(f"Job Name: {job_run['job']['name']}")
|
47
47
|
|
48
|
+
git_repo_full_name = job_run["gitCommit"]["repoFullName"]
|
49
|
+
git_ref = job_run["gitCommit"]["sha"]
|
50
|
+
logger.debug(
|
51
|
+
f"Downloading repository {git_repo_full_name} at ref {git_ref}"
|
52
|
+
)
|
53
|
+
|
54
|
+
github_access_token = (
|
55
|
+
self.primitive.projects.github_access_token_for_job_run(
|
56
|
+
job_run["id"]
|
57
|
+
)
|
58
|
+
)
|
59
|
+
|
60
|
+
downloaded_git_repository_dir = (
|
61
|
+
self.primitive.git.download_git_repository_at_ref(
|
62
|
+
git_repo_full_name=git_repo_full_name,
|
63
|
+
git_ref=git_ref,
|
64
|
+
github_access_token=github_access_token,
|
65
|
+
)
|
66
|
+
)
|
67
|
+
|
48
68
|
if job_run["job"]["slug"] == "lint":
|
49
69
|
logger.debug("Executing Lint Job")
|
50
70
|
|
51
71
|
self.primitive.projects.job_run_update(
|
52
|
-
job_run["id"], status="
|
72
|
+
job_run["id"], status="request_in_progress"
|
53
73
|
)
|
54
74
|
|
55
|
-
result, message = self.primitive.lint.execute(
|
75
|
+
result, message = self.primitive.lint.execute(
|
76
|
+
source=downloaded_git_repository_dir
|
77
|
+
)
|
56
78
|
if result:
|
57
|
-
|
58
|
-
job_run["id"],
|
59
|
-
status="request_completed",
|
60
|
-
conclusion="success",
|
61
|
-
stdout=message,
|
62
|
-
)
|
79
|
+
conclusion = "success"
|
63
80
|
else:
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
81
|
+
conclusion = "failure"
|
82
|
+
self.primitive.projects.job_run_update(
|
83
|
+
job_run["id"],
|
84
|
+
status="request_completed",
|
85
|
+
conclusion=conclusion,
|
86
|
+
stdout=message,
|
87
|
+
)
|
88
|
+
|
89
|
+
logger.debug("Lint Job Completed")
|
70
90
|
|
71
91
|
sleep(5)
|
72
92
|
except KeyboardInterrupt:
|
primitive/cli.py
CHANGED
@@ -8,6 +8,7 @@ from .files.commands import cli as file_commands
|
|
8
8
|
from .hardware.commands import cli as hardware_commands
|
9
9
|
from .lint.commands import cli as lint_commands
|
10
10
|
from .agent.commands import cli as agent_commands
|
11
|
+
from .git.commands import cli as git_commands
|
11
12
|
|
12
13
|
|
13
14
|
@click.group()
|
@@ -57,6 +58,7 @@ cli.add_command(file_commands, "files")
|
|
57
58
|
cli.add_command(hardware_commands, "hardware")
|
58
59
|
cli.add_command(lint_commands, "lint")
|
59
60
|
cli.add_command(agent_commands, "agent")
|
61
|
+
cli.add_command(git_commands, "git")
|
60
62
|
|
61
63
|
if __name__ == "__main__":
|
62
64
|
cli(obj={})
|
primitive/client.py
CHANGED
@@ -8,6 +8,7 @@ from .simulations.actions import Simulations
|
|
8
8
|
from .hardware.actions import Hardware
|
9
9
|
from .lint.actions import Lint
|
10
10
|
from .agent.actions import Agent
|
11
|
+
from .git.actions import Git
|
11
12
|
|
12
13
|
from loguru import logger
|
13
14
|
|
@@ -59,6 +60,7 @@ class Primitive:
|
|
59
60
|
self.hardware: Hardware = Hardware(self)
|
60
61
|
self.lint: Lint = Lint(self)
|
61
62
|
self.agent: Agent = Agent(self)
|
63
|
+
self.git: Git = Git(self)
|
62
64
|
|
63
65
|
def get_host_config(self):
|
64
66
|
self.full_config = read_config_file()
|
File without changes
|
primitive/git/actions.py
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
from pathlib import Path
|
2
|
+
from primitive.utils.actions import BaseAction
|
3
|
+
from loguru import logger
|
4
|
+
import os
|
5
|
+
|
6
|
+
|
7
|
+
class Git(BaseAction):
|
8
|
+
def get_github_access_token(self) -> str:
|
9
|
+
query = """
|
10
|
+
query githubAppToken{
|
11
|
+
githubAppToken {
|
12
|
+
token
|
13
|
+
}
|
14
|
+
}
|
15
|
+
"""
|
16
|
+
|
17
|
+
filters = {}
|
18
|
+
variables = {
|
19
|
+
"filters": filters,
|
20
|
+
}
|
21
|
+
result = self.primitive.session.execute(query, variable_values=variables)
|
22
|
+
return result
|
23
|
+
|
24
|
+
def download_git_repository_at_ref(
|
25
|
+
self,
|
26
|
+
git_repo_full_name: str,
|
27
|
+
github_access_token: str,
|
28
|
+
git_ref: str = "main",
|
29
|
+
destination: Path = Path.cwd(),
|
30
|
+
) -> Path:
|
31
|
+
logger.debug(f"Downloading source code from {git_repo_full_name} {git_ref}")
|
32
|
+
# TODO: switch to subprocess.run or subprocess.Popen
|
33
|
+
url = f"https://api.github.com/repos/{git_repo_full_name}/tarball/{git_ref}"
|
34
|
+
untar_dir = Path(destination).joinpath(git_repo_full_name.split("/")[-1])
|
35
|
+
untar_dir.mkdir(parents=True, exist_ok=True)
|
36
|
+
|
37
|
+
result = os.system(
|
38
|
+
f"curl -s -L -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer {github_access_token}' -H 'X-GitHub-Api-Version: 2022-11-28' {url} | tar zx --strip-components 1 -C {untar_dir}"
|
39
|
+
)
|
40
|
+
if result != 0:
|
41
|
+
raise Exception("Failed to download repository")
|
42
|
+
return untar_dir
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import click
|
2
|
+
from pathlib import Path
|
3
|
+
import typing
|
4
|
+
from ..utils.printer import print_result
|
5
|
+
import os
|
6
|
+
|
7
|
+
if typing.TYPE_CHECKING:
|
8
|
+
from ..client import Primitive
|
9
|
+
|
10
|
+
|
11
|
+
import typing
|
12
|
+
|
13
|
+
if typing.TYPE_CHECKING:
|
14
|
+
from ..client import Primitive
|
15
|
+
|
16
|
+
|
17
|
+
@click.group()
|
18
|
+
@click.pass_context
|
19
|
+
def cli(context):
|
20
|
+
"""Git related commands"""
|
21
|
+
pass
|
22
|
+
|
23
|
+
|
24
|
+
@cli.command("download-ref")
|
25
|
+
@click.pass_context
|
26
|
+
@click.argument("git_repo_full_name", type=str)
|
27
|
+
@click.argument("git_ref", default="main", type=str)
|
28
|
+
@click.option(
|
29
|
+
"--github-access-token",
|
30
|
+
type=str,
|
31
|
+
default=lambda: os.environ.get("GITHUB_ACCESS_TOKEN", ""),
|
32
|
+
)
|
33
|
+
@click.argument("destination", type=click.Path(exists=True), default=".")
|
34
|
+
def download_ref_command(
|
35
|
+
context,
|
36
|
+
git_repo_full_name: str,
|
37
|
+
git_ref: str = "main",
|
38
|
+
github_access_token: str = "",
|
39
|
+
destination: Path = Path.cwd(),
|
40
|
+
):
|
41
|
+
primitive: Primitive = context.obj.get("PRIMITIVE")
|
42
|
+
result, message = primitive.git.download_git_repository_at_ref(
|
43
|
+
git_repo_full_name=git_repo_full_name,
|
44
|
+
git_ref=git_ref,
|
45
|
+
github_access_token=github_access_token,
|
46
|
+
destination=destination,
|
47
|
+
)
|
48
|
+
fg = "red" if not result else "green"
|
49
|
+
print_result(message, context=context, fg=fg)
|
primitive/lint/actions.py
CHANGED
@@ -9,7 +9,7 @@ from ..utils.verible import install_verible
|
|
9
9
|
|
10
10
|
class Lint(BaseAction):
|
11
11
|
def execute(self, source: Path = Path.cwd()) -> Tuple[bool, str]:
|
12
|
-
logger.debug("Starting linter
|
12
|
+
logger.debug("Starting linter for source: {source}")
|
13
13
|
files = find_files_for_extension(source, ".sv")
|
14
14
|
if not files:
|
15
15
|
message = "No files found to lint."
|
@@ -48,14 +48,11 @@ class Lint(BaseAction):
|
|
48
48
|
logger.debug("Linting complete.")
|
49
49
|
|
50
50
|
message = ""
|
51
|
-
if
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
message = "See above logs for linter output."
|
57
|
-
else:
|
58
|
-
message = result.stderr
|
51
|
+
if result.stderr:
|
52
|
+
logger.error("\n" + result.stderr)
|
53
|
+
if result.stdout:
|
54
|
+
logger.info("\n" + result.stdout)
|
55
|
+
message = "See above logs for linter output."
|
59
56
|
|
60
57
|
if result.returncode != 0:
|
61
58
|
if not self.primitive.DEBUG:
|
primitive/projects/actions.py
CHANGED
@@ -45,6 +45,11 @@ fragment JobRunFragment on JobRun {
|
|
45
45
|
createdAt
|
46
46
|
updatedAt
|
47
47
|
}
|
48
|
+
gitCommit {
|
49
|
+
sha
|
50
|
+
branch
|
51
|
+
repoFullName
|
52
|
+
}
|
48
53
|
}
|
49
54
|
|
50
55
|
query jobRuns(
|
@@ -156,3 +161,15 @@ query jobRuns(
|
|
156
161
|
variables = {"input": input}
|
157
162
|
result = self.primitive.session.execute(mutation, variable_values=variables)
|
158
163
|
return result
|
164
|
+
|
165
|
+
def github_access_token_for_job_run(self, job_run_id: str):
|
166
|
+
query = gql(
|
167
|
+
"""
|
168
|
+
query ghAppTokenForJobRun($jobRunId: GlobalID!) {
|
169
|
+
ghAppTokenForJobRun(jobRunId: $jobRunId)
|
170
|
+
}
|
171
|
+
"""
|
172
|
+
)
|
173
|
+
variables = {"jobRunId": job_run_id}
|
174
|
+
result = self.primitive.session.execute(query, variable_values=variables)
|
175
|
+
return result["ghAppTokenForJobRun"]
|
primitive/utils/files.py
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
from typing import List, Tuple
|
2
2
|
from pathlib import Path
|
3
3
|
from loguru import logger
|
4
|
+
import os
|
4
5
|
|
5
6
|
|
6
7
|
def find_files_for_extension(source: Path, extensions: Tuple[str]) -> List[Path]:
|
7
8
|
matching_files = []
|
8
9
|
logger.debug(f"Looking for files at {source} with extensions {extensions}")
|
9
|
-
for
|
10
|
+
# for those on python 3.12+
|
11
|
+
# for dirpath, dirnames, filenames in source.walk():
|
12
|
+
# for filename in filenames:
|
13
|
+
# if filename.endswith(extensions):
|
14
|
+
# matching_files.append(dirpath.joinpath(filename))
|
15
|
+
|
16
|
+
for dirpath, dirnames, filenames in os.walk(source):
|
10
17
|
for filename in filenames:
|
11
18
|
if filename.endswith(extensions):
|
12
|
-
matching_files.append(dirpath.joinpath(filename))
|
19
|
+
matching_files.append(Path(dirpath).joinpath(filename))
|
13
20
|
logger.debug(
|
14
21
|
f"Found {len(matching_files)} following files that match: {matching_files}"
|
15
22
|
)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: primitive
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.12
|
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,34 +1,37 @@
|
|
1
|
-
primitive/__about__.py,sha256=
|
1
|
+
primitive/__about__.py,sha256=35zrg1jAPnEjmmKrCnH1TpiDYB4jwmc5kkbIoAHlG84,129
|
2
2
|
primitive/__init__.py,sha256=bwKdgggKNVssJFVPfKSxqFMz4IxSr54WWbmiZqTMPNI,106
|
3
|
-
primitive/cli.py,sha256=
|
4
|
-
primitive/client.py,sha256=
|
5
|
-
primitive/agent/actions.py,sha256=
|
3
|
+
primitive/cli.py,sha256=fWv1gnUs7U6yWRrv1fYjt2bNBclIvp6okKTxrl_Il24,1879
|
4
|
+
primitive/client.py,sha256=dkbHg2Pbxl7NjIk2O6Shvz7TE7uDQezGQkNwmTzKdNs,2146
|
5
|
+
primitive/agent/actions.py,sha256=8eQDvUy0THT-zVvSTVgrDAsthRdSIpmhCkDr0iTXqDE,3673
|
6
6
|
primitive/agent/commands.py,sha256=-dVDilELfkGfbZB7qfEPs77Dm1oT62qJj4tsIk4KoxI,254
|
7
7
|
primitive/auth/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
8
|
primitive/auth/actions.py,sha256=N2bGcwXNsB89pzs66gF9A5_WzUScY5fhfOyWixqo2y8,1054
|
9
9
|
primitive/auth/commands.py,sha256=JahUq0E2e7Xa-FX1WEUv7TgM6ieDvNH4VwRRtxAW7HE,2340
|
10
10
|
primitive/files/actions.py,sha256=f4JN3QFB2WXw-0JpnE-4-movnqtvXIpCrGd_9pdkeW4,2624
|
11
11
|
primitive/files/commands.py,sha256=DDizo3xJnU3KLUBTMeeM72viVpnJinLwxs84tmqKhqo,810
|
12
|
+
primitive/git/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
|
+
primitive/git/actions.py,sha256=fepcl5529w_hsaC6fBw9f-QHeyqNjGXz8HI5ebzbZMs,1386
|
14
|
+
primitive/git/commands.py,sha256=64B2STTOn0dwVDmJHqEwekmIqKMfSyBBFwKg29Wt8Aw,1230
|
12
15
|
primitive/graphql/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
16
|
primitive/graphql/sdk.py,sha256=BhCGmDtc4sNnH8CxbQSJyFwOZ-ZSqMtjsxMB3JRBhPw,1456
|
14
17
|
primitive/hardware/actions.py,sha256=Ea3_2E3F_3WapV60g_mOIcpXhadoknwihR7slXyUWtk,18840
|
15
18
|
primitive/hardware/commands.py,sha256=QE7LLeFdfOqlvz3JwdwJJRZAY3fHI1zB9kYmmDajpq0,1477
|
16
|
-
primitive/lint/actions.py,sha256=
|
19
|
+
primitive/lint/actions.py,sha256=PDw0fkIkI5hHHjoHaAiXvQUocwHZkgB2mfI-LGMl6TI,2267
|
17
20
|
primitive/lint/commands.py,sha256=3CZvkOEMpJspJWmaQzA5bpPKx0_VCijQIXA9l-eTnZE,487
|
18
21
|
primitive/projects/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
19
|
-
primitive/projects/actions.py,sha256=
|
22
|
+
primitive/projects/actions.py,sha256=4Fwq2KTBuhDy8SfEIqPhR_8rW2rAL76cGWIQS40a96A,4039
|
20
23
|
primitive/simulations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
21
24
|
primitive/simulations/actions.py,sha256=YR0oxxd7_kuUIH77BWZLUs9rLRiSJztPPhpgDJU2PbY,1267
|
22
25
|
primitive/utils/actions.py,sha256=HOFrmM3-0A_A3NS84MqrZ6JmQEiiPSoDqEeuu6b_qfQ,196
|
23
26
|
primitive/utils/config.py,sha256=DlFM5Nglo22WPtbpZSVtH7NX-PTMaKYlcrUE7GPRG4c,1058
|
24
|
-
primitive/utils/files.py,sha256=
|
27
|
+
primitive/utils/files.py,sha256=Yv__bQes3YIlzhOT9kVxtYhoA5CmUjPSvphl9PZ41k4,867
|
25
28
|
primitive/utils/git.py,sha256=1qNOu8X-33CavmrD580BmrFhD_WVO9PGWHUUboXJR_g,663
|
26
29
|
primitive/utils/memory_size.py,sha256=4xfha21kW82nFvOTtDFx9Jk2ZQoEhkfXii-PGNTpIUk,3058
|
27
30
|
primitive/utils/printer.py,sha256=f1XUpqi5dkTL3GWvYRUGlSwtj2IxU1q745T4Fxo7Tn4,370
|
28
31
|
primitive/utils/shell.py,sha256=-7UjQaBqSGHzEEyX8pNjeYFFP0P3lVnDV0OkgPz1qHU,1050
|
29
32
|
primitive/utils/verible.py,sha256=QYczN1IvxODfj4jeq0nqjFuF0Oi0Zdx-Q32ySOJgcw8,2205
|
30
|
-
primitive-0.1.
|
31
|
-
primitive-0.1.
|
32
|
-
primitive-0.1.
|
33
|
-
primitive-0.1.
|
34
|
-
primitive-0.1.
|
33
|
+
primitive-0.1.12.dist-info/METADATA,sha256=Zpkvn5C7K77B5vWuLDBp1SATMc_sZM6iR4J15DVzN8w,1818
|
34
|
+
primitive-0.1.12.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
35
|
+
primitive-0.1.12.dist-info/entry_points.txt,sha256=p1K8DMCWka5FqLlqP1sPek5Uovy9jq8u51gUsP-z334,48
|
36
|
+
primitive-0.1.12.dist-info/licenses/LICENSE.txt,sha256=B8kmQMJ2sxYygjCLBk770uacaMci4mPSoJJ8WoDBY_c,1098
|
37
|
+
primitive-0.1.12.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|