Skip to content

Commit

Permalink
Move _package_version to travertino
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsmith committed Feb 11, 2025
1 parent 32000af commit 615251d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 38 deletions.
1 change: 1 addition & 0 deletions changes/3183.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move ``_package_version`` to travertino
26 changes: 2 additions & 24 deletions core/src/toga/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import warnings
from importlib import import_module

from travertino import _package_version

toga_core_imports = {
# toga.app imports
"App": "toga.app",
Expand Down Expand Up @@ -119,28 +121,4 @@ def warn(cls, platform: str, feature: str) -> None:
warnings.warn(NotImplementedWarning(f"[{platform}] Not implemented: {feature}"))


def _package_version(file, name):
try:
# Read version from SCM metadata
# This will only exist in a development environment
from setuptools_scm import get_version

# Excluded from coverage because a pure test environment (such as the one
# used by tox in CI) won't have setuptools_scm
return get_version(root="../../..", relative_to=file) # pragma: no cover
except (
ModuleNotFoundError,
LookupError,
): # pragma: no-cover-if-missing-setuptools_scm
# If setuptools_scm isn't in the environment, the call to import will fail.
# If it *is* in the environment, but the code isn't a git checkout (e.g.,
# it's been pip installed non-editable) the call to get_version() will fail.
# If either of these occurs, read version from the installer metadata.
import importlib.metadata

# The Toga package names as defined in setup.cfg all use dashes.
package = "toga-core" if name == "toga" else name.replace("_", "-")
return importlib.metadata.version(package)


__version__ = _package_version(__file__, __name__)
36 changes: 22 additions & 14 deletions travertino/src/travertino/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
try:
# Read version from SCM metadata
# This will only exist in a development environment
from setuptools_scm import get_version
def _package_version(file, name):
try:
# Read version from SCM metadata
# This will only exist in a development environment
from setuptools_scm import get_version

# Excluded from coverage because a pure test environment (such as the one
# used by tox in CI) won't have setuptools_scm
__version__ = get_version("../../..", relative_to=__file__) # pragma: no cover
except (ModuleNotFoundError, LookupError):
# If setuptools_scm isn't in the environment, the call to import will fail.
# If it *is* in the environment, but the code isn't a git checkout (e.g.,
# it's been pip installed non-editable) the call to get_version() will fail.
# If either of these occurs, read version from the installer metadata.
# Excluded from coverage because a pure test environment (such as the one
# used by tox in CI) won't have setuptools_scm
return get_version(root="../../..", relative_to=file) # pragma: no cover
except (
ModuleNotFoundError,
LookupError,
): # pragma: no-cover-if-missing-setuptools_scm
# If setuptools_scm isn't in the environment, the call to import will fail.
# If it *is* in the environment, but the code isn't a git checkout (e.g.,
# it's been pip installed non-editable) the call to get_version() will fail.
# If either of these occurs, read version from the installer metadata.
import importlib.metadata

from importlib.metadata import version
# The Toga package names as defined in pyproject.toml all use dashes.
package = "toga-core" if name == "toga" else name.replace("_", "-")
return importlib.metadata.version(package)

__version__ = version("travertino")

__version__ = _package_version(__file__, __name__)

0 comments on commit 615251d

Please sign in to comment.