Skip to content

Commit 3c9797e

Browse files
committed
flake8 + travis
1 parent 376b664 commit 3c9797e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1220
-958
lines changed

.flake8

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
exclude = .git,__pycache__,docs,build,dist,mlcomp/server/front

.style.yapf

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[style]
2+
based_on_style=pep8
3+
allow_split_before_dict_value=False
4+
join_multiple_lines=False
5+
split_before_named_assigns=True
6+
dedent_closing_brackets=True

.travis.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
group: travis_latest
2+
language: python
3+
cache: pip
4+
5+
branches:
6+
only:
7+
- master
8+
9+
python:
10+
- '3.6'
11+
12+
before_install: &before_install
13+
sudo ls
14+
15+
install: &requirements
16+
pip install -r requirements.txt
17+
18+
jobs:
19+
include:
20+
- stage: Tests
21+
install:
22+
- *requirements
23+
- pip install flake8 flake8-quotes yapf
24+
- pip install -U pytest
25+
script:
26+
# stop the build if there are any unexpected flake8 issues
27+
- flake8 . --count
28+
--max-complexity=16
29+
--inline-quotes "single"
30+
--multiline-quotes "single"
31+
--docstring-quotes "single"
32+
--show-source --statistics
33+
# test to make sure the code is yapf compliant
34+
#- ./yapf.sh --all
35+
- pytest

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# mlcomp
1+
# MLComp
22
Machine learning pipelines. Especially, for competitions, like Kaggle
33

44
![MLComp logo](mlcomp/server/front/src/assets/img/mlcomp_logo.jpg)

examples/cifar/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# flake8: noqa
12
from catalyst.dl import SupervisedRunner as Runner
23
from experiment import Experiment
3-
from model import SimpleNet
4+
from model import SimpleNet

examples/mnist/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# flake8: noqa
12
from catalyst.dl import SupervisedRunner as Runner
23
from experiment import Experiment
34
from model import Net

examples/mnist/dataset.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66

77
class MnistDataset(Dataset):
8-
def __init__(self,
9-
file: str,
10-
fold_csv: str = None,
11-
fold_number: int = 0,
12-
is_test: bool = False
13-
):
8+
def __init__(
9+
self,
10+
file: str,
11+
fold_csv: str = None,
12+
fold_number: int = 0,
13+
is_test: bool = False
14+
):
1415
df = pd.read_csv(file)
1516
if fold_csv is not None:
1617
fold = pd.read_csv(fold_csv)
@@ -29,7 +30,7 @@ def __init__(self,
2930

3031
def __len__(self):
3132
return len(self.x)
32-
33+
3334
def __getitem__(self, index):
3435
res = {'features': self.x[index] / 255}
3536
if self.y is not None:

mlcomp/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .__version__ import __version__ # noqa: F401
1+
from .__version__ import __version__ # noqa: F401

mlcomp/__main__.py

+34-26
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88

99
from mlcomp.db.enums import DagType, ComponentType, TaskStatus
1010
from mlcomp.db.models import Computer
11+
from mlcomp.db.providers import \
12+
ComputerProvider, \
13+
TaskProvider, \
14+
StepProvider, \
15+
ProjectProvider
1116
from mlcomp.utils.io import yaml_load
1217
from mlcomp.utils.logging import create_logger
13-
from mlcomp.db.providers import *
1418
from multiprocessing import cpu_count
1519

1620
from mlcomp.utils.settings import ROOT_FOLDER, DATA_FOLDER, MODEL_FOLDER
@@ -26,25 +30,26 @@ def _dag(config: str, debug: bool = False):
2630

2731
type_name = config_parsed['info'].get('type', "standard")
2832
if type_name == DagType.Standard.name.lower():
29-
return dag_standard(config_parsed,
30-
debug=debug,
31-
config_text=config_text)
33+
return dag_standard(
34+
config_parsed, debug=debug, config_text=config_text
35+
)
3236

33-
return dag_pipe(config_parsed,
34-
config_text=config_text)
37+
return dag_pipe(config_parsed, config_text=config_text)
3538

3639

3740
def _create_computer():
3841
tot_m, used_m, free_m = memory()
3942
tot_d, used_d, free_d = disk(ROOT_FOLDER)
40-
computer = Computer(name=socket.gethostname(),
41-
gpu=len(GPUtil.getGPUs()),
42-
cpu=cpu_count(), memory=tot_m,
43-
ip=os.getenv('IP'),
44-
port=int(os.getenv('PORT')),
45-
user=os.getenv('USER'),
46-
disk=tot_d
47-
)
43+
computer = Computer(
44+
name=socket.gethostname(),
45+
gpu=len(GPUtil.getGPUs()),
46+
cpu=cpu_count(),
47+
memory=tot_m,
48+
ip=os.getenv('IP'),
49+
port=int(os.getenv('PORT')),
50+
user=os.getenv('USER'),
51+
disk=tot_d
52+
)
4853
ComputerProvider().create_or_update(computer, 'name')
4954

5055

@@ -72,16 +77,15 @@ def execute(config: str, debug: bool):
7277
provider = TaskProvider()
7378
step_provider = StepProvider()
7479

75-
for t in provider.by_status(TaskStatus.InProgress,
76-
worker_index=worker_index):
80+
for t in provider.by_status(
81+
TaskStatus.InProgress, worker_index=worker_index
82+
):
7783
step = step_provider.last_for_task(t.id)
7884
logger.error(
7985
f'Task Id = {t.id} was in InProgress state '
8086
f'when another tasks arrived to the same worker',
81-
ComponentType.Worker,
82-
t.computer_assigned,
83-
t.id,
84-
step)
87+
ComponentType.Worker, t.computer_assigned, t.id, step
88+
)
8589
provider.change_status(t, TaskStatus.Failed)
8690

