Skip to content

Commit

Permalink
Merge pull request #1496 from pyiron/ruff
Browse files Browse the repository at this point in the history
ruff fixes
  • Loading branch information
jan-janssen authored Jul 18, 2024
2 parents 1668de1 + cd9e9f2 commit dc6fadd
Show file tree
Hide file tree
Showing 147 changed files with 4,150 additions and 1,951 deletions.
22 changes: 13 additions & 9 deletions .ci_support/pyironconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@

def main():
current_path = os.path.abspath(os.path.curdir)
top_level_path = current_path.replace('\\', '/')
resource_path = os.path.join(current_path, "tests", "static").replace('\\', '/')
pyiron_config = os.path.expanduser('~/.pyiron').replace('\\', '/')
top_level_path = current_path.replace("\\", "/")
resource_path = os.path.join(current_path, "tests", "static").replace("\\", "/")
pyiron_config = os.path.expanduser("~/.pyiron").replace("\\", "/")
if not os.path.exists(pyiron_config):
with open(pyiron_config, 'w') as f:
f.writelines(['[DEFAULT]\n',
'TOP_LEVEL_DIRS = ' + top_level_path + '\n',
'RESOURCE_PATHS = ' + resource_path + '\n'])
with open(pyiron_config, "w") as f:
f.writelines(
[
"[DEFAULT]\n",
"TOP_LEVEL_DIRS = " + top_level_path + "\n",
"RESOURCE_PATHS = " + resource_path + "\n",
]
)
else:
print('config exists')
print("config exists")


if __name__ == '__main__':
if __name__ == "__main__":
main()
37 changes: 23 additions & 14 deletions .ci_support/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,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 @@ -19,10 +26,10 @@ 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])
Expand All @@ -43,7 +50,7 @@ def update_dependencies(setup_content, version_low_dict, version_high_dict):
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


Expand All @@ -55,13 +62,13 @@ def convert_key(key, convert_dict):


if __name__ == "__main__":
with open('.ci_support/pypi_vs_conda_names.json', 'r') as f:
with open(".ci_support/pypi_vs_conda_names.json", "r") as f:
name_conversion_dict = {v: k for k, v in json.load(f).items()}

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()

