princeton-vl / RAFT

BSD 3-Clause "New" or "Revised" License
3.23k stars 629 forks source link

Prefix top-level modules: * -> raft.* #176

Open SomeoneSerge opened 11 months ago

SomeoneSerge commented 11 months ago

This change is semi-automated and relies on the python-rope/rope refactoring library:

$ nix shell github:SomeoneSerge/pkgs#prefix-python-modules
$ pname=raft
$ find -iname '*.py' -exec \
  sed -i 's/sys.path.append.*$/pass/' '{}' '+'
$ rm -rf alt_cuda_corr # confuses rope, recover later
$ prefix-python-modules . --prefix "$pname"
$ prefix-python-modules . --prefix "$pname" \
    --rename-external 'utils' "$pname".core.utils "**" \
    --rename-external 'update' "$pname".core.update "**" \
    --rename-external 'extractor' "$pname".core.extractor "**" \
    --rename-external 'corr' "$pname".core.corr "**"
$ git checkout -- alt_cuda_corr

This change augments generic names like core and utils, which are unspecific and may cause conflicts when used as top-level, with project name as the prefix. This change makes it easier to just compose raft in the same environment with other projects without "human intervention" or microservices. In particular, this makes it easier to run comparisons against the exact code, rather than reimplementations. E.g. sys.path manipulations and git-submodules -> raft used as a library

One of the commits also adds pyproject.toml: this was just the easiest way to have wheels and entry points automatically generated, both when used with pip, and when packaging for other distributions (wheels have been somewhat of an exchange format lately)

I didn't try restructuring alt_cuda_corr, other than prefixing the .so and the .dist-info with raft_, because there are other projects that intend to ship this exact same module, but may actually diverge in the implementation. I thought it reasonable that each project would use its own version of the kernel, because that's safer and not much more expensive

The top-level project declares raft-alt-cuda-corr as Requires-dist:. The intention is that, when used outside the dev environment, the kernel package is just installed first. Cf. an example

I can revert any particular bit if you like, but it would be nice if you agreed with the prefix thing, because that really makes consumption easier, regardless of distro/environment/etc