8791
# Create dag
@@ -93,12 +97,16 @@ def execute(config: str, debug: bool):
9397

9498
@main.command()
9599
@click.option('--computer', help='sync computer with all the others')
96-
@click.option('--only_from',
97-
is_flag=True,
98-
help='only copy files from the computer to all the others')
99-
@click.option('--only_to',
100-
is_flag=True,
101-
help='only copy files from all the others to the computer')
100+
@click.option(
101+
'--only_from',
102+
is_flag=True,
103+
help='only copy files from the computer to all the others'
104+
)
105+
@click.option(
106+
'--only_to',
107+
is_flag=True,
108+
help='only copy files from all the others to the computer'
109+
)
102110
def sync(computer: str, only_from: bool, only_to: bool):
103111
computer = computer or socket.gethostname()
104112
provider = ComputerProvider()

mlcomp/contrib/catalyst/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
from .register import register
1+
from .register import register
2+
3+
__all__ = ['register']
+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
from .cosineanneal import OneCycleCosineAnnealLR
1+
from .cosineanneal import OneCycleCosineAnnealLR
2+
3+
__all__ = ['OneCycleCosineAnnealLR']

mlcomp/contrib/catalyst/register.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ def register():
1313

1414
registry.Callback(InferBestCallback)
1515

16-
registry.Scheduler(OneCycleCosineAnnealLR)
16+
registry.Scheduler(OneCycleCosineAnnealLR)

mlcomp/contrib/criterion/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
from .ring import RingLoss
1+
from .ring import RingLoss
2+
3+
__all__ = ['RingLoss']

mlcomp/contrib/model/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
from .pretrained import Pretrained
1+
from .pretrained import Pretrained
2+
3+
__all__ = ['Pretrained']

mlcomp/contrib/scripts/split.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
from sklearn.model_selection import GroupKFold
66

77

8-
def file_group_kfold(n_splits: int,
9-
output: str,
10-
get_group=None,
11-
sort=False,
12-
must_equal = (),
13-
**files):
8+
def file_group_kfold(
9+
n_splits: int,
10+
output: str,
11+
get_group=None,
12+
sort=False,
13+
must_equal=(),
14+
**files
15+
):
1416
assert len(files) > 0, 'at lease 1 type of files is required'
1517
fold = GroupKFold(n_splits)
1618
keys = sorted(list(files))
@@ -38,16 +40,18 @@ def get_name(file):
3840
names_equal = get_name(v[i]) == get_name(file_first[i])
3941
assert names_equal, \
4042
f'file name in {k} does not equal to {keys[0]}, ' \
41-
f'file name = {basename(v[i])}'
43+
f'file name = {basename(v[i])}'
4244

