Skip to content

Commit a186acb

Browse files
authored
Merge pull request #496 from statisticsnorway/poetry-2.0
Remove Nexus proxy when present. Add support for Poetry 2.0
2 parents a0d0a6c + 29f0cb3 commit a186acb

File tree

12 files changed

+835
-607
lines changed

12 files changed

+835
-607
lines changed

.github/workflows/constraints.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
pip==24.1
2-
nox==2024.4.15
3-
nox-poetry==1.0.3
4-
poetry==1.8.3
5-
virtualenv==20.26.3
1+
pip==25.0.1
2+
nox==2025.02.09
3+
nox-poetry==1.1.0
4+
poetry==2.1.1
5+
virtualenv==20.29.2
66
urllib3>=1.26.0,<3.0.0

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
- name: Install Poetry
3030
run: |
3131
pipx install --pip-args "-c ${{ github.workspace }}/.github/workflows/constraints.txt" poetry
32+
pipx inject poetry poetry-plugin-export
3233
poetry --version
3334
3435
- name: Check if there is a parent commit

.github/workflows/tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ jobs:
6060
- name: Install Poetry
6161
run: |
6262
pipx install --pip-args "-c ${{ github.workspace }}/.github/workflows/constraints.txt" poetry
63+
pipx inject poetry poetry-plugin-export
6364
poetry --version
6465
6566
- name: Install Nox
@@ -131,6 +132,7 @@ jobs:
131132
- name: Install Poetry
132133
run: |
133134
pipx install --pip-args "-c ${{ github.workspace }}/.github/workflows/constraints.txt" poetry
135+
pipx inject poetry poetry-plugin-export
134136
poetry --version
135137
136138
- name: Install Nox

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
INTEGRATION_TESTS_PATH = "tests/integration"
2727
package = "ssb_project_cli"
2828
python_versions = ["3.10", "3.11"]
29-
nox.needs_version = ">= 2021.6.6"
29+
nox.needs_version = ">= 2025.02.09"
3030
nox.options.sessions = (
3131
"pre-commit",
3232
"mypy",

poetry.lock

Lines changed: 770 additions & 534 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "ssb-project-cli"
3-
version = "1.4.10"
3+
version = "1.5.0"
44
description = "SSB Project CLI"
55
authors = ["Statistics Norway <stat-dev@ssb.no>"]
66
license = "MIT"
@@ -29,7 +29,7 @@ types-urllib3 = ">=1.26.25.10"
2929
types-requests = ">=2.28.11.17"
3030
types-psutil = ">=5.9.5.12"
3131
kvakk-git-tools = "2.4.2"
32-
poetry = ">=1.8.0"
32+
poetry = ">=2.0"
3333
jupyter-client = ">=8.3.1"
3434
ipykernel = ">=6.25.2"
3535
tomli = ">=2.0.1"
@@ -58,8 +58,8 @@ xdoctest = { extras = ["colors"], version = ">=0.15.10" }
5858
mock = ">=4.0.3"
5959
build = ">=0.8.0"
6060
jinja2 = ">=3.1.4"
61-
nox = ">=2022.11.21"
62-
nox-poetry = ">=1.0.2"
61+
nox = ">=2025.02.09"
62+
nox-poetry = ">=1.1.0"
6363
tomli-w = ">=1.0.0"
6464
bandit = ">=1.7.9"
6565
cryptography = ">=42.0.8"
@@ -81,8 +81,8 @@ xdoctest = { extras = ["colors"], version = ">=0.15.10" }
8181
myst-parser = { version = ">=0.16.1" }
8282
mock = ">=4.0.3"
8383
mkdocs-click = ">=0.8.0"
84-
nox = ">=2022.11.21"
85-
nox-poetry = ">=1.0.2"
84+
nox = ">=2025.02.09"
85+
nox-poetry = ">=1.1.0"
8686
build = ">=0.8.0"
8787
Jinja2 = ">=3.1.2"
8888
furo = ">=2021.11.12"
@@ -125,7 +125,7 @@ module = [
125125
ignore_missing_imports = true
126126

127127
[build-system]
128-
requires = ["poetry-core>=1.0.0"]
128+
requires = ["poetry-core>=2.0"]
129129
build-backend = "poetry.core.masonry.api"
130130

131131
[tool.pytest.ini_options]

src/ssb_project_cli/ssb_project/build/build.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
"""Build command module."""
22

3-
import os
43
import json
4+
import os
55
import re
6-
7-
from pathlib import Path
86
import sys
7+
from pathlib import Path
98
from typing import List
109

1110
import kvakk_git_tools.validate_ssb_gitconfig # type: ignore
12-
13-
from .environment import verify_local_config
14-
from .poetry import install_ipykernel
15-
from .poetry import poetry_install
16-
from .poetry import check_and_fix_onprem_source
1711
from rich import print
1812

19-
from .prompt import confirm_fix_ssb_git_config
20-
2113
from ssb_project_cli.ssb_project.util import (
2214
get_kernels_dict,
2315
get_project_name_and_root_path,
2416
)
2517

18+
from .environment import verify_local_config
19+
from .poetry import check_and_remove_onprem_source, install_ipykernel, poetry_install
20+
from .prompt import confirm_fix_ssb_git_config
21+
2622

2723
def build_project(
2824
path: Path | None,
@@ -60,7 +56,7 @@ def build_project(
6056
template_repo_url, checkout, project_name, project_root
6157
)
6258

63-
check_and_fix_onprem_source(project_root)
59+
check_and_remove_onprem_source(project_root)
6460

6561
poetry_install(project_root)
6662
if not no_kernel:

src/ssb_project_cli/ssb_project/build/poetry.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
import os
44
from pathlib import Path
5-
from rich.progress import Progress
6-
from rich.progress import SpinnerColumn
7-
from rich.progress import TextColumn
5+
86
from rich import print
7+
from rich.progress import Progress, SpinnerColumn, TextColumn
98

10-
from .environment import NEXUS_SOURCE_NAME
119
from ssb_project_cli.ssb_project.util import execute_command
12-
from .environment import JUPYTER_IMAGE_SPEC
13-
from .environment import PIP_INDEX_URL
14-
from .environment import running_onprem
10+
11+
from .environment import (
12+
JUPYTER_IMAGE_SPEC,
13+
NEXUS_SOURCE_NAME,
14+
running_onprem,
15+
)
1516

1617

1718
def poetry_install(project_directory: Path) -> None:
@@ -136,14 +137,14 @@ def poetry_source_add(
136137

137138

138139
def update_lock(cwd: Path) -> None:
139-
"""Runs poetry lock --no-update command in CWD.
140+
"""Runs poetry lock command in CWD.
140141
141142
Args:
142143
cwd: Path of project to add source to.
143144
"""
144145
print("Refreshing lock file...")
145146
execute_command(
146-
"poetry lock --no-update".split(" "),
147+
"poetry lock".split(" "),
147148
"update_lock",
148149
"Poetry successfully refreshed lock file!",
149150
"Poetry failed to refresh lock file.",
@@ -197,21 +198,15 @@ def install_ipykernel(project_directory: Path, project_name: str) -> None:
197198
)
198199

199200

200-
def check_and_fix_onprem_source(project_root: Path) -> None:
201+
def check_and_remove_onprem_source(project_root: Path) -> None:
201202
"""Check if running onprem and fix source in pyproject.toml if so.
202203
203204
Args:
204205
project_root: Path to the root of the project
205206
"""
206-
if running_onprem(JUPYTER_IMAGE_SPEC):
207-
print(
208-
":twisted_rightwards_arrows:\tDetected onprem environment, using proxy for package installation"
209-
)
210-
if poetry_source_includes_source_name(project_root):
211-
poetry_source_remove(project_root, lock_update=False)
212-
poetry_source_add(PIP_INDEX_URL, project_root)
213-
elif poetry_source_includes_source_name(project_root):
214-
print(
215-
":twisted_rightwards_arrows:\tDetected non-onprem environment, removing proxy for package installation"
216-
)
207+
if poetry_source_includes_source_name(project_root):
208+
if running_onprem(JUPYTER_IMAGE_SPEC):
209+
print(
210+
":twisted_rightwards_arrows:\tRemoving proxy, it is no longer needed onprem"
211+
)
217212
poetry_source_remove(project_root)

src/ssb_project_cli/ssb_project/create/local_repo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from git import Repo
1212
from rich import print
1313

14-
from ssb_project_cli.ssb_project.build.poetry import check_and_fix_onprem_source
14+
from ssb_project_cli.ssb_project.build.poetry import check_and_remove_onprem_source
1515
from ssb_project_cli.ssb_project.build.poetry import poetry_update_lockfile_dependencies
1616
from ssb_project_cli.ssb_project.create import temp_git_repo
1717
from ssb_project_cli.ssb_project.create.github import (
@@ -75,7 +75,7 @@ def create_project_from_template(
7575
extra_context=template_info,
7676
)
7777
project_root = project_dir / project_name
78-
check_and_fix_onprem_source(project_root)
78+
check_and_remove_onprem_source(project_root)
7979
poetry_update_lockfile_dependencies(project_root)
8080

8181
return project_dir

tests/unit/build_test/test_build.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
BUILD = "ssb_project_cli.ssb_project.build.build"
2020

2121

22-
@patch(f"{BUILD}.check_and_fix_onprem_source")
22+
@patch(f"{BUILD}.check_and_remove_onprem_source")
2323
@patch(f"{BUILD}.poetry_install")
2424
@patch(f"{BUILD}.install_ipykernel")
2525
@patch(f"{BUILD}.ipykernel_attach_bashrc")
@@ -36,7 +36,7 @@ def test_build(
3636
mock_install_ipykernel: Mock,
3737
mock_ipykernel_attach_bashrc: Mock,
3838
mock_poetry_install: Mock,
39-
mock_check_and_fix_onprem_source: Mock,
39+
mock_check_and_remove_onprem_source: Mock,
4040
no_kernel: bool,
4141
tmp_path: Path,
4242
) -> None:
@@ -59,7 +59,7 @@ def test_build(
5959
assert mock_poetry_install.call_count == 1
6060
assert mock_install_ipykernel.call_count == int(not no_kernel)
6161
assert mock_ipykernel_attach_bashrc.call_count == int(not no_kernel)
62-
assert mock_check_and_fix_onprem_source.call_count == 1
62+
assert mock_check_and_remove_onprem_source.call_count == 1
6363

6464

6565
@patch(f"{BUILD}.get_kernels_dict")

0 commit comments

Comments
 (0)