Skip to content

Commit

Permalink
pre-commit: sort Python includes (PEP8) (openPMD#1175)
Browse files Browse the repository at this point in the history
* pre-commit: sort Python includes (PEP8)

Sort Python includes according to PEP8

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
ax3l and pre-commit-ci[bot] authored Jan 15, 2022
1 parent dcf4bf0 commit 0bcc5b2
Show file tree
Hide file tree
Showing 27 changed files with 78 additions and 43 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ trim_trailing_whitespace = false
# TABs are part of its syntax
indent_style = tab
indent_size = unset


[*.py]
# isort config
force_sort_within_sections = true
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,32 @@ repos:
# C++ formatting
# clang-format

# Autoremoves unused Python imports
- repo: https://github.com/hadialqattan/pycln
rev: v1.1.0
hooks:
- id: pycln
name: pycln (python)

# Sorts Python imports according to PEP8
# https://www.python.org/dev/peps/pep-0008/#imports
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python)

# Python: Flake8 (checks only, does this support auto-fixes?)
#- repo: https://github.com/PyCQA/flake8
# rev: 4.0.1
# hooks:
# - id: flake8
# additional_dependencies: &flake8_dependencies
# - flake8-bugbear
# - pep8-naming
# exclude: ^(docs/.*|tools/.*)$
# Alternatively: use autopep8?

# Python Formatting
#- repo: https://github.com/psf/black
# rev: 21.10b0 # Keep in sync with blacken-docs
Expand Down
2 changes: 2 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#
import os
import subprocess

from recommonmark.parser import CommonMarkParser

# import sys
# sys.path.insert(0, os.path.abspath('.'))

Expand Down
3 changes: 2 additions & 1 deletion examples/10_streaming_read.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env python
import json
import openpmd_api as io
import sys

import openpmd_api as io

# pass-through for ADIOS2 engine parameters
# https://adios2.readthedocs.io/en/latest/engines/engines.html
config = {'adios2': {'engine': {}, 'dataset': {}}}
Expand Down
5 changes: 3 additions & 2 deletions examples/10_streaming_write.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python
import json
import openpmd_api as io
import numpy as np
import sys

import numpy as np
import openpmd_api as io

# pass-through for ADIOS2 engine parameters
# https://adios2.readthedocs.io/en/latest/engines/engines.html
config = {'adios2': {'engine': {}, 'dataset': {}}}
Expand Down
10 changes: 6 additions & 4 deletions examples/11_particle_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
Authors: Axel Huebl, Dmitry Ganyushin
License: LGPLv3+
"""
import openpmd_api as io
import numpy as np
import sys

import numpy as np
import openpmd_api as io

try:
import pandas as pd
except ImportError:
print("pandas NOT found. Install pandas to run this example.")
sys.exit()
found_dask = False
try:
from dask.delayed import delayed
import dask.array as da
import dask
import dask.array as da
from dask.delayed import delayed
found_dask = True
except ImportError:
print("dask NOT found. Install dask to run the 2nd example.")
Expand Down
2 changes: 1 addition & 1 deletion examples/12_span_write.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import openpmd_api as io
import numpy as np
import openpmd_api as io


def span_write(filename):
Expand Down
4 changes: 2 additions & 2 deletions examples/13_write_dynamic_configuration.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python
import json
import openpmd_api as io
import numpy as np

import numpy as np
import openpmd_api as io

# This example demonstrates how to use JSON/TOML-based dynamic
# configuration for openPMD.
Expand Down
1 change: 0 additions & 1 deletion examples/2_read_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"""
import openpmd_api as io


if __name__ == "__main__":
series = io.Series("../samples/git-sample/data%T.h5",
io.Access.read_only)
Expand Down
1 change: 0 additions & 1 deletion examples/2a_read_thetaMode_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"""
import openpmd_api as io


if __name__ == "__main__":
series = io.Series("../samples/git-sample/thetaMode/data%T.h5",
io.Access.read_only)
Expand Down
3 changes: 1 addition & 2 deletions examples/3_write_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
Authors: Axel Huebl
License: LGPLv3+
"""
import openpmd_api as io
import numpy as np

import openpmd_api as io

if __name__ == "__main__":
# user input: size of matrix to write, default 3x3
Expand Down
3 changes: 1 addition & 2 deletions examples/3a_write_thetaMode_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
Authors: Axel Huebl
License: LGPLv3+
"""
import openpmd_api as io
import numpy as np

import openpmd_api as io

if __name__ == "__main__":
# open file for writing
Expand Down
3 changes: 1 addition & 2 deletions examples/3b_write_resizable_particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
Authors: Axel Huebl
License: LGPLv3+
"""
import openpmd_api as io
import numpy as np

