Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: automate creation of double project.toml/hatch.toml tabs #966

Merged
merged 7 commits into from
Oct 8, 2023
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
47 changes: 17 additions & 30 deletions backend/src/hatchling/builders/hooks/plugin/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,25 @@ class BuildHookInterface(Generic[BuilderConfigBound]): # no cov
"""
Example usage:

=== ":octicons-file-code-16: plugin.py"
```python tab="plugin.py"
from hatchling.builders.hooks.plugin.interface import BuildHookInterface

```python
from hatchling.builders.hooks.plugin.interface import BuildHookInterface

class SpecialBuildHook(BuildHookInterface):
PLUGIN_NAME = 'special'
...
```

class SpecialBuildHook(BuildHookInterface):
PLUGIN_NAME = 'special'
...
```

=== ":octicons-file-code-16: hooks.py"
```python tab="hooks.py"
from hatchling.plugin import hookimpl

```python
from hatchling.plugin import hookimpl
from .plugin import SpecialBuildHook

from .plugin import SpecialBuildHook


@hookimpl
def hatch_register_build_hook():
return SpecialBuildHook
```
@hookimpl
def hatch_register_build_hook():
return SpecialBuildHook
```
"""

PLUGIN_NAME = ''
Expand Down Expand Up @@ -83,19 +79,10 @@ def config(self) -> dict[str, Any]:
"""
The cumulative hook configuration.

=== ":octicons-file-code-16: pyproject.toml"

```toml
[tool.hatch.build.hooks.<PLUGIN_NAME>]
[tool.hatch.build.targets.<TARGET_NAME>.hooks.<PLUGIN_NAME>]
```

=== ":octicons-file-code-16: hatch.toml"

```toml
[build.hooks.<PLUGIN_NAME>]
[build.targets.<TARGET_NAME>.hooks.<PLUGIN_NAME>]
```
```toml config-example
[tool.hatch.build.hooks.<PLUGIN_NAME>]
[tool.hatch.build.targets.<TARGET_NAME>.hooks.<PLUGIN_NAME>]
```
"""
return self.__config

Expand Down
58 changes: 19 additions & 39 deletions backend/src/hatchling/builders/plugin/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,25 @@ class BuilderInterface(ABC, Generic[BuilderConfigBound, PluginManagerBound]):
"""
Example usage:

=== ":octicons-file-code-16: plugin.py"

```python
from hatchling.builders.plugin.interface import BuilderInterface
```python tab="plugin.py"
from hatchling.builders.plugin.interface import BuilderInterface


class SpecialBuilder(BuilderInterface):
PLUGIN_NAME = 'special'
...
```
class SpecialBuilder(BuilderInterface):
PLUGIN_NAME = 'special'
...
```

=== ":octicons-file-code-16: hooks.py"
```python tab="hooks.py"
from hatchling.plugin import hookimpl

```python
from hatchling.plugin import hookimpl
from .plugin import SpecialBuilder

from .plugin import SpecialBuilder


@hookimpl
def hatch_register_builder():
return SpecialBuilder
```
@hookimpl
def hatch_register_builder():
return SpecialBuilder
```
"""

PLUGIN_NAME = ''
Expand Down Expand Up @@ -324,17 +320,9 @@ def config(self) -> BuilderConfigBound:
@property
def build_config(self) -> dict[str, Any]:
"""
=== ":octicons-file-code-16: pyproject.toml"

```toml
[tool.hatch.build]
```

=== ":octicons-file-code-16: hatch.toml"

```toml
[build]
```
```toml config-example
[tool.hatch.build]
```
"""
if self.__build_config is None:
self.__build_config = self.metadata.hatch.build_config
Expand All @@ -344,17 +332,9 @@ def build_config(self) -> dict[str, Any]:
@property
def target_config(self) -> dict[str, Any]:
"""
=== ":octicons-file-code-16: pyproject.toml"

```toml
[tool.hatch.build.targets.<PLUGIN_NAME>]
```

=== ":octicons-file-code-16: hatch.toml"

```toml
[build.targets.<PLUGIN_NAME>]
```
```toml config-example
[tool.hatch.build.targets.<PLUGIN_NAME>]
```
"""
if self.__target_config is None:
target_config: dict[str, Any] = self.metadata.hatch.build_targets.get(self.PLUGIN_NAME, {})
Expand Down
44 changes: 16 additions & 28 deletions backend/src/hatchling/metadata/plugin/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,25 @@ class MetadataHookInterface(ABC): # no cov
"""
Example usage:

=== ":octicons-file-code-16: plugin.py"
```python tab="plugin.py"
from hatchling.metadata.plugin.interface import MetadataHookInterface

```python
from hatchling.metadata.plugin.interface import MetadataHookInterface

class SpecialMetadataHook(MetadataHookInterface):
PLUGIN_NAME = 'special'
...
```

class SpecialMetadataHook(MetadataHookInterface):
PLUGIN_NAME = 'special'
...
```

=== ":octicons-file-code-16: hooks.py"
```python tab="hooks.py"
from hatchling.plugin import hookimpl

```python
from hatchling.plugin import hookimpl
from .plugin import SpecialMetadataHook

from .plugin import SpecialMetadataHook


@hookimpl
def hatch_register_metadata_hook():
return SpecialMetadataHook
```
@hookimpl
def hatch_register_metadata_hook():
return SpecialMetadataHook
```
"""

