-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit dabb6da
Showing
8 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024-present Angus Hollands <goosey15@gmail.com> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# hatch-deps-selector | ||
|
||
[](https://pypi.org/project/hatch-deps-selector) | ||
[](https://pypi.org/project/hatch-deps-selector) | ||
|
||
----- | ||
|
||
## Table of Contents | ||
|
||
- [Installation](#installation) | ||
- [License](#license) | ||
|
||
## Installation | ||
|
||
```console | ||
pip install hatch-deps-selector | ||
``` | ||
|
||
## License | ||
|
||
`hatch-deps-selector` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[build-system] | ||
requires = ["hatchling"] | ||
build-backend = "hatchling.build" | ||
|
||
[project] | ||
name = "hatch-deps-selector" | ||
dynamic = ["version"] | ||
description = 'Select variants of your dependencies with environment variables' | ||
readme = "README.md" | ||
requires-python = ">=3.8" | ||
license = "MIT" | ||
keywords = [] | ||
authors = [ | ||
{ name = "Angus Hollands", email = "goosey15@gmail.com" }, | ||
] | ||
classifiers = [ | ||
"Development Status :: 4 - Beta", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: 3.12", | ||
"Programming Language :: Python :: Implementation :: CPython", | ||
"Programming Language :: Python :: Implementation :: PyPy", | ||
] | ||
dependencies = [] | ||
|
||
[project.urls] | ||
Documentation = "https://github.com/jupyter-book/hatch-deps-selector#readme" | ||
Issues = "https://github.com/jupyter-book/hatch-deps-selector/issues" | ||
Source = "https://github.com/jupyter-book/hatch-deps-selector" | ||
|
||
[tool.hatch.version] | ||
path = "src/hatch_deps_selector/__about__.py" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# SPDX-FileCopyrightText: 2024-present Angus Hollands <goosey15@gmail.com> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
__version__ = "0.0.1" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# SPDX-FileCopyrightText: 2022-present Angus Hollands <goosey15@gmail.com> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
from hatchling.plugin import hookimpl | ||
|
||
from .plugin import DependenciesSelectorHook | ||
|
||
|
||
@hookimpl | ||
def hatch_register_build_hook(): | ||
return DependenciesSelectorHook | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
from hatchling.builders.hooks.plugin.interface import BuildHookInterface | ||
|
||
|
||
class DependenciesSelectorHook(BuildHookInterface): | ||
PLUGIN_NAME = "selector" | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
self.__env_var = None | ||
self.__variants = None | ||
|
||
@property | ||
def env_var(self): | ||
if self.__env_var is None: | ||
env_var = self.config.get("env-var", "HATCH_SELECTOR_VARIANT") | ||
if not isinstance(env_var, str): | ||
raise TypeError(f"Option `env-var` for build hook `{self.PLUGIN_NAME}` must be a string") | ||
|
||
self.__env_var = env_var | ||
return self.__env_var | ||
|
||
@property | ||
def variants(self): | ||
if self.__variants is None: | ||
variants = self.config.get("variants", {}) | ||
if not isinstance(variants, dict): | ||
raise TypeError(f"Option `variants` for build hook `{self.PLUGIN_NAME}` must be a table") | ||
|
||
self.__variants = variants | ||
return self.variants | ||
|
||
|
||
def initialize(self, version, build_data): | ||
# Allow variant to be unset or empty | ||
variant = os.environ.get(self.env_var) | ||
if not variant: | ||
return | ||
|
||
# But if defined, should be valid | ||
dependencies = self.variants.get(variant, []) | ||
if dependencies is None: | ||
raise ValueError(f"Variant `{variant}` not found for build hook `{self.PLUGIN_NAME}`") | ||
build_data["dependencies"].extend(dependencies) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# SPDX-FileCopyrightText: 2024-present Angus Hollands <goosey15@gmail.com> | ||
# | ||
# SPDX-License-Identifier: MIT |