Skip to content

Commit 1579e97

Browse files
committed
apply pre-commit
1 parent ba2c46d commit 1579e97

20 files changed

+200
-55
lines changed

.devcontainer/Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,9 @@ RUN python3 -m pip install -U pip \
2828

2929
WORKDIR /app
3030

31-
COPY requirements.txt .
32-
RUN $PYTHON -m pip install -r requirements.txt && rm -rf /root/.cache
31+
COPY pyproject.toml .
32+
COPY poetry.lock .
33+
COPY scripts/clean_requirements.sh .
34+
RUN $PYTHON -m poetry export -f requirements.txt -o requirements.txt --without-hashes
35+
RUN sh clean_requirements.sh
36+
RUN $PYTHON -m pip install -r requirements.txt && rm -rf /root/.cache

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,4 @@ model.tar.gz
247247
data
248248
checkpoints
249249
.pytest_cache
250-
pytestdebug.log
250+
pytestdebug.log

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ checkpoints
3838
.pytest_cache
3939
pytestdebug.log
4040
*log
41-
.venv
41+
.venv

.pre-commit-config.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
exclude: 'benchmark|conf|data|docs|outputs'
2+
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v1.2.3
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-added-large-files
10+
args: [--maxkb=15000]
11+
- id: check-yaml
12+
13+
- repo: https://github.com/ambv/black
14+
rev: stable
15+
hooks:
16+
- id: black
17+
language_version: python3.7
18+
19+
- repo: https://github.com/humitos/mirrors-autoflake.git
20+
rev: v1.3
21+
hooks:
22+
- id: autoflake
23+
args:
24+
[
25+
'--in-place',
26+
'--remove-unused-variable',
27+
'--ignore-init-module-imports',
28+
'--imports=torch,torch_geometric,torch_scatter,torch_cluster,numpy,sklearn,scipy,torch_sparse,torch_points_kernels',
29+
]
30+
- repo: https://github.com/kynan/nbstripout
31+
rev: master
32+
hooks:
33+
- id: nbstripout
34+
files: '.ipynb'
35+
36+
- repo: local
37+
hooks:
38+
- id: requirements.txt
39+
name: Generate requirements.txt
40+
entry: poetry export
41+
args:
42+
[
43+
'-f',
44+
'requirements.txt',
45+
'-o',
46+
'requirements.txt',
47+
'--without-hashes',
48+
]
49+
pass_filenames: false
50+
language: system
51+
files: 'poetry.lock'

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ workflow-test-xdist:
1111
coverage run -m pytest -n `python -c 'import multiprocessing as mp; print(mp.cpu_count())'` --color=yes
1212

1313
workflow-test:
14-
coverage run -m pytest --color=yes
14+
coverage run -m pytest --color=yes

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ build-backend = "poetry.masonry.api"
2323

2424
[[tool.poetry.source]]
2525
name = 'private'
26-
url = 'https://pypi.org/project'
26+
url = 'https://pypi.org/project'

requirements.txt

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
absl-py==0.10.0
2+
antlr4-python3-runtime==4.8
3+
apipkg==1.5
4+
atomicwrites==1.4.0; sys_platform == "win32"
5+
attrs==20.2.0
6+
cachetools==4.1.1
7+
certifi==2020.6.20
8+
chardet==3.0.4
9+
click==7.1.2
10+
colorama==0.4.3; sys_platform == "win32"
11+
configparser==5.0.0
12+
coverage==5.3
13+
docker-pycreds==0.4.0
14+
execnet==1.7.1
15+
fsspec==0.8.3
16+
future==0.18.2
17+
gitdb==4.0.5
18+
gitpython==3.1.9
19+
google-auth-oauthlib==0.4.1
20+
google-auth==1.22.1
21+
grpcio==1.32.0
22+
hydra-core==1.0.3
23+
idna==2.10
24+
importlib-metadata==2.0.0; python_version < "3.8"
25+
importlib-resources==3.0.0; python_version < "3.9"
26+
iniconfig==1.0.1
27+
joblib==0.17.0
28+
markdown==3.3
29+
numpy==1.19.2
30+
oauthlib==3.1.0
31+
omegaconf==2.0.2
32+
packaging==20.4
33+
pathtools==0.1.2
34+
pillow==7.2.0
35+
pluggy==0.13.1
36+
promise==2.3
37+
protobuf==3.13.0
38+
psutil==5.7.2
39+
py==1.9.0
40+
pyasn1-modules==0.2.8
41+
pyasn1==0.4.8
42+
pyparsing==2.4.7
43+
pytest-forked==1.3.0
44+
pytest-xdist==2.1.0
45+
pytest==6.1.1
46+
python-dateutil==2.8.1
47+
pytorch-lightning==0.10.0
48+
pyyaml==5.3.1
49+
requests-oauthlib==1.3.0
50+
requests==2.24.0
51+
rsa==4.6; python_version >= "3.5"
52+
scikit-learn==0.23.2
53+
scipy==1.5.2
54+
sentry-sdk==0.18.0
55+
shortuuid==1.0.1
56+
six==1.15.0
57+
smmap==3.0.4
58+
subprocess32==3.5.4
59+
tensorboard-plugin-wit==1.7.0
60+
tensorboard==2.2.0
61+
threadpoolctl==2.1.0
62+
toml==0.10.1
63+
torch==1.6.0
64+
torchvision==0.7.0
65+
tqdm==4.50.1
66+
typing-extensions==3.7.4.3
67+
urllib3==1.25.10
68+
wandb==0.10.5
69+
watchdog==0.10.3
70+
werkzeug==1.0.1
71+
zipp==3.3.0
72+
zipp==3.3.0; python_version < "3.8"

