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

Add isort to CI and pre-commit configuration #47

Merged
merged 5 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ jobs:
run: |
poetry run black --diff --check .

- name: Import-check with isort
run: |
poetry run isort --diff --check-only .

- name: Lint with flake8
run: |
poetry run flake8 --show-source --statistics .
Expand Down
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ repos:
files: ^src/|^tests/
types: [python]

- repo: local
hooks:
- id: python-import
name: isort
entry: poetry run isort
args: [--diff, --check-only]
language: system
files: ^src/|^tests/
types: [python]

- repo: local
hooks:
- id: python-lint
Expand Down
31 changes: 24 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ flake8 = "^5.0.4"
shellcheck-py = "^0.8.0"
shfmt-py = "^3.4.3"
pytest-mock = "^3.8.2"
isort = "^5.10.1"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand All @@ -48,6 +49,12 @@ extend-exclude = """
)/
"""

[tool.isort]
profile = "black"
skip_glob = ["data/*", "runs/*", "scripts/*",
"submodules/*", ".venv/*", "cov_html/*"]
line_length = 88

[tool.coverage.run]
branch = true
source = ["src"]
Expand Down
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ evaluate==0.2.2; python_full_version >= "3.7.0"
filelock==3.4.0; python_version >= "3.6" and python_full_version >= "3.7.0"
flake8==5.0.4; python_full_version >= "3.6.1"
frozenlist==1.2.0; python_version >= "3.6"
fsspec==2022.8.2; python_version >= "3.7" and python_full_version >= "3.7.0"
fsspec==2022.10.0; python_version >= "3.7" and python_full_version >= "3.7.0"
gitdb==4.0.9; python_version >= "3.7"
gitpython==3.1.27; python_version >= "3.7"
huggingface-hub==0.9.1; python_full_version >= "3.7.0"
idna==3.3; python_version >= "3.6" and python_full_version >= "3.7.0" and (python_version >= "2.7" and python_full_version < "3.0.0" or python_full_version >= "3.6.0") and (python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.6.0" and python_version >= "3.6")
iniconfig==1.1.1; python_version >= "3.7"
ipdb==0.13.9; python_version >= "2.7"
ipython==7.30.0; python_version >= "3.7"
isort==5.10.1; python_full_version >= "3.6.1" and python_version < "4.0"
jedi==0.18.1; python_version >= "3.7"
joblib==1.1.0; python_version >= "3.8"
matplotlib-inline==0.1.3; python_version >= "3.7"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ docker-pycreds==0.4.0; python_version >= "3.6"
evaluate==0.2.2; python_full_version >= "3.7.0"
filelock==3.4.0; python_version >= "3.6" and python_full_version >= "3.7.0"
frozenlist==1.2.0; python_version >= "3.6"
fsspec==2022.8.2; python_version >= "3.7" and python_full_version >= "3.7.0"
fsspec==2022.10.0; python_version >= "3.7" and python_full_version >= "3.7.0"
gitdb==4.0.9; python_version >= "3.7"
gitpython==3.1.27; python_version >= "3.7"
huggingface-hub==0.9.1; python_full_version >= "3.7.0"
Expand Down
7 changes: 4 additions & 3 deletions src/parser.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from transformers.hf_argparser import DataClassType
from transformers import HfArgumentParser, TrainingArguments
import os
from dataclasses import dataclass, field
from typing import Optional
import os

from transformers import HfArgumentParser, TrainingArguments
from transformers.hf_argparser import DataClassType

# 1. NOTE: Fields with no default value set will be transformed
# into`required arguments within the HuggingFace argument parser
Expand Down
1 change: 1 addition & 0 deletions src/privacy_glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

from parser import get_parser

from utils.experiment_utils import Privacy_GLUE_Experiment_Manager


Expand Down
3 changes: 2 additions & 1 deletion src/tasks/opp_115.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os

import datasets
import pandas as pd
import os


def load_opp_115(directory: str) -> datasets.DatasetDict:
Expand Down
5 changes: 3 additions & 2 deletions src/tasks/piextract.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from typing import Dict, List, Tuple
import os
from glob import glob
from typing import Dict, List, Tuple

import datasets
import os


def read_conll_file(file_path: str) -> Dict[str, List[List[str]]]:
Expand Down
5 changes: 3 additions & 2 deletions src/tasks/policy_detection.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import pandas as pd
import datasets
import os

import datasets
import pandas as pd


def load_policy_detection(directory: str) -> datasets.DatasetDict:
# initialize DatasetDict object
Expand Down
3 changes: 2 additions & 1 deletion src/tasks/policy_ie_a.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
from typing import Dict, cast

import datasets
import os


def file_mapping(directory: str, filename: str) -> Dict[str, str]:
Expand Down
4 changes: 3 additions & 1 deletion src/tasks/policy_ie_b.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from .policy_ie_a import file_mapping
from typing import cast

import datasets

from .policy_ie_a import file_mapping


def load_policy_ie_b(directory: str) -> datasets.DatasetDict:
# initialize DatasetDict object
Expand Down
7 changes: 4 additions & 3 deletions src/tasks/policy_qa.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from typing import Dict, List, Any
from glob import glob
import datasets
import json
import os
from glob import glob
from typing import Any, Dict, List

import datasets


def load_policy_qa(directory: str) -> datasets.DatasetDict:
Expand Down
5 changes: 3 additions & 2 deletions src/tasks/privacy_qa.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import pandas as pd
import datasets
import os

import datasets
import pandas as pd


def load_privacy_qa(directory: str) -> datasets.DatasetDict:
# load and process the train dataset
Expand Down
10 changes: 6 additions & 4 deletions src/utils/experiment_utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
import re
from parser import TASKS

from wandb.util import generate_id

from reading_comprehension import Reading_Comprehension_Pipeline
from sequence_classification import Sequence_Classification_Pipeline
from sequence_tagging import Sequence_Tagging_Pipeline
from reading_comprehension import Reading_Comprehension_Pipeline
from parser import TASKS
import os
import re


class Privacy_GLUE_Experiment_Manager:
Expand Down
4 changes: 2 additions & 2 deletions src/utils/parser_utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from typing import Iterable, Optional, cast
from operator import attrgetter
import argparse
import os
import re
from operator import attrgetter
from typing import Iterable, Optional, cast


def dir_path(path: str) -> str:
Expand Down
22 changes: 12 additions & 10 deletions src/utils/pipeline_utils.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import logging
import os
import shutil
from abc import ABC, abstractmethod
from datasets import DatasetDict
from glob import glob
from parser import DataArguments, ModelArguments

import datasets
import torch
import transformers
import wandb
from datasets import DatasetDict
from transformers import TrainingArguments, set_seed
from transformers.trainer_utils import get_last_checkpoint
from parser import DataArguments, ModelArguments

from tasks.opp_115 import load_opp_115
from tasks.piextract import load_piextract
from tasks.policy_detection import load_policy_detection
from tasks.policy_ie_a import load_policy_ie_a
from tasks.policy_ie_b import load_policy_ie_b
from tasks.policy_qa import load_policy_qa
from tasks.privacy_qa import load_privacy_qa
from utils.logging_utils import init_logger, add_file_handler
import transformers
import datasets
import logging
import wandb
import shutil
import torch
import os
from utils.logging_utils import add_file_handler, init_logger


class SuccessFileFoundException(Exception):
Expand Down
9 changes: 5 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from types import SimpleNamespace
import logging
import os
from copy import deepcopy
from functools import partial
from types import SimpleNamespace
from unittest.mock import MagicMock
from copy import deepcopy

import datasets
import logging
import pytest
import os


def pytest_configure():
Expand Down
3 changes: 2 additions & 1 deletion tests/tasks/test_opp_115.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from tasks.opp_115 import load_opp_115
import os

from tasks.opp_115 import load_opp_115


def test_load_opp_115():
# load sample data
Expand Down
Loading