From 33be91437d16a36e6a848ce22b3a34cae84c8f12 Mon Sep 17 00:00:00 2001 From: mikel-brostrom Date: Sun, 12 Jul 2026 18:32:07 +0200 Subject: [PATCH 1/5] build: modernize packaging and release workflow --- .github/workflows/publish-to-pypi.yml | 77 ++++ .github/workflows/python-package.yml | 31 +- Dockerfile | 2 - MANIFEST.in | 3 - Readme.md | 32 +- Release.md | 78 +++- environment.yml | 10 - motmetrics/tests/test_mot.py | 3 + precommit.sh | 8 - pylintrc | 591 -------------------------- pyproject.toml | 70 +++ requirements.txt | 5 - requirements_dev.txt | 4 - setup.py | 41 -- test.sh.example | 1 - 15 files changed, 234 insertions(+), 722 deletions(-) create mode 100644 .github/workflows/publish-to-pypi.yml delete mode 100644 MANIFEST.in delete mode 100644 environment.yml delete mode 100644 precommit.sh delete mode 100644 pylintrc create mode 100644 pyproject.toml delete mode 100644 requirements.txt delete mode 100644 requirements_dev.txt delete mode 100644 setup.py delete mode 100644 test.sh.example diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml new file mode 100644 index 00000000..19cf9b46 --- /dev/null +++ b/.github/workflows/publish-to-pypi.yml @@ -0,0 +1,77 @@ +name: Publish to PyPI + +on: + push: + tags: ["v*"] + +permissions: + contents: read + +jobs: + test: + name: Test on Python ${{ matrix.python-version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] + steps: + - uses: actions/checkout@v6 + with: + persist-credentials: false + - uses: actions/setup-python@v6 + with: + python-version: ${{ matrix.python-version }} + - uses: astral-sh/setup-uv@v7 + - name: Install and test + run: | + uv venv --python ${{ matrix.python-version }} + uv pip install --group dev + uv run --no-project --no-sync pytest + + build: + name: Build and validate distributions + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + with: + persist-credentials: false + - uses: actions/setup-python@v6 + with: + python-version: "3.x" + - name: Build wheel and source distribution + run: | + python -m pip install --upgrade build twine + python -m build + python -m twine check dist/* + - name: Verify version matches tag + env: + RELEASE_TAG: ${{ github.ref_name }} + run: | + python -c "import os, pathlib, sys; from packaging.utils import parse_sdist_filename, parse_wheel_filename; from packaging.version import Version; expected=Version(os.environ['RELEASE_TAG'].removeprefix('v')); files=list(pathlib.Path('dist').iterdir()); versions=[parse_wheel_filename(p.name)[1] if p.suffix == '.whl' else parse_sdist_filename(p.name)[1] for p in files]; sys.exit(0 if files and all(v == expected for v in versions) else f'artifact versions {versions} do not match tag {expected}')" + - name: Smoke-test the wheel + run: | + python -m venv /tmp/motmetrics-wheel-test + /tmp/motmetrics-wheel-test/bin/python -m pip install dist/*.whl + /tmp/motmetrics-wheel-test/bin/python -c "import motmetrics; print(motmetrics.__version__)" + - uses: actions/upload-artifact@v5 + with: + name: python-package-distributions + path: dist/ + if-no-files-found: error + + publish: + name: Publish distribution to PyPI + needs: [test, build] + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/motmetrics + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v6 + with: + name: python-package-distributions + path: dist/ + - uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 8a266b06..30ef3ee9 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -5,9 +5,13 @@ name: Python package on: push: - branches: [develop] + branches: [master, develop] + tags: ["v*"] pull_request: - branches: [develop] + branches: [master, develop] + +permissions: + contents: read jobs: build: @@ -15,32 +19,31 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 + uses: actions/setup-python@v6 with: python-version: ${{ matrix.python-version }} + - uses: astral-sh/setup-uv@v7 - name: Install dependencies run: | - # The following is commented due to issue in package lap - # python -m pip install --upgrade pip - pip install --upgrade pip==22.0.3 - python -m pip install flake8 pytest pytest-benchmark - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + uv venv --python ${{ matrix.python-version }} + uv pip install --group dev # lapsolver is unmaintained and no longer builds with the C++ # toolchain on current GitHub-hosted runners. The test suite # discovers optional solvers dynamically, so exercise the # maintained LAP backends here instead. - pip install lap scipy "ortools<9.4" munkres + uv pip install lap scipy munkres + uv pip install "ortools<9.12; python_version < '3.9'" "ortools; python_version >= '3.9'" - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + uv run --no-project --no-sync flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + uv run --no-project --no-sync flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | - pytest + uv run --no-project --no-sync pytest diff --git a/Dockerfile b/Dockerfile index 510d6ae9..9d5a79a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,11 +22,9 @@ COPY ./data /motmetrics/data #RUN pip install motmetrics RUN pip install -e ./motmetrics/py-motmetrics/ -#RUN pip install -r motmetrics/py-motmetrics/requirements.txt ENV GT_DIR motmetrics/data/train/ ENV TEST_DIR motmetrics/data/test/ #ENTRYPOINT python3 -m motmetrics.apps.eval_motchallenge motmetrics/data/train/ motmetrics/data/test/ && /bin/bash CMD ["sh", "-c", "python3 -m motmetrics.apps.eval_motchallenge ${GT_DIR} ${TEST_DIR} && /bin/bash"] - diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index b0af762e..00000000 --- a/MANIFEST.in +++ /dev/null @@ -1,3 +0,0 @@ -include README.md LICENSE requirements.txt -recursive-include motmetrics/data * -recursive-include motmetrics/etc * \ No newline at end of file diff --git a/Readme.md b/Readme.md index 3c65ec25..000262c1 100644 --- a/Readme.md +++ b/Readme.md @@ -134,37 +134,21 @@ To install **py-motmetrics** use `pip` pip install motmetrics ``` -Python 3.5/3.6/3.9 and numpy, pandas and scipy is required. If no binary packages are available for your platform and building source packages fails, you might want to try a distribution like Conda (see below) to install dependencies. +Python 3.8 through 3.14 and NumPy, pandas, and SciPy are required. If no binary packages are available for your platform and building source packages fails, you might want to try a distribution like Conda (see below) to install dependencies. Alternatively for developing, clone or fork this repository and install in editing mode. ``` -pip install -e +uv venv +uv pip install --group dev ``` -### Install via Conda - -In case you are using Conda, a simple way to run **py-motmetrics** is to create a virtual environment with all the necessary dependencies - -``` -conda env create -f environment.yml -> activate motmetrics-env -``` - -Then activate / source the `motmetrics-env` and install **py-motmetrics** and run the tests. - -``` -activate motmetrics-env -pip install . -pytest -``` - -In case you already have an environment you install the dependencies from within your environment by +To install the development dependencies and run the tests: ``` -conda install --file requirements.txt -pip install . -pytest +uv venv +uv pip install --group dev +uv run --no-project --no-sync pytest ``` ## Usage @@ -472,7 +456,7 @@ For large datasets solving the minimum cost assignment becomes the dominant runt - `lapsolver` - https://github.com/cheind/py-lapsolver - `lapjv` - https://github.com/gatagat/lap - `scipy` - https://github.com/scipy/scipy/tree/master/scipy -- `ortools<9.4` - https://github.com/google/or-tools +- `ortools` - https://github.com/google/or-tools - `munkres` - http://software.clapper.org/munkres/ A comparison for different sized matrices is shown below (taken from [here](https://github.com/cheind/py-lapsolver#benchmarks)) diff --git a/Release.md b/Release.md index 9b8882af..1e92a118 100644 --- a/Release.md +++ b/Release.md @@ -1,20 +1,60 @@ +# Release procedure -## Release - - - git flow release start - - version bump motmetrics/__init__.py - - conda env create -f environment.yml - - activate motmetrics-env - - [pip install lapsolver] - - pip install . - - pytest - - deactivate - - conda env remove -n motmetrics-env - - git add, commit - - git flow release finish - - git push - - git push --tags - - git checkout master - - git push - - git checkout develop - - check appveyor, travis and pypi \ No newline at end of file +Releases are built from Git tags and published by GitHub Actions using PyPI +Trusted Publishing. Maintainers do not need to store a long-lived PyPI token in +GitHub. + +## One-time repository setup + +1. In the PyPI settings for `motmetrics`, add a GitHub Trusted Publisher with: + - owner: `cheind` + - repository: `py-motmetrics` + - workflow: `publish-to-pypi.yml` + - environment: `pypi` +2. Create a protected GitHub environment named `pypi` and require maintainer + approval before deployment. +3. Protect `master` and require the Python package workflow to pass before a + release pull request can merge. + +## Prepare a release + +1. Create a short `release/` branch from an up-to-date `master`. +2. Update `motmetrics.__version__` in `motmetrics/__init__.py` using a valid PEP + 440 version without a leading `v`. +3. Update the changelog or release notes with user-visible changes. +4. Run the supported-version CI matrix and local checks: + + python -m pip install --upgrade build twine + python -m build + python -m twine check dist/* + uv venv + uv pip install --group dev + uv run --no-project --no-sync pytest + +5. Install the generated wheel in a clean environment and smoke-test the + import and version. +6. Open a pull request to `master`, obtain review, and merge only after all + required checks pass. + +## Publish + +1. From the merged `master` commit, create and push a signed tag whose name is + the package version prefixed with `v`: + + git tag -s v1.5.0 -m "Release 1.5.0" + git push origin v1.5.0 + +2. The `Publish to PyPI` workflow builds one source distribution and one + universal wheel with a current Python and setuptools 77 or newer, checks + their metadata, verifies the artifact version + against the tag, smoke-tests the wheel, and waits for approval on the `pypi` + environment before publishing. +3. After the workflow succeeds, create GitHub release notes for the same tag + and verify the published package: + + python -m pip install --no-cache-dir motmetrics==1.5.0 + python -c "import motmetrics; print(motmetrics.__version__)" + +PyPI files are immutable. If publishing fails after any artifact was accepted, +increment the version and publish a new release; never reuse or move a release +tag. diff --git a/environment.yml b/environment.yml deleted file mode 100644 index 50062681..00000000 --- a/environment.yml +++ /dev/null @@ -1,10 +0,0 @@ -# conda env create -f environment.yml -name: motmetrics-env -dependencies: -- python=3.6 -- numpy -- scipy -- pandas -- pip -- pip: - - pytest \ No newline at end of file diff --git a/motmetrics/tests/test_mot.py b/motmetrics/tests/test_mot.py index 67a6826c..54a71292 100644 --- a/motmetrics/tests/test_mot.py +++ b/motmetrics/tests/test_mot.py @@ -130,6 +130,9 @@ def test_merge_dataframes(): ) expect = mm.MOTAccumulator.new_event_dataframe() + # Remapped IDs are strings. Declare those columns accordingly because + # pandas 3 no longer permits implicit string upcasts from float columns. + expect = expect.astype({"OId": object, "HId": object}) expect.loc[(0, 0), :] = ["RAW", np.nan, np.nan, np.nan] expect.loc[(0, 1), :] = ["RAW", np.nan, mappings[0]["hid_map"][1], np.nan] diff --git a/precommit.sh b/precommit.sh deleted file mode 100644 index 87debd7f..00000000 --- a/precommit.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -set -o xtrace - -pytest --benchmark-disable && \ -flake8 . && \ -pylint motmetrics && \ -pylint --py3k motmetrics diff --git a/pylintrc b/pylintrc deleted file mode 100644 index 75c81675..00000000 --- a/pylintrc +++ /dev/null @@ -1,591 +0,0 @@ -[MASTER] - -# A comma-separated list of package or module names from where C extensions may -# be loaded. Extensions are loading into the active Python interpreter and may -# run arbitrary code. -extension-pkg-whitelist= - -# Add files or directories to the blacklist. They should be base names, not -# paths. -ignore=CVS - -# Add files or directories matching the regex patterns to the blacklist. The -# regex matches against base names, not paths. -ignore-patterns= - -# Python code to execute, usually for sys.path manipulation such as -# pygtk.require(). -#init-hook= - -# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the -# number of processors available to use. -jobs=1 - -# Control the amount of potential inferred values when inferring a single -# object. This can help the performance when dealing with large functions or -# complex, nested conditions. -limit-inference-results=100 - -# List of plugins (as comma separated values of python module names) to load, -# usually to register additional checkers. -load-plugins= - -# Pickle collected data for later comparisons. -persistent=yes - -# Specify a configuration file. -#rcfile= - -# When enabled, pylint would attempt to guess common misconfiguration and emit -# user-friendly hints instead of false-positive error messages. -suggestion-mode=yes - -# Allow loading of arbitrary C extensions. Extensions are imported into the -# active Python interpreter and may run arbitrary code. -unsafe-load-any-extension=no - - -[MESSAGES CONTROL] - -# Only show warnings with the listed confidence levels. Leave empty to show -# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED. -confidence= - -# Disable the message, report, category or checker with the given id(s). You -# can either give multiple identifiers separated by comma (,) or put this -# option multiple times (only on the command line, not in the configuration -# file where it should appear only once). You can also use "--disable=all" to -# disable everything first and then reenable specific checks. For example, if -# you want to run only the similarities checker, you can use "--disable=all -# --enable=similarities". If you want to run only the classes checker, but have -# no Warning level messages displayed, use "--disable=all --enable=classes -# --disable=W". -disable=line-too-long, - too-many-arguments, - too-many-branches, - invalid-name, - no-else-return, - useless-object-inheritance, - too-many-instance-attributes, - similarities, - import-error, - -# Enable the message, report, category or checker with the given id(s). You can -# either give multiple identifier separated by comma (,) or put this option -# multiple time (only on the command line, not in the configuration file where -# it should appear only once). See also the "--disable" option for examples. -enable=c-extension-no-member, - # List of options disabled by default: - print-statement, - parameter-unpacking, - unpacking-in-except, - old-raise-syntax, - backtick, - long-suffix, - old-ne-operator, - old-octal-literal, - import-star-module-level, - non-ascii-bytes-literal, - raw-checker-failed, - bad-inline-option, - # locally-disabled, - file-ignored, - # suppressed-message, - useless-suppression, - deprecated-pragma, - use-symbolic-message-instead, - apply-builtin, - basestring-builtin, - buffer-builtin, - cmp-builtin, - coerce-builtin, - execfile-builtin, - file-builtin, - long-builtin, - raw_input-builtin, - reduce-builtin, - standarderror-builtin, - unicode-builtin, - xrange-builtin, - coerce-method, - delslice-method, - getslice-method, - setslice-method, - no-absolute-import, - old-division, - dict-iter-method, - dict-view-method, - next-method-called, - metaclass-assignment, - indexing-exception, - raising-string, - reload-builtin, - oct-method, - hex-method, - nonzero-method, - cmp-method, - input-builtin, - round-builtin, - intern-builtin, - unichr-builtin, - map-builtin-not-iterating, - zip-builtin-not-iterating, - range-builtin-not-iterating, - filter-builtin-not-iterating, - using-cmp-argument, - eq-without-hash, - div-method, - idiv-method, - rdiv-method, - exception-message-attribute, - invalid-str-codec, - sys-max-int, - bad-python3-import, - deprecated-string-function, - deprecated-str-translate-call, - deprecated-itertools-function, - deprecated-types-field, - next-method-defined, - dict-items-not-iterating, - dict-keys-not-iterating, - dict-values-not-iterating, - deprecated-operator-function, - deprecated-urllib-function, - xreadlines-attribute, - deprecated-sys-function, - exception-escape, - comprehension-escape, - - -[REPORTS] - -# Python expression which should return a score less than or equal to 10. You -# have access to the variables 'error', 'warning', 'refactor', and 'convention' -# which contain the number of messages in each category, as well as 'statement' -# which is the total number of statements analyzed. This score is used by the -# global evaluation report (RP0004). -evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) - -# Template used to display messages. This is a python new-style format string -# used to format the message information. See doc for all details. -#msg-template= - -# Set the output format. Available formats are text, parseable, colorized, json -# and msvs (visual studio). You can also give a reporter class, e.g. -# mypackage.mymodule.MyReporterClass. -output-format=text - -# Tells whether to display a full report or only the messages. -reports=no - -# Activate the evaluation score. -score=yes - - -[REFACTORING] - -# Maximum number of nested blocks for function / method body -max-nested-blocks=5 - -# Complete name of functions that never returns. When checking for -# inconsistent-return-statements if a never returning function is called then -# it will be considered as an explicit return statement and no message will be -# printed. -never-returning-functions=sys.exit - - -[STRING] - -# This flag controls whether the implicit-str-concat-in-sequence should -# generate a warning on implicit string concatenation in sequences defined over -# several lines. -check-str-concat-over-line-jumps=no - - -[FORMAT] - -# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. -expected-line-ending-format= - -# Regexp for a line that is allowed to be longer than the limit. -ignore-long-lines=^\s*(# )??$ - -# Number of spaces of indent required inside a hanging or continued line. -indent-after-paren=4 - -# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 -# tab). -indent-string=' ' - -# Maximum number of characters on a single line. -max-line-length=100 - -# Maximum number of lines in a module. -max-module-lines=1000 - -# List of optional constructs for which whitespace checking is disabled. `dict- -# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. -# `trailing-comma` allows a space between comma and closing bracket: (a, ). -# `empty-line` allows space-only lines. -no-space-check=trailing-comma, - dict-separator - -# Allow the body of a class to be on the same line as the declaration if body -# contains single statement. -single-line-class-stmt=no - -# Allow the body of an if to be on the same line as the test if there is no -# else. -single-line-if-stmt=no - - -[TYPECHECK] - -# List of decorators that produce context managers, such as -# contextlib.contextmanager. Add to this list to register other decorators that -# produce valid context managers. -contextmanager-decorators=contextlib.contextmanager - -# List of members which are set dynamically and missed by pylint inference -# system, and so shouldn't trigger E1101 when accessed. Python regular -# expressions are accepted. -generated-members=(numpy|np)\.random - -# Tells whether missing members accessed in mixin class should be ignored. A -# mixin class is detected if its name ends with "mixin" (case insensitive). -ignore-mixin-members=yes - -# Tells whether to warn about missing members when the owner of the attribute -# is inferred to be None. -ignore-none=yes - -# This flag controls whether pylint should warn about no-member and similar -# checks whenever an opaque object is returned when inferring. The inference -# can return multiple potential results while evaluating a Python object, but -# some branches might not be evaluated, which results in partial inference. In -# that case, it might be useful to still emit no-member and other checks for -# the rest of the inferred objects. -ignore-on-opaque-inference=yes - -# List of class names for which member attributes should not be checked (useful -# for classes with dynamically set attributes). This supports the use of -# qualified names. -ignored-classes=optparse.Values,thread._local,_thread._local - -# List of module names for which member attributes should not be checked -# (useful for modules/projects where namespaces are manipulated during runtime -# and thus existing member attributes cannot be deduced by static analysis). It -# supports qualified module names, as well as Unix pattern matching. -ignored-modules= - -# Show a hint with possible names when a member name was not found. The aspect -# of finding the hint is based on edit distance. -missing-member-hint=yes - -# The minimum edit distance a name should have in order to be considered a -# similar match for a missing member name. -missing-member-hint-distance=1 - -# The total number of similar names that should be taken in consideration when -# showing a hint for a missing member. -missing-member-max-choices=1 - -# List of decorators that change the signature of a decorated function. -signature-mutators= - - -[MISCELLANEOUS] - -# List of note tags to take in consideration, separated by a comma. -notes=FIXME, - XXX, - TODO - - -[LOGGING] - -# Format style used to check logging format string. `old` means using % -# formatting, `new` is for `{}` formatting,and `fstr` is for f-strings. -logging-format-style=old - -# Logging modules to check that the string format arguments are in logging -# function parameter format. -logging-modules=logging - - -[SPELLING] - -# Limits count of emitted suggestions for spelling mistakes. -max-spelling-suggestions=4 - -# Spelling dictionary name. Available dictionaries: none. To make it work, -# install the python-enchant package. -spelling-dict= - -# List of comma separated words that should not be checked. -spelling-ignore-words= - -# A path to a file that contains the private dictionary; one word per line. -spelling-private-dict-file= - -# Tells whether to store unknown words to the private dictionary (see the -# --spelling-private-dict-file option) instead of raising a message. -spelling-store-unknown-words=no - - -[VARIABLES] - -# List of additional names supposed to be defined in builtins. Remember that -# you should avoid defining new builtins when possible. -additional-builtins= - -# Tells whether unused global variables should be treated as a violation. -allow-global-unused-variables=yes - -# List of strings which can identify a callback function by name. A callback -# name must start or end with one of those strings. -callbacks=cb_, - _cb - -# A regular expression matching the name of dummy variables (i.e. expected to -# not be used). -dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ - -# Argument names that match this expression will be ignored. Default to name -# with leading underscore. -ignored-argument-names=_.*|^ignored_|^unused_ - -# Tells whether we should check for unused import in __init__ files. -init-import=no - -# List of qualified module names which can have objects that can redefine -# builtins. -redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io - - -[SIMILARITIES] - -# Ignore comments when computing similarities. -ignore-comments=yes - -# Ignore docstrings when computing similarities. -ignore-docstrings=yes - -# Ignore imports when computing similarities. -ignore-imports=no - -# Minimum lines number of a similarity. -min-similarity-lines=4 - - -[BASIC] - -# Naming style matching correct argument names. -argument-naming-style=snake_case - -# Regular expression matching correct argument names. Overrides argument- -# naming-style. -#argument-rgx= - -# Naming style matching correct attribute names. -attr-naming-style=snake_case - -# Regular expression matching correct attribute names. Overrides attr-naming- -# style. -#attr-rgx= - -# Bad variable names which should always be refused, separated by a comma. -bad-names=foo, - bar, - baz, - toto, - tutu, - tata - -# Naming style matching correct class attribute names. -class-attribute-naming-style=any - -# Regular expression matching correct class attribute names. Overrides class- -# attribute-naming-style. -#class-attribute-rgx= - -# Naming style matching correct class names. -class-naming-style=PascalCase - -# Regular expression matching correct class names. Overrides class-naming- -# style. -#class-rgx= - -# Naming style matching correct constant names. -const-naming-style=UPPER_CASE - -# Regular expression matching correct constant names. Overrides const-naming- -# style. -#const-rgx= - -# Minimum line length for functions/classes that require docstrings, shorter -# ones are exempt. -docstring-min-length=10 - -# Naming style matching correct function names. -function-naming-style=snake_case - -# Regular expression matching correct function names. Overrides function- -# naming-style. -#function-rgx= - -# Good variable names which should always be accepted, separated by a comma. -good-names=i, - j, - k, - ex, - Run, - _ - -# Include a hint for the correct naming format with invalid-name. -include-naming-hint=no - -# Naming style matching correct inline iteration names. -inlinevar-naming-style=any - -# Regular expression matching correct inline iteration names. Overrides -# inlinevar-naming-style. -#inlinevar-rgx= - -# Naming style matching correct method names. -method-naming-style=snake_case - -# Regular expression matching correct method names. Overrides method-naming- -# style. -#method-rgx= - -# Naming style matching correct module names. -module-naming-style=snake_case - -# Regular expression matching correct module names. Overrides module-naming- -# style. -#module-rgx= - -# Colon-delimited sets of names that determine each other's naming style when -# the name regexes allow several styles. -name-group= - -# Regular expression which should only match function or class names that do -# not require a docstring. -no-docstring-rgx=^_ - -# List of decorators that produce properties, such as abc.abstractproperty. Add -# to this list to register other decorators that produce valid properties. -# These decorators are taken in consideration only for invalid-name. -property-classes=abc.abstractproperty - -# Naming style matching correct variable names. -variable-naming-style=snake_case - -# Regular expression matching correct variable names. Overrides variable- -# naming-style. -#variable-rgx= - - -[CLASSES] - -# List of method names used to declare (i.e. assign) instance attributes. -defining-attr-methods=__init__, - __new__, - setUp, - __post_init__ - -# List of member names, which should be excluded from the protected access -# warning. -exclude-protected=_asdict, - _fields, - _replace, - _source, - _make - -# List of valid names for the first argument in a class method. -valid-classmethod-first-arg=cls - -# List of valid names for the first argument in a metaclass class method. -valid-metaclass-classmethod-first-arg=cls - - -[DESIGN] - -# Maximum number of arguments for function / method. -max-args=5 - -# Maximum number of attributes for a class (see R0902). -max-attributes=7 - -# Maximum number of boolean expressions in an if statement (see R0916). -max-bool-expr=5 - -# Maximum number of branch for function / method body. -max-branches=12 - -# Maximum number of locals for function / method body. -max-locals=15 - -# Maximum number of parents for a class (see R0901). -max-parents=7 - -# Maximum number of public methods for a class (see R0904). -max-public-methods=20 - -# Maximum number of return / yield for function / method body. -max-returns=6 - -# Maximum number of statements in function / method body. -max-statements=50 - -# Minimum number of public methods for a class (see R0903). -min-public-methods=2 - - -[IMPORTS] - -# List of modules that can be imported at any level, not just the top level -# one. -allow-any-import-level= - -# Allow wildcard imports from modules that define __all__. -allow-wildcard-with-all=no - -# Analyse import fallback blocks. This can be used to support both Python 2 and -# 3 compatible code, which means that the block might have code that exists -# only in one or another interpreter, leading to false positives when analysed. -analyse-fallback-blocks=no - -# Deprecated modules which should not be used, separated by a comma. -deprecated-modules=optparse,tkinter.tix - -# Create a graph of external dependencies in the given file (report RP0402 must -# not be disabled). -ext-import-graph= - -# Create a graph of every (i.e. internal and external) dependencies in the -# given file (report RP0402 must not be disabled). -import-graph= - -# Create a graph of internal dependencies in the given file (report RP0402 must -# not be disabled). -int-import-graph= - -# Force import order to recognize a module as part of the standard -# compatibility libraries. -known-standard-library= - -# Force import order to recognize a module as part of a third party library. -known-third-party=enchant - -# Couples of modules and preferred modules, separated by a comma. -preferred-modules= - - -[EXCEPTIONS] - -# Exceptions that will emit a warning when being caught. Defaults to -# "BaseException, Exception". -overgeneral-exceptions=BaseException, - Exception diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..3b45e5ac --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,70 @@ +[build-system] +requires = ["setuptools>=77.0.3"] +build-backend = "setuptools.build_meta" + +[project] +name = "motmetrics" +dynamic = ["version"] +description = "Metrics for multiple object tracker benchmarking." +readme = { file = "Readme.md", content-type = "text/markdown" } +requires-python = ">=3.8,<3.15" +license = "MIT" +license-files = ["LICENSE"] +authors = [ + { name = "Christoph Heindl" }, + { name = "Jack Valmadre" }, +] +keywords = ["tracker", "MOT", "evaluation", "metrics", "compare"] +classifiers = [ + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", +] +dependencies = [ + "numpy>=1.23.2", + "pandas>=1.5.0", + "scipy>=1.9.3", + "xmltodict>=0.13.0", +] + +[dependency-groups] +dev = [ + "numpy>=1.23.2", + "pandas>=1.5.0", + "scipy>=1.9.3", + "xmltodict>=0.13.0", + "flake8>=5.0.0,<7.2.0; python_version < '3.9'", + "flake8>=7.3.0; python_version >= '3.9'", + "flake8-import-order>=0.18.2,<0.19.0; python_version < '3.9'", + "flake8-import-order>=0.19.2; python_version >= '3.9'", + "pytest>=7.4.4,<8.4.0; python_version < '3.9'", + "pytest>=8.4.1; python_version >= '3.9'", + "pytest-benchmark>=4.0.0,<5.0.0; python_version < '3.9'", + "pytest-benchmark>=5.1.0; python_version >= '3.9'", +] + +[project.urls] +Homepage = "https://github.com/cheind/py-motmetrics" +Issues = "https://github.com/cheind/py-motmetrics/issues" + +[tool.setuptools] +include-package-data = true + +[tool.setuptools.package-data] +motmetrics = [ + "data/**/*.mat", + "data/**/*.txt", + "data/**/*.xml", + "etc/*.png", +] + +[tool.setuptools.packages.find] +include = ["motmetrics*"] + +[tool.setuptools.dynamic] +version = { attr = "motmetrics.__version__" } diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 71b0ee99..00000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -numpy>=1.12.1 -pandas>=0.23.1 -scipy>=0.19.0 -xmltodict>=0.12.0 -enum34; python_version < '3' diff --git a/requirements_dev.txt b/requirements_dev.txt deleted file mode 100644 index 3dae07bf..00000000 --- a/requirements_dev.txt +++ /dev/null @@ -1,4 +0,0 @@ -flake8 -flake8-import-order -pytest -pytest-benchmark diff --git a/setup.py b/setup.py deleted file mode 100644 index 7682093a..00000000 --- a/setup.py +++ /dev/null @@ -1,41 +0,0 @@ -"""py-motmetrics - Metrics for multiple object tracker (MOT) benchmarking. - -Christoph Heindl, 2017 -https://github.com/cheind/py-motmetrics -""" -import io -import os - -try: - from setuptools import setup -except ImportError: - from distutils.core import setup - -with io.open("requirements.txt") as f: - required = f.read().splitlines() - -with io.open("Readme.md", encoding="utf-8") as f: - long_description = f.read() - -# Handle version number with optional .dev postfix when building a develop branch -# on AppVeyor. -VERSION = io.open("motmetrics/__init__.py").readlines()[-1].split()[-1].strip('"') -BUILD_NUMBER = os.environ.get("APPVEYOR_BUILD_NUMBER", None) -BRANCH_NAME = os.environ.get("APPVEYOR_REPO_BRANCH", "develop") -if BUILD_NUMBER is not None and BRANCH_NAME != "master": - VERSION = "{}.dev{}".format(VERSION, BUILD_NUMBER) - -setup( - name="motmetrics", - version=VERSION, - description="Metrics for multiple object tracker benchmarking.", - author="Christoph Heindl, Jack Valmadre", - url="https://github.com/cheind/py-motmetrics", - license="MIT", - install_requires=required, - packages=["motmetrics", "motmetrics.tests", "motmetrics.apps"], - include_package_data=True, - keywords="tracker MOT evaluation metrics compare", - long_description=long_description, - long_description_content_type="text/markdown", -) diff --git a/test.sh.example b/test.sh.example deleted file mode 100644 index aa73e5c2..00000000 --- a/test.sh.example +++ /dev/null @@ -1 +0,0 @@ -python3 -u -m motmetrics.apps.evaluateTracking ./gt_dir/ ./res_dir/ ./seqmaps/example.txt From 34ea153d40b01d8edf5ceb422a0197525457c33b Mon Sep 17 00:00:00 2001 From: mikel-brostrom Date: Sun, 12 Jul 2026 18:43:07 +0200 Subject: [PATCH 2/5] ci: scope linting to package sources --- .github/workflows/publish-to-pypi.yml | 2 +- .github/workflows/python-package.yml | 6 +++--- Readme.md | 2 +- Release.md | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 19cf9b46..8b280184 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -27,7 +27,7 @@ jobs: run: | uv venv --python ${{ matrix.python-version }} uv pip install --group dev - uv run --no-project --no-sync pytest + uv run --no-project pytest build: name: Build and validate distributions diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 30ef3ee9..edaf2780 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -41,9 +41,9 @@ jobs: - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names - uv run --no-project --no-sync flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + uv run --no-project flake8 motmetrics --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - uv run --no-project --no-sync flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + uv run --no-project flake8 motmetrics --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | - uv run --no-project --no-sync pytest + uv run --no-project pytest diff --git a/Readme.md b/Readme.md index 000262c1..d38de8ef 100644 --- a/Readme.md +++ b/Readme.md @@ -148,7 +148,7 @@ To install the development dependencies and run the tests: ``` uv venv uv pip install --group dev -uv run --no-project --no-sync pytest +uv run --no-project pytest ``` ## Usage diff --git a/Release.md b/Release.md index 1e92a118..7fa750b4 100644 --- a/Release.md +++ b/Release.md @@ -29,7 +29,7 @@ GitHub. python -m twine check dist/* uv venv uv pip install --group dev - uv run --no-project --no-sync pytest + uv run --no-project pytest 5. Install the generated wheel in a clean environment and smoke-test the import and version. From 71ba4a570e367e2a0ccb2c7b6f5f7070512c64cc Mon Sep 17 00:00:00 2001 From: mikel-brostrom Date: Sun, 12 Jul 2026 18:48:34 +0200 Subject: [PATCH 3/5] fix: migrate to current ortools assignment API --- motmetrics/lap.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/motmetrics/lap.py b/motmetrics/lap.py index f647aba2..9266c627 100644 --- a/motmetrics/lap.py +++ b/motmetrics/lap.py @@ -173,7 +173,7 @@ def _zero_pad_to_square(costs): def lsa_solve_ortools(costs): """Solves the LSA problem using Google's optimization tools. """ - from ortools.graph import pywrapgraph + from ortools.graph.python import linear_sum_assignment as ortools_lsa if costs.shape[0] != costs.shape[1]: # ortools assumes that the problem is square. @@ -189,17 +189,17 @@ def lsa_solve_ortools(costs): warnings.warn('costs are not integers; using approximation') int_costs = np.round(scale * finite_costs).astype(int) - assignment = pywrapgraph.LinearSumAssignment() + assignment = ortools_lsa.SimpleLinearSumAssignment() # OR-Tools does not like to receive indices of type np.int64. rs = rs.tolist() # pylint: disable=no-member cs = cs.tolist() int_costs = int_costs.tolist() for r, c, int_cost in zip(rs, cs, int_costs): - assignment.AddArcWithCost(r, c, int_cost) + assignment.add_arc_with_cost(r, c, int_cost) - status = assignment.Solve() + status = assignment.solve() try: - _ortools_assert_is_optimal(pywrapgraph, status) + _ortools_assert_is_optimal(ortools_lsa, status) except AssertionError: # Default to scipy solver rather than add finite edges. # (This maintains the same behaviour as previous versions.) @@ -259,24 +259,25 @@ def _assert_integer(costs): np.testing.assert_equal(np.round(costs), costs) -def _ortools_assert_is_optimal(pywrapgraph, status): - if status == pywrapgraph.LinearSumAssignment.OPTIMAL: +def _ortools_assert_is_optimal(ortools_lsa, status): + assignment = ortools_lsa.SimpleLinearSumAssignment + if status == assignment.OPTIMAL: pass - elif status == pywrapgraph.LinearSumAssignment.INFEASIBLE: + elif status == assignment.INFEASIBLE: raise AssertionError('ortools: infeasible assignment problem') - elif status == pywrapgraph.LinearSumAssignment.POSSIBLE_OVERFLOW: + elif status == assignment.POSSIBLE_OVERFLOW: raise AssertionError('ortools: possible overflow in assignment problem') else: raise AssertionError('ortools: unknown status') def _ortools_extract_solution(assignment): - if assignment.NumNodes() == 0: + if assignment.num_nodes() == 0: return np.array([], dtype=int), np.array([], dtype=int) pairings = [] - for i in range(assignment.NumNodes()): - pairings.append([i, assignment.RightMate(i)]) + for i in range(assignment.num_nodes()): + pairings.append([i, assignment.right_mate(i)]) indices = np.array(pairings, dtype=int) return indices[:, 0], indices[:, 1] From c1ee282338c1897f984216d8104f90df27dab257 Mon Sep 17 00:00:00 2001 From: mikel-brostrom Date: Sun, 12 Jul 2026 18:51:27 +0200 Subject: [PATCH 4/5] ci: replace flake8 with ruff --- .github/workflows/python-package.yml | 8 ++++---- pyproject.toml | 15 +++++++++++---- setup.cfg | 8 -------- 3 files changed, 15 insertions(+), 16 deletions(-) delete mode 100644 setup.cfg diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index edaf2780..cac6629c 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -38,12 +38,12 @@ jobs: # maintained LAP backends here instead. uv pip install lap scipy munkres uv pip install "ortools<9.12; python_version < '3.9'" "ortools; python_version >= '3.9'" - - name: Lint with flake8 + - name: Lint with Ruff run: | # stop the build if there are Python syntax errors or undefined names - uv run --no-project flake8 motmetrics --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - uv run --no-project flake8 motmetrics --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + uv run --no-project ruff check motmetrics --select E9,F63,F7,F82 + # report all configured lint findings without failing the build + uv run --no-project ruff check motmetrics --exit-zero - name: Test with pytest run: | uv run --no-project pytest diff --git a/pyproject.toml b/pyproject.toml index 3b45e5ac..9c60df33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,10 +38,7 @@ dev = [ "pandas>=1.5.0", "scipy>=1.9.3", "xmltodict>=0.13.0", - "flake8>=5.0.0,<7.2.0; python_version < '3.9'", - "flake8>=7.3.0; python_version >= '3.9'", - "flake8-import-order>=0.18.2,<0.19.0; python_version < '3.9'", - "flake8-import-order>=0.19.2; python_version >= '3.9'", + "ruff>=0.12.0", "pytest>=7.4.4,<8.4.0; python_version < '3.9'", "pytest>=8.4.1; python_version >= '3.9'", "pytest-benchmark>=4.0.0,<5.0.0; python_version < '3.9'", @@ -68,3 +65,13 @@ include = ["motmetrics*"] [tool.setuptools.dynamic] version = { attr = "motmetrics.__version__" } + +[tool.ruff] +line-length = 127 + +[tool.ruff.lint] +select = ["C90", "E", "F", "I", "N", "W"] +ignore = ["E501"] + +[tool.ruff.lint.isort] +known-first-party = ["motmetrics"] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index ddb083b7..00000000 --- a/setup.cfg +++ /dev/null @@ -1,8 +0,0 @@ -[pycodestyle] -ignore = W503,W504,E501 - -[flake8] -ignore = W503,W504,E501 -# Options for flake8-import-order: -import-order-style = google -application-import-names = motmetrics From 8953ab21101fb34ca764a579e6ff421e722c9358 Mon Sep 17 00:00:00 2001 From: mikel-brostrom Date: Sun, 12 Jul 2026 19:01:05 +0200 Subject: [PATCH 5/5] docs: explain TrackEval-compatible HOTA aggregation --- Readme.md | 66 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/Readme.md b/Readme.md index d38de8ef..6a2e31dc 100644 --- a/Readme.md +++ b/Readme.md @@ -349,13 +349,16 @@ OVERALL 80.0% 80.0% 80.0% 80.0% 80.0% 4 2 2 0 2 2 1 1 50.0% 0.275 """ ``` -#### [Underdeveloped] Computing HOTA metrics +#### Computing HOTA metrics -Computing HOTA metrics is also possible. However, it cannot be used with the `Accumulator` class directly, as HOTA requires to computing a reweighting matrix from all the frames at the beginning. Here is an example of how to use it: +HOTA cannot use `MOTAccumulator` directly because it requires a reweighting matrix computed from all frames. The example below computes HOTA over the standard alpha thresholds for one or more MOTChallenge sequences: ```python import os + import numpy as np +import pandas as pd + import motmetrics as mm @@ -368,35 +371,44 @@ def compute_motchallenge(dir_name): res_list = mm.utils.compare_to_groundtruth_reweighting(df_gt, df_test, "iou", distth=th_list) return res_list -# `data_dir` is the directory containing the gt.txt and test.txt files -acc = compute_motchallenge("data_dir") -mh = mm.metrics.create() -summary = mh.compute_many( - acc, - metrics=[ - "deta_alpha", - "assa_alpha", - "hota_alpha", - ], - generate_overall=True, # `Overall` is the average we need only -) -strsummary = mm.io.render_summary( - summary.iloc[[-1], :], # Use list to preserve `DataFrame` type +def compute_hota(sequence_dirs): + sequence_accs = [compute_motchallenge(path) for path in sequence_dirs] + mh = mm.metrics.create() + metrics = ["deta_alpha", "assa_alpha", "hota_alpha"] + alpha_results = [] + + for alpha_idx in range(len(sequence_accs[0])): + summary = mh.compute_many( + [accs[alpha_idx] for accs in sequence_accs], + metrics=metrics, + names=sequence_dirs, + generate_overall=True, + ) + alpha_results.append(summary.loc["OVERALL"]) + + # HOTA, DetA, and AssA are averaged over the alpha thresholds. + result = pd.DataFrame(alpha_results).mean().to_frame().T + result.index = ["OVERALL"] + return result, mh + + +summary, mh = compute_hota([ + "motmetrics/data/TUD-Campus", + "motmetrics/data/TUD-Stadtmitte", +]) +print(mm.io.render_summary( + summary, formatters=mh.formatters, - namemap={"hota_alpha": "HOTA", "assa_alpha": "ASSA", "deta_alpha": "DETA"}, -) -print(strsummary) -""" -# data_dir=motmetrics/data/TUD-Campus - DETA ASSA HOTA -OVERALL 41.8% 36.9% 39.1% -# data_dir=motmetrics/data/TUD-Stadtmitte - DETA ASSA HOTA -OVERALL 39.2% 40.9% 39.8% -""" + namemap={"hota_alpha": "HOTA", "assa_alpha": "AssA", "deta_alpha": "DetA"}, +)) + +# DetA AssA HOTA +# OVERALL 39.8% 41.2% 40.0% ``` +When multiple sequences are supplied, `OVERALL` follows TrackEval's combination rules: detection counts are summed for DetA, AssA is weighted by detections, and HOTA is recomputed as `sqrt(DetA * AssA)` at each alpha before the final threshold average. This avoids incorrectly averaging per-sequence HOTA values. + ### Computing distances Up until this point we assumed the pairwise object/hypothesis distances to be known. Usually this is not the case. You are mostly given either rectangles or points (centroids) of related objects. To compute a distance matrix from them you can use `motmetrics.distance` module as shown below.