-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
4fea4bb
commit 67afae9
Showing
10 changed files
with
148 additions
and
23 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 |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" | |
|
||
[tool.poetry] | ||
name = "pyvarium" | ||
version = "0.1.1" | ||
version = "0.2.0" | ||
description = "Tool for managing mixed Spack and pip packages" | ||
readme = "README.md" | ||
authors = ["Robert Rosca <[email protected]>"] | ||
|
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 +1 @@ | ||
__version__ = "0.1.1" | ||
__version__ = "0.2.0" |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from pathlib import Path | ||
|
||
import typer | ||
from rich.status import Status | ||
from loguru import logger | ||
|
||
from pyvarium.installers import spack | ||
|
||
app = typer.Typer( | ||
help="Check that python packages in view are still provided by spack." | ||
) | ||
|
||
|
||
@app.callback(invoke_without_command=True) | ||
def main(path: Path = typer.Option(".", file_okay=False), fix: bool = False): | ||
path = path.resolve() | ||
|
||
with Status("Checking status of Spack packages in view") as status: | ||
se = spack.SpackEnvironment(path, status=status) | ||
warnings = se.verify() | ||
|
||
if all(len(w) == 0 for w in warnings.values()): | ||
logger.info("All packages in view are correctly symlinked to spack") | ||
raise typer.Exit(0) | ||
|
||
for path, warning in warnings.items(): | ||
package_name = path.name | ||
if len(warning) > 0: | ||
logger.warning( | ||
f"[bold]{package_name}[/bold] has " | ||
f"[bold red]{len(warning)}[/bold red] files which are not linked correctly" | ||
) | ||
if fix: | ||
logger.info(f"Fixing {package_name}") | ||
for file, target in warning: | ||
if file.exists(): | ||
file.unlink() | ||
file.symlink_to(target) | ||
|
||
if fix: | ||
logger.info("Re-checking status of Spack packages in view") | ||
warnings = se.verify() | ||
if all(len(w) == 0 for w in warnings.values()): | ||
logger.info("All packages in view are correctly symlinked to spack") | ||
raise typer.Exit(0) | ||
else: | ||
broken_packages = [p.name for p in warnings if len(warnings[p]) > 0] | ||
logger.error( | ||
f"Some packages are still not linked correctly: {broken_packages}" | ||
) | ||
|
||
raise typer.Exit(1) |
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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
import pytest | ||
from typer.testing import CliRunner | ||
|
||
from pyvarium.cli import app | ||
|
||
runner = CliRunner() | ||
|
||
|
||
@pytest.fixture(autouse=True, scope="module") | ||
def tmp_cwd(tmp_path_factory): | ||
tmpdir = tmp_path_factory.mktemp("cli.verify") | ||
os.chdir(tmpdir) | ||
|
||
res = runner.invoke(app, ["new", "test-env"]) | ||
assert res.exit_code == 0 | ||
|
||
os.chdir(tmpdir / "test-env") | ||
|
||
res = runner.invoke(app, ["add", "spack", "py-numpy"]) | ||
assert res.exit_code == 0 | ||
|
||
yield tmpdir / "test-env" | ||
|
||
|
||
def test_verify_success(tmp_cwd: Path): | ||
res = runner.invoke(app, ["verify"]) | ||
venv_site_packages = tmp_cwd / ".venv" / "lib" / "python3.8" / "site-packages" | ||
assert (venv_site_packages / "numpy" / "version.py").is_symlink() | ||
assert res.exit_code == 0 | ||
assert "correctly symlinked to spack" in res.stdout | ||
|
||
|
||
@pytest.mark.xfail( | ||
reason="binary cache injects placeholders to path which breaks tests in image" | ||
) | ||
def test_verify_failure(tmp_cwd: Path): | ||
venv_site_packages = tmp_cwd / ".venv" / "lib" / "python3.8" / "site-packages" | ||
numpy_file = venv_site_packages / "numpy" / "version.py" | ||
numpy_file.unlink() | ||
assert not numpy_file.is_symlink() | ||
res = runner.invoke(app, ["verify"]) | ||
print(res.stdout) | ||
assert res.exit_code != 0 |