4345
df = pd.DataFrame(files)[keys]
4446
df['fold'] = 0
4547

46-
groups = [i if not get_group else get_group(file) for i, file in
47-
enumerate(file_first)]
48+
groups = [
49+
i if not get_group else get_group(file)
50+
for i, file in enumerate(file_first)
51+
]
4852

49-
for i, (train_index, test_index) in enumerate(
50-
fold.split(groups, groups=groups)):
53+
for i, (train_index,
54+
test_index) in enumerate(fold.split(groups, groups=groups)):
5155
df.loc[test_index, 'fold'] = i
5256

5357
df = df.sample(frac=1)

mlcomp/contrib/split/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
from .frame import split_frame
2+
3+
__all__ = ['split_frame']

mlcomp/db/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
# flake8: noqa
12
from .signals import *

mlcomp/db/conf.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
'host': os.getenv('POSTGRES_HOST', 'localhost'),
99
'port': int(os.getenv('POSTGRES_PORT', 5432)),
1010
}
11-
if DB_DRIVER=='sqlite':
11+
if DB_DRIVER == 'sqlite':
1212
f = os.path.dirname(__file__)
1313
f = os.path.join(f, '../migration')
1414
f = os.path.abspath(f)
@@ -18,6 +18,4 @@
1818
f"{DATABASE['password']}@{DATABASE['host']}:" \
1919
f"{DATABASE['port']}/{DATABASE['dbname']}"
2020

21-
__all__ = [
22-
'SA_CONNECTION_STRING'
23-
]
21+
__all__ = ['SA_CONNECTION_STRING']

mlcomp/db/core/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
from .db import *
2-
from .options import *
1+
from .db import Session
2+
from .options import PaginatorOptions
3+
4+
__all__ = ['Session', 'PaginatorOptions']

mlcomp/db/core/db.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
import sqlalchemy.orm.session as session
33
from sqlalchemy.orm import scoped_session, sessionmaker
44

5-
from mlcomp.db.conf import *
5+
from mlcomp.db.conf import SA_CONNECTION_STRING
66
from mlcomp.utils.misc import adapt_db_types
77

8-
__all__ = ['Session']
9-
108

119
class Session(session.Session):
1210
__session = dict()
@@ -23,19 +21,20 @@ def create_session(connection_string: str = None, key='default'):
2321
return Session.__session[key][0]
2422

2523
session_factory = scoped_session(sessionmaker(class_=Session, key=key))
26-
engine = sa.create_engine(connection_string or SA_CONNECTION_STRING,
27-
echo=False)
24+
engine = sa.create_engine(
25+
connection_string or SA_CONNECTION_STRING, echo=False
26+
)
2827
session_factory.configure(bind=engine)
29-
session = session_factory()
28+
s = session_factory()
3029

31-
Session.__session[key] = [session, engine]
32-
return session
30+
Session.__session[key] = [s, engine]
31+
return s
3332

3433
@classmethod
3534
def cleanup(cls):
36-
for k, (session, engine) in cls.__session.items():
35+
for k, (s, engine) in cls.__session.items():
3736
try:
38-
session.close()
37+
s.close()
3938
except Exception:
4039
pass
4140
try:
@@ -94,3 +93,6 @@ def update(self):
9493
except Exception as e:
9594
self.rollback()
9695
raise e
96+
97+
98+
__all__ = ['Session']

mlcomp/db/core/options.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
class PaginatorOptions:
2-
def __init__(self,
3-
page_number: int,
4-
page_size: int,
5-
sort_column: str = None,
6-
sort_descending: bool = None):
2+
def __init__(
3+
self,
4+
page_number: int,
5+
page_size: int,
6+
sort_column: str = None,
7+
sort_descending: bool = None
8+
):
79
self.sort_column = sort_column
810
self.sort_descending = sort_descending
911
self.page_number = page_number
1012
self.page_size = page_size
1113

1214
assert (page_number is not None and page_size) \
13-
or (not page_number is None and not page_size), \
15+
or (page_number is not None and not page_size), \
1416
'Specify both page_number and page_size'
1517

1618
if not sort_column:

0 commit comments

Comments
 (0)