Skip to content
This repository was archived by the owner on Nov 29, 2024. It is now read-only.

Code tidy-ups, updates #7

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import setuptools
from setuptools import find_packages
import re
import os
import re
import subprocess

import setuptools
from setuptools import find_packages

with open("./visionscript/__init__.py", 'r') as f:
content = f.read()
# from https://www.py4u.net/discuss/139845
version = re.search(r'__version__\s*=\s*[\'"]([^\'"]*)[\'"]', content).group(1)

with open("README.md", "r") as fh:
long_description = fh.read()

Expand All @@ -28,7 +29,7 @@ def install_fast_sam_for_segmentation() -> None:
for command in commands:
subprocess.run(f"cd {HOME} && {command}", shell=True)


setuptools.setup(
name="visionscript",
version=version,
Expand Down Expand Up @@ -56,4 +57,4 @@ def install_fast_sam_for_segmentation() -> None:
python_requires=">=3.7",
)

# install_fast_sam_for_segmentation()
# install_fast_sam_for_segmentation()
10 changes: 6 additions & 4 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import visionscript as lang
import os

import tqdm

import visionscript as lang

TEST_DIR = "./"

tests = os.listdir(TEST_DIR)

passed = 0
test_count = len(tests)

for file in tqdm.tqdm(os.listdir(TEST_DIR)):
for file in tqdm.tqdm(os.listdir(TEST_DIR)):
session = lang.VisionScript()

if file.endswith(".vic"):
print(f"Testing {file}...")

try:
with open(TEST_DIR + file, "r") as f:
session.parse_tree(lang.parser.parse(f.read() + "\n"))
Expand All @@ -25,4 +27,4 @@

passed += 1

print(f"{passed}/{test_count} tests passed!")
print(f"{passed}/{test_count} tests passed!")
6 changes: 2 additions & 4 deletions visionscript/error_handling.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from spellchecker import SpellChecker

from visionscript.usage import (
language_grammar_reference,
lowercase_language_grammar_reference,
)
from visionscript.usage import (language_grammar_reference,
lowercase_language_grammar_reference)

spell = SpellChecker()

Expand Down
27 changes: 13 additions & 14 deletions visionscript/lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
from watchdog.observers import Observer

from visionscript import registry
from visionscript.error_handling import (
handle_unexpected_characters,
handle_unexpected_token,
)
from visionscript.error_handling import (handle_unexpected_characters,
handle_unexpected_token)
from visionscript.grammar import grammar
from visionscript.paper_ocr_correction import line_processing, syntax_correction
from visionscript.paper_ocr_correction import (line_processing,
syntax_correction)
from visionscript.state import init_state
from visionscript.usage import USAGE, language_grammar_reference

Expand Down Expand Up @@ -255,7 +254,7 @@ def __init__(self, notebook=False, debug=False):

def random(self, args):
return random.choice(args)


def opposite(self, args):
statement = True if args[0] == "True" else False
Expand Down Expand Up @@ -428,7 +427,7 @@ def input_(self, key):
return self.state["input_variables"][literal_eval(key)]

if not self.notebook:
return input("Enter a value for {}: ".format(key))
return input(f"Enter a value for {key}: ")

return None

Expand Down Expand Up @@ -1185,7 +1184,7 @@ def comparepose(self, args):
if len(args) == 0:
if len(self.state["poses_stack"]) < 2:
return 0

item1 = self._get_item(-1, "poses_stack")
# should be -2, 0 for testing
item2 = self._get_item(0, "poses_stack")
Expand Down Expand Up @@ -2523,8 +2522,8 @@ def evaluate_tree(self, tree):
if token.value == "usecamera":
self.state["ctx"]["fps"] = 0
self.state["ctx"]["active_file"] = None
from threading import Thread, Event
from threading import Event, Thread

self.state["ctx"]["camera"] = cv2.VideoCapture(0)

context = node.children
Expand Down Expand Up @@ -2562,7 +2561,7 @@ def process_context(context):
break

self.parse_tree(item)

if self.state["ctx"].get("break"):
print("breaking")
stop_event.set()
Expand All @@ -2575,7 +2574,7 @@ def process_context(context):
thread = None
# stop camera
break

if self.state["run_video_in_background"]:
if not thread:
print('starting thread')
Expand Down Expand Up @@ -3010,14 +3009,14 @@ def on_modified(event):
print("-" * 20)

for command, runtime in profile_command_run_time:
runtime = "{:.2f}".format(runtime)
runtime = f"{runtime:.2f}"
print(command, ":", runtime + "s")

current_time = time.time()

print(
"Total run time:",
"{:.2f}s".format(current_time - session.run_start_time),
f"{current_time - session.run_start_time:.2f}s",
)

# if no file:
Expand Down