Skip to content

Commit 34c5f16

Browse files
authored
Merge pull request #437 from eli-schwartz/plugin-defer
Delay imports of non-stdlib dependencies until time of use
2 parents d7868df + c46d355 commit 34c5f16

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44
### Changed
55
- Use the base interpreter path when running inside a virtual environment to avoid recompilation when switching between virtual environments. [#429](https://github.com/PyO3/setuptools-rust/pull/429)
6+
- Delay import of dependencies until use to avoid import errors during a partially complete install when multiple packages are installing at once. [#437](https://github.com/PyO3/setuptools-rust/pull/437)
67

78
## 1.9.0 (2024-02-24)
89
### Changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ classifiers = [
2626
dependencies = [
2727
"setuptools>=62.4",
2828
"semantic_version>=2.8.2,<3",
29-
'tomli>=1.2.1; python_version<"3.11"'
3029
]
3130

3231
[project.entry-points."distutils.commands"]

setuptools_rust/extension.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import json
24
import os
35
import re
@@ -14,11 +16,13 @@
1416
NewType,
1517
Optional,
1618
Sequence,
19+
TYPE_CHECKING,
1720
Union,
1821
cast,
1922
)
2023

21-
from semantic_version import SimpleSpec
24+
if TYPE_CHECKING:
25+
from semantic_version import SimpleSpec
2226

2327
from ._utils import format_called_process_error
2428

@@ -185,6 +189,8 @@ def get_rust_version(self) -> Optional[SimpleSpec]: # type: ignore[no-any-unimp
185189
if self.rust_version is None:
186190
return None
187191
try:
192+
from semantic_version import SimpleSpec
193+
188194
return SimpleSpec(self.rust_version)
189195
except ValueError:
190196
raise SetupError(

setuptools_rust/rustc_info.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1+
from __future__ import annotations
2+
13
import subprocess
24
from setuptools.errors import PlatformError
35
from functools import lru_cache
4-
from typing import Dict, List, NewType, Optional
6+
from typing import Dict, List, NewType, Optional, TYPE_CHECKING
57

6-
from semantic_version import Version
8+
if TYPE_CHECKING:
9+
from semantic_version import Version
710

811

912
def get_rust_version() -> Optional[Version]: # type: ignore[no-any-unimported]
1013
try:
1114
# first line of rustc -Vv is something like
1215
# rustc 1.61.0 (fe5b13d68 2022-05-18)
16+
from semantic_version import Version
17+
1318
return Version(_rust_version().split(" ")[1])
1419
except (subprocess.CalledProcessError, OSError):
1520
return None

setuptools_rust/setuptools_ext.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
if sys.version_info[:2] >= (3, 11):
2727
from tomllib import load as toml_load
2828
else:
29-
from tomli import load as toml_load
29+
try:
30+
from tomli import load as toml_load
31+
except ImportError:
32+
from setuptools.extern.tomli import load as toml_load
3033

3134

3235
logger = logging.getLogger(__name__)

0 commit comments

Comments
 (0)