Skip to content
Open
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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ dependencies = [
"opentelemetry-instrumentation-fastapi>=0.48b0",
"observability-utils>=0.1.4",
"pyjwt[crypto]",
"tomlkit",
"graypy>=2.1.0",
"httpx>=0.28.1",
"aiohttp>=3.13.5",
Expand Down
12 changes: 1 addition & 11 deletions src/blueapi/cli/scratch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from subprocess import Popen

from git import Repo
from tomlkit import parse

from blueapi.config import FORBIDDEN_OWN_REMOTE_URL, ScratchConfig
from blueapi.service.model import PackageInfo, PythonEnvironmentResponse, SourceInfo
Expand Down Expand Up @@ -180,15 +179,6 @@ def _validate_directory(path: Path) -> None:
raise KeyError(f"{path}: Is a file, not a directory")


def _get_project_name_from_pyproject(path: Path) -> str:
pyproject_path = path / "pyproject.toml"
if pyproject_path.exists():
with pyproject_path.open("r", encoding="utf-8") as file:
toml_data = parse(file.read())
return toml_data.get("project", {}).get("name", "")
return ""


def _fetch_installed_packages_details() -> list[PackageInfo]:
installed_packages = importlib.metadata.distributions()
return [
Expand Down Expand Up @@ -234,7 +224,7 @@ def get_python_environment(
if repo.remotes
else f"UNKNOWN REMOTE @{branch}"
)
package_name = _get_project_name_from_pyproject(local_directory)
package_name = local_directory.name
package_location = ""

packages.append(
Expand Down
65 changes: 7 additions & 58 deletions tests/unit_tests/cli/test_scratch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from blueapi.cli.scratch import (
_fetch_installed_packages_details,
_get_project_name_from_pyproject,
ensure_repo,
get_python_environment,
scratch_install,
Expand Down Expand Up @@ -404,9 +403,7 @@ def config(directory_path_with_sgid: Path) -> ScratchConfig:

@patch("blueapi.cli.scratch.Repo")
@patch("blueapi.cli.scratch._fetch_installed_packages_details")
@patch("blueapi.cli.scratch._get_project_name_from_pyproject")
def test_get_python_env_returns_correct_packages(
mock_get_project_name: Mock,
mock_fetch_installed_packages: Mock,
mock_repo: Mock,
directory_path_with_sgid: Path,
Expand All @@ -429,7 +426,6 @@ def test_get_python_env_returns_correct_packages(

mock_repo.side_effect = [mock_repo_1, mock_repo_2]

mock_get_project_name.side_effect = ["foo-package", "bar-package"]
mock_fetch_installed_packages.return_value = [
PackageInfo(
name="package-01",
Expand All @@ -443,14 +439,14 @@ def test_get_python_env_returns_correct_packages(

assert response.installed_packages == [
PackageInfo(
name="bar-package",
name="bar",
version="http://example.com/bar.git @adsad23123",
location="",
is_dirty=True,
source=SourceInfo.SCRATCH,
),
PackageInfo(
name="foo-package",
name="foo",
version="http://example.com/foo.git @main",
location="",
is_dirty=False,
Expand All @@ -468,9 +464,7 @@ def test_get_python_env_returns_correct_packages(

@patch("blueapi.cli.scratch.Repo")
@patch("blueapi.cli.scratch._fetch_installed_packages_details")
@patch("blueapi.cli.scratch._get_project_name_from_pyproject")
def test_fetch_python_env_with_identical_packages(
mock_get_project_name: Mock,
mock_fetch_installed_packages: Mock,
mock_repo: Mock,
directory_path_with_sgid: Path,
Expand All @@ -484,10 +478,9 @@ def test_fetch_python_env_with_identical_packages(

mock_repo.return_value = mock_repo_instance

mock_get_project_name.return_value = "foo-package"
mock_fetch_installed_packages.return_value = [
PackageInfo(
name="foo-package",
name="foo",
version="http://example.com/foo.git @main",
location="/some/location",
is_dirty=False,
Expand All @@ -507,7 +500,7 @@ def test_fetch_python_env_with_identical_packages(

assert response.installed_packages == [
PackageInfo(
name="foo-package",
name="foo",
version="http://example.com/foo.git @main",
location="/some/location &&",
is_dirty=False,
Expand Down Expand Up @@ -539,9 +532,7 @@ def test_fetch_installed_packages_details_returns_correct_packages(mock_distribu

@patch("blueapi.cli.scratch.Repo")
@patch("blueapi.cli.scratch._fetch_installed_packages_details")
@patch("blueapi.cli.scratch._get_project_name_from_pyproject")
def test_get_python_env_filters_by_name_and_source(
mock_get_project_name: Mock,
mock_fetch_installed_packages: Mock,
mock_repo: Mock,
directory_path_with_sgid: Path,
Expand All @@ -555,7 +546,6 @@ def test_get_python_env_filters_by_name_and_source(
mock_repo_instance.remotes = [Mock(url="http://example.com/foo.git")]
mock_repo.return_value = mock_repo_instance

mock_get_project_name.return_value = "foo-package"
mock_fetch_installed_packages.return_value = [
PackageInfo(
name="bar-package",
Expand All @@ -575,10 +565,10 @@ def test_get_python_env_filters_by_name_and_source(
],
)
# Test filtering by name
response_by_name = get_python_environment(config, name="foo-package")
response_by_name = get_python_environment(config, name="foo")
assert response_by_name.installed_packages == [
PackageInfo(
name="foo-package",
name="foo",
version="http://example.com/foo.git @main",
location="",
is_dirty=False,
Expand All @@ -590,51 +580,10 @@ def test_get_python_env_filters_by_name_and_source(
response_by_source = get_python_environment(config, source=SourceInfo.SCRATCH)
assert response_by_source.installed_packages == [
PackageInfo(
name="foo-package",
name="foo",
version="http://example.com/foo.git @main",
location="",
is_dirty=False,
source=SourceInfo.SCRATCH,
)
]


@pytest.fixture
def pyproject_file(tmp_path: Path) -> Generator[Path]:
pyproject_path = tmp_path / "pyproject.toml"
with pyproject_path.open("w") as f:
f.write(
"""
[project]
name = "example-project"
"""
)
yield pyproject_path
os.remove(pyproject_path)


def test_get_project_name_from_pyproject_returns_name(pyproject_file: Path):
project_name = _get_project_name_from_pyproject(pyproject_file.parent)
assert project_name == "example-project"


def test_get_project_name_from_pyproject_returns_empty_if_no_pyproject(
tmp_path: Path,
):
project_name = _get_project_name_from_pyproject(tmp_path)
assert project_name == ""


def test_get_project_name_from_pyproject_returns_empty_if_no_name_key(
tmp_path: Path,
):
pyproject_path = tmp_path / "pyproject.toml"
with pyproject_path.open("w") as f:
f.write(
"""
[project]
version = "1.0.0"
"""
)
project_name = _get_project_name_from_pyproject(tmp_path)
assert project_name == ""
11 changes: 0 additions & 11 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading