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

Support Python 3.12 and apply ruff as formatter #55

Merged
merged 9 commits into from
Feb 26, 2024
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
13 changes: 6 additions & 7 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install poetry
poetry install
- name: run formatter
- name: Run formatter
run: |
poetry run yapf --diff --recursive --verbose thunderbolt test
poetry run isort --diff thunderbolt test
poetry run tox -e ruff
5 changes: 2 additions & 3 deletions .github/workflows/python_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/python_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ jobs:
max-parallel: 4
matrix:
platform: [ubuntu-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions poetry
python -m pip install poetry
poetry run python -m pip install tox-gh-actions
poetry install
- name: Test with tox
run: tox
run: poetry run tox
4 changes: 3 additions & 1 deletion examples/task.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# define tasks
from logging import getLogger

import gokart
import luigi
from luigi.util import requires
from logging import getLogger

logger = getLogger(__name__)

Expand All @@ -25,4 +26,5 @@ def run(self):
sample = self.load()
self.dump(sample + f'add task: {self.param}')


gokart.run()
2,004 changes: 1,070 additions & 934 deletions poetry.lock

Large diffs are not rendered by default.

37 changes: 26 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,47 @@ license = "MIT"
readme = "README.md"
homepage = "https://github.com/m3dev/thunderbolt"
repository = "https://github.com/m3dev/thunderbolt"
documentation = ""

[tool.poetry-dynamic-versioning]
enable = true
style = "pep440"
pattern = "^(?P<base>\\d+\\.\\d+\\.\\d+)"

[tool.poetry.dependencies]
python = ">=3.8,<3.12"
python = ">=3.9,<3.13"
gokart = "*"
boto3 = "*"
tqdm = "*"

[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
ruff = "*"
tox = "*"
coverage = "*"
mock = "*"
isort = "*"
yapf = "*"
toml = "*"

[tool.yapf]
based_on_style = "pep8"
column_limit = 160
[tool.ruff]
line-length = 160
exclude = ["venv/*", "tox/*"]

[tool.isort]
line_length = 160
[tool.ruff.lint]
# All the rules are listed on https://docs.astral.sh/ruff/rules/
extend-select = [
"B", # bugbear
"I" # isort
]

# B006: Do not use mutable data structures for argument defaults. They are created during function definition time. All calls to the function reuse this one instance of that data structure, persisting changes between them.
# B008 Do not perform function calls in argument defaults. The call is performed only once at function definition time. All calls to your function will reuse the result of that definition-time function call. If this is intended, assign the function call to a module-level variable and use that variable as a default value.
ignore = ["B006", "B008"]

# Avoid automatically removing unused imports in __init__.py files.
ignore-init-module-imports = true

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
Comment on lines +43 to +47
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid unused imports error. I think this configurations are redundant but currently there's no workaround.


[tool.ruff.format]
quote-style = "single"

[build-system]
requires = ["poetry"]
Expand Down
1 change: 0 additions & 1 deletion test/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import gokart
import luigi
from luigi.util import requires

logger = getLogger(__name__)

Expand Down
1 change: 0 additions & 1 deletion test/test_gcs_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class TestGCSClient(unittest.TestCase):

def setUp(self):
self.base_path = 'gs://bucket/prefix/'
self.client = GCSClient(self.base_path, None, None, use_cache=False)
Expand Down
1 change: 0 additions & 1 deletion test/test_local_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class TestLocalCache(unittest.TestCase):

def setUp(self):
self.base_path = './resources'
self.local_cache = LocalCache(self.base_path, True)
Expand Down
6 changes: 1 addition & 5 deletions test/test_local_cache_regression.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import pickle
import unittest
from os import path

import pandas as pd

from thunderbolt import Thunderbolt
from thunderbolt.client.local_cache import LocalCache

"""
requires:
python sample.py test.TestCaseTask --param=sample --number=1 --workspace-directory=./test_case --local-scheduler
"""


class LocalCacheTest(unittest.TestCase):

def test_running(self):
target = Thunderbolt(self._get_test_case_path(), use_cache=False)
_ = Thunderbolt(self._get_test_case_path())
Expand Down
1 change: 0 additions & 1 deletion test/test_local_directory_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class TestLocalDirectoryClient(unittest.TestCase):

def setUp(self):
self.client = LocalDirectoryClient('.', None, None, use_cache=False)

Expand Down
1 change: 0 additions & 1 deletion test/test_s3_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class TestS3Client(unittest.TestCase):

def setUp(self):
self.base_path = 's3://bucket/prefix/'
self.client = S3Client(self.base_path, None, None, use_cache=False)
Expand Down
97 changes: 34 additions & 63 deletions test/test_thunderbolt.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@


class TestThunderbolt(unittest.TestCase):

def setUp(self):

def get_tasks():
return []

Expand All @@ -35,35 +33,14 @@ def test_get_client(self):
self.assertEqual(type(output), t)

def test_get_tasks_dic(self):
tasks_list = [{
'task_name': 'task',
'last_modified': 'last_modified_2',
'task_params': 'task_params_1',
'task_hash': 'task_hash_1',
'task_log': 'task_log_1'
}, {
'task_name': 'task',
'last_modified': 'last_modified_1',
'task_params': 'task_params_1',
'task_hash': 'task_hash_1',
'task_log': 'task_log_1'
}]
tasks_list = [
{'task_name': 'task', 'last_modified': 'last_modified_2', 'task_params': 'task_params_1', 'task_hash': 'task_hash_1', 'task_log': 'task_log_1'},
{'task_name': 'task', 'last_modified': 'last_modified_1', 'task_params': 'task_params_1', 'task_hash': 'task_hash_1', 'task_log': 'task_log_1'},
]

target = {
0: {
'task_name': 'task',
'last_modified': 'last_modified_1',
'task_params': 'task_params_1',
'task_hash': 'task_hash_1',
'task_log': 'task_log_1'
},
1: {
'task_name': 'task',
'last_modified': 'last_modified_2',
'task_params': 'task_params_1',
'task_hash': 'task_hash_1',
'task_log': 'task_log_1'
}
0: {'task_name': 'task', 'last_modified': 'last_modified_1', 'task_params': 'task_params_1', 'task_hash': 'task_hash_1', 'task_log': 'task_log_1'},
1: {'task_name': 'task', 'last_modified': 'last_modified_2', 'task_params': 'task_params_1', 'task_hash': 'task_hash_1', 'task_log': 'task_log_1'},
}
output = self.tb._get_tasks_dic(tasks_list=tasks_list)
self.assertDictEqual(output, target)
Expand All @@ -85,27 +62,31 @@ def test_get_task_df(self):
'last_modified': 'last_modified_1',
'task_params': 'task_params_1',
'task_hash': 'task_hash_1',
'task_log': 'task_log_1'
'task_log': 'task_log_1',
}
}

