Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -144,3 +144,6 @@ dmypy.json

# tempory generated files
pyproject-sha.toml

#version ignore
surface_apps/_version.py
37 changes: 33 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
[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 = "surface-apps"
version = "0.1.0b2"
requires-python = '>=3.10,<4.0'

description = "Find Iso-surfaces in 3D data."
license = "MIT"
keywords = ["geology", "geophysics", "earth sciences"]
readme = "package.rst"
dynamic = ["dependencies", "classifiers"]
dynamic = ["version", "dependencies", "classifiers"]
authors = [{name = "Mira Geoscience", email = "support@mirageoscience.com"}]
maintainers = [
{ name = "Benjamin Kary", email = "benjamink@mirageoscience.com" },
Expand Down Expand Up @@ -51,6 +50,8 @@ include = [
{ path = "docs/**/THIRD_PARTY_SOFTWARE.rst" },
]

version = "0.0.0.dev0"

[tool.poetry.dependencies]
python = "^3.10"

Expand Down Expand Up @@ -96,6 +97,34 @@ sphinx-autodoc-typehints = "*"
sphinx-rtd-theme = "*"
tomli = "*"

[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 = ["surface_apps/_version.py", "recipe.yaml"]
patterns = [
{ value = '''(^__version__\s*(?::.*?)?=\s*['"])[^'"]*(['"])''', mode = "str" },
{ value = '''(^\s*version\s*(?::.*?)?:\s*['"])[^'"]*(['"])''', mode = "str" },
]

[tool.poetry-dynamic-versioning.files."surface_apps/_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.conda-lock]
platforms = ['win-64', 'linux-64']
channels = ['conda-forge']
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: "surface-apps"
version: "0.1.0b2"
version: "0.0.0.dev0" # This will be replaced by the actual version in the build process
python_min: "3.10"

package:
Expand All @@ -20,7 +20,8 @@ build:
requirements:
host:
- python 3.10.*
- poetry-core >=1.0.0
- poetry-core >=1.8.0
- poetry-dynamic-versioning >=1.9, <2.0.dev
- setuptools
- pip
run:
Expand All @@ -39,6 +40,7 @@ tests:
- python:
imports:
- surface_apps
- surface_apps._version
- script:
- pytest --ignore=tests/version_test.py
requirements:
Expand Down
10 changes: 9 additions & 1 deletion surface_apps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@
from __future__ import annotations

import logging
from importlib.metadata import PackageNotFoundError, version
from pathlib import Path


__version__ = "0.1.0b2"
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

logging.basicConfig(level=logging.INFO)


Expand Down
54 changes: 40 additions & 14 deletions tests/version_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,17 @@

from __future__ import annotations

import importlib
from pathlib import Path

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

import surface_apps


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 @@ -43,10 +35,44 @@ def get_conda_recipe_version():


def test_version_is_consistent():
assert surface_apps.__version__ == get_pyproject_version()
normalized_conda_version = Version(get_conda_recipe_version())
normalized_version = Version(surface_apps.__version__)
assert normalized_conda_version == normalized_version
project_version = Version(surface_apps.__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("surface_apps._version")
return True
except ModuleNotFoundError:
return False


@pytest.mark.skipif(
_version_module_exists(),
reason="surface_apps._version can be found: package is built",
)
def test_fallback_version_is_zero():
project_version = Version(surface_apps.__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="surface_apps._version cannot be found: uses a fallback version",
)
def test_conda_version_is_consistent():
project_version = Version(surface_apps.__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 test_conda_version_is_pep440():
Expand Down
Loading