Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixes CICD and updates Readme.md #7

Merged
merged 8 commits into from
May 21, 2024
Merged
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
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Run Tests

on:
push:
branches: main
branches:
- "**"
pull_request:
branches: main

Expand Down
126 changes: 65 additions & 61 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,93 +1,97 @@
name: Publish RetailTree Python package distribution to PyPI

on: push
on:
workflow_run:
workflows: ["Run Tests"]
types:
- completed

jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish RetailTree Python package distribution to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/retailtree
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
needs:
- publish-to-pypi
- publish-to-pypi
runs-on: ubuntu-latest

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/gh-action-sigstore-python@v2.1.1
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/gh-action-sigstore-python@v2.1.1
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
57 changes: 45 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@ RetailTree is a Python library designed for efficient management and querying of

You can install retailTree via pip:

```
```python
pip install retailtree
```

# Usage

```
# Import necessary modules and functions
### Import necessary modules and functions

```python
# Imports
from retailtree import RetailTree, Annotation
from retailtree.utils.dist_func import manhattan, euclidean
import json
```

### Sample Usage 1: Creating Annotations with Annotation Class using a sample JSON file

```python
# Define the path to the JSON file containing annotations
file_path = './tests/test_data/test_data.json'

Expand All @@ -42,21 +48,48 @@ for ann in annotations:
ann_obj = Annotation(id=ann['id'], x_min=ann['x_min'], y_min=ann['y_min'], x_max=ann['x_max'], y_max=ann['y_max'])
# Add the created Annotation object to the RetailTree
rt.add_annotation(ann_obj)
```

# Build the spatial tree structure using the euclidean distance function
rt.build_tree(dist_func=euclidean)
# OR

### Sample Usage 2: Creating Annotations with Annotation Class

```python
# Create annotation object
ann1 = Annotation(id=1, x_min=2, y_min=1, x_max=3, y_max=2)
ann2 = Annotation(id=2, x_min=1, y_min=2, x_max=2, y_max=3)
ann3 = Annotation(id=3, x_min=2, y_min=2, x_max=3, y_max=3)
ann4 = Annotation(id=4, x_min=3, y_min=2, x_max=4, y_max=3)
ann5 = Annotation(id=5, x_min=2, y_min=3, x_max=3, y_max=4)
annotations = [ann1, ann2, ann3, ann4, ann5]

# Retrieve and print annotations within a radius of 1 from the annotation with id=3
# Create retailtree object
rt = RetailTree()

# Adding annotations to retailtree
for ann in annotations:
rt.add_annotation(ann)
```

## Building the Tree and Querying

### Building the Tree

```python
# Build the retail tree structure using the euclidean distance function
rt.build_tree(dist_func=euclidean)
```
### Querying the Tree
```python
# Retrieve and print annotations within a radius.
print(rt.neighbors(id=3, radius=1))

# Retrieve and print the Top, Bottom, Left, and Right neighboring annotations
# of the annotation with id=3 within a radius of 1 and a minimum overlap of 0.5
# Retrieve and print the Top, Bottom, Left, and Right neighboring annotations.
print(rt.TBLR(id=3, radius=1, overlap=0.5))

# Retrieve and print neighboring annotations of the annotation with id=3
# within a radius of 1 and angle range from 0 to 180 degrees
print(rt.neighbors_wa(id=3, radius=1, amin=0, amax=180))
# Retrieve and print neighboring annotations of the annotation.
print(rt.neighbors_wa(id=3, radius=2, amin=0, amax=180))

# Retrieve and print the coordinates of the annotation with id=3
# Retrieve and print the coordinates of the annotation.
print(rt.get(id=3).get_coords())
```
Loading