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

Create .pre-commit-config.yaml #5

Merged
merged 13 commits into from
Jan 3, 2024
Merged
37 changes: 23 additions & 14 deletions .ci_support/release.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
def get_setup_version_and_pattern(setup_content):
depend_lst, version_lst = [], []
for l in setup_content:
if '==' in l:
lst = l.split('[')[-1].split(']')[0].replace(' ', '').replace('"', '').replace("'", '').split(',')
if "==" in l:
lst = (
l.split("[")[-1]
.split("]")[0]
.replace(" ", "")
.replace('"', "")
.replace("'", "")
.split(",")
)
for dep in lst:
if dep != '\n':
version_lst.append(dep.split('==')[1])
depend_lst.append(dep.split('==')[0])
if dep != "\n":
version_lst.append(dep.split("==")[1])
depend_lst.append(dep.split("==")[0])

version_high_dict = {d: v for d, v in zip(depend_lst, version_lst)}
return version_high_dict
Expand All @@ -16,14 +23,14 @@ def get_env_version(env_content):
read_flag = False
depend_lst, version_lst = [], []
for l in env_content:
if 'dependencies:' in l:
if "dependencies:" in l:
read_flag = True
elif read_flag:
lst = l.replace('-', '').replace(' ', '').replace('\n', '').split("=")
lst = l.replace("-", "").replace(" ", "").replace("\n", "").split("=")
if len(lst) == 2:
depend_lst.append(lst[0])
version_lst.append(lst[1])
return {d:v for d, v in zip(depend_lst, version_lst)}
return {d: v for d, v in zip(depend_lst, version_lst)}


def update_dependencies(setup_content, version_low_dict, version_high_dict):
Expand All @@ -35,27 +42,29 @@ def update_dependencies(setup_content, version_low_dict, version_high_dict):
version_combo_dict[dep] = dep + "==" + ver

setup_content_new = ""
pattern_dict = {d:d + "==" + v for d, v in version_high_dict.items()}
pattern_dict = {d: d + "==" + v for d, v in version_high_dict.items()}
for l in setup_content:
for k, v in pattern_dict.items():
if v in l:
l = l.replace(v, version_combo_dict[k])
setup_content_new +=l
setup_content_new += l
return setup_content_new


if __name__ == "__main__":
with open('pyproject.toml', "r") as f:
with open("pyproject.toml", "r") as f:
setup_content = f.readlines()

with open('environment.yml', "r") as f:
with open("environment.yml", "r") as f:
env_content = f.readlines()

setup_content_new = update_dependencies(
setup_content=setup_content[2:],
version_low_dict=get_env_version(env_content=env_content),
version_high_dict=get_setup_version_and_pattern(setup_content=setup_content[2:]),
version_high_dict=get_setup_version_and_pattern(
setup_content=setup_content[2:]
),
)

with open('pyproject.toml', "w") as f:
with open("pyproject.toml", "w") as f:
f.writelines("".join(setup_content[:2]) + setup_content_new)
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.9
hooks:
- id: ruff
name: ruff lint
args: ["--fix"]
files: ^h5io_browser/
- id: ruff-format
name: ruff format
14 changes: 7 additions & 7 deletions h5io_browser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from h5io_browser.pointer import Pointer
from h5io_browser.base import (
delete_item,
list_hdf,
read_dict_from_hdf,
write_dict_to_hdf,
)
from h5io_browser.pointer import Pointer # noqa
from h5io_browser.base import ( # noqa
delete_item, # noqa
list_hdf, # noqa
read_dict_from_hdf, # noqa
write_dict_to_hdf, # noqa
) # noqa

from ._version import get_versions

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
setup(
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
)
)
Loading
Loading