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

Feature/SK-736 | Ruff linter #552

Merged
merged 33 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
448e3e7
revert --fix etc
viktorvaladi Mar 25, 2024
276c9e7
move setup.py configs
viktorvaladi Apr 5, 2024
60f9382
reset repo change
viktorvaladi Apr 29, 2024
7027d20
move init for pyproject
viktorvaladi Apr 30, 2024
81f41ff
include setup.py changes
viktorvaladi Apr 30, 2024
f3fd13c
remove generated
viktorvaladi Apr 30, 2024
ac87c09
Merge remote-tracking branch 'origin/master' into feature/SK-736
viktorvaladi Apr 30, 2024
0889f42
fix minor ruff errors
viktorvaladi Apr 30, 2024
28612e9
ruff fix
viktorvaladi Apr 30, 2024
0ff77e4
remove setup.py
viktorvaladi Apr 30, 2024
b6bf066
update test build path
viktorvaladi Apr 30, 2024
2a2ca70
cli path update
viktorvaladi Apr 30, 2024
b78ae9d
update cli path
viktorvaladi Apr 30, 2024
88c0d30
update cli path
viktorvaladi Apr 30, 2024
27b940e
fix cli path
viktorvaladi May 2, 2024
26c41e5
change dockerfile path
viktorvaladi May 2, 2024
769fd6a
change compose paths
viktorvaladi May 2, 2024
1169f15
update compose paths
viktorvaladi May 2, 2024
d426042
change path
viktorvaladi May 2, 2024
a3b338c
change pash
viktorvaladi May 2, 2024
106ec8d
add editable
viktorvaladi May 3, 2024
d8d0443
add virtualenv to pyproject
viktorvaladi May 3, 2024
69b6693
fix pyproject.toml
viktorvaladi May 3, 2024
6762531
change project structure
viktorvaladi May 3, 2024
7768adb
trigger CI
viktorvaladi May 3, 2024
e2d29c3
trigger CI
viktorvaladi May 3, 2024
daa0c62
merge main
viktorvaladi May 3, 2024
c379889
fix paths compose
viktorvaladi May 4, 2024
709c0a7
fix compose paths
viktorvaladi May 4, 2024
3730f77
setuptools for -e . in dockers
viktorvaladi May 6, 2024
ced7da9
revert setuptools enforce
viktorvaladi May 6, 2024
0baf159
Merge remote-tracking branch 'origin/master' into feature/SK-736
viktorvaladi May 6, 2024
a5855ad
enforce setuptools>65 in dockerfile
viktorvaladi May 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ci/tests/examples/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ helper="$2"

python -m venv ".$example"
source ".$example/bin/activate"
".$example/bin/pip" install ./fedn/ fire
".$example/bin/pip" install . fire

>&2 echo "Start FEDn"
pushd "examples/$example"
Expand Down
5 changes: 1 addition & 4 deletions .devcontainer/bin/init_venv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,5 @@ python -m venv .venv
sphinx==4.4.0 \
sphinx_press_theme==0.8.0 \
sphinx-autobuild==2021.3.14 \
autopep8==1.5.7 \
isort==5.10.1 \
flake8==4.0.1 \
sphinx_rtd_theme==0.5.2
.venv/bin/pip install -e fedn
.venv/bin/pip install -e .
25 changes: 14 additions & 11 deletions .devcontainer/devcontainer.json.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@
"remoteUser": "default",
// "workspaceFolder": "/fedn",
// "workspaceMount": "source=/path/to/fedn,target=/fedn,type=bind,consistency=default",
"extensions": [
"ms-azuretools.vscode-docker",
"ms-python.python",
"exiasr.hadolint",
"yzhang.markdown-all-in-one",
"ms-python.isort"
],
"customizations": {
"vscode": {
"extensions": [
"ms-azuretools.vscode-docker",
"ms-python.python",
"exiasr.hadolint",
"yzhang.markdown-all-in-one",
"charliermarsh.ruff"
]
}
},
"mounts": [
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind,consistency=default",
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind,consistency=default"
],
"runArgs": [
"--net=host"
],
"build": {
"args": {
"BASE_IMG": "python:3.9"
"BASE_IMG": "python:3.11"
}
}
}

}
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ docs/*
**/.mnist-pytorch
**/*.npz
**/data
**/*.tgz
**/*.tgz
dist
25 changes: 2 additions & 23 deletions .github/workflows/code-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,9 @@ jobs:

