-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow to use pyproject name (by default) when packaging
- Loading branch information
Showing
3 changed files
with
103 additions
and
32 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
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,10 +1,12 @@ | ||
import importlib | ||
|
||
import pip | ||
import pytest | ||
|
||
from edspdf.utils.package import package | ||
|
||
|
||
def test_blank_package(frozen_pipeline, tmp_path): | ||
|
||
# Missing metadata makes poetry fail due to missing author / description | ||
with pytest.raises(Exception): | ||
package( | ||
|
@@ -32,11 +34,12 @@ def test_blank_package(frozen_pipeline, tmp_path): | |
assert (tmp_path / "build" / "test-model").is_dir() | ||
|
||
|
||
def test_package_with_files(frozen_pipeline, tmp_path): | ||
@pytest.mark.parametrize("package_name", ["my-test-model", None]) | ||
def test_package_with_files(frozen_pipeline, tmp_path, package_name): | ||
frozen_pipeline.save(tmp_path / "model") | ||
|
||
((tmp_path / "test_model_trainer").mkdir(parents=True)) | ||
(tmp_path / "test_model_trainer" / "__init__.py").write_text( | ||
((tmp_path / "test_model").mkdir(parents=True)) | ||
(tmp_path / "test_model" / "__init__.py").write_text( | ||
"""\ | ||
print("Hello World!") | ||
""" | ||
|
@@ -48,7 +51,7 @@ def test_package_with_files(frozen_pipeline, tmp_path): | |
build-backend = "poetry.core.masonry.api" | ||
[tool.poetry] | ||
name = "test-model-trainer" | ||
name = "test-model" | ||
version = "0.0.0" | ||
description = "A test model" | ||
authors = ["Test Author <[email protected]>"] | ||
|
@@ -64,26 +67,76 @@ def test_package_with_files(frozen_pipeline, tmp_path): | |
pipeline=frozen_pipeline, | ||
root_dir=tmp_path, | ||
version="0.1.0", | ||
name="test-model", | ||
name=package_name, | ||
metadata={ | ||
"description": "Wrong description", | ||
"authors": "Test Author <[email protected]>", | ||
}, | ||
) | ||
|
||
package( | ||
name=package_name, | ||
pipeline=tmp_path / "model", | ||
root_dir=tmp_path, | ||
check_dependencies=True, | ||
version="0.1.0", | ||
name="test-model", | ||
distributions=None, | ||
metadata={ | ||
"description": "A test model", | ||
"authors": "Test Author <[email protected]>", | ||
}, | ||
) | ||
|
||
module_name = "test_model" if package_name is None else "my_test_model" | ||
|
||
assert (tmp_path / "dist").is_dir() | ||
assert (tmp_path / "dist" / "test_model-0.1.0.tar.gz").is_file() | ||
assert (tmp_path / "dist" / "test_model-0.1.0-py3-none-any.whl").is_file() | ||
assert (tmp_path / "dist" / f"{module_name}-0.1.0.tar.gz").is_file() | ||
assert (tmp_path / "dist" / f"{module_name}-0.1.0-py3-none-any.whl").is_file() | ||
assert (tmp_path / "pyproject.toml").is_file() | ||
|
||
# pip install the whl file | ||
pip.main( | ||
[ | ||
"install", | ||
str(tmp_path / "dist" / f"{module_name}-0.1.0-py3-none-any.whl"), | ||
"--force-reinstall", | ||
] | ||
) | ||
|
||
module = importlib.import_module(module_name) | ||
|
||
assert module.__version__ == "0.1.0" | ||
|
||
with open(module.__file__) as f: | ||
assert f.read() == ( | ||
( | ||
"""\ | ||
print("Hello World!") | ||
""" | ||
if package_name is None | ||
else "" | ||
) | ||
+ """ | ||
# ----------------------------------------- | ||
# This section was autogenerated by edspdf | ||
# ----------------------------------------- | ||
import edspdf | ||
from pathlib import Path | ||
__version__ = '0.1.0' | ||
def load(device: "torch.device" = "cpu") -> edspdf.Pipeline: | ||
artifacts_path = Path(__file__).parent / "artifacts" | ||
model = edspdf.load(artifacts_path, device=device) | ||
return model | ||
""" | ||
) | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def clean_after(): | ||
yield | ||
|
||
pip.main(["uninstall", "-y", "test-model"]) | ||
pip.main(["uninstall", "-y", "my-test-model"]) |