Skip to content

Commit

Permalink
Prepare release (#33)
Browse files Browse the repository at this point in the history
* Release preparation.
- README updated.
- polygon is excluded from the codebase.

* Test utils separated.

* load_json moved to tests/utils.
  • Loading branch information
devrimcavusoglu authored Oct 7, 2024
1 parent bcd2b18 commit a96dc46
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 78 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ Light weight toolkit for bounding boxes providing conversion between bounding bo
- **w:** width
- **c:** center


## News 🔥

* 2024/10/07 - [Annotations](#annotation-file-conversion) are supported for YOLO, COCO and VOC formats.

## Roadmap 🛣️

- [X] Annotation file support.
- [ ] (Upcoming) 3D Bounding Box support.
- [ ] (Upcoming) Polygon support.

### Important Notice
Support for Python<3.8 will be dropped starting version `0.2` though the development for Python3.6 and Python3.7 may
continue where it will be developed under version `0.1.x` for future versions. This may introduce; however, certain
Expand Down Expand Up @@ -287,17 +298,17 @@ pip install -e .[dev]

To tests simply run.

python tests/run_tests.py
python -m tests.run_tests

### Code Style

To check code style,

python tests/run_code_style.py check
python -m tests.run_code_style check

To format codebase,

python tests/run_code_style.py format
python -m tests.run_code_style format

## License

Expand Down
18 changes: 0 additions & 18 deletions pybboxes/types/polygon.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/run_code_style.py → scripts/run_code_style.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys

from tests.utils import shell, validate_and_exit
from scripts.utils import shell, validate_and_exit

if __name__ == "__main__":
arg = sys.argv[1]
Expand Down
2 changes: 1 addition & 1 deletion tests/run_tests.py → scripts/run_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from tests.utils import shell, validate_and_exit
from scripts.utils import shell, validate_and_exit

if __name__ == "__main__":
sts_tests = shell("pytest --cov pybboxes --cov-report term-missing --cov-report xml")
Expand Down
51 changes: 51 additions & 0 deletions scripts/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import json
import os
import re
import shutil
import sys


def shell(command, exit_status=0):
"""
Run command through shell and return exit status if exit status of command run match with given exit status.
Args:
command: (str) Command string which runs through system shell.
exit_status: (int) Expected exit status of given command run.
Returns: actual_exit_status
"""
actual_exit_status = os.system(command)
if actual_exit_status == exit_status:
return 0
return actual_exit_status


def validate_and_exit(expected_out_status=0, **kwargs):
if all([arg == expected_out_status for arg in kwargs.values()]):
# Expected status, OK
sys.exit(0)
else:
# Failure
print_console_centered("Summary Results")
fail_count = 0
for component, exit_status in kwargs.items():
if exit_status != expected_out_status:
print(f"{component} failed.")
fail_count += 1
print_console_centered(f"{len(kwargs)-fail_count} success, {fail_count} failure")
sys.exit(1)


def print_console_centered(text: str, fill_char="="):
w, _ = shutil.get_terminal_size((80, 20))
print(f" {text} ".center(w, fill_char))


def shell_capture(command, out_json=True):
out = os.popen(command).read()
if out_json:
out = re.findall(r"{\s+.*\}", out, flags=re.MULTILINE | re.DOTALL)[0].replace("\n", "")
return json.loads(out)
return out
59 changes: 4 additions & 55 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,67 +1,16 @@
import json
import os
import re
import shutil
import sys
from typing import Dict

from deepdiff import DeepDiff


def load_json(path: str):
with open(path, "r") as jf:
content = json.load(jf)
return content


def shell(command, exit_status=0):
"""
Run command through shell and return exit status if exit status of command run match with given exit status.
Args:
command: (str) Command string which runs through system shell.
exit_status: (int) Expected exit status of given command run.
Returns: actual_exit_status
"""
actual_exit_status = os.system(command)
if actual_exit_status == exit_status:
return 0
return actual_exit_status


def validate_and_exit(expected_out_status=0, **kwargs):
if all([arg == expected_out_status for arg in kwargs.values()]):
# Expected status, OK
sys.exit(0)
else:
# Failure
print_console_centered("Summary Results")
fail_count = 0
for component, exit_status in kwargs.items():
if exit_status != expected_out_status:
print(f"{component} failed.")
fail_count += 1
print_console_centered(f"{len(kwargs)-fail_count} success, {fail_count} failure")
sys.exit(1)


def print_console_centered(text: str, fill_char="="):
w, _ = shutil.get_terminal_size((80, 20))
print(f" {text} ".center(w, fill_char))


def assert_almost_equal(actual, desired, decimal=3, exclude_paths=None, **kwargs):
# significant digits default value changed to 3 (from 5) due to variety in
# results for different hardware architectures.
diff = DeepDiff(actual, desired, significant_digits=decimal, exclude_paths=exclude_paths, **kwargs)
assert diff == {}, f"Actual and Desired Dicts are not Almost Equal:\n {json.dumps(diff, indent=2, default=str)}"


def shell_capture(command, out_json=True):
out = os.popen(command).read()
if out_json:
out = re.findall(r"{\s+.*\}", out, flags=re.MULTILINE | re.DOTALL)[0].replace("\n", "")
return json.loads(out)
return out
def load_json(path: str):
with open(path, "r") as jf:
content = json.load(jf)
return content

0 comments on commit a96dc46

Please sign in to comment.