-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(hatch): lookup bricks in another TOML section (#150)
* feat(hatch): lookup bricks in another TOML section, preparing for library support using Hatch build hooks
- Loading branch information
1 parent
f712ef0
commit 3855a02
Showing
2 changed files
with
82 additions
and
11 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
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 |
---|---|---|
@@ -1,37 +1,82 @@ | ||
from polylith import project | ||
import tomlkit | ||
from polylith import project | ||
|
||
namespace = "unittest" | ||
|
||
poetry_toml = """\ | ||
[tool.poetry] | ||
packages = [ | ||
{include = "unittest/one",from = "../../components"} | ||
{include = "unittest/one",from = "../../bases"}, | ||
{include = "unittest/two",from = "../../components"} | ||
] | ||
""" | ||
|
||
|
||
hatch_toml = """\ | ||
[tool.hatch.build.force-include] | ||
"../../bases/unittest/one" = "unittest/one" | ||
"../../components/unittest/two" = "unittest/two" | ||
""" | ||
|
||
hatch_toml_alternative = """\ | ||
[tool.hatch.build.hooks.targets.wheel.polylith.bricks] | ||
"../../bases/unittest/one" = "unittest/one" | ||
"../../components/unittest/two" = "unittest/two" | ||
""" | ||
|
||
hatch_toml_combined = """\ | ||
[tool.hatch.build.force-include] | ||
"../../bases/unittest/one" = "unittest/one" | ||
"../../components/unittest/two" = "unittest/two" | ||
[tool.hatch.build.hooks.targets.wheel.polylith.bricks] | ||
"something" = "else" | ||
""" | ||
|
||
expected = [ | ||
{"include": "unittest/one", "from": "../../bases"}, | ||
{"include": "unittest/two", "from": "../../components"}, | ||
] | ||
|
||
|
||
def test_get_poetry_package_includes(): | ||
data = tomlkit.loads(poetry_toml) | ||
|
||
res = project.get.get_project_package_includes(namespace, data) | ||
|
||
assert res == [{"include": "unittest/one", "from": "../../components"}] | ||
assert res == expected | ||
|
||
|
||
def test_get_pep_621_includes(): | ||
def test_get_hatch_package_includes(): | ||
data = tomlkit.loads(hatch_toml) | ||
|
||
res = project.get.get_project_package_includes(namespace, data) | ||
|
||
assert res == [ | ||
{"include": "unittest/one", "from": "../../bases"}, | ||
{"include": "unittest/two", "from": "../../components"}, | ||
] | ||
assert res == expected | ||
|
||
|
||
def test_get_hatch_package_includes_in_build_hook(): | ||
data = tomlkit.loads(hatch_toml_alternative) | ||
|
||
res = project.get.get_project_package_includes(namespace, data) | ||
|
||
assert res == expected | ||
|
||
|
||
def test_get_hatch_package_includes_from_default_when_in_both(): | ||
data = tomlkit.loads(hatch_toml_combined) | ||
|
||
res = project.get.get_project_package_includes(namespace, data) | ||
|
||
assert res == expected | ||
|
||
|
||
def test_get_hatch_package_includes_lookup_with_unexpected_format(): | ||
unexpected = """\ | ||
[tool.hatch.build.hooks.targets.wheel] | ||
"polylith" = "this-is-unexpected" | ||
""" | ||
data = tomlkit.loads(unexpected) | ||
|
||
res = project.get.get_project_package_includes(namespace, data) | ||
|
||
assert res == [] |