scripts/clean_requirements.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
python -c "print(''.join([l.split(';')[0]+'\n' if ('python_version' in l or 'sys_platform' in l) else l for l in open('requirements.txt', 'r').readlines()]))" > requirements_tmp.txt
2-
mv requirements_tmp.txt requirements.txt
1+
python -c "print(''.join([l.split(';')[0]+'\n' if ('python_version' in l or 'sys_platform' in l) else l for l in open('requirements.txt', 'r').readlines()]))" > requirements_tmp.txt
2+
mv requirements_tmp.txt requirements.txt

src/__init__.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
from src.core.base_dataset import BaseDataset
88
from src.core.base_model import BaseModel
99

10+
1011
def custom_instantiate(dataset_cfg, task_cfg):
1112
dataset_dict = OmegaConf.to_container(dataset_cfg, resolve=True)
1213
task_dict = OmegaConf.to_container(task_cfg, resolve=True)
1314
dataset_dict["task_config"] = task_dict
1415
t_cls = get_class(dataset_dict["_target_"])
1516
return t_cls(**dataset_dict)
1617

18+
1719
def attach_step_and_epoch_functions(model, datamodule):
1820
datamodule.forward = model.forward
1921
datamodule.log = model.log
@@ -22,19 +24,25 @@ def attach_step_and_epoch_functions(model, datamodule):
2224
if not is_overridden(attr, model):
2325
setattr(model, attr, getattr(datamodule, attr))
2426

27+
2528
def check_task_possible(task, cfg):
26-
assert task in [c._target_ for c in cfg], f"Provided {task} isn't supported by {cfg}"
29+
assert task in [
30+
c._target_ for c in cfg
31+
], f"Provided {task} isn't supported by {cfg}"
32+
2733

2834
def initialize_task(cfg: DictConfig):
2935
# Extract task mixin
30-
check_task_possible(cfg.task._target_, cfg.model.authorized_tasks)
31-
check_task_possible(cfg.task._target_, cfg.dataset.authorized_tasks)
36+
check_task_possible(cfg.task._target_, cfg.model.authorized_tasks)
37+
check_task_possible(cfg.task._target_, cfg.dataset.authorized_tasks)
3238

3339
data_module: BaseDataset = custom_instantiate(cfg.dataset, cfg.task)
34-
model: BaseModel = instantiate(cfg.model, **data_module.hyper_parameters, optimizers=cfg.optimizers.optimizers)
40+
model: BaseModel = instantiate(
41+
cfg.model, **data_module.hyper_parameters, optimizers=cfg.optimizers.optimizers
42+
)
3543

3644
attach_step_and_epoch_functions(model, data_module)
3745

3846
data_module.prepare_data()
3947

40-
return model, data_module
48+
return model, data_module

src/core/base_model.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
import os.path as osp
21
from omegaconf import OmegaConf, DictConfig, ListConfig
32
from functools import partial
43
from hydra.utils import instantiate, get_class
5-
import torch
6-
from torch import nn
7-
from torch.nn import Module
8-
from torch.nn import Sequential, ModuleDict, ModuleList
9-
import torch.nn.functional as F
104
from pytorch_lightning import LightningModule
115

6+
127
def delete_key(d, key):
138
try:
149
del d[key]
@@ -28,8 +23,7 @@ def __init__(self, *args, **kwargs):
2823
if len(self._optimizers_conf) == 1:
2924
self._optimizer_name = self._optimizers_conf[0]["name"]
3025
self._init_optim = partial(
31-
self._init_optim,
32-
optimizers_conf=self._optimizers_conf,
26+
self._init_optim, optimizers_conf=self._optimizers_conf,
3327
)
3428

3529
@property
@@ -117,4 +111,3 @@ def _sanetize_kwargs(value):
117111
for key, value in kwargs.items():
118112
kwargs[key] = _sanetize_kwargs(value)
119113
return kwargs
120-

0 commit comments

Comments
 (0)