env_version_dict = {
Expand All @@ -72,8 +79,10 @@ def convert_key(key, convert_dict):
setup_content_new = update_dependencies(
setup_content=setup_content[2:],
version_low_dict=env_version_dict,
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:
f.writelines("".join(setup_content[:2]) + setup_content_new)
with open("pyproject.toml", "w") as f:
f.writelines("".join(setup_content[:2]) + setup_content_new)
36 changes: 21 additions & 15 deletions .ci_support/update_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import yaml

environment_file = '.ci_support/environment.yml'
name_mapping_file = '.ci_support/pypi_vs_conda_names.json'
environment_file = ".ci_support/environment.yml"
name_mapping_file = ".ci_support/pypi_vs_conda_names.json"


class EnvironmentUpdater:
Expand All @@ -24,10 +24,10 @@ def __init__(self, package_name, from_version, to_version):
"""
self.from_version = from_version
self.to_version = to_version
with open(name_mapping_file, 'r') as f:
with open(name_mapping_file, "r") as f:
self._name_conversion_dict = json.load(f)

with open(environment_file, 'r') as f:
with open(environment_file, "r") as f:
self.environment = yaml.safe_load(f)

self.package_name = self._convert_package_name(package_name)
Expand All @@ -42,17 +42,19 @@ def _convert_package_name(self, name):
def _update_dependencies(self):
updated_dependencies = []

for dep in self.environment['dependencies']:
updated_dependencies.append(re.sub(
r'(' + self.package_name + '.*)' + self.from_version,
r'\g<1>' + self.to_version,
dep
))
for dep in self.environment["dependencies"]:
updated_dependencies.append(
re.sub(
r"(" + self.package_name + ".*)" + self.from_version,
r"\g<1>" + self.to_version,
dep,
)
)

self.environment['dependencies'] = updated_dependencies
self.environment["dependencies"] = updated_dependencies

def _write(self):
with open(environment_file, 'w') as f:
with open(environment_file, "w") as f:
yaml.safe_dump(self.environment, f)

def update_dependencies(self):
Expand All @@ -61,9 +63,13 @@ def update_dependencies(self):
self._write()


if len(sys.argv) != 7 or not (sys.argv[1] == 'Bump' and sys.argv[3] == 'from' and sys.argv[5] == 'to'):
raise ValueError(f"Title of a dependabot PR 'Bump <package> from <version> to <version>' expected, "
f"but got {' '.join(sys.argv[1:])}")
if len(sys.argv) != 7 or not (
sys.argv[1] == "Bump" and sys.argv[3] == "from" and sys.argv[5] == "to"
):
raise ValueError(
f"Title of a dependabot PR 'Bump <package> from <version> to <version>' expected, "
f"but got {' '.join(sys.argv[1:])}"
)
package_to_update = sys.argv[2]
from_version = sys.argv[4]
to_version = sys.argv[6]
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,3 @@ jobs:
- name: Coveralls
if: matrix.label == 'linux-64-py-3-12'
uses: coverallsapp/github-action@v2
- name: Codacy
if: matrix.label == 'linux-64-py-3-12' && github.event_name != 'push'
continue-on-error: True
shell: bash -l {0}
run: |
python-codacy-coverage -r coverage.xml
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.5.2
hooks:
- id: ruff
name: ruff lint
args: ["--select", "I", "--fix"]
files: ^pyiron_atomistics/
- id: ruff-format
name: ruff format
12 changes: 6 additions & 6 deletions pyiron_atomistics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from pyiron_atomistics.project import Project
from pyiron_atomistics.toolkit import AtomisticsTools
from pyiron_base import JOB_CLASS_DICT, Notebook, install_dialog
from pyiron_base import Project as ProjectBase

from pyiron_atomistics.atomistics.structure.atoms import (
Atoms,
ase_to_pyiron,
pyiron_to_ase,
Atoms,
)
from pyiron_base import Notebook, install_dialog, JOB_CLASS_DICT

from pyiron_base import Project as ProjectBase
from pyiron_atomistics.project import Project
from pyiron_atomistics.toolkit import AtomisticsTools

ProjectBase.register_tools("atomistics", AtomisticsTools)

Expand Down
7 changes: 4 additions & 3 deletions pyiron_atomistics/_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
"""

import unittest
from os.path import split, join
from os import remove
from pyiron_atomistics.project import Project
from abc import ABC
from inspect import getfile
from os import remove
from os.path import join, split

from pyiron_atomistics.project import Project

__author__ = "Liam Huber"
__copyright__ = (
Expand Down
2 changes: 1 addition & 1 deletion pyiron_atomistics/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"""Git implementation of _version.py."""

import errno
import functools
import os
import re
import subprocess
import sys
from typing import Any, Callable, Dict, List, Optional, Tuple
import functools


def get_keywords() -> Dict[str, str]:
Expand Down
1 change: 1 addition & 0 deletions pyiron_atomistics/atomistics/generic/object_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Distributed under the terms of "New BSD License", see the LICENSE file.

from __future__ import print_function

import importlib

__author__ = "Joerg Neugebauer, Jan Janssen"
Expand Down
21 changes: 12 additions & 9 deletions pyiron_atomistics/atomistics/job/atomistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@
# Distributed under the terms of "New BSD License", see the LICENSE file.

import copy
import warnings
import numpy as np
import numbers
import os
from typing import Callable, Union, Tuple
from ase.io import write as ase_write
import posixpath
import warnings
from functools import wraps
from typing import Callable, Tuple, Union

from pyiron_atomistics.atomistics.structure.atoms import Atoms
from pyiron_atomistics.atomistics.structure.neighbors import NeighborsTrajectory
from pyiron_atomistics.atomistics.structure.has_structure import HasStructure
import numpy as np
from ase.io import write as ase_write
from pyiron_base import (
GenericParameters,
GenericMaster,
GenericJob as GenericJobCore,
)
from pyiron_base import (
GenericMaster,
GenericParameters,
)
from pyiron_snippets.deprecate import deprecate
from pyiron_snippets.logger import logger

from pyiron_atomistics.atomistics.structure.atoms import Atoms
from pyiron_atomistics.atomistics.structure.has_structure import HasStructure
from pyiron_atomistics.atomistics.structure.neighbors import NeighborsTrajectory

try:
from pyiron_base import ProjectGUI
except (ImportError, TypeError, AttributeError):
Expand Down
8 changes: 5 additions & 3 deletions pyiron_atomistics/atomistics/job/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
# Distributed under the terms of "New BSD License", see the LICENSE file.

from collections import defaultdict

import numpy as np
from pyiron_base import state, InteractiveBase
from pyiron_atomistics.atomistics.structure.periodic_table import PeriodicTable
from pyiron_base import InteractiveBase, state

from pyiron_atomistics.atomistics.job.atomistic import (
AtomisticGenericJob,
GenericOutput,
)
from collections import defaultdict
from pyiron_atomistics.atomistics.structure.periodic_table import PeriodicTable

__author__ = "Osamu Waseda, Jan Janssen"
__copyright__ = (
Expand Down
3 changes: 2 additions & 1 deletion pyiron_atomistics/atomistics/job/interactivewrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

from pyiron_base import InteractiveWrapper as InteractiveWrapperBase
from pyiron_snippets.deprecate import deprecate
from pyiron_atomistics.atomistics.structure.atoms import ase_to_pyiron

from pyiron_atomistics.atomistics.structure.atoms import Atoms as PAtoms
from pyiron_atomistics.atomistics.structure.atoms import ase_to_pyiron

__author__ = "Osamu Waseda, Jan Janssen"
__copyright__ = (
Expand Down
4 changes: 3 additions & 1 deletion pyiron_atomistics/atomistics/job/potentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
An abstract Potential class to provide an easy access for the available potentials. Currently implemented for the
OpenKim https://openkim.org database.
"""
import pandas

import os

import pandas
from pyiron_base import state

__author__ = "Martin Boeckmann, Jan Janssen"
Expand Down
13 changes: 7 additions & 6 deletions pyiron_atomistics/atomistics/job/sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
# Distributed under the terms of "New BSD License", see the LICENSE file.

import itertools
import random
import warnings
import itertools

import numpy as np
from pyiron_base import DataContainer, GenericParameters, state
from pyiron_snippets.import_alarm import ImportAlarm
from structuretoolkit.build import sqs_structures

from pyiron_atomistics.atomistics.job.atomistic import AtomisticGenericJob
from pyiron_base import state, DataContainer, GenericParameters
from pyiron_snippets.import_alarm import ImportAlarm
from pyiron_atomistics.atomistics.structure.atoms import Atoms, ase_to_pyiron
import numpy as np


try:
from sqsgenerator import IterationMode, process_settings, sqs_optimize
from sqsgenerator.settings import BadSettings
from sqsgenerator import sqs_optimize, process_settings, IterationMode

import_alarm = ImportAlarm()
except ImportError:
Expand Down
1 change: 1 addition & 0 deletions pyiron_atomistics/atomistics/job/structurecontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from pyiron_base import DataContainer, GenericJob
from pyiron_snippets.deprecate import deprecate

from pyiron_atomistics.atomistics.job.atomistic import AtomisticGenericJob
from pyiron_atomistics.atomistics.structure.atoms import Atoms
from pyiron_atomistics.atomistics.structure.has_structure import HasStructure
Expand Down
9 changes: 5 additions & 4 deletions pyiron_atomistics/atomistics/master/elasticmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
from collections import OrderedDict

import numpy as np
import spglib
import scipy.constants
import spglib
from atomistics.workflows.elastic.elastic_moduli import ElasticProperties
from atomistics.workflows.elastic.helper import (
generate_structures_helper,
analyse_structures_helper,
generate_structures_helper,
)
from atomistics.workflows.elastic.elastic_moduli import ElasticProperties
from pyiron_atomistics.atomistics.master.parallel import AtomisticParallelMaster
from pyiron_base import JobGenerator

from pyiron_atomistics.atomistics.master.parallel import AtomisticParallelMaster

__author__ = "Yury Lysogorskiy"
__copyright__ = "Copyright 2020, Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department"
__version__ = "1.0"
Expand Down
Loading

0 comments on commit dc6fadd

Please sign in to comment.