Skip to content

Commit

Permalink
Fea/release semantic versionning (#7)
Browse files Browse the repository at this point in the history
* refacto: rename package name

* fix: poetry lock

* refacto: adapt makefile+pyproject order+template

* fea: release workflow

* fix: custom token

* fix: poetry in CI

* fix: author

* fix :poetry core

* fix: install cython

* fix: require cython

* fix: GH token name

* fix: doc

* fix: install poetry pip

* fix: syntax

* fix: remove path

* fix: add lapx as dependency

* fix: official script

* fix: remove lock

* fix: poetry lock ignore

* fix: remove tests

* fix: eol

---------

Co-authored-by: TomDarmon <tom.darmon@artefact.com>
  • Loading branch information
TomDarmon and TomDarmon authored Nov 8, 2023
1 parent 308be7b commit 870f546
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 66 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ jobs:
python-version: ['3.10']

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install poetry
run: make download-poetry

- name: Install requirements
run: |
python -m pip install --upgrade pip
make install_project_requirements
- name: Run Pre commit hook (formatting, linting & tests)
run: pre-commit run --all-files --hook-stage pre-push --show-diff-on-failure
poetry install
- name: Run Pre commit hooks
run: make format-code
2 changes: 0 additions & 2 deletions .github/workflows/deploy_docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,3 @@ jobs:
run: |
mkdocs build
mkdocs gh-deploy --force
36 changes: 36 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow triggers the CI, updates the version, and uploads the release to GitHub and Google Cloud Storage when a push is made to either the 'main' or 'develop' branch.
#
# Workflow Steps:
#
# 1. Ci is triggered using the CI workflow defined in .github/workflows/ci.yaml
# 2. If it succeeds, the version is updated using Python Semantic Release
# 3. The release is uploaded to GitHub (same step and GitHub action)

name: CI and Release on main

on:
push:
branches:
- main

jobs:
CI:
uses: ./.github/workflows/ci.yaml

Release:
runs-on: ubuntu-latest
concurrency: Release
needs: CI
permissions:
id-token: write
contents: write

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Python Semantic Release
uses: python-semantic-release/python-semantic-release@master
with:
github_token: ${{ secrets.GH_TOKEN }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,7 @@ secrets/*

# Data ignore everythin data/detections and data/frames
data/detections/*
data/frames/*
data/frames/*

# poetry
poetry.lock
44 changes: 31 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PYTHON_VERSION = 3.10
USE_CONDA ?= 1
INSTALL_SCRIPT = install_with_conda.sh
ifeq (false,$(USE_CONDA))
Expand All @@ -9,21 +10,38 @@ endif
help:
@grep "^# help\:" Makefile | grep -v grep | sed 's/\# help\: //' | sed 's/\# help\://'

# help: install - Create a virtual environment and install dependencies
# help: download-poetry - Download poetry
download-poetry:
curl -sSL https://install.python-poetry.org | python3 -

# help: install - Install python dependencies using poetry
.PHONY: install
install:
@bash bin/$(INSTALL_SCRIPT)

# help: install_project_requirements - Install prohect requirements
.PHONY: install_project_requirements
install_project_requirements:
@pip install -r requirements-dev.txt

# help: install_precommit - Install pre-commit hooks
.PHONY: install_precommit
install_precommit:
@pre-commit install -t pre-commit
@pre-commit install -t pre-push
@poetry env use $(PYTHON_VERSION)
@poetry lock -n
@poetry install -n
@poetry run pre-commit install -t pre-commit -t pre-push

.PHONY: install-requirements
# help: requirements - Install Python Dependencies
install-requirements:
@poetry install -n


.PHONY: install-dev-requirements
# help : install-dev-requirements - Install Python Dependencies for development
install-dev-requirements:
@poetry install -n --with dev

.PHONY: update-requirements
#help: update-requirements - Update Python Dependencies (requirements.txt and requirements-dev.txt)
update-requirements:
@poetry lock -n

.PHONY: format-code
#help: format-code - Format/lint all-files using pre-commit hooks (black, flake8, isort, ...)
format-code:
@poetry run pre-commit run -a

# help: deploy_docs - Deploy documentation to GitHub Pages
.PHONY: deploy_docs
Expand Down
59 changes: 48 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "track-reid"
authors = [
{ name = "tristanpepinartefact", email = "tristan.pepin@artefact.com" },
] # TODO: Add more authors if collaborators are added
[tool.poetry]
name = "trackreid"
authors = ["tristanpepinartefact <tristan.pepin@artefact.com>"]
description = "This Git repository is dedicated to the development of a Python library aimed at correcting the results of tracking algorithms. The primary goal of this library is to reconcile and reassign lost or misidentified IDs, ensuring a consistent and accurate tracking of objects over time. "
version = "0.0.1"
readme = "README.md"
requires-python = ">=3.8"


[tool.poetry.dependencies]
python = ">=3.8, <3.11.0"
pandas = "1.5.3"
numpy = "1.24.2"
llist = "0.7.1"
pydantic = "2.4.2"
torch = ">=1.13.1"
Cython = ">=0.29.23"
bytetracker = { git = "https://github.com/TomDarmon/bytetrack-pip.git", branch = "main" }

[tool.poetry.group.dev.dependencies]
black = "22.10.0"
ruff = "0.0.272"
isort = "5.12.0"
pre-commit = "3.3.3"
pytest = "7.3.2"
mkdocs = "1.4.3"
mkdocs-material = "9.1.15"
mkdocstrings-python = "1.1.2"
bandit = "1.7.5"
nbstripout = "0.6.1"
ipykernel = "6.24.0"


[build-system]
requires = ["poetry-core>=1.0.0", "Cython=^0.29.23"]
build-backend = "poetry.core.masonry.api"


[project.urls]
"Homepage" = "https://github.com/artefactory-fr/track-reid"
Expand All @@ -32,7 +55,7 @@ select = [
"PD",
] # See: https://beta.ruff.rs/docs/rules/
ignore = ["D203", "D213", "ANN101", "ANN102"]
line-length = 100
line-length = 120
target-version = "py310"
exclude = [
".bzr",
Expand Down Expand Up @@ -78,3 +101,17 @@ exclude = '''

[tool.isort]
profile = "black"


[tool.semantic_release]
version_variables = ["deployer/__init__.py:__version__"]
version_toml = ["pyproject.toml:tool.poetry.version"]
branch = "main"
upload_to_pypi = false
upload_to_release = true
build_command = "pip install poetry && poetry build"
commit_message = "chore(release): {version}\n\nAutomatically generated by semantic-release"
tag_format = "{version}"

[tool.semantic_release.changelog]
exclude_commit_patterns = ['''^chore\(release\).*''']
12 changes: 0 additions & 12 deletions requirements-dev.txt

This file was deleted.

7 changes: 0 additions & 7 deletions requirements.txt

This file was deleted.

21 changes: 21 additions & 0 deletions templates/CHANGELOG.md.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# CHANGELOG
{% if context.history.unreleased | length > 0 %}
{# UNRELEASED #}
## Unreleased
{% for type_, commits in context.history.unreleased | dictsort %}
### {{ type_ | capitalize }}
{% for commit in commits %}{% if type_ != "unknown" %}
* {{ commit.message.rstrip() }} ([`{{ commit.short_hash }}`]({{ commit.hexsha | commit_hash_url }}))
{% else %}
* {{ commit.message.rstrip() }} ([`{{ commit.short_hash }}`]({{ commit.hexsha | commit_hash_url }}))
{% endif %}{% endfor %}{% endfor %}{% endif %}
{% for version, release in context.history.released.items() %}
{# RELEASED #}
## {{ version.as_tag() }} ({{ release.tagged_date.strftime("%Y-%m-%d") }})
{% for type_, commits in release["elements"] | dictsort %}
### {{ type_ | capitalize }}
{% for commit in commits %}{% if type_ != "unknown" %}
* {{ commit.message.rstrip() }} ([`{{ commit.short_hash }}`]({{ commit.hexsha | commit_hash_url }}))
{% else %}
* {{ commit.message.rstrip() }} ([`{{ commit.short_hash }}`]({{ commit.hexsha | commit_hash_url }}))
{% endif %}{% endfor %}{% endfor %}{% endfor %}
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion track_reid/matcher.py → trackreid/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import numpy as np
from scipy.optimize import linear_sum_assignment

from track_reid.tracked_object import TrackedObject


Expand Down
8 changes: 0 additions & 8 deletions track_reid/reid_processor.py → trackreid/reid_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Dict, List, Set

import numpy as np

from track_reid.constants.reid_constants import reid_constants
from track_reid.matcher import Matcher
from track_reid.tracked_object import TrackedObject
Expand All @@ -21,7 +20,6 @@ def __init__(
max_frames_to_rematch: int = 100,
max_attempt_to_rematch: int = 1,
) -> None:

self.matcher = Matcher(cost_function=cost_function, selection_function=selection_function)

self.tracked_filter = TrackedObjectFilter(
Expand Down Expand Up @@ -52,7 +50,6 @@ def _preprocess(self, tracker_output: np.ndarray):
self.all_tracked_objects = self._apply_filtering()

def _update_tracked_objects(self, tracker_output: np.ndarray):

self.frame_id = tracker_output[0, 0]
for object_id, data_line in zip(tracker_output[:, 1], tracker_output):
if object_id not in self.all_tracked_objects:
Expand Down Expand Up @@ -80,7 +77,6 @@ def _apply_filtering(self):
return self.all_tracked_objects

def _perform_reid_process(self, tracker_output: np.ndarray):

tracked_ids = filter_objects_by_state(
self.all_tracked_objects, states=reid_constants.BYETRACK_OUTPUT, exclusion=True
)
Expand Down Expand Up @@ -151,13 +147,11 @@ def identify_candidates(tracked_ids: List["TrackedObject"]):

@staticmethod
def compute_stable_objects(tracked_ids: list, current_tracker_ids: Set[int]):

top_list_correction = get_top_list_correction(tracked_ids)

for current_object in current_tracker_ids:
tracked_id = tracked_ids[tracked_ids.index(current_object)]
if current_object not in top_list_correction:

tracked_ids.remove(tracked_id)
new_object, tracked_id = tracked_id.cut(current_object)

Expand All @@ -175,7 +169,6 @@ def process_matches(
candidates: List["TrackedObject"],
current_tracker_ids: Set[int],
):

for match in matches:
candidate_match, switcher_match = match.popitem()

Expand All @@ -194,7 +187,6 @@ def drop_switchers(
max_frames_to_rematch: int,
frame_id: int,
):

switchers_to_drop = set(switchers).intersection(current_tracker_ids)
filtered_switchers = switchers.copy()

Expand Down
3 changes: 0 additions & 3 deletions track_reid/tracked_object.py → trackreid/tracked_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np
from llist import sllist

from track_reid.constants.reid_constants import reid_constants
from track_reid.tracked_object_metadata import TrackedObjectMetaData
from track_reid.utils import split_list_around_value
Expand All @@ -17,7 +16,6 @@ def __init__(
state: int,
metadata: Union[np.ndarray, TrackedObjectMetaData],
):

self.state = state

if isinstance(object_ids, int):
Expand Down Expand Up @@ -99,7 +97,6 @@ def __eq__(self, other):
return False

def cut(self, object_id: int):

if object_id not in self.re_id_chain:
raise NameError(
f"Trying to cut object {self} with {object_id} that is not in the re-id chain."
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions track_reid/utils.py → trackreid/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@


def get_top_list_correction(tracked_ids: list):

top_list_correction = [tracked_id.re_id_chain.last.value for tracked_id in tracked_ids]

return top_list_correction


def split_list_around_value(my_list: sllist, value_to_split: int):

if value_to_split == my_list.last.value:
raise NameError("split on the last")
before = sllist()
Expand Down

0 comments on commit 870f546

Please sign in to comment.