Announcing a small Colcon extension:
pip install colcon-package-of
Given a set of files, output a list of packages which contain those files.
$ colcon package-of src/pkgX/foo.txt src/pkgY/bar.txt
pkgX src/pkgX (python)
pkgY src/pkgY (python)
The --names-only
and --paths-only
options can be used to adjust the output.
For convince, there is also a --git-diff
option, which is basically equivalent
to using git diff
with xargs
. If there are added, deleted, modified, or
untracked files corresponding to a package, that package will be listed:
$ touch src/pkgA/newfoo.txt
$ rm src/pkgB/oldbar.txt
$ colcon package-of --git-diff HEAD
pkgA src/pkgA (python)
pkgB src/pkgB (python)
The intention is for this to be useful as part of a CI pipeline, to build only the packages that have changed since the last commit, for example:
DIFF_PKGS=$(colcon package-of -n --git-diff HEAD^)
[ -z "$DIFF_PKGS" ] || colcon build --packages-above $DIFF_PKGS
Please let me know what you think!