Skip to content

Commit ddee853

Browse files
authored
Migrate to pyproject.toml and update project structure (#281)
* commit * train: get version from toml instead of __init__ * fixup * revert black to clarify pr * Remove setup.py * Test new build * try again * gitignore * get version a different way * Try again * Try again * tweak buildscript * catch ffmpeg errors
1 parent 946ebcd commit ddee853

28 files changed

+563
-561
lines changed

.flake8

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[flake8]
2+
max-line-length = 88
3+
# E203: black conflict
4+
# E701: black conflict
5+
# F821: lot of issues regarding type annotations
6+
extend-ignore = E203,E701,F821

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ var/
2222
wheels/
2323
pip-wheel-metadata/
2424
share/python-wheels/
25-
*.egg-info/
2625
.installed.cfg
2726
*.egg
2827
MANIFEST
@@ -152,5 +151,5 @@ preds/
152151
scripts/.ipynb_checkpoints
153152
tb_logs
154153
tests/utils/test_cropzoom_data/
155-
tests/test_model_mirror_mouse/
156-
tests/test_model_mirror_mouse_multiview/
154+
tests/api/test_model_mirror_mouse/
155+
tests/api/test_model_mirror_mouse_multiview/

docs/source/api.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ You create a model object using `Model.from_dir`:
4747

4848
.. code-block:: python
4949
50-
from lightning_pose.model import Model
50+
from lightning_pose.api.model import Model
5151
5252
model = Model.from_dir("outputs/doc_model")
5353
@@ -66,7 +66,7 @@ or:
6666
API Reference
6767
=============
6868

69-
.. autoclass:: lightning_pose.model.Model
69+
.. autoclass:: lightning_pose.api.model.Model
7070
:members:
7171
:exclude-members: __init__, from_dir2
7272

lightning_pose/__init__.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,54 @@
1-
__version__ = "1.7.1"
2-
31
from pathlib import Path
42

53
from omegaconf import OmegaConf
64

75
LP_ROOT_PATH = (Path(__file__).parent.parent).absolute()
86
OmegaConf.register_new_resolver("LP_ROOT_PATH", lambda: LP_ROOT_PATH)
7+
8+
9+
# Hacky way to get version from pypackage.toml.
10+
# Adapted from: https://github.com/python-poetry/poetry/issues/273#issuecomment-1877789967
11+
from typing import Any
12+
import importlib.metadata
13+
from pathlib import Path
14+
15+
__package_version = "unknown"
16+
17+
18+
def __get_package_version() -> str:
19+
"""Find the version of this package."""
20+
global __package_version
21+
22+
if __package_version != "unknown":
23+
# We already set it at some point in the past,
24+
# so return that previous value without any
25+
# extra work.
26+
return __package_version
27+
28+
try:
29+
# Try to get the version of the current package if
30+
# it is running from a distribution.
31+
__package_version = importlib.metadata.version("lightning-pose")
32+
except importlib.metadata.PackageNotFoundError:
33+
# Fall back on getting it from a local pyproject.toml.
34+
# This works in a development environment where the
35+
# package has not been installed from a distribution.
36+
import toml
37+
import warnings
38+
39+
warnings.warn(
40+
"lightning-pose not pip-installed, getting version from pyproject.toml."
41+
)
42+
43+
pyproject_toml_file = Path(__file__).parent.parent / "pyproject.toml"
44+
__package_version = toml.load(pyproject_toml_file)["project"]["version"]
45+
46+
return __package_version
47+
48+
49+
def __getattr__(name: str) -> Any:
50+
"""Get package attributes."""
51+
if name in ("version", "__version__"):
52+
return __get_package_version()
53+
else:
54+
raise AttributeError(f"No attribute {name} in module {__name__}.")
File renamed without changes.

0 commit comments

Comments
 (0)