Skip to content

Commit d9f9c3d

Browse files
Merge pull request #17 from CrackingShells/feature/v1-2-2-conda-support
feat: Add v1.2.2 schema with conda package manager support
2 parents 3e7df1e + 6cfddf1 commit d9f9c3d

File tree

12 files changed

+1227
-6
lines changed

12 files changed

+1227
-6
lines changed

hatch_validator/core/pkg_accessor_base.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,23 @@ def get_citations(self, metadata: Dict[str, Any]) -> Any:
347347
if self.next_accessor:
348348
return self.next_accessor.get_citations(metadata)
349349
raise NotImplementedError("Citations accessor not implemented for this schema version")
350+
351+
def get_python_dependency_channel(self, dependency: Dict[str, Any]) -> Any:
352+
"""Get channel from a Python dependency.
353+
354+
This method is only available for schema versions >= 1.2.2 which support
355+
conda package manager with channel specification.
356+
357+
Args:
358+
dependency (Dict[str, Any]): Python dependency object
359+
360+
Returns:
361+
Any: Channel value (e.g., "conda-forge", "bioconda")
362+
363+
Raises:
364+
NotImplementedError: If there is no next accessor and this method is not overridden,
365+
or if the schema version does not support channels
366+
"""
367+
if self.next_accessor:
368+
return self.next_accessor.get_python_dependency_channel(dependency)
369+
raise NotImplementedError("Python dependency channel accessor not implemented for this schema version")

hatch_validator/core/pkg_accessor_factory.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ def _ensure_accessors_loaded(cls) -> None:
7070
except ImportError as e:
7171
logger.warning(f"Could not load v1.2.1 accessor: {e}")
7272

73+
try:
74+
from hatch_validator.package.v1_2_2.accessor import HatchPkgAccessor as V122HatchPkgAccessor
75+
cls.register_accessor("1.2.2", V122HatchPkgAccessor)
76+
except ImportError as e:
77+
logger.warning(f"Could not load v1.2.2 accessor: {e}")
78+
7379
@classmethod
7480
def create_accessor_chain(cls, target_version: Optional[str] = None) -> HatchPkgAccessor:
7581
"""Create appropriate accessor chain based on target version.

hatch_validator/core/validator_factory.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ def _ensure_validators_loaded(cls) -> None:
7272
cls.register_validator("1.2.1", V121Validator)
7373
except ImportError as e:
7474
logger.warning(f"Could not load v1.2.1 validator: {e}")
75+
76+
try:
77+
from hatch_validator.package.v1_2_2.validator import Validator as V122Validator
78+
cls.register_validator("1.2.2", V122Validator)
79+
except ImportError as e:
80+
logger.warning(f"Could not load v1.2.2 validator: {e}")
7581

7682
@classmethod
7783
def create_validator_chain(cls, target_version: Optional[str] = None) -> Validator:

hatch_validator/package/package_service.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,23 @@ def get_tools(self) -> Any:
160160
if not self.is_loaded():
161161
raise ValueError("Package metadata is not loaded.")
162162
return self._accessor.get_tools(self._metadata)
163+
164+
def get_python_dependency_channel(self, dependency: Dict[str, Any]) -> Any:
165+
"""Get channel from a Python dependency.
166+
167+
This method is only available for schema versions >= 1.2.2 which support
168+
conda package manager with channel specification.
169+
170+
Args:
171+
dependency (Dict[str, Any]): Python dependency object
172+
173+
Returns:
174+
Any: Channel value (e.g., "conda-forge", "bioconda"), or None if not specified
175+
176+
Raises:
177+
ValueError: If metadata is not loaded.
178+
NotImplementedError: If the schema version does not support channels.
179+
"""
180+
if not self.is_loaded():
181+
raise ValueError("Package metadata is not loaded.")
182+
return self._accessor.get_python_dependency_channel(dependency)

hatch_validator/package/v1_2_1/accessor.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,31 @@ def can_handle(self, schema_version: str) -> bool:
3030
return schema_version == "1.2.1"
3131

3232
def get_entry_point(self, metadata):
33-
"""From v1.2.1, returns the same as get_mcp_entry_point().
33+
"""Get the full entry point dict for v1.2.1.
34+
35+
In v1.2.1, entry_point is a dict with mcp_server and hatch_mcp_server keys.
36+
This method returns the full dict to maintain backward compatibility with
37+
code that expects to access both entry points.
3438
3539
Args:
3640
metadata (dict): Package metadata
3741
3842
Returns:
39-
Any: Dual entry point value
43+
dict: Dual entry point dict with mcp_server and hatch_mcp_server keys
4044
"""
41-
return metadata.get('entry_point').get('mcp_server')
42-
45+
return metadata.get('entry_point', {})
46+
4347
def get_mcp_entry_point(self, metadata):
4448
"""Get MCP entry point from metadata.
4549
4650
Args:
4751
metadata (dict): Package metadata
4852
4953
Returns:
50-
Any: MCP entry point value
54+
str: MCP entry point value (e.g., "mcp_server.py")
5155
"""
52-
return self.get_entry_point(metadata)
56+
entry_point = metadata.get('entry_point', {})
57+
return entry_point.get('mcp_server') if isinstance(entry_point, dict) else None
5358

5459
def get_hatch_mcp_entry_point(self, metadata):
5560
"""Get Hatch MCP entry point from metadata.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""Schema validation package for v1.2.2.
2+
3+
This package contains the validator and strategies for schema version 1.2.2,
4+
which introduces conda package manager support for Python dependencies.
5+
"""
6+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""Package metadata accessor for schema version 1.2.2.
2+
3+
This module provides the metadata accessor for schema version 1.2.2,
4+
which introduces conda package manager support for Python dependencies.
5+
All metadata access patterns remain unchanged from v1.2.1, except for
6+
the new channel field in Python dependencies.
7+
"""
8+
9+
import logging
10+
from typing import Dict, Any
11+
from hatch_validator.core.pkg_accessor_base import HatchPkgAccessor as HatchPkgAccessorBase
12+
13+
logger = logging.getLogger("hatch.package.v1_2_2.accessor")
14+
15+
class HatchPkgAccessor(HatchPkgAccessorBase):
16+
"""Metadata accessor for Hatch package schema version 1.2.2.
17+
18+
Schema version 1.2.2 introduces conda package manager support for Python
19+
dependencies with optional channel specification. This accessor implements
20+
the channel accessor while delegating all other operations to v1.2.1.
21+
"""
22+
23+
def can_handle(self, schema_version: str) -> bool:
24+
"""Check if this accessor can handle schema version 1.2.2.
25+
26+
Args:
27+
schema_version (str): Schema version to check
28+
29+
Returns:
30+
bool: True if schema_version is '1.2.2'
31+
"""
32+
return schema_version == "1.2.2"
33+
34+
def get_python_dependency_channel(self, dependency: Dict[str, Any]) -> Any:
35+
"""Get channel from a Python dependency.
36+
37+
This method retrieves the channel field from a Python dependency,
38+
which is available in schema version 1.2.2 for conda packages.
39+
40+
Args:
41+
dependency (Dict[str, Any]): Python dependency object
42+
43+
Returns:
44+
Any: Channel value (e.g., "conda-forge", "bioconda"), or None if not specified
45+
"""
46+
return dependency.get('channel')
47+

0 commit comments

Comments
 (0)