import openpmd_api as io

if __name__ == "__main__":
# open file for writing
Expand Down
2 changes: 0 additions & 2 deletions examples/4_read_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
# on import: calls MPI_Init_thread()
# exit hook: calls MPI_Finalize()
from mpi4py import MPI

import openpmd_api as io


if __name__ == "__main__":
# also works with any other MPI communicator
comm = MPI.COMM_WORLD
Expand Down
4 changes: 1 addition & 3 deletions examples/5_write_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
# on import: calls MPI_Init_thread()
# exit hook: calls MPI_Finalize()
from mpi4py import MPI

import openpmd_api as io
import numpy as np

import openpmd_api as io

if __name__ == "__main__":
# also works with any other MPI communicator
Expand Down
6 changes: 3 additions & 3 deletions examples/7_extended_write_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
Authors: Axel Huebl, Fabian Koller
License: LGPLv3+
"""
from openpmd_api import Series, Access, Dataset, Mesh_Record_Component, \
Unit_Dimension
import json
import numpy as np

import numpy as np
from openpmd_api import (Access, Dataset, Mesh_Record_Component, Series,
Unit_Dimension)

SCALAR = Mesh_Record_Component.SCALAR

Expand Down
5 changes: 2 additions & 3 deletions examples/9_particle_write_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
Authors: Axel Huebl
License: LGPLv3+
"""
from openpmd_api import Series, Access, Dataset, Mesh_Record_Component, \
Unit_Dimension
import numpy as np

from openpmd_api import (Access, Dataset, Mesh_Record_Component, Series,
Unit_Dimension)

SCALAR = Mesh_Record_Component.SCALAR

Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from distutils.version import LooseVersion
import os
import re
import sys
import platform
import re
import subprocess
import sys

from setuptools import setup, Extension
from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext
from distutils.version import LooseVersion


class CMakeExtension(Extension):
Expand Down
2 changes: 2 additions & 0 deletions src/binding/python/openpmd_api/DaskArray.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
License: LGPLv3+
"""
import math

import numpy as np

try:
from dask.array import from_array
found_dask = True
Expand Down
1 change: 1 addition & 0 deletions src/binding/python/openpmd_api/DaskDataFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
License: LGPLv3+
"""
import numpy as np

try:
import dask.dataframe as dd
from dask.delayed import delayed
Expand Down
2 changes: 2 additions & 0 deletions src/binding/python/openpmd_api/DataFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
License: LGPLv3+
"""
import math

import numpy as np

try:
import pandas as pd
found_pandas = True
Expand Down
7 changes: 3 additions & 4 deletions src/binding/python/openpmd_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from . import openpmd_api_cxx as cxx
from .openpmd_api_cxx import * # noqa
from .DataFrame import particles_to_dataframe
from .DaskDataFrame import particles_to_daskdataframe
from .DaskArray import record_component_to_daskarray

from .DaskDataFrame import particles_to_daskdataframe
from .DataFrame import particles_to_dataframe
from .openpmd_api_cxx import * # noqa

__version__ = cxx.__version__
__doc__ = cxx.__doc__
Expand Down
1 change: 1 addition & 0 deletions src/binding/python/openpmd_api/ls/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
License: LGPLv3+
"""
import sys

from ..openpmd_api_cxx import _ls_run


Expand Down
3 changes: 2 additions & 1 deletion src/binding/python/openpmd_api/pipe/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
Authors: Franz Poeschel
License: LGPLv3+
"""
from .. import openpmd_api_cxx as io
import argparse
import os # os.path.basename
import sys # sys.stderr.write

from .. import openpmd_api_cxx as io

# MPI is an optional dependency
try:
from mpi4py import MPI
Expand Down
3 changes: 2 additions & 1 deletion src/cli/pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
Authors: Franz Poeschel
License: LGPLv3+
"""
import openpmd_api.pipe.__main__ as pipe
import sys

import openpmd_api.pipe.__main__ as pipe

if __name__ == "__main__":
pipe.main()
sys.exit()
7 changes: 4 additions & 3 deletions test/python/unittest/API/APITest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
License: LGPLv3+
"""

import openpmd_api as io

import ctypes
import gc
import os
import shutil
import unittest
import ctypes

import openpmd_api as io

try:
import numpy as np
found_numpy = True
Expand Down
2 changes: 1 addition & 1 deletion test/python/unittest/Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
License: LGPLv3+
"""

import unittest
import sys
import unittest

# Import suites to run.
from API.APITest import APITest
Expand Down

0 comments on commit 0bcc5b2

Please sign in to comment.