Repository: pypa/hatch

Issue:
`hatch version <new-version>` fails when any custom metadata hook is installed
### Setup

hatch 1.4.1

#### pyproject.toml
```toml
[project]
name = "myapp"
dynamic = ["version"]

[tool.hatch.version]
path = "myapp/__init__.py"

[tool.hatch.metadata.hooks]
custom = {}
```

#### hatch_build.py
```py
from hatchling.metadata.plugin.interface import MetadataHookInterface


class CustomMetadataHook(MetadataHookInterface):
    def update(self, metadata: dict) -> None:
        pass
```

#### myapp/\_\_init\_\_.py
```py
__version__ = '1.0.0'
```

### Steps

`hatch version patch`

### Result

```
Cannot set version when it is statically defined by the `project.version` field
```

### Expected

```
Old: 1.0.0
New: 1.0.1
```

### More details

Commenting out the custom metadata hook works around the error.

Perhaps the test in hatch/cli/version/\_\_init\_\_.py should be more like `'version' in app.project.metadata.config['project']`?

Discussion:

Patch:
diff --git a/backend/src/hatchling/cli/version/__init__.py b/backend/src/hatchling/cli/version/__init__.py
index babc7f00..a67fc430 100644
--- a/backend/src/hatchling/cli/version/__init__.py
+++ b/backend/src/hatchling/cli/version/__init__.py
@@ -14,7 +14,7 @@ def version_impl(called_by_app, desired_version):
     plugin_manager = PluginManager()
     metadata = ProjectMetadata(root, plugin_manager)
 
-    if metadata.core.version is not None:
+    if 'version' in metadata.config.get('project', {}):
         if desired_version:
             app.abort('Cannot set version when it is statically defined by the `project.version` field')
         else:
diff --git a/docs/history.md b/docs/history.md
index 8e9f170d..1d5cdd7c 100644
--- a/docs/history.md
+++ b/docs/history.md
@@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 
 ### Unreleased
 
+***Fixed:***
+
+- Fix check for updating static versions with the `version` command when metadata hooks are in use
+
 ### [1.4.1](https://github.com/pypa/hatch/releases/tag/hatch-v1.4.1) - 2022-08-13 ### {: #hatch-v1.4.1 }
 
 ***Fixed:***
@@ -136,6 +140,10 @@ This is the first stable release of Hatch v1, a complete rewrite. Enjoy!
 
 ### Unreleased
 
+***Fixed:***
+
+- Fix check for updating static versions with the `version` command when metadata hooks are in use
+
 ### [1.7.1](https://github.com/pypa/hatch/releases/tag/hatchling-v1.7.1) - 2022-08-13 ### {: #hatchling-v1.7.1 }
 
 ***Fixed:***
diff --git a/src/hatch/cli/version/__init__.py b/src/hatch/cli/version/__init__.py
index 80120f2e..d87b2120 100644
--- a/src/hatch/cli/version/__init__.py
+++ b/src/hatch/cli/version/__init__.py
@@ -6,7 +6,7 @@ import click
 @click.pass_obj
 def version(app, desired_version):
     """View or set a project's version."""
-    if app.project.metadata.core.version is not None:
+    if 'version' in app.project.metadata.config.get('project', {}):
         if desired_version:
             app.abort('Cannot set version when it is statically defined by the `project.version` field')
         else:


Test patch:
diff --git a/tests/cli/version/test_version.py b/tests/cli/version/test_version.py
index a2e2ec23..5cb34a00 100644
--- a/tests/cli/version/test_version.py
+++ b/tests/cli/version/test_version.py
@@ -1,4 +1,5 @@
 from hatch.project.core import Project
+from hatchling.utils.constants import DEFAULT_BUILD_SCRIPT
 
 
 def test_show_dynamic(hatch, temp_dir):
@@ -24,6 +25,24 @@ def test_set_dynamic(hatch, helpers, temp_dir):
 
     path = temp_dir / 'my-app'
 
+    project = Project(path)
+    config = dict(project.raw_config)
+    config['tool']['hatch']['metadata'] = {'hooks': {'custom': {}}}
+    project.save_config(config)
+
+    build_script = path / DEFAULT_BUILD_SCRIPT
+    build_script.write_text(
+        helpers.dedent(
+            """
+            from hatchling.metadata.plugin.interface import MetadataHookInterface
+
+            class CustomMetadataHook(MetadataHookInterface):
+                def update(self, metadata):
+                    pass
+            """
+        )
+    )
+
     with path.as_cwd():
         result = hatch('version', 'minor,rc')