- name: init venv
run: .devcontainer/bin/init_venv.sh
viktorvaladi marked this conversation as resolved.
Show resolved Hide resolved

- name: check Python imports
run: >
.venv/bin/isort . --check --diff
--skip .venv
--skip .mnist-keras
--skip .mnist-pytorch
--skip fedn_pb2.py
--skip fedn_pb2_grpc.py

- name: check Python formatting
run: >
.venv/bin/autopep8 --recursive --diff
--exclude .venv
--exclude .mnist-keras
--exclude .mnist-pytorch
--exclude fedn_pb2.py
--exclude fedn_pb2_grpc.py
.

- name: run Python linter
run: >
.venv/bin/flake8 .
--exclude ".venv,.mnist-keras,.mnist-pytorch,fedn_pb2.py,fedn_pb2_grpc.py"
- name: Ruff Linting
uses: chartboost/ruff-action@v1

- name: check for floating imports
run: >
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/push-to-pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ jobs:

- name: Install pypa/build
run: python -m pip install build
working-directory: ./fedn
working-directory: ./

- name: Build package
run: python -m build
working-directory: ./fedn
working-directory: ./

- name: Publish to Test PyPI
uses: pypa/gh-action-pypi-publish@v1.8.14
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
packages_dir: fedn/dist
packages_dir: ./dist
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ __pycache__/
.Python
build/
develop-eggs/
#dist/
downloads/
eggs/
.eggs/
Expand All @@ -38,6 +37,7 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST
dist

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ARG GRPC_HEALTH_PROBE_VERSION=""
ARG REQUIREMENTS=""

# Add FEDn and default configs
COPY fedn /app/fedn
COPY . /app
COPY config/settings-client.yaml.template /app/config/settings-client.yaml
COPY config/settings-combiner.yaml.template /app/config/settings-combiner.yaml
COPY config/settings-reducer.yaml.template /app/config/settings-reducer.yaml
Expand All @@ -27,6 +27,8 @@ RUN if [ ! -z "$GRPC_HEALTH_PROBE_VERSION" ]; then \
echo "No grpc_health_probe version specified, skipping installation"; \
fi

# Setup working directory
WORKDIR /app

# Create FEDn app directory
SHELL ["/bin/bash", "-c"]
Expand All @@ -39,14 +41,13 @@ RUN mkdir -p /app \
# Install FEDn and requirements
&& python -m venv /venv \
&& /venv/bin/pip install --upgrade pip \
&& /venv/bin/pip install --no-cache-dir -e /app/fedn \
&& /venv/bin/pip install --no-cache-dir setuptools>=65 \
&& /venv/bin/pip install --no-cache-dir -e . \
&& if [[ ! -z "$REQUIREMENTS" ]]; then \
/venv/bin/pip install --no-cache-dir -r /app/config/requirements.txt; \
fi \
#
# Clean up
&& rm -r /app/config/requirements.txt

# Setup working directory
WORKDIR /app
ENTRYPOINT [ "/venv/bin/fedn" ]
2 changes: 1 addition & 1 deletion config/combiner-settings.override.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ version: '3.3'
services:
combiner:
volumes:
- ${HOST_REPO_DIR:-.}/fedn:/app/fedn
- ${HOST_REPO_DIR:-.}:/app
- ${HOST_REPO_DIR:-.}/config/settings-combiner.yaml:/app/config/settings-combiner.yaml
2 changes: 1 addition & 1 deletion config/reducer-settings.override.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ version: '3.3'
services:
reducer:
volumes:
- ${HOST_REPO_DIR:-.}/fedn:/app/fedn
- ${HOST_REPO_DIR:-.}:/app
- ${HOST_REPO_DIR:-.}/config/settings-reducer.yaml:/app/config/settings-reducer.yaml
6 changes: 3 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ services:
- mongo
entrypoint: [ "sh", "-c" ]
command:
- "/venv/bin/pip install --no-cache-dir -e /app/fedn && /venv/bin/python fedn/fedn/network/api/server.py"
- "/venv/bin/pip install --no-cache-dir -e . && /venv/bin/python fedn/network/api/server.py"
ports:
- 8092:8092

