Repository: conda-forge/conda-smithy

Issue:
Package version "0" causes a false positive
### Solution to issue cannot be found in the documentation.

- [x] I checked the documentation.

### Issue

If the recipe has:

```yaml
package:
  ...
  version: "0"
```

```
$ conda smithy lint recipe
recipe has some lint:
  Package version is missing.
```

Not a big deal but looks like something is misinterpreting `0` as `False`.

### Installed packages

```shell
n/a
```

### Environment info

```shell
n/a
```

Discussion:

Patch:
diff --git a/conda_smithy/linter/conda_recipe_v1_linter.py b/conda_smithy/linter/conda_recipe_v1_linter.py
index 27746227..53be7cc1 100644
--- a/conda_smithy/linter/conda_recipe_v1_linter.py
+++ b/conda_smithy/linter/conda_recipe_v1_linter.py
@@ -122,13 +122,11 @@ def get_recipe_version(recipe_content: RecipeWithContext) -> Optional[str]:
     package_version = rendered_context_recipe.get("package", {}).get("version")
     recipe_version = rendered_context_recipe.get("recipe", {}).get("version")
 
-    if not package_version and not recipe_version:
-        return None
-
-    if package_version:
+    if package_version is not None:
         return str(package_version).strip()
-
-    return str(recipe_version).strip()
+    if recipe_version is not None:
+        return str(recipe_version).strip()
+    return None
 
 
 def lint_recipe_name(
diff --git a/conda_smithy/linter/lints.py b/conda_smithy/linter/lints.py
index 8929504c..562dbe23 100644
--- a/conda_smithy/linter/lints.py
+++ b/conda_smithy/linter/lints.py
@@ -6,7 +6,6 @@ import tempfile
 from collections.abc import Sequence
 from typing import Any, Literal, Optional
 
-from conda.exceptions import InvalidVersionSpec
 from conda.models.version import VersionOrder
 from rattler_build_conda_compat.jinja.jinja import render_recipe_with_context
 from rattler_build_conda_compat.loader import parse_recipe_config_file
@@ -20,6 +19,7 @@ from conda_smithy.linter.utils import (
     REQUIREMENTS_ORDER,
     TEST_FILES,
     TEST_KEYS,
+    _lint_package_version,
     _lint_recipe_name,
     flatten_v1_if_else,
     get_section,
@@ -395,17 +395,11 @@ def lint_noarch_and_runtime_dependencies(
 
 def lint_package_version(package_section, lints):
     version = package_section.get("version")
-    if not version:
-        lints.append("Package version is missing.")
-        return
-    if package_section.get("version") is not None:
-        ver = str(package_section.get("version"))
-        try:
-            VersionOrder(ver)
-        except InvalidVersionSpec as e:
-            lints.append(
-                f"Package version {ver} doesn't match conda spec: {e}"
-            )
+    lint_msg = _lint_package_version(
+        str(version) if version is not None else None
+    )
+    if lint_msg:
+        lints.append(lint_msg)
 
 
 def lint_jinja_variables_definitions(meta_fname, lints):
diff --git a/conda_smithy/linter/utils.py b/conda_smithy/linter/utils.py
index 5c7ea72b..825d6d04 100644
--- a/conda_smithy/linter/utils.py
+++ b/conda_smithy/linter/utils.py
@@ -208,7 +208,7 @@ def _lint_package_version(version: Optional[str]) -> Optional[str]:
     no_package_version = "Package version is missing."
     invalid_version = "Package version {ver} doesn't match conda spec: {err}"
 
-    if not version:
+    if version is None:
         return no_package_version
 
     ver = str(version)
diff --git a/news/fix-version-0.rst b/news/fix-version-0.rst
new file mode 100644
index 00000000..1065d2ad
--- /dev/null
+++ b/news/fix-version-0.rst
@@ -0,0 +1,23 @@
+**Added:**
+
+* <news item>
+
+**Changed:**
+
+* <news item>
+
+**Deprecated:**
+
+* <news item>
+
+**Removed:**
+
+* <news item>
+
+**Fixed:**
+
+* Fixed "missing package version" false positives for version "0". (#2217)
+
+**Security:**
+
+* <news item>


Test patch:
diff --git a/tests/test_lint_recipe.py b/tests/test_lint_recipe.py
index 3596a261..dc0fa104 100644
--- a/tests/test_lint_recipe.py
+++ b/tests/test_lint_recipe.py
@@ -3972,5 +3972,22 @@ def test_lint_recipe_v1_comment_selectors():
         ]
 
 
+@pytest.mark.parametrize("filename", ["meta.yaml", "recipe.yaml"])
+def test_version_zero(filename: str):
+    with tempfile.TemporaryDirectory() as tmpdir:
+        with open(os.path.join(tmpdir, filename), "w") as f:
+            f.write(
+                textwrap.dedent(
+                    """
+                package:
+                  name: test
+                  version: 0
+                """
+                )
+            )
+        lints, _ = linter.main(tmpdir, return_hints=True, conda_forge=True)
+        assert "Package version is missing." not in lints
+
+
 if __name__ == "__main__":
     unittest.main()