Skip to content

Commit

Permalink
refactor(camtools): improve version handling and add dependency compa…
Browse files Browse the repository at this point in the history
…tibility check

- Refactor version retrieval into a reusable function `_get_package_version`
- Add logging configuration and compatibility check for open3d and numpy
- Warn users if incompatible versions of open3d and numpy are detected
  • Loading branch information
yxlao committed Jan 11, 2025
1 parent 04a1785 commit 15eeb34
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions camtools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from . import artifact
from . import camera
from . import colmap
Expand All @@ -16,13 +18,42 @@
from . import transform
from . import util


# Get package version for camtools
try:
# Python >= 3.8
from importlib.metadata import version

__version__ = version("camtools")
def _get_package_version(package):
return version(package)

except ImportError:
# Python < 3.8
import pkg_resources

__version__ = pkg_resources.get_distribution("camtools").version
def _get_package_version(package):
return pkg_resources.get_distribution(package).version


__version__ = _get_package_version("camtools")


# Check open3d and numpy compatibility
try:
logging.basicConfig(format="%(message)s")
_logger = logging.getLogger(__name__)

o3d_version = _get_package_version("open3d")
np_version = _get_package_version("numpy")

o3d_version_tuple = tuple(map(int, o3d_version.split(".")[:2]))
np_version_tuple = tuple(map(int, np_version.split(".")[:2]))

if o3d_version_tuple < (0, 19) and np_version_tuple >= (2, 0):
_logger.warning(
f"[Warning] Incompatible versions: open3d {o3d_version} does "
f"not support numpy {np_version}. You may upgrade open3d to >= 0.19.0 "
f"or downgrade numpy to 1.x."
)
except Exception as e:
pass

0 comments on commit 15eeb34

Please sign in to comment.