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
1 change: 1 addition & 0 deletions .github/workflows/python_deploy_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
source-repo-names: '["public-noremote-conda-dev"]'
conda-channels: '["conda-forge"]'
publish-repo-names: '["public-noremote-conda-dev"]'
build-experimental: true
secrets:
JFROG_ARTIFACTORY_URL: ${{ secrets.JFROG_ARTIFACTORY_URL }}
JFROG_ARTIFACTORY_TOKEN: ${{ secrets.JFROG_ARTIFACTORY_TOKEN }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Byte-compiled / optimized / DLL files
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
Expand Down Expand Up @@ -148,3 +148,4 @@ pyproject-sha.toml

#version ignore
grid_apps/_version.py
/_version.json
14 changes: 8 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,23 @@ style = "pep440"
vcs = "git"

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

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

[tool.poetry-dynamic-versioning.files."recipe.yaml"]
[tool.poetry-dynamic-versioning.files."_version.json"]
persistent-substitution = true
initial-content = """
{ "version": "0.0.0.dev0" }
"""

[tool.ruff]
target-version = "py312"
Expand Down
5 changes: 3 additions & 2 deletions recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ schema_version: 1

context:
name: "grid-apps"
version: "0.0.0.dev0" # This will be replaced by the actual version in the build process
python_min: "3.12"
# Extract version from auto-generated _version.json
version: ${{ load_from_file("_version.json").version | trim }}
python_min: '3.12'
Comment on lines +5 to +7
module_name: ${{ name|lower|replace("-", "_") }}

package:
Expand Down
57 changes: 24 additions & 33 deletions tests/version_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,35 @@
# (see LICENSE file at the root of this source code package). '
# '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


from __future__ import annotations
Comment thread
sebhmg marked this conversation as resolved.

import importlib
import json
import re
from pathlib import Path

import pytest
import yaml
from packaging.version import InvalidVersion, Version
from packaging.version import Version

import grid_apps


def get_conda_recipe_version():
def _get_json_version() -> str:
version_json_path = Path(__file__).resolve().parents[1] / "_version.json"
with version_json_path.open(encoding="utf-8") as file:
version_json = json.load(file)
return version_json["version"]


def _get_conda_recipe_version_def() -> str:
recipe_path = Path(__file__).resolve().parents[1] / "recipe.yaml"

with recipe_path.open(encoding="utf-8") as file:
recipe = yaml.safe_load(file)
return recipe["context"]["version"]


def test_version_is_consistent():
project_version = Version(grid_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("grid_apps._version")
Expand All @@ -42,6 +44,16 @@ def _version_module_exists():
return False


def test_conda_recipe_version_loads_json():
conda_version_def = _get_conda_recipe_version_def()
regex = (
r"\$\{\{\s*load_from_file\(\s*['\"](_version\.json)['\"]\s*\)"
r"\s*\.version\b.*\}\}"
)
regex_match = re.match(regex, conda_version_def)
assert regex_match is not None


@pytest.mark.skipif(
_version_module_exists(),
reason="grid_apps._version can be found: package is built",
Expand All @@ -59,28 +71,7 @@ def test_fallback_version_is_zero():
not _version_module_exists(),
reason="grid_apps._version cannot be found: uses a fallback version",
)
def test_conda_version_is_consistent():
def test_version_json_is_consistent():
project_version = Version(grid_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():
version = Version(get_conda_recipe_version())
assert version is not None


def validate_version(version_str):
try:
version = Version(version_str)
return (version.major, version.minor, version.micro, version.pre, version.post)
except InvalidVersion:
return None


def test_version_is_valid():
assert validate_version(grid_apps.__version__) is not None
json_version = Version(_get_json_version())
assert project_version == json_version
Loading