Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing | Init Checker #582

Merged
merged 40 commits into from
Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
9f6fea1
Add docformatter to pyproject.toml
Nov 18, 2020
32ad116
Add docformatter to test.sh
Nov 18, 2020
3fbaf05
Add docformatter to format.sh
Nov 18, 2020
55065c8
Add docformatter to CI
Nov 18, 2020
8362048
add init_py_check.py under src/py/flwr_tool
Jan 12, 2021
41b749a
Update init_py_check.py
Jan 12, 2021
21d5f26
Add another word to ignore_list
Jan 12, 2021
440cc0d
Add init_py_check.py to test.sh
Jan 12, 2021
7f828b0
Merge branch 'main' into init_check
CanTuerk Jan 12, 2021
21eab2f
Update init_py_check.py
Jan 12, 2021
cdb6a9c
Merge branch 'init_check' of github.com:adap/flower into init_check
Jan 12, 2021
e5014df
Update init_py_check.py
Jan 12, 2021
a3ea3b2
Update test.sh
CanTuerk Jan 12, 2021
efd153d
Update __init__.py
CanTuerk Jan 12, 2021
78664cd
Update init_py_check.py
CanTuerk Jan 12, 2021
28c425a
Delete __init__.py
CanTuerk Jan 12, 2021
63c3e9f
add init py
Jan 12, 2021
0947bb6
Merge branch 'main' into init_check
Jan 12, 2021
d5be376
update init_py_check.py
Jan 12, 2021
26520b6
Merge branch 'main' into init_check
tanertopal Jan 12, 2021
e38fc50
Delete useless init file
Jan 12, 2021
2c86549
add another element to ignore_list in init_py_Check.py
Jan 12, 2021
336dfa6
Merge branch 'init_check' of github.com:adap/flower into init_check
Jan 12, 2021
3f2eba4
update init_py_check.py
Jan 12, 2021
c29d51f
Add final newline in init_py_check.py
Jan 15, 2021
aa8af43
Remove py from ignore_list
Jan 15, 2021
93dccae
Update src/py/flwr_tool/init_py_check.py
CanTuerk Jan 15, 2021
fcdc592
Merge branch 'main' into init_check
tanertopal Jan 15, 2021
a273238
Merge branch 'init_check' of github.com:adap/flower into init_check
Jan 15, 2021
ea9602a
Merge branch 'init_check' of github.com:adap/flower into init_check
Jan 15, 2021
61d9ca4
update init_py_check.py
Jan 15, 2021
ab67eef
Merge branch 'main' into init_check
tanertopal Jan 15, 2021
ff41e8e
Run fnt
tanertopal Jan 15, 2021
29a0f1a
Merge branch 'main' into init_check
tanertopal Jan 18, 2021
1f3e2f9
Merge branch 'main' into init_check
danieljanes Jan 18, 2021
888c97a
Add missing init file
Jan 18, 2021
242c245
Merge branch 'main' into init_check
tanertopal Jan 18, 2021
99ef559
Fixes linter errors
tanertopal Jan 18, 2021
2888265
Update __init__.py
danieljanes Jan 18, 2021
6dae1f4
Update common.py
danieljanes Jan 18, 2021
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
4 changes: 4 additions & 0 deletions dev/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ echo "=== test.sh ==="
clang-format-10 --Werror --dry-run src/proto/flwr/proto/* && echo "- clang-format: done" &&
python -m isort --check-only --skip src/py/flwr/proto src/py/flwr && echo "- isort: done" &&
python -m black --exclude "src\/py\/flwr\/proto" --check src/py/flwr && echo "- black: done" &&
python -m flwr_tool.init_py_check \
src/py/flwr src/py/flwr_tool \
src/py/flwr_example \
src/py/flwr_experimental
python -m docformatter -c -r src/py/flwr -e src/py/flwr/proto && echo "- docformatter: done" &&
python -m mypy src/py && echo "- mypy: done" &&
python -m pylint --ignore=src/py/flwr/proto src/py/flwr && echo "- pylint: done" &&
Expand Down
15 changes: 15 additions & 0 deletions src/py/flwr/dataset/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2020 Adap GmbH. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Flower Datasets utility functions."""
3 changes: 2 additions & 1 deletion src/py/flwr/dataset/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

"""Provides commonely used functions when generating a dataset for Federated
Learning."""
# pylint: disable=invalid-name

from typing import List, Tuple, cast
Expand Down
2 changes: 1 addition & 1 deletion src/py/flwr/dataset/utils/common_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CifarPartitionedTestCase(unittest.TestCase):
"""Tests for partitioned CIFAR-10/100 dataset generation."""

def setUp(self) -> None:
x = np.random.random(size=(500, 3, 32, 32))
x = np.random.random(size=(500, 3, 32, 32)) # pylint: disable=no-member
y = np.concatenate(np.array([50 * [j] for j in range(10)]), axis=0)
y = np.expand_dims(y, axis=1)

Expand Down
2 changes: 0 additions & 2 deletions src/py/flwr_example/pytorch_save_weights/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

import argparse
import timeit

# pylint: enable=no-member
from typing import Dict, List, Tuple

import numpy as np
Expand Down
45 changes: 45 additions & 0 deletions src/py/flwr_tool/init_py_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2020 Adap GmbH. All Rights Reserved.

"""Check provided directory and sub-directories for missing __init__.py files.

Example:
python -m flwr_tool.init_py_check src/py/flwr
"""

import os
import re
import sys


def check_missing_init_files(absolute_path: str) -> None:
"""Searches through the specified absolute_path and looks for missing __init__.py
files."""
path = os.walk(absolute_path)
warning_list = []
ignore_list = ["__pycache__$", ".pytest_cache.*$", "dist", "flwr.egg-info$"]

for dir_path, _, files_in_dir in path:
# As some directories are automatically generated we are going to ignore them
if any([re.search(iw, dir_path) is not None for iw in ignore_list]):
continue

# If no init is found in current directory add a warning_message to warning_list
if not any(filename == "__init__.py" for filename in files_in_dir):
warning_message = "- " + dir_path
warning_list.append(warning_message)

if len(warning_list) > 0:
print("Could not find '__init__.py' in the following directories:")
for warning in warning_list:
print(warning)
sys.exit(1)


if __name__ == "__main__":
if len(sys.argv) == 0:
raise Exception(
"Please provide at least one directory path relative to your current working directory."
)
for i in range(len(sys.argv)):
abs_path: str = os.path.abspath(os.path.join(os.getcwd(), sys.argv[i]))
check_missing_init_files(abs_path)