Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,6 @@ dmypy.json

# geoh5 locks
*.geoh5.lock

#version ignore
omf/_version.py
10 changes: 9 additions & 1 deletion omf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import logging
import sys
from importlib.metadata import PackageNotFoundError, version

from .base import Project
from .data import (
Expand Down Expand Up @@ -44,7 +45,14 @@
from .volume import VolumeElement, VolumeGridGeometry


__version__ = "3.4.0a1"
try:
from ._version import __version__
except ModuleNotFoundError:
from datetime import datetime

__date_str = datetime.today().strftime("%Y%m%d")
__version__ = "0.0.0.dev0+" + __date_str

__author__ = "Global Mining Standards and Guidelines Group, Mira Geoscience Ltd."
__license__ = "MIT License"
__copyright__ = (
Expand Down
36 changes: 32 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
[build-system]
requires = ["poetry-core>=1.8.0"]
build-backend = "poetry.core.masonry.api"
requires = ["poetry-core>=1.8.0", "poetry-dynamic-versioning>=1.9.0,<2.0.0"]
build-backend = "poetry_dynamic_versioning.backend"

[project]
name = "mira-omf"
version = "3.4.0a1"
requires-python = ">=3.10,<4.0"
description = "API Library for Open Mining Format"
license = "MIT"
keywords = ["geology", "geophysics", "earth sciences"]
readme = "README.rst"
dynamic = ["dependencies", "classifiers"]
dynamic = ["version", "dependencies", "classifiers"]
authors = [
{ name = "Mira Geoscience", email = "support@mirageoscience.com" },
{ name = "Global Mining Guidelines Group", email = "info@gmggroup.org" }
Expand Down Expand Up @@ -54,6 +53,7 @@ include = [
{ path = "THIRD_PARTY_SOFTWARE.rst" },
{ path = "docs/**/THIRD_PARTY_SOFTWARE.rst" },
]
version = "0.0.0.dev0"

[tool.poetry.dependencies]
numpy = "~1.26.0" # also in geoh5py
Expand All @@ -79,6 +79,34 @@ jinja2 = '*'
packaging = '*'
tomli = "*" # for tests only

[tool.poetry.requires-plugins]
poetry-dynamic-versioning = { version = ">=1.0.0,<2.0.0", extras = ["plugin"] }

[tool.poetry-dynamic-versioning]
bump = true
enable = true
fix-shallow-repository = true
strict = true
style = "pep440"
vcs = "git"

[tool.poetry-dynamic-versioning.substitution]
files = ["omf/_version.py", "recipe.yaml"]
patterns = [
{ value = '''(^__version__\s*(?::.*?)?=\s*['"])[^'"]*(['"])''', mode = "str" },
{ value = '''(^\s*version\s*(?::.*?)?:\s*['"])[^'"]*(['"])''', mode = "str" },
]

[tool.poetry-dynamic-versioning.files."omf/_version.py"]
persistent-substitution = true
initial-content = """
# Version placeholder that will be replaced during substitution
__version__ = "0.0.0"
"""

[tool.poetry-dynamic-versioning.files."recipe.yaml"]
persistent-substitution = true

[tool.ruff]
target-version = "py310"

Expand Down
6 changes: 4 additions & 2 deletions recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ schema_version: 1

context:
name: "mira-omf"
version: "3.4.0a1"
version: "0.0.0.dev0" # This will be replaced by the actual version in the build process
python_min: "3.10"

package:
Expand All @@ -25,7 +25,8 @@ requirements:
host:
- pip
- python 3.10.*
- poetry-core >=1.0.0
- poetry-core >=1.8.0
- poetry-dynamic-versioning >=1.9, <2.0.dev
- setuptools
run:
- python >=${{ python_min }}
Expand All @@ -42,6 +43,7 @@ tests:
- python:
imports:
- omf
- omf._version
pip_check: false # unclear why pip check reports that installed versions
# of vectormath and properties are "not supported on this platform"
# while they seem to work fine in the tests
Expand Down
54 changes: 40 additions & 14 deletions tests/version_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,18 @@

from __future__ import annotations

import importlib
import re
from pathlib import Path

import tomli as toml
import pytest
import yaml
from jinja2 import Template
from packaging.version import InvalidVersion, Version

import omf


def get_pyproject_version():
path = Path(__file__).resolve().parents[1] / "pyproject.toml"

with open(str(path), encoding="utf-8") as file:
pyproject = toml.loads(file.read())

return pyproject["project"]["version"]


def get_conda_recipe_version():
path = Path(__file__).resolve().parents[1] / "recipe.yaml"

Expand All @@ -47,10 +39,44 @@ def get_conda_recipe_version():


def test_version_is_consistent():
assert omf.__version__ == get_pyproject_version()
normalized_conda_version = Version(get_conda_recipe_version())
normalized_version = Version(omf.__version__)
assert normalized_conda_version == normalized_version
project_version = Version(omf.__version__)
conda_version = Version(get_conda_recipe_version())
assert conda_version.base_version == project_version.base_version


def _version_module_exists():
try:
importlib.import_module("omf._version")
return True
except ModuleNotFoundError:
return False


@pytest.mark.skipif(
_version_module_exists(),
reason="omf._version can be found: package is built",
)
def test_fallback_version_is_zero():
project_version = Version(omf.__version__)
fallback_version = Version("0.0.0.dev0")
assert project_version.base_version == fallback_version.base_version
assert project_version.pre is None
assert project_version.post is None
assert project_version.dev == fallback_version.dev


@pytest.mark.skipif(
not _version_module_exists(),
reason="omf._version cannot be found: uses a fallback version",
)
def test_conda_version_is_consistent():
project_version = Version(omf.__version__)
conda_version = Version(get_conda_recipe_version())

assert conda_version.is_devrelease == project_version.is_devrelease
assert conda_version.is_prerelease == project_version.is_prerelease
assert conda_version.is_postrelease == project_version.is_postrelease
assert conda_version == project_version


def version_base_and_pre() -> tuple[str, str]:
Expand Down
Loading