flwr-nightly 1.9.0.dev20240531__py3-none-any.whl → 1.10.0.dev20240612__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of flwr-nightly might be problematic. Click here for more details.
- flwr/cli/app.py +2 -0
- flwr/cli/build.py +2 -15
- flwr/cli/config_utils.py +11 -4
- flwr/cli/install.py +196 -0
- flwr/cli/new/templates/app/pyproject.hf.toml.tpl +1 -1
- flwr/cli/new/templates/app/pyproject.jax.toml.tpl +1 -1
- flwr/cli/new/templates/app/pyproject.mlx.toml.tpl +1 -1
- flwr/cli/new/templates/app/pyproject.numpy.toml.tpl +1 -1
- flwr/cli/new/templates/app/pyproject.pytorch.toml.tpl +1 -1
- flwr/cli/new/templates/app/pyproject.sklearn.toml.tpl +1 -1
- flwr/cli/new/templates/app/pyproject.tensorflow.toml.tpl +1 -1
- flwr/cli/utils.py +14 -0
- flwr/client/__init__.py +1 -0
- flwr/client/app.py +135 -97
- flwr/client/client_app.py +1 -1
- flwr/client/grpc_rere_client/client_interceptor.py +1 -1
- flwr/client/grpc_rere_client/connection.py +1 -4
- flwr/client/mod/__init__.py +1 -1
- flwr/client/rest_client/connection.py +1 -2
- flwr/client/supernode/app.py +29 -5
- flwr/common/object_ref.py +13 -9
- flwr/proto/driver_pb2.py +20 -19
- flwr/proto/driver_pb2_grpc.py +35 -0
- flwr/proto/driver_pb2_grpc.pyi +14 -0
- flwr/proto/fleet_pb2.py +28 -33
- flwr/proto/fleet_pb2.pyi +0 -42
- flwr/proto/fleet_pb2_grpc.py +7 -6
- flwr/proto/fleet_pb2_grpc.pyi +5 -4
- flwr/proto/run_pb2.py +30 -0
- flwr/proto/run_pb2.pyi +52 -0
- flwr/proto/run_pb2_grpc.py +4 -0
- flwr/proto/run_pb2_grpc.pyi +4 -0
- flwr/server/__init__.py +0 -4
- flwr/server/app.py +57 -214
- flwr/server/run_serverapp.py +29 -5
- flwr/server/server_app.py +2 -2
- flwr/server/superlink/driver/driver_servicer.py +7 -0
- flwr/server/superlink/fleet/grpc_rere/fleet_servicer.py +1 -2
- flwr/server/superlink/fleet/grpc_rere/server_interceptor.py +1 -2
- flwr/server/superlink/fleet/message_handler/message_handler.py +5 -3
- flwr/server/superlink/fleet/rest_rere/rest_api.py +1 -1
- {flwr_nightly-1.9.0.dev20240531.dist-info → flwr_nightly-1.10.0.dev20240612.dist-info}/METADATA +1 -1
- {flwr_nightly-1.9.0.dev20240531.dist-info → flwr_nightly-1.10.0.dev20240612.dist-info}/RECORD +46 -41
- {flwr_nightly-1.9.0.dev20240531.dist-info → flwr_nightly-1.10.0.dev20240612.dist-info}/entry_points.txt +0 -2
- {flwr_nightly-1.9.0.dev20240531.dist-info → flwr_nightly-1.10.0.dev20240612.dist-info}/LICENSE +0 -0
- {flwr_nightly-1.9.0.dev20240531.dist-info → flwr_nightly-1.10.0.dev20240612.dist-info}/WHEEL +0 -0
flwr/cli/app.py
CHANGED
|
@@ -18,6 +18,7 @@ import typer
|
|
|
18
18
|
|
|
19
19
|
from .build import build
|
|
20
20
|
from .example import example
|
|
21
|
+
from .install import install
|
|
21
22
|
from .new import new
|
|
22
23
|
from .run import run
|
|
23
24
|
|
|
@@ -34,6 +35,7 @@ app.command()(new)
|
|
|
34
35
|
app.command()(example)
|
|
35
36
|
app.command()(run)
|
|
36
37
|
app.command()(build)
|
|
38
|
+
app.command()(install)
|
|
37
39
|
|
|
38
40
|
if __name__ == "__main__":
|
|
39
41
|
app()
|
flwr/cli/build.py
CHANGED
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
# ==============================================================================
|
|
15
15
|
"""Flower command line interface `build` command."""
|
|
16
16
|
|
|
17
|
-
import hashlib
|
|
18
17
|
import os
|
|
19
18
|
import zipfile
|
|
20
19
|
from pathlib import Path
|
|
@@ -25,7 +24,7 @@ import typer
|
|
|
25
24
|
from typing_extensions import Annotated
|
|
26
25
|
|
|
27
26
|
from .config_utils import load_and_validate
|
|
28
|
-
from .utils import is_valid_project_name
|
|
27
|
+
from .utils import get_sha256_hash, is_valid_project_name
|
|
29
28
|
|
|
30
29
|
|
|
31
30
|
# pylint: disable=too-many-locals
|
|
@@ -115,7 +114,7 @@ def build(
|
|
|
115
114
|
fab_file.write(file_path, archive_path)
|
|
116
115
|
|
|
117
116
|
# Calculate file info
|
|
118
|
-
sha256_hash =
|
|
117
|
+
sha256_hash = get_sha256_hash(file_path)
|
|
119
118
|
file_size_bits = os.path.getsize(file_path) * 8 # size in bits
|
|
120
119
|
list_file_content += f"{archive_path},{sha256_hash},{file_size_bits}\n"
|
|
121
120
|
|
|
@@ -127,18 +126,6 @@ def build(
|
|
|
127
126
|
)
|
|
128
127
|
|
|
129
128
|
|
|
130
|
-
def _get_sha256_hash(file_path: Path) -> str:
|
|
131
|
-
"""Calculate the SHA-256 hash of a file."""
|
|
132
|
-
sha256 = hashlib.sha256()
|
|
133
|
-
with open(file_path, "rb") as f:
|
|
134
|
-
while True:
|
|
135
|
-
data = f.read(65536) # Read in 64kB blocks
|
|
136
|
-
if not data:
|
|
137
|
-
break
|
|
138
|
-
sha256.update(data)
|
|
139
|
-
return sha256.hexdigest()
|
|
140
|
-
|
|
141
|
-
|
|
142
129
|
def _load_gitignore(directory: Path) -> pathspec.PathSpec:
|
|
143
130
|
"""Load and parse .gitignore file, returning a pathspec."""
|
|
144
131
|
gitignore_path = directory / ".gitignore"
|
flwr/cli/config_utils.py
CHANGED
|
@@ -24,6 +24,7 @@ from flwr.common import object_ref
|
|
|
24
24
|
|
|
25
25
|
def load_and_validate(
|
|
26
26
|
path: Optional[Path] = None,
|
|
27
|
+
check_module: bool = True,
|
|
27
28
|
) -> Tuple[Optional[Dict[str, Any]], List[str], List[str]]:
|
|
28
29
|
"""Load and validate pyproject.toml as dict.
|
|
29
30
|
|
|
@@ -42,7 +43,7 @@ def load_and_validate(
|
|
|
42
43
|
]
|
|
43
44
|
return (None, errors, [])
|
|
44
45
|
|
|
45
|
-
is_valid, errors, warnings = validate(config)
|
|
46
|
+
is_valid, errors, warnings = validate(config, check_module)
|
|
46
47
|
|
|
47
48
|
if not is_valid:
|
|
48
49
|
return (None, errors, warnings)
|
|
@@ -102,7 +103,9 @@ def validate_fields(config: Dict[str, Any]) -> Tuple[bool, List[str], List[str]]
|
|
|
102
103
|
return len(errors) == 0, errors, warnings
|
|
103
104
|
|
|
104
105
|
|
|
105
|
-
def validate(
|
|
106
|
+
def validate(
|
|
107
|
+
config: Dict[str, Any], check_module: bool = True
|
|
108
|
+
) -> Tuple[bool, List[str], List[str]]:
|
|
106
109
|
"""Validate pyproject.toml."""
|
|
107
110
|
is_valid, errors, warnings = validate_fields(config)
|
|
108
111
|
|
|
@@ -110,12 +113,16 @@ def validate(config: Dict[str, Any]) -> Tuple[bool, List[str], List[str]]:
|
|
|
110
113
|
return False, errors, warnings
|
|
111
114
|
|
|
112
115
|
# Validate serverapp
|
|
113
|
-
is_valid, reason = object_ref.validate(
|
|
116
|
+
is_valid, reason = object_ref.validate(
|
|
117
|
+
config["flower"]["components"]["serverapp"], check_module
|
|
118
|
+
)
|
|
114
119
|
if not is_valid and isinstance(reason, str):
|
|
115
120
|
return False, [reason], []
|
|
116
121
|
|
|
117
122
|
# Validate clientapp
|
|
118
|
-
is_valid, reason = object_ref.validate(
|
|
123
|
+
is_valid, reason = object_ref.validate(
|
|
124
|
+
config["flower"]["components"]["clientapp"], check_module
|
|
125
|
+
)
|
|
119
126
|
|
|
120
127
|
if not is_valid and isinstance(reason, str):
|
|
121
128
|
return False, [reason], []
|
flwr/cli/install.py
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# Copyright 2024 Flower Labs GmbH. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# ==============================================================================
|
|
15
|
+
"""Flower command line interface `install` command."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
import os
|
|
19
|
+
import shutil
|
|
20
|
+
import tempfile
|
|
21
|
+
import zipfile
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from typing import Optional
|
|
24
|
+
|
|
25
|
+
import typer
|
|
26
|
+
from typing_extensions import Annotated
|
|
27
|
+
|
|
28
|
+
from .config_utils import load_and_validate
|
|
29
|
+
from .utils import get_sha256_hash
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def install(
|
|
33
|
+
source: Annotated[
|
|
34
|
+
Optional[Path],
|
|
35
|
+
typer.Argument(metavar="source", help="The source FAB file to install."),
|
|
36
|
+
] = None,
|
|
37
|
+
flwr_dir: Annotated[
|
|
38
|
+
Optional[Path],
|
|
39
|
+
typer.Option(help="The desired install path."),
|
|
40
|
+
] = None,
|
|
41
|
+
) -> None:
|
|
42
|
+
"""Install a Flower App Bundle.
|
|
43
|
+
|
|
44
|
+
It can be ran with a single FAB file argument:
|
|
45
|
+
|
|
46
|
+
``flwr install ./target_project.fab``
|
|
47
|
+
|
|
48
|
+
The target install directory can be specified with ``--flwr-dir``:
|
|
49
|
+
|
|
50
|
+
``flwr install ./target_project.fab --flwr-dir ./docs/flwr``
|
|
51
|
+
|
|
52
|
+
This will install ``target_project`` to ``./docs/flwr/``. By default,
|
|
53
|
+
``flwr-dir`` is equal to:
|
|
54
|
+
|
|
55
|
+
- ``$FLWR_HOME/`` if ``$FLWR_HOME`` is defined
|
|
56
|
+
- ``$XDG_DATA_HOME/.flwr/`` if ``$XDG_DATA_HOME`` is defined
|
|
57
|
+
- ``$HOME/.flwr/`` in all other cases
|
|
58
|
+
"""
|
|
59
|
+
if source is None:
|
|
60
|
+
source = Path(typer.prompt("Enter the source FAB file"))
|
|
61
|
+
|
|
62
|
+
source = source.resolve()
|
|
63
|
+
if not source.exists() or not source.is_file():
|
|
64
|
+
typer.secho(
|
|
65
|
+
f"❌ The source {source} does not exist or is not a file.",
|
|
66
|
+
fg=typer.colors.RED,
|
|
67
|
+
bold=True,
|
|
68
|
+
)
|
|
69
|
+
raise typer.Exit(code=1)
|
|
70
|
+
|
|
71
|
+
if source.suffix != ".fab":
|
|
72
|
+
typer.secho(
|
|
73
|
+
f"❌ The source {source} is not a `.fab` file.",
|
|
74
|
+
fg=typer.colors.RED,
|
|
75
|
+
bold=True,
|
|
76
|
+
)
|
|
77
|
+
raise typer.Exit(code=1)
|
|
78
|
+
|
|
79
|
+
install_from_fab(source, flwr_dir)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def install_from_fab(
|
|
83
|
+
fab_file: Path, flwr_dir: Optional[Path], skip_prompt: bool = False
|
|
84
|
+
) -> None:
|
|
85
|
+
"""Install from a FAB file after extracting and validating."""
|
|
86
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
87
|
+
with zipfile.ZipFile(fab_file, "r") as zipf:
|
|
88
|
+
zipf.extractall(tmpdir)
|
|
89
|
+
tmpdir_path = Path(tmpdir)
|
|
90
|
+
info_dir = tmpdir_path / ".info"
|
|
91
|
+
if not info_dir.exists():
|
|
92
|
+
typer.secho(
|
|
93
|
+
"❌ FAB file has incorrect format.",
|
|
94
|
+
fg=typer.colors.RED,
|
|
95
|
+
bold=True,
|
|
96
|
+
)
|
|
97
|
+
raise typer.Exit(code=1)
|
|
98
|
+
|
|
99
|
+
content_file = info_dir / "CONTENT"
|
|
100
|
+
|
|
101
|
+
if not content_file.exists() or not _verify_hashes(
|
|
102
|
+
content_file.read_text(), tmpdir_path
|
|
103
|
+
):
|
|
104
|
+
typer.secho(
|
|
105
|
+
"❌ File hashes couldn't be verified.",
|
|
106
|
+
fg=typer.colors.RED,
|
|
107
|
+
bold=True,
|
|
108
|
+
)
|
|
109
|
+
raise typer.Exit(code=1)
|
|
110
|
+
|
|
111
|
+
shutil.rmtree(info_dir)
|
|
112
|
+
|
|
113
|
+
validate_and_install(tmpdir_path, fab_file.stem, flwr_dir, skip_prompt)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def validate_and_install(
|
|
117
|
+
project_dir: Path,
|
|
118
|
+
fab_name: str,
|
|
119
|
+
flwr_dir: Optional[Path],
|
|
120
|
+
skip_prompt: bool = False,
|
|
121
|
+
) -> None:
|
|
122
|
+
"""Validate TOML files and install the project to the desired directory."""
|
|
123
|
+
config, _, _ = load_and_validate(project_dir / "pyproject.toml", check_module=False)
|
|
124
|
+
|
|
125
|
+
if config is None:
|
|
126
|
+
typer.secho(
|
|
127
|
+
"❌ Invalid config inside FAB file.",
|
|
128
|
+
fg=typer.colors.RED,
|
|
129
|
+
bold=True,
|
|
130
|
+
)
|
|
131
|
+
raise typer.Exit(code=1)
|
|
132
|
+
|
|
133
|
+
publisher = config["flower"]["publisher"]
|
|
134
|
+
project_name = config["project"]["name"]
|
|
135
|
+
version = config["project"]["version"]
|
|
136
|
+
|
|
137
|
+
if fab_name != f"{publisher}.{project_name}.{version.replace('.', '-')}":
|
|
138
|
+
typer.secho(
|
|
139
|
+
"❌ FAB file has incorrect name. The file name must follow the format "
|
|
140
|
+
"`<publisher>.<project_name>.<version>.fab`.",
|
|
141
|
+
fg=typer.colors.RED,
|
|
142
|
+
bold=True,
|
|
143
|
+
)
|
|
144
|
+
raise typer.Exit(code=1)
|
|
145
|
+
|
|
146
|
+
install_dir: Path = (
|
|
147
|
+
(
|
|
148
|
+
Path(
|
|
149
|
+
os.getenv(
|
|
150
|
+
"FLWR_HOME",
|
|
151
|
+
f"{os.getenv('XDG_DATA_HOME', os.getenv('HOME'))}/.flwr",
|
|
152
|
+
)
|
|
153
|
+
)
|
|
154
|
+
if not flwr_dir
|
|
155
|
+
else flwr_dir
|
|
156
|
+
)
|
|
157
|
+
/ "apps"
|
|
158
|
+
/ publisher
|
|
159
|
+
/ project_name
|
|
160
|
+
/ version
|
|
161
|
+
)
|
|
162
|
+
if install_dir.exists() and not skip_prompt:
|
|
163
|
+
if not typer.confirm(
|
|
164
|
+
typer.style(
|
|
165
|
+
f"\n💬 {project_name} version {version} is already installed, "
|
|
166
|
+
"do you want to reinstall it?",
|
|
167
|
+
fg=typer.colors.MAGENTA,
|
|
168
|
+
bold=True,
|
|
169
|
+
)
|
|
170
|
+
):
|
|
171
|
+
return
|
|
172
|
+
|
|
173
|
+
install_dir.mkdir(parents=True, exist_ok=True)
|
|
174
|
+
|
|
175
|
+
# Move contents from source directory
|
|
176
|
+
for item in project_dir.iterdir():
|
|
177
|
+
if item.is_dir():
|
|
178
|
+
shutil.copytree(item, install_dir / item.name, dirs_exist_ok=True)
|
|
179
|
+
else:
|
|
180
|
+
shutil.copy2(item, install_dir / item.name)
|
|
181
|
+
|
|
182
|
+
typer.secho(
|
|
183
|
+
f"🎊 Successfully installed {project_name} to {install_dir}.",
|
|
184
|
+
fg=typer.colors.GREEN,
|
|
185
|
+
bold=True,
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _verify_hashes(list_content: str, tmpdir: Path) -> bool:
|
|
190
|
+
"""Verify file hashes based on the LIST content."""
|
|
191
|
+
for line in list_content.strip().split("\n"):
|
|
192
|
+
rel_path, hash_expected, _ = line.split(",")
|
|
193
|
+
file_path = tmpdir / rel_path
|
|
194
|
+
if not file_path.exists() or get_sha256_hash(file_path) != hash_expected:
|
|
195
|
+
return False
|
|
196
|
+
return True
|
flwr/cli/utils.py
CHANGED
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
# ==============================================================================
|
|
15
15
|
"""Flower command line interface utils."""
|
|
16
16
|
|
|
17
|
+
import hashlib
|
|
17
18
|
import re
|
|
19
|
+
from pathlib import Path
|
|
18
20
|
from typing import Callable, List, Optional, cast
|
|
19
21
|
|
|
20
22
|
import typer
|
|
@@ -122,3 +124,15 @@ def sanitize_project_name(name: str) -> str:
|
|
|
122
124
|
sanitized_name = sanitized_name[1:]
|
|
123
125
|
|
|
124
126
|
return sanitized_name
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def get_sha256_hash(file_path: Path) -> str:
|
|
130
|
+
"""Calculate the SHA-256 hash of a file."""
|
|
131
|
+
sha256 = hashlib.sha256()
|
|
132
|
+
with open(file_path, "rb") as f:
|
|
133
|
+
while True:
|
|
134
|
+
data = f.read(65536) # Read in 64kB blocks
|
|
135
|
+
if not data:
|
|
136
|
+
break
|
|
137
|
+
sha256.update(data)
|
|
138
|
+
return sha256.hexdigest()
|