Skip to content

Commit f740d6b

Browse files
committed
Defer imports
Signed-off-by: Pedro Algarvio <[email protected]>
1 parent 3f44586 commit f740d6b

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

changelog/68.improvement.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Several improvements to the project
22

33
* The `salt-analytics.examples` package now uses the same version as `salt-analytics-framework`
4+
* Defer imports of uncommon usage libraries to reduce base requirements

examples/src/saltext/safexamples/collect/mnist_digits.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
from typing import AsyncIterator
1313
from typing import Type
1414

15-
from tensorflow import keras
16-
1715
from saf.models import CollectConfigBase
1816
from saf.models import CollectedEvent
1917
from saf.models import PipelineRunContext
@@ -41,6 +39,8 @@ async def collect(*, ctx: PipelineRunContext[MNISTDigitsConfig]) -> AsyncIterato
4139
"""
4240
Periodically yield a random MNIST test digit and it's desired output.
4341
"""
42+
from tensorflow import keras
43+
4444
file_path = pathlib.Path(ctx.config.path)
4545
log.debug("Downloading the MNIST digits dataset to %s", file_path)
4646
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data(path=file_path)

examples/src/saltext/safexamples/process/mnist_network.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
from typing import AsyncIterator
1111
from typing import Type
1212

13-
import numpy as np
14-
from tensorflow import keras
15-
1613
from saf.models import CollectedEvent
1714
from saf.models import PipelineRunContext
1815
from saf.models import ProcessConfigBase
@@ -43,6 +40,9 @@ async def process(
4340
"""
4441
Run the MNIST network.
4542
"""
43+
import numpy as np
44+
from tensorflow import keras
45+
4646
if "mnist_model" not in ctx.cache:
4747
model_path = pathlib.Path(ctx.config.model)
4848
log.debug("Loading the mnist model from %s", model_path)

examples/src/saltext/safexamples/process/numpy_save_keys.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
from typing import AsyncIterator
1111
from typing import Type
1212

13-
import numpy as np
14-
1513
from saf.models import CollectedEvent
1614
from saf.models import PipelineRunContext
1715
from saf.models import ProcessConfigBase
@@ -42,6 +40,8 @@ async def process(
4240
"""
4341
Save the keys using numpy.
4442
"""
43+
import numpy as np
44+
4545
config = ctx.config
4646
if not config.base_path.exists():
4747
config.base_path.mkdir(parents=True)

0 commit comments

Comments
 (0)