target = pd.DataFrame({
'task_id': ['Task1'],
'task_name': ['task_name_1'],
'last_modified': ['last_modified_1'],
'task_params': ['task_params_1'],
'task_hash': ['task_hash_1'],
'task_log': ['task_log_1']
})
target = pd.DataFrame(
{
'task_id': ['Task1'],
'task_name': ['task_name_1'],
'last_modified': ['last_modified_1'],
'task_params': ['task_params_1'],
'task_hash': ['task_hash_1'],
'task_log': ['task_log_1'],
}
)
output = self.tb.get_task_df(all_data=True)
pd.testing.assert_frame_equal(output, target)

target = pd.DataFrame({
'task_id': ['Task1'],
'task_name': ['task_name_1'],
'last_modified': ['last_modified_1'],
'task_params': ['task_params_1'],
})
target = pd.DataFrame(
{
'task_id': ['Task1'],
'task_name': ['task_name_1'],
'last_modified': ['last_modified_1'],
'task_params': ['task_params_1'],
}
)
output = self.tb.get_task_df(all_data=False)
pd.testing.assert_frame_equal(output, target)

Expand All @@ -116,15 +97,15 @@ def test_get_data(self):
'last_modified': 'last_modified_1',
'task_params': 'task_params_1',
'task_hash': 'task_hash_1',
'task_log': 'task_log_1'
'task_log': 'task_log_1',
},
'Task2': {
'task_name': 'task',
'last_modified': 'last_modified_2',
'task_params': 'task_params_2',
'task_hash': 'task_hash_2',
'task_log': 'task_log_2'
}
'task_log': 'task_log_2',
},
}
target = 'Task2'

Expand All @@ -139,22 +120,22 @@ def test_get_data_top_k(self):
'last_modified': 'last_modified_1',
'task_params': 'task_params_1',
'task_hash': 'task_hash_1',
'task_log': 'task_log_1'
'task_log': 'task_log_1',
},
'Task2': {
'task_name': 'task',
'last_modified': 'last_modified_2',
'task_params': 'task_params_2',
'task_hash': 'task_hash_2',
'task_log': 'task_log_2'
'task_log': 'task_log_2',
},
'Task3': {
'task_name': 'task',
'last_modified': 'last_modified_3',
'task_params': 'task_params_3',
'task_hash': 'task_hash_3',
'task_log': 'task_log_3'
}
'task_log': 'task_log_3',
},
}
target = ['Task3', 'Task2']

Expand All @@ -164,16 +145,8 @@ def test_get_data_top_k(self):

def test_load(self):
self.tb.tasks = {
'Task1': {
'task_log': {
'file_path': ['./hoge', './piyo']
}
},
'Task2': {
'task_log': {
'file_path': ['./hoge']
}
},
'Task1': {'task_log': {'file_path': ['./hoge', './piyo']}},
'Task2': {'task_log': {'file_path': ['./hoge']}},
}

source = 'Task1'
Expand All @@ -193,9 +166,7 @@ def test_target_load(self):
target = 'hoge'

def make_target(file_path):

class mock:

def __init__(self, file_path):
self.file_path = file_path

Expand Down
Loading