PLUGIN_NAME = ''
Expand All @@ -51,17 +47,9 @@ def config(self) -> dict:
"""
The hook configuration.

=== ":octicons-file-code-16: pyproject.toml"

```toml
[tool.hatch.metadata.hooks.<PLUGIN_NAME>]
```

=== ":octicons-file-code-16: hatch.toml"

```toml
[metadata.hooks.<PLUGIN_NAME>]
```
```toml config-example
[tool.hatch.metadata.hooks.<PLUGIN_NAME>]
```
"""
return self.__config

Expand Down
44 changes: 16 additions & 28 deletions backend/src/hatchling/version/scheme/plugin/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,25 @@ class VersionSchemeInterface(ABC): # no cov
"""
Example usage:

=== ":octicons-file-code-16: plugin.py"
```python tab="plugin.py"
from hatchling.version.scheme.plugin.interface import VersionSchemeInterface

```python
from hatchling.version.scheme.plugin.interface import VersionSchemeInterface

class SpecialVersionScheme(VersionSchemeInterface):
PLUGIN_NAME = 'special'
...
```

class SpecialVersionScheme(VersionSchemeInterface):
PLUGIN_NAME = 'special'
...
```

=== ":octicons-file-code-16: hooks.py"
```python tab="hooks.py"
from hatchling.plugin import hookimpl

```python
from hatchling.plugin import hookimpl
from .plugin import SpecialVersionScheme

from .plugin import SpecialVersionScheme


@hookimpl
def hatch_register_version_scheme():
return SpecialVersionScheme
```
@hookimpl
def hatch_register_version_scheme():
return SpecialVersionScheme
```
"""

PLUGIN_NAME = ''
Expand All @@ -49,17 +45,9 @@ def root(self) -> str:
@property
def config(self) -> dict:
"""
=== ":octicons-file-code-16: pyproject.toml"

```toml
[tool.hatch.version]
```

=== ":octicons-file-code-16: hatch.toml"

```toml
[version]
```
```toml config-example
[tool.hatch.version]
```
"""
return self.__config

Expand Down
44 changes: 16 additions & 28 deletions backend/src/hatchling/version/source/plugin/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,25 @@ class VersionSourceInterface(ABC): # no cov
"""
Example usage:

=== ":octicons-file-code-16: plugin.py"
```python tab="plugin.py"
from hatchling.version.source.plugin.interface import VersionSourceInterface

```python
from hatchling.version.source.plugin.interface import VersionSourceInterface

class SpecialVersionSource(VersionSourceInterface):
PLUGIN_NAME = 'special'
...
```

class SpecialVersionSource(VersionSourceInterface):
PLUGIN_NAME = 'special'
...
```

=== ":octicons-file-code-16: hooks.py"
```python tab="hooks.py"
from hatchling.plugin import hookimpl

```python
from hatchling.plugin import hookimpl
from .plugin import SpecialVersionSource

from .plugin import SpecialVersionSource


@hookimpl
def hatch_register_version_source():
return SpecialVersionSource
```
@hookimpl
def hatch_register_version_source():
return SpecialVersionSource
```
"""

PLUGIN_NAME = ''
Expand All @@ -49,17 +45,9 @@ def root(self) -> str:
@property
def config(self) -> dict:
"""
=== ":octicons-file-code-16: pyproject.toml"

```toml
[tool.hatch.version]
```

=== ":octicons-file-code-16: hatch.toml"

```toml
[version]
```
```toml config-example
[tool.hatch.version]
```
"""
return self.__config

Expand Down
27 changes: 8 additions & 19 deletions docs/blog/posts/release-hatch-160.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,17 @@ The [`virtual`](../../plugins/environment/virtual.md) environment type now uses

For example, if you define the following Hatch configuration:

=== ":octicons-file-code-16: config.toml"

```toml
[dirs.env]
virtual = ".hatch"
```
```toml tab="config.toml"
[dirs.env]
virtual = ".hatch"
```

and the following [matrix](../../config/environment/advanced.md#matrix):

=== ":octicons-file-code-16: pyproject.toml"

```toml
[[tool.hatch.envs.test.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
```

=== ":octicons-file-code-16: hatch.toml"

```toml
[[envs.test.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
```
```toml config-example
[[tool.hatch.envs.test.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
```

then [locating](../../cli/reference.md#hatch-env-find) environments with the following command:

Expand Down
Loading