primitive 0.1.1__py3-none-any.whl → 0.1.4__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 +4 -0
- primitive/__init__.py +3 -0
- primitive/auth/__init__.py +0 -0
- primitive/auth/actions.py +43 -0
- primitive/auth/commands.py +77 -0
- primitive/cli.py +60 -0
- primitive/client.py +66 -0
- primitive/files/actions.py +76 -0
- primitive/files/commands.py +28 -0
- primitive/graphql/__init__.py +0 -0
- primitive/graphql/sdk.py +53 -0
- primitive/hardware/actions.py +447 -0
- primitive/hardware/commands.py +53 -0
- primitive/lint/actions.py +67 -0
- primitive/lint/commands.py +17 -0
- primitive/projects/__init__.py +0 -0
- primitive/projects/actions.py +55 -0
- primitive/simulations/__init__.py +0 -0
- primitive/simulations/actions.py +48 -0
- primitive/utils/actions.py +9 -0
- primitive/utils/config.py +34 -0
- primitive/utils/files.py +16 -0
- primitive/utils/git.py +15 -0
- primitive/utils/memory_size.py +87 -0
- primitive/utils/printer.py +14 -0
- primitive/utils/shell.py +63 -0
- primitive/utils/verible.py +51 -0
- primitive-0.1.4.dist-info/METADATA +49 -0
- primitive-0.1.4.dist-info/RECORD +32 -0
- {primitive-0.1.1.dist-info → primitive-0.1.4.dist-info}/WHEEL +1 -1
- primitive-0.1.4.dist-info/entry_points.txt +2 -0
- primitive-0.1.4.dist-info/licenses/LICENSE.txt +9 -0
- primitive/main.py +0 -18
- primitive/scope/__init__.py +0 -2
- primitive/scope/simulator.py +0 -12
- primitive/scope/watch.py +0 -42
- primitive-0.1.1.dist-info/METADATA +0 -15
- primitive-0.1.1.dist-info/RECORD +0 -9
- primitive-0.1.1.dist-info/entry_points.txt +0 -3
@@ -0,0 +1,34 @@
|
|
1
|
+
import json
|
2
|
+
from pathlib import Path
|
3
|
+
from typing import Dict
|
4
|
+
|
5
|
+
HOME_DIRECTORY = Path.home()
|
6
|
+
PRIMITIVE_CREDENTIALS_FILEPATH = Path(
|
7
|
+
HOME_DIRECTORY / ".config" / "primitive" / "credentials.json"
|
8
|
+
)
|
9
|
+
|
10
|
+
|
11
|
+
def create_directory(filepath: Path = PRIMITIVE_CREDENTIALS_FILEPATH):
|
12
|
+
filepath.mkdir(parents=True, exist_ok=True)
|
13
|
+
|
14
|
+
|
15
|
+
def create_config_file(filepath: Path = PRIMITIVE_CREDENTIALS_FILEPATH):
|
16
|
+
filepath.parent.mkdir(parents=True, exist_ok=True)
|
17
|
+
filepath.touch()
|
18
|
+
with filepath.open("w") as json_file:
|
19
|
+
json.dump({}, json_file)
|
20
|
+
|
21
|
+
|
22
|
+
def update_config_file(
|
23
|
+
filepath: Path = PRIMITIVE_CREDENTIALS_FILEPATH, new_config: Dict = {}
|
24
|
+
):
|
25
|
+
existing_config = read_config_file(filepath=filepath)
|
26
|
+
merged_config = {**existing_config, **new_config}
|
27
|
+
with filepath.open("w") as json_file:
|
28
|
+
json.dump(merged_config, json_file, indent=2)
|
29
|
+
|
30
|
+
|
31
|
+
def read_config_file(filepath: Path = PRIMITIVE_CREDENTIALS_FILEPATH) -> Dict:
|
32
|
+
if not filepath.exists():
|
33
|
+
create_config_file(filepath=filepath)
|
34
|
+
return json.loads(filepath.read_text())
|
primitive/utils/files.py
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
from typing import List, Tuple
|
2
|
+
from pathlib import Path
|
3
|
+
from loguru import logger
|
4
|
+
|
5
|
+
|
6
|
+
def find_files_for_extension(source: Path, extensions: Tuple[str]) -> List[Path]:
|
7
|
+
matching_files = []
|
8
|
+
logger.debug(f"Looking for files at {source} with extensions {extensions}")
|
9
|
+
for dirpath, dirnames, filenames in source.walk():
|
10
|
+
for filename in filenames:
|
11
|
+
if filename.endswith(extensions):
|
12
|
+
matching_files.append(dirpath.joinpath(filename))
|
13
|
+
logger.debug(
|
14
|
+
f"Found {len(matching_files)} following files that match: {matching_files}"
|
15
|
+
)
|
16
|
+
return matching_files
|
primitive/utils/git.py
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
import os
|
2
|
+
from loguru import logger
|
3
|
+
|
4
|
+
|
5
|
+
def download_source(github_access_token, git_repository, git_ref) -> None:
|
6
|
+
# Download code to current directory
|
7
|
+
logger.debug(f"Downloading source code from {git_repository} {git_ref}")
|
8
|
+
url = f"https://api.github.com/repos/{git_repository}/tarball/{git_ref}"
|
9
|
+
# TODO: switch to supbrocess.run or subprocess.Popen
|
10
|
+
result = os.system(
|
11
|
+
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 ."
|
12
|
+
)
|
13
|
+
|
14
|
+
if result != 0:
|
15
|
+
raise Exception("Failed to import repository.")
|
@@ -0,0 +1,87 @@
|
|
1
|
+
from typing import Tuple
|
2
|
+
|
3
|
+
|
4
|
+
class MemorySize:
|
5
|
+
CONVERSION_FACTORS: dict[str, float] = {
|
6
|
+
"b": 1 / 8,
|
7
|
+
"B": 1,
|
8
|
+
"KB": 1000,
|
9
|
+
"MB": 1000**2,
|
10
|
+
"GB": 1000**3,
|
11
|
+
"TB": 1000**4,
|
12
|
+
"PB": 1000**5,
|
13
|
+
"KiB": 2**10,
|
14
|
+
"MiB": 2**20,
|
15
|
+
"GiB": 2**30,
|
16
|
+
"TiB": 2**40,
|
17
|
+
"PiB": 2**50,
|
18
|
+
}
|
19
|
+
|
20
|
+
def __init__(self, value_or_string: int | float | str, unit: str | None = None):
|
21
|
+
"""
|
22
|
+
Initializes MemorySize in two ways:
|
23
|
+
size = MemorySize("3.14 GB") - value_or_string is str and unit is None
|
24
|
+
size = MemorySize(42, "MB") - value_or_string is int and unit is str
|
25
|
+
size = MemorySize(2.718, "PB") - value_or_string is float and unit is str
|
26
|
+
"""
|
27
|
+
if isinstance(value_or_string, str):
|
28
|
+
parts = value_or_string.split()
|
29
|
+
if len(parts) != 2:
|
30
|
+
raise ValueError(f"Invalid size string format: {value_or_string}")
|
31
|
+
|
32
|
+
value_string, unit = parts
|
33
|
+
try:
|
34
|
+
self.value = float(value_string)
|
35
|
+
except ValueError:
|
36
|
+
raise ValueError(f"Invalid size value: {value_string}")
|
37
|
+
self.unit = unit
|
38
|
+
elif isinstance(value_or_string, int | float) and isinstance(unit, str):
|
39
|
+
self.value = float(value_or_string)
|
40
|
+
self.unit = unit
|
41
|
+
else:
|
42
|
+
message = f"Invalid arguments provided: {value_or_string}:{type(value_or_string)} and {unit}:{type(unit)}" # noqa
|
43
|
+
raise ValueError(message)
|
44
|
+
|
45
|
+
if not self.CONVERSION_FACTORS.get(self.unit):
|
46
|
+
message = f"Invalid unit: {self.unit}"
|
47
|
+
raise ValueError(message)
|
48
|
+
|
49
|
+
def __str__(self):
|
50
|
+
return f"{self.value:.3f} {self.unit}"
|
51
|
+
|
52
|
+
def __eq__(self, other):
|
53
|
+
if not isinstance(other, MemorySize):
|
54
|
+
raise TypeError(f"Comparison with unsupported type: {type(other)}")
|
55
|
+
return self.to_bytes() == other.to_bytes()
|
56
|
+
|
57
|
+
def to_bytes(self):
|
58
|
+
"""
|
59
|
+
Converts value to bytes (B)
|
60
|
+
"""
|
61
|
+
return self.value * self.CONVERSION_FACTORS.get(self.unit, 1)
|
62
|
+
|
63
|
+
def convert_to(self, target_unit):
|
64
|
+
"""
|
65
|
+
Converts the stored value to a different unit and updates the instance.
|
66
|
+
"""
|
67
|
+
if target_unit not in self.CONVERSION_FACTORS:
|
68
|
+
raise ValueError(f"Invalid unit {target_unit}")
|
69
|
+
|
70
|
+
factor = (
|
71
|
+
self.CONVERSION_FACTORS[self.unit] / self.CONVERSION_FACTORS[target_unit]
|
72
|
+
)
|
73
|
+
self.value *= factor
|
74
|
+
self.unit = target_unit
|
75
|
+
|
76
|
+
def get_human_readable(self) -> Tuple[float, str]:
|
77
|
+
"""
|
78
|
+
Converts the stored value to a human-readable format
|
79
|
+
"""
|
80
|
+
HUMAN_READABLE_UNITS: list[str] = ["PB", "TB", "GB", "MB", "KB", "B"]
|
81
|
+
|
82
|
+
value_in_bytes = self.to_bytes()
|
83
|
+
for unit in HUMAN_READABLE_UNITS:
|
84
|
+
value_in_unit = value_in_bytes * (1.000 / self.CONVERSION_FACTORS[unit])
|
85
|
+
if value_in_unit >= 1.0:
|
86
|
+
return (value_in_unit, unit)
|
87
|
+
return (value_in_bytes, "B")
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import json
|
2
|
+
|
3
|
+
import click
|
4
|
+
from loguru import logger
|
5
|
+
|
6
|
+
|
7
|
+
def print_result(message: str, context: click.Context, fg: str = None):
|
8
|
+
"""Print message to stdout or stderr"""
|
9
|
+
if context.obj["DEBUG"]:
|
10
|
+
logger.info(json.dumps(message))
|
11
|
+
else:
|
12
|
+
if context.obj["JSON"]:
|
13
|
+
message = json.dumps(message, indent=2)
|
14
|
+
click.secho(message, fg=fg)
|
primitive/utils/shell.py
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
from pathlib import Path
|
2
|
+
import subprocess
|
3
|
+
|
4
|
+
|
5
|
+
def add_path_to_shell(path: Path):
|
6
|
+
try:
|
7
|
+
subprocess.run(["fish_add_path", path], capture_output=True)
|
8
|
+
return True
|
9
|
+
except FileNotFoundError:
|
10
|
+
pass
|
11
|
+
|
12
|
+
if Path.home() / ".bash_profile":
|
13
|
+
subprocess.run(
|
14
|
+
[
|
15
|
+
"echo",
|
16
|
+
f"'export PATH={path}:$PATH'",
|
17
|
+
">>",
|
18
|
+
"~/.bash_profile",
|
19
|
+
],
|
20
|
+
capture_output=True,
|
21
|
+
)
|
22
|
+
elif Path.home() / ".bashrc":
|
23
|
+
subprocess.run(
|
24
|
+
[
|
25
|
+
"echo",
|
26
|
+
f"'export PATH={path}:$PATH'",
|
27
|
+
">>",
|
28
|
+
"~/.bashrc",
|
29
|
+
],
|
30
|
+
capture_output=True,
|
31
|
+
)
|
32
|
+
elif Path.home() / ".zshrc":
|
33
|
+
subprocess.run(
|
34
|
+
[
|
35
|
+
"echo",
|
36
|
+
f"'export PATH={path}:$PATH'",
|
37
|
+
">>",
|
38
|
+
"~/.zshrc",
|
39
|
+
],
|
40
|
+
capture_output=True,
|
41
|
+
)
|
42
|
+
elif Path.home() / ".profile":
|
43
|
+
subprocess.run(
|
44
|
+
[
|
45
|
+
"echo",
|
46
|
+
f"'export PATH={path}:$PATH'",
|
47
|
+
">>",
|
48
|
+
"~/.profile",
|
49
|
+
],
|
50
|
+
capture_output=True,
|
51
|
+
)
|
52
|
+
elif Path.home() / ".bash_login":
|
53
|
+
subprocess.run(
|
54
|
+
[
|
55
|
+
"echo",
|
56
|
+
f"'export PATH={path}:$PATH'",
|
57
|
+
">>",
|
58
|
+
"~/.bash_login",
|
59
|
+
],
|
60
|
+
capture_output=True,
|
61
|
+
)
|
62
|
+
else:
|
63
|
+
raise Exception(f"Failed to add {path} to PATH")
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import tarfile
|
2
|
+
import requests
|
3
|
+
from .shell import add_path_to_shell
|
4
|
+
from pathlib import Path
|
5
|
+
|
6
|
+
from loguru import logger
|
7
|
+
|
8
|
+
|
9
|
+
VERIBLE_MAC_OS_LINK = "https://github.com/chipsalliance/verible/releases/download/v0.0-3752-g8b64887e/verible-v0.0-3752-g8b64887e-macOS.tar.gz"
|
10
|
+
VERIBLE_WINDOWS_64_OS_LINK = "https://github.com/chipsalliance/verible/releases/download/v0.0-3752-g8b64887e/verible-v0.0-3752-g8b64887e-win64.zip"
|
11
|
+
VERIBLE_LINUX_X86_64_OS_LINK = "https://github.com/chipsalliance/verible/releases/download/v0.0-3752-g8b64887e/verible-v0.0-3752-g8b64887e-linux-static-x86_64.tar.gz"
|
12
|
+
VERIBLE_LINUX_ARM64_LINK = "https://github.com/chipsalliance/verible/releases/download/v0.0-3752-g8b64887e/verible-v0.0-3752-g8b64887e-linux-static-arm64.tar.gz"
|
13
|
+
|
14
|
+
|
15
|
+
def install_verible(system_info: dict) -> bool:
|
16
|
+
url = None
|
17
|
+
if system_info.get("os_family") == "Darwin":
|
18
|
+
url = VERIBLE_MAC_OS_LINK
|
19
|
+
elif system_info.get("os_family") == "Windows":
|
20
|
+
url = VERIBLE_WINDOWS_64_OS_LINK
|
21
|
+
elif system_info.processor == "x86_64":
|
22
|
+
url = VERIBLE_LINUX_X86_64_OS_LINK
|
23
|
+
elif system_info.processor == "arm":
|
24
|
+
url = VERIBLE_LINUX_X86_64_OS_LINK
|
25
|
+
|
26
|
+
verible_dir_name = url.split("/")[-1].split(".tar.gz")[0]
|
27
|
+
file_download_path = Path.home() / f"{verible_dir_name}.tar.gz"
|
28
|
+
|
29
|
+
logger.debug("Downloading verible")
|
30
|
+
response = requests.get(url, stream=True)
|
31
|
+
if response.status_code == 200:
|
32
|
+
with open(file_download_path, "wb") as file:
|
33
|
+
file.write(response.raw.read())
|
34
|
+
else:
|
35
|
+
raise Exception(
|
36
|
+
f"Failed to download verible. {response.status_code}. {response.text}"
|
37
|
+
)
|
38
|
+
|
39
|
+
logger.debug("Untaring verible")
|
40
|
+
with tarfile.open(file_download_path) as tar:
|
41
|
+
tar.extractall(Path.home())
|
42
|
+
|
43
|
+
logger.debug("Deleting tar.gz artifact")
|
44
|
+
file_download_path.unlink()
|
45
|
+
|
46
|
+
verible_bin = Path.home() / verible_dir_name / "bin"
|
47
|
+
|
48
|
+
logger.debug("Adding verible to PATH")
|
49
|
+
add_path_to_shell(verible_bin)
|
50
|
+
|
51
|
+
return True
|
@@ -0,0 +1,49 @@
|
|
1
|
+
Metadata-Version: 2.3
|
2
|
+
Name: primitive
|
3
|
+
Version: 0.1.4
|
4
|
+
Project-URL: Documentation, https://github.com//primitivecorp/primitive-cli#readme
|
5
|
+
Project-URL: Issues, https://github.com//primitivecorp/primitive-cli/issues
|
6
|
+
Project-URL: Source, https://github.com//primitivecorp/primitive-cli
|
7
|
+
Author-email: Dylan Stein <dylan@primitive.tech>, Chase Zimmerman <chase@primitive.tech>
|
8
|
+
License-Expression: MIT
|
9
|
+
License-File: LICENSE.txt
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
11
|
+
Classifier: Programming Language :: Python
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
18
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
19
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
20
|
+
Requires-Python: >=3.12
|
21
|
+
Requires-Dist: click
|
22
|
+
Requires-Dist: gql[all]
|
23
|
+
Requires-Dist: ipdb
|
24
|
+
Requires-Dist: loguru
|
25
|
+
Requires-Dist: pyright
|
26
|
+
Requires-Dist: ruff
|
27
|
+
Description-Content-Type: text/markdown
|
28
|
+
|
29
|
+
# primitive
|
30
|
+
|
31
|
+
[](https://pypi.org/project/primitive-cli)
|
32
|
+
[](https://pypi.org/project/primitive-cli)
|
33
|
+
|
34
|
+
---
|
35
|
+
|
36
|
+
**Table of Contents**
|
37
|
+
|
38
|
+
- [Installation](#installation)
|
39
|
+
- [License](#license)
|
40
|
+
|
41
|
+
## Installation
|
42
|
+
|
43
|
+
```console
|
44
|
+
pip install primitive
|
45
|
+
```
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
`primitive` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
@@ -0,0 +1,32 @@
|
|
1
|
+
primitive/__about__.py,sha256=E2SXPkbuFZByKB4zIeOf_Me_bVBs-mUA8TpF7fO1FrM,128
|
2
|
+
primitive/__init__.py,sha256=bwKdgggKNVssJFVPfKSxqFMz4IxSr54WWbmiZqTMPNI,106
|
3
|
+
primitive/cli.py,sha256=QC4jbu8s0uhNxFmaTO2B-X1o1gpyFX3xJVHU-j5CvQE,1705
|
4
|
+
primitive/client.py,sha256=cZiJjzZ4HkCtYViDNOIoNuf7mcp772eSCSztsqh381E,2010
|
5
|
+
primitive/auth/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
+
primitive/auth/actions.py,sha256=N2bGcwXNsB89pzs66gF9A5_WzUScY5fhfOyWixqo2y8,1054
|
7
|
+
primitive/auth/commands.py,sha256=JahUq0E2e7Xa-FX1WEUv7TgM6ieDvNH4VwRRtxAW7HE,2340
|
8
|
+
primitive/files/actions.py,sha256=f4JN3QFB2WXw-0JpnE-4-movnqtvXIpCrGd_9pdkeW4,2624
|
9
|
+
primitive/files/commands.py,sha256=DDizo3xJnU3KLUBTMeeM72viVpnJinLwxs84tmqKhqo,810
|
10
|
+
primitive/graphql/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
|
+
primitive/graphql/sdk.py,sha256=BhCGmDtc4sNnH8CxbQSJyFwOZ-ZSqMtjsxMB3JRBhPw,1456
|
12
|
+
primitive/hardware/actions.py,sha256=BbFz17NKVDiI-9SiV1R1GPqsXRZwUm9oNj-Dc_bBFJ8,17133
|
13
|
+
primitive/hardware/commands.py,sha256=QE7LLeFdfOqlvz3JwdwJJRZAY3fHI1zB9kYmmDajpq0,1477
|
14
|
+
primitive/lint/actions.py,sha256=FVigksFrADPDD3zHS0g0riyVrge7eEtwWk5PG2aZv9A,2352
|
15
|
+
primitive/lint/commands.py,sha256=3CZvkOEMpJspJWmaQzA5bpPKx0_VCijQIXA9l-eTnZE,487
|
16
|
+
primitive/projects/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
17
|
+
primitive/projects/actions.py,sha256=Zi0uFCUG5KU7w7HNE8eGlhUPdsJyjVrakcdU1PR8-MQ,1481
|
18
|
+
primitive/simulations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
19
|
+
primitive/simulations/actions.py,sha256=YR0oxxd7_kuUIH77BWZLUs9rLRiSJztPPhpgDJU2PbY,1267
|
20
|
+
primitive/utils/actions.py,sha256=HOFrmM3-0A_A3NS84MqrZ6JmQEiiPSoDqEeuu6b_qfQ,196
|
21
|
+
primitive/utils/config.py,sha256=DlFM5Nglo22WPtbpZSVtH7NX-PTMaKYlcrUE7GPRG4c,1058
|
22
|
+
primitive/utils/files.py,sha256=Ug5UqrS9eZoTd08EFtgyyp8flsJTfsG9CwXBWmI-yFA,606
|
23
|
+
primitive/utils/git.py,sha256=1qNOu8X-33CavmrD580BmrFhD_WVO9PGWHUUboXJR_g,663
|
24
|
+
primitive/utils/memory_size.py,sha256=4xfha21kW82nFvOTtDFx9Jk2ZQoEhkfXii-PGNTpIUk,3058
|
25
|
+
primitive/utils/printer.py,sha256=f1XUpqi5dkTL3GWvYRUGlSwtj2IxU1q745T4Fxo7Tn4,370
|
26
|
+
primitive/utils/shell.py,sha256=xGsz3-3mmUP5xRrFotNj0UpbHmRSsiliQnyPzB48xLI,1567
|
27
|
+
primitive/utils/verible.py,sha256=o2NBbqteePgFY-28S7AaEivSEszZcePFkMRXpg_XhHg,1990
|
28
|
+
primitive-0.1.4.dist-info/METADATA,sha256=bW4QfYYNW6TWBazUnmjK3s7see0nYczt4UHcyupynYw,1642
|
29
|
+
primitive-0.1.4.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
30
|
+
primitive-0.1.4.dist-info/entry_points.txt,sha256=p1K8DMCWka5FqLlqP1sPek5Uovy9jq8u51gUsP-z334,48
|
31
|
+
primitive-0.1.4.dist-info/licenses/LICENSE.txt,sha256=B8kmQMJ2sxYygjCLBk770uacaMci4mPSoJJ8WoDBY_c,1098
|
32
|
+
primitive-0.1.4.dist-info/RECORD,,
|
@@ -0,0 +1,9 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024-present Dylan Stein <dylan@steins.studio>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
primitive/main.py
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
import click
|
2
|
-
from scope import DirectoryWatch
|
3
|
-
|
4
|
-
@click.group()
|
5
|
-
def cli():
|
6
|
-
pass
|
7
|
-
|
8
|
-
# Watch filesystem for changes
|
9
|
-
@cli.command()
|
10
|
-
@click.option('--path', default='.', help='Path to watch for changes.')
|
11
|
-
@click.option('--ask', default=False, help='Ask before running simulation.')
|
12
|
-
def watch(path, ask):
|
13
|
-
click.echo(f"Watching {path} for changes")
|
14
|
-
watcher = DirectoryWatch(path, ask)
|
15
|
-
watcher.run()
|
16
|
-
|
17
|
-
if __name__ == '__main__':
|
18
|
-
cli()
|
primitive/scope/__init__.py
DELETED
primitive/scope/simulator.py
DELETED
primitive/scope/watch.py
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
""" Watch filesystem for changes and manage simulation data """
|
2
|
-
import click
|
3
|
-
import time
|
4
|
-
from watchdog.observers import Observer
|
5
|
-
from watchdog.events import FileSystemEventHandler
|
6
|
-
from scope.simulator import Simulator
|
7
|
-
|
8
|
-
class Handler(FileSystemEventHandler):
|
9
|
-
def __init__(self, ask):
|
10
|
-
self.ask = ask
|
11
|
-
self.simulator = Simulator()
|
12
|
-
|
13
|
-
def on_any_event(self, event):
|
14
|
-
if event.is_directory: return None
|
15
|
-
|
16
|
-
if event.event_type == 'created' or event.event_type == 'modified' or event.event_type == 'deleted':
|
17
|
-
# If we recognize a file has changed, prompt user to run simulation
|
18
|
-
click.echo(f"File {event.src_path} has changed. ", nl=False)
|
19
|
-
if self.ask:
|
20
|
-
click.echo(f"Press enter to start simulation.")
|
21
|
-
input()
|
22
|
-
|
23
|
-
click.echo(f"Running simulation...")
|
24
|
-
|
25
|
-
class DirectoryWatch:
|
26
|
-
def __init__(self, path, ask):
|
27
|
-
self.path = path
|
28
|
-
self.ask = ask
|
29
|
-
self.observer = Observer()
|
30
|
-
|
31
|
-
def run(self):
|
32
|
-
event_handler = Handler(self.ask)
|
33
|
-
self.observer.schedule(event_handler, self.path, recursive = True)
|
34
|
-
self.observer.start()
|
35
|
-
try:
|
36
|
-
while True:
|
37
|
-
time.sleep(5)
|
38
|
-
except:
|
39
|
-
self.observer.stop()
|
40
|
-
print("Observer Stopped")
|
41
|
-
|
42
|
-
self.observer.join()
|
@@ -1,15 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: primitive
|
3
|
-
Version: 0.1.1
|
4
|
-
Summary: cli tool for interacting with primitive
|
5
|
-
Author: Chase Zimmerman
|
6
|
-
Author-email: chaseklvk@icloud.com
|
7
|
-
Requires-Python: >=3.10,<4.0
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
9
|
-
Classifier: Programming Language :: Python :: 3.10
|
10
|
-
Classifier: Programming Language :: Python :: 3.11
|
11
|
-
Requires-Dist: click (>=8.1.7,<9.0.0)
|
12
|
-
Requires-Dist: watchdog (>=3.0.0,<4.0.0)
|
13
|
-
Description-Content-Type: text/markdown
|
14
|
-
|
15
|
-
# cli
|
primitive-0.1.1.dist-info/RECORD
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
primitive/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
primitive/main.py,sha256=ZC_2xwCBbCjihKpVCq2EO3QW7C9RfZnL0WtZ3FPdd1s,433
|
3
|
-
primitive/scope/__init__.py,sha256=Te58G6-QBLjsRJBE78puT5vzYIxMcXKebFRCDGUhbNc,49
|
4
|
-
primitive/scope/simulator.py,sha256=VV6YewLkGvGBCTogRWJ85FmZyuuG--mLmoX6_-N9IvI,223
|
5
|
-
primitive/scope/watch.py,sha256=Abq-Ncvmx3PykI6Qn92J2wmFd6y8-wQSKf8IWTvnws4,1158
|
6
|
-
primitive-0.1.1.dist-info/METADATA,sha256=79KL3BNNfw6tvqa7zJCURf9PdMVsDYrfMSzopiWgNoA,466
|
7
|
-
primitive-0.1.1.dist-info/WHEEL,sha256=d2fvjOD7sXsVzChCqf0Ty0JbHKBaLYwDbGQDwQTnJ50,88
|
8
|
-
primitive-0.1.1.dist-info/entry_points.txt,sha256=v26R3swfLXOD1XUSqQN7hZWC2CYH49Hp7iq7Tzk2NYE,48
|
9
|
-
primitive-0.1.1.dist-info/RECORD,,
|