Skip to content
Merged
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
10 changes: 5 additions & 5 deletions .github/workflows/constraints.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pip==24.1
nox==2024.4.15
nox-poetry==1.0.3
poetry==1.8.3
virtualenv==20.26.3
pip==25.0.1
nox==2025.02.09
nox-poetry==1.1.0
poetry==2.1.1
virtualenv==20.29.2
urllib3>=1.26.0,<3.0.0
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
- name: Install Poetry
run: |
pipx install --pip-args "-c ${{ github.workspace }}/.github/workflows/constraints.txt" poetry
pipx inject poetry poetry-plugin-export
poetry --version

- name: Check if there is a parent commit
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ jobs:
- name: Install Poetry
run: |
pipx install --pip-args "-c ${{ github.workspace }}/.github/workflows/constraints.txt" poetry
pipx inject poetry poetry-plugin-export
poetry --version

- name: Install Nox
Expand Down Expand Up @@ -131,6 +132,7 @@ jobs:
- name: Install Poetry
run: |
pipx install --pip-args "-c ${{ github.workspace }}/.github/workflows/constraints.txt" poetry
pipx inject poetry poetry-plugin-export
poetry --version

- name: Install Nox
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
INTEGRATION_TESTS_PATH = "tests/integration"
package = "ssb_project_cli"
python_versions = ["3.10", "3.11"]
nox.needs_version = ">= 2021.6.6"
nox.needs_version = ">= 2025.02.09"
nox.options.sessions = (
"pre-commit",
"mypy",
Expand Down
1,304 changes: 770 additions & 534 deletions poetry.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ssb-project-cli"
version = "1.4.10"
version = "1.5.0"
description = "SSB Project CLI"
authors = ["Statistics Norway <stat-dev@ssb.no>"]
license = "MIT"
Expand Down Expand Up @@ -29,7 +29,7 @@ types-urllib3 = ">=1.26.25.10"
types-requests = ">=2.28.11.17"
types-psutil = ">=5.9.5.12"
kvakk-git-tools = "2.4.2"
poetry = ">=1.8.0"
poetry = ">=2.0"
jupyter-client = ">=8.3.1"
ipykernel = ">=6.25.2"
tomli = ">=2.0.1"
Expand Down Expand Up @@ -58,8 +58,8 @@ xdoctest = { extras = ["colors"], version = ">=0.15.10" }
mock = ">=4.0.3"
build = ">=0.8.0"
jinja2 = ">=3.1.4"
nox = ">=2022.11.21"
nox-poetry = ">=1.0.2"
nox = ">=2025.02.09"
nox-poetry = ">=1.1.0"
tomli-w = ">=1.0.0"
bandit = ">=1.7.9"
cryptography = ">=42.0.8"
Expand All @@ -81,8 +81,8 @@ xdoctest = { extras = ["colors"], version = ">=0.15.10" }
myst-parser = { version = ">=0.16.1" }
mock = ">=4.0.3"
mkdocs-click = ">=0.8.0"
nox = ">=2022.11.21"
nox-poetry = ">=1.0.2"
nox = ">=2025.02.09"
nox-poetry = ">=1.1.0"
build = ">=0.8.0"
Jinja2 = ">=3.1.2"
furo = ">=2021.11.12"
Expand Down Expand Up @@ -125,7 +125,7 @@ module = [
ignore_missing_imports = true

[build-system]
requires = ["poetry-core>=1.0.0"]
requires = ["poetry-core>=2.0"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
Expand Down
18 changes: 7 additions & 11 deletions src/ssb_project_cli/ssb_project/build/build.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
"""Build command module."""

import os
import json
import os
import re

from pathlib import Path
import sys
from pathlib import Path
from typing import List

import kvakk_git_tools.validate_ssb_gitconfig # type: ignore

from .environment import verify_local_config
from .poetry import install_ipykernel
from .poetry import poetry_install
from .poetry import check_and_fix_onprem_source
from rich import print

from .prompt import confirm_fix_ssb_git_config

from ssb_project_cli.ssb_project.util import (
get_kernels_dict,
get_project_name_and_root_path,
)

from .environment import verify_local_config
from .poetry import check_and_remove_onprem_source, install_ipykernel, poetry_install
from .prompt import confirm_fix_ssb_git_config


def build_project(
path: Path | None,
Expand Down Expand Up @@ -60,7 +56,7 @@ def build_project(
template_repo_url, checkout, project_name, project_root
)

check_and_fix_onprem_source(project_root)
check_and_remove_onprem_source(project_root)

poetry_install(project_root)
if not no_kernel:
Expand Down
37 changes: 16 additions & 21 deletions src/ssb_project_cli/ssb_project/build/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

import os
from pathlib import Path
from rich.progress import Progress
from rich.progress import SpinnerColumn
from rich.progress import TextColumn

from rich import print
from rich.progress import Progress, SpinnerColumn, TextColumn

from .environment import NEXUS_SOURCE_NAME
from ssb_project_cli.ssb_project.util import execute_command
from .environment import JUPYTER_IMAGE_SPEC
from .environment import PIP_INDEX_URL
from .environment import running_onprem

from .environment import (
JUPYTER_IMAGE_SPEC,
NEXUS_SOURCE_NAME,
running_onprem,
)


def poetry_install(project_directory: Path) -> None:
Expand Down Expand Up @@ -136,14 +137,14 @@ def poetry_source_add(


def update_lock(cwd: Path) -> None:
"""Runs poetry lock --no-update command in CWD.
"""Runs poetry lock command in CWD.

Args:
cwd: Path of project to add source to.
"""
print("Refreshing lock file...")
execute_command(
"poetry lock --no-update".split(" "),
"poetry lock".split(" "),
"update_lock",
"Poetry successfully refreshed lock file!",
"Poetry failed to refresh lock file.",
Expand Down Expand Up @@ -197,21 +198,15 @@ def install_ipykernel(project_directory: Path, project_name: str) -> None:
)


def check_and_fix_onprem_source(project_root: Path) -> None:
def check_and_remove_onprem_source(project_root: Path) -> None:
"""Check if running onprem and fix source in pyproject.toml if so.

Args:
project_root: Path to the root of the project
"""
if running_onprem(JUPYTER_IMAGE_SPEC):
print(
":twisted_rightwards_arrows:\tDetected onprem environment, using proxy for package installation"
)
if poetry_source_includes_source_name(project_root):
poetry_source_remove(project_root, lock_update=False)
poetry_source_add(PIP_INDEX_URL, project_root)
elif poetry_source_includes_source_name(project_root):
print(
":twisted_rightwards_arrows:\tDetected non-onprem environment, removing proxy for package installation"
)
if poetry_source_includes_source_name(project_root):
if running_onprem(JUPYTER_IMAGE_SPEC):
print(
":twisted_rightwards_arrows:\tRemoving proxy, it is no longer needed onprem"
)
poetry_source_remove(project_root)
4 changes: 2 additions & 2 deletions src/ssb_project_cli/ssb_project/create/local_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from git import Repo
from rich import print

from ssb_project_cli.ssb_project.build.poetry import check_and_fix_onprem_source
from ssb_project_cli.ssb_project.build.poetry import check_and_remove_onprem_source
from ssb_project_cli.ssb_project.build.poetry import poetry_update_lockfile_dependencies
from ssb_project_cli.ssb_project.create import temp_git_repo
from ssb_project_cli.ssb_project.create.github import (
Expand Down Expand Up @@ -75,7 +75,7 @@ def create_project_from_template(
extra_context=template_info,
)
project_root = project_dir / project_name
check_and_fix_onprem_source(project_root)
check_and_remove_onprem_source(project_root)
poetry_update_lockfile_dependencies(project_root)

return project_dir
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/build_test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
BUILD = "ssb_project_cli.ssb_project.build.build"


@patch(f"{BUILD}.check_and_fix_onprem_source")
@patch(f"{BUILD}.check_and_remove_onprem_source")
@patch(f"{BUILD}.poetry_install")
@patch(f"{BUILD}.install_ipykernel")
@patch(f"{BUILD}.ipykernel_attach_bashrc")
Expand All @@ -36,7 +36,7 @@ def test_build(
mock_install_ipykernel: Mock,
mock_ipykernel_attach_bashrc: Mock,
mock_poetry_install: Mock,
mock_check_and_fix_onprem_source: Mock,
mock_check_and_remove_onprem_source: Mock,
no_kernel: bool,
tmp_path: Path,
) -> None:
Expand All @@ -59,7 +59,7 @@ def test_build(
assert mock_poetry_install.call_count == 1
assert mock_install_ipykernel.call_count == int(not no_kernel)
assert mock_ipykernel_attach_bashrc.call_count == int(not no_kernel)
assert mock_check_and_fix_onprem_source.call_count == 1
assert mock_check_and_remove_onprem_source.call_count == 1


@patch(f"{BUILD}.get_kernels_dict")
Expand Down
26 changes: 12 additions & 14 deletions tests/unit/build_test/test_poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pytest

from ssb_project_cli.ssb_project.build.environment import NEXUS_SOURCE_NAME
from ssb_project_cli.ssb_project.build.poetry import check_and_fix_onprem_source
from ssb_project_cli.ssb_project.build.poetry import check_and_remove_onprem_source
from ssb_project_cli.ssb_project.build.poetry import poetry_install
from ssb_project_cli.ssb_project.build.poetry import poetry_source_add
from ssb_project_cli.ssb_project.build.poetry import poetry_source_includes_source_name
Expand Down Expand Up @@ -102,7 +102,7 @@ def test_update_lock_execute_command_call_args(mock_run: Mock) -> None:
update_lock(Path("fake_path"))
assert (
call(
["poetry", "lock", "--no-update"],
["poetry", "lock"],
"update_lock",
"Poetry successfully refreshed lock file!",
"Poetry failed to refresh lock file.",
Expand Down Expand Up @@ -155,26 +155,23 @@ def test_poetry_source_add() -> None:

@patch(f"{POETRY}.running_onprem")
@patch(f"{POETRY}.poetry_source_includes_source_name")
@patch(f"{POETRY}.poetry_source_add")
@patch(f"{POETRY}.poetry_source_remove")
@pytest.mark.parametrize(
"running_onprem_return,poetry_source_includes_source_name_return,calls_to_poetry_source_includes_source_name,calls_to_poetry_source_add,calls_to_poetry_source_remove",
"running_onprem_return,poetry_source_includes_source_name_return,calls_to_poetry_source_includes_source_name,calls_to_poetry_source_remove",
[
(False, False, 1, 0, 0),
(True, False, 1, 1, 0),
(True, True, 1, 1, 1),
(False, True, 1, 0, 1),
(False, False, 1, 0),
(True, False, 1, 0),
(True, True, 1, 1),
(False, True, 1, 1),
],
)
def test_check_and_fix_onprem_source(
def test_check_and_remove_onprem_source(
mock_poetry_source_remove: Mock,
mock_poetry_source_add: Mock,
mock_poetry_source_includes_source_name: Mock,
mock_running_onprem: Mock,
running_onprem_return: bool,
poetry_source_includes_source_name_return: bool,
calls_to_poetry_source_includes_source_name: int,
calls_to_poetry_source_add: int,
calls_to_poetry_source_remove: int,
tmp_path: Path,
) -> None:
Expand All @@ -183,12 +180,13 @@ def test_check_and_fix_onprem_source(
poetry_source_includes_source_name_return
)

check_and_fix_onprem_source(tmp_path)
check_and_remove_onprem_source(tmp_path)

assert mock_running_onprem.call_count == 1
assert mock_running_onprem.call_count == int(
poetry_source_includes_source_name_return
)
assert (
mock_poetry_source_includes_source_name.call_count
== calls_to_poetry_source_includes_source_name
)
assert mock_poetry_source_add.call_count == calls_to_poetry_source_add
assert mock_poetry_source_remove.call_count == calls_to_poetry_source_remove
18 changes: 9 additions & 9 deletions tests/unit/create_test/test_local_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_extract_name_email(mock_run: Mock) -> None:
assert extract_name_email() == ("Name2", "")


@patch(f"{LOCAL_REPO}.check_and_fix_onprem_source")
@patch(f"{LOCAL_REPO}.check_and_remove_onprem_source")
@patch(f"{LOCAL_REPO}.poetry_update_lockfile_dependencies")
@patch(f"{LOCAL_REPO}.extract_name_email")
@patch(f"{LOCAL_REPO}.request_name_email")
Expand All @@ -147,7 +147,7 @@ def test_create_project_from_template(
mock_request: Mock,
mock_extract: Mock,
mock_poetry: Mock,
mock_check_and_fix_onprem_source: Mock,
mock_check_and_remove_onprem_source: Mock,
tmp_path: Path,
) -> None:
"""Checks if create_project_from_template works for a temporary path."""
Expand All @@ -165,10 +165,10 @@ def test_create_project_from_template(
assert mock_extract.call_count == 1
assert mock_request.call_count == 1
assert mock_poetry.call_count == 1
assert mock_check_and_fix_onprem_source.call_count == 1
assert mock_check_and_remove_onprem_source.call_count == 1


@patch(f"{LOCAL_REPO}.check_and_fix_onprem_source")
@patch(f"{LOCAL_REPO}.check_and_remove_onprem_source")
@patch(f"{LOCAL_REPO}.poetry_update_lockfile_dependencies")
@patch(f"{LOCAL_REPO}.extract_name_email")
@patch(f"{LOCAL_REPO}.request_name_email")
Expand All @@ -178,7 +178,7 @@ def test_create_project_from_template_license_year(
mock_request: Mock,
mock_extract: Mock,
mock_poetry: Mock,
mock_check_and_fix_onprem_source: Mock,
mock_check_and_remove_onprem_source: Mock,
tmp_path: Path,
) -> None:
"""Verify that we supply the license year to Cruft"""
Expand All @@ -198,10 +198,10 @@ def test_create_project_from_template_license_year(
assert context["license_year"] == license_year
assert context["project_name"] == project_name
assert mock_poetry.call_count == 1
assert mock_check_and_fix_onprem_source.call_count == 1
assert mock_check_and_remove_onprem_source.call_count == 1


@patch(f"{LOCAL_REPO}.check_and_fix_onprem_source")
@patch(f"{LOCAL_REPO}.check_and_remove_onprem_source")
@patch(f"{LOCAL_REPO}.poetry_update_lockfile_dependencies")
@patch(f"{LOCAL_REPO}.extract_name_email")
@patch(f"{LOCAL_REPO}.request_name_email")
Expand All @@ -211,7 +211,7 @@ def test_create_project_from_template_different_template_uri(
mock_request: Mock,
mock_extract: Mock,
mock_poetry: Mock,
mock_check_and_fix_onprem_source: Mock,
mock_check_and_remove_onprem_source: Mock,
tmp_path: Path,
) -> None:
"""Check that different template uri works"""
Expand All @@ -231,4 +231,4 @@ def test_create_project_from_template_different_template_uri(
assert context["license_year"] == license_year
assert context["project_name"] == project_name
assert mock_poetry.call_count == 1
assert mock_check_and_fix_onprem_source.call_count == 1
assert mock_check_and_remove_onprem_source.call_count == 1
Loading