Expand All @@ -97,7 +97,7 @@ services:
- ${HOST_REPO_DIR:-.}/fedn:/app/fedn
entrypoint: [ "sh", "-c" ]
command:
- "/venv/bin/pip install --no-cache-dir -e /app/fedn && /venv/bin/fedn run combiner --init config/settings-combiner.yaml"
- "/venv/bin/pip install --no-cache-dir -e . && /venv/bin/fedn run combiner --init config/settings-combiner.yaml"
ports:
- 12080:12080
healthcheck:
Expand Down Expand Up @@ -127,7 +127,7 @@ services:
- ${HOST_REPO_DIR:-.}/fedn:/app/fedn
entrypoint: [ "sh", "-c" ]
command:
- "/venv/bin/pip install --no-cache-dir -e /app/fedn && /venv/bin/fedn run client --init config/settings-client.yaml"
- "/venv/bin/pip install --no-cache-dir -e . && /venv/bin/fedn run client --init config/settings-client.yaml"
deploy:
replicas: 0
depends_on:
Expand Down
4 changes: 2 additions & 2 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ Clone the FEDn repository and install the package:
.. code-block:: bash

git clone https://github.com/scaleoutsystems/fedn.git
cd fedn/fedn
pip install -e .
cd fedn
pip install .

It is recommended to use a virtual environment when installing FEDn.

Expand Down
8 changes: 3 additions & 5 deletions examples/flower-client/client/flwr_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from collections import OrderedDict

import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.nn.functional as F # noqa: N812
from flwr_datasets import FederatedDataset
from torch import nn
from torch.utils.data import DataLoader
from torchvision.transforms import Compose, Normalize, ToTensor
from tqdm import tqdm
Expand Down Expand Up @@ -42,9 +42,7 @@ def load_data(partition_id, num_clients):
partition = fds.load_partition(partition_id)
# Divide data on each node: 80% train, 20% test
partition_train_test = partition.train_test_split(test_size=0.2)
pytorch_transforms = Compose(
[ToTensor(), Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))]
)
pytorch_transforms = Compose([ToTensor(), Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])

def apply_transforms(batch):
"""Apply transforms to the partition from FederatedDataset."""
Expand Down
2 changes: 1 addition & 1 deletion examples/flower-client/client/python_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ dependencies:
- torchvision==0.17.1
- fire==0.3.1
- fedn[flower]==0.9.0
- flwr-datasets[vision]==0.1.0
- flwr-datasets[vision]==0.1.0
3 changes: 1 addition & 2 deletions examples/mnist-pytorch/docker-compose.override.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ version: '3.4'

# Overriding requirements

x-env:
&defaults
x-env: &defaults
GET_HOSTS_FROM: dns
FEDN_PACKAGE_EXTRACT_DIR: package
FEDN_NUM_DATA_SPLITS: 2
Expand Down
22 changes: 21 additions & 1 deletion fedn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
"""The fedn package."""
import glob
import os
from os.path import basename, dirname, isfile

from fedn.network.api.client import APIClient

# flake8: noqa


modules = glob.glob(dirname(__file__) + "/fedn" + "/*.py")
__all__ = [basename(f)[:-3] for f in modules if isfile(f) and not f.endswith("__init__.py")]


_ROOT = os.path.abspath(os.path.dirname(__file__))


def get_data(path):
"""

:param path:
:return:
"""
return os.path.join(_ROOT, "data", path)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 0 additions & 24 deletions fedn/fedn/__init__.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
50 changes: 0 additions & 50 deletions fedn/setup.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.