diff --git a/.flake8 b/.flake8 new file mode 100644 index 000000000..6781ba03b --- /dev/null +++ b/.flake8 @@ -0,0 +1,23 @@ +[flake8] +extend-ignore = + E114, + E115, + E116, + E201, + E202, + E203, + E204, + E231, + E265, + E266, + E303, + E402, + E501, +exclude = + ; __init__.py # totally ignore __init__.py files + setup.py # ignore setup.py file + docs/ +#F401 ignore unused imports in __init__.py files +#F403 ignore unable to detect undefined names from import * +per-file-ignores = + __init__.py:F401,F403 \ No newline at end of file diff --git a/.github/linters/.flake8 b/.github/linters/.flake8 deleted file mode 100644 index e30e76b99..000000000 --- a/.github/linters/.flake8 +++ /dev/null @@ -1,2 +0,0 @@ -[flake8] -select: "F402,F404,F812,F823,F831,F821,F822,E112,E113,E901,E902,E999" diff --git a/.github/workflows/build-flake.yml b/.github/workflows/build-flake.yml deleted file mode 100644 index 3393b7908..000000000 --- a/.github/workflows/build-flake.yml +++ /dev/null @@ -1,40 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: Check module can be imported - -on: - push: - branches: [ "dev" ] - pull_request: - branches: [ "dev" ] - -permissions: - contents: read - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Set up Python 3.10 - uses: actions/setup-python@v3 - with: - python-version: "3.10" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test that the module imports - run: | - pip install . - python -c "import py4DSTEM; print(py4DSTEM.__version__)" diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 3e8071f6f..39fa51f72 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -1,4 +1,4 @@ -name: Check for errors with flake8 +name: Lint with super-linter@v5-slim on: push: @@ -17,9 +17,14 @@ jobs: fetch-depth: 0 - name: Lint Code Base - uses: github/super-linter@v4 + uses: super-linter/super-linter/slim@v5 # updated to latest slim as quicker to download env: - VALIDATE_ALL_CODEBASE: false - VALIDATE_PYTHON_FLAKE8: true - DEFAULT_BRANCH: "dev" - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VALIDATE_ALL_CODEBASE: false # only check changes + VALIDATE_PYTHON_FLAKE8: true # lint with flake8 + DEFAULT_BRANCH: "dev" # set default branch to dev + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # for github things + # FILTER_REGEX_EXCLUDE: .*test/.* # exclude test dirs + FILTER_REGEX_EXCLUDE: .*__init__.py/.* # exclude test dirs + FILTER_REGEX_INCLUDE: .*py4DSTEM/.* # only look for py4DSTEM + LINTER_RULES_PATH: / # set toplevel dir as the path to look for rules + PYTHON_FLAKE8_CONFIG_FILE: .flake8 # set specific config file \ No newline at end of file diff --git a/py4DSTEM/process/diffraction/crystal.py b/py4DSTEM/process/diffraction/crystal.py index fb2911992..9d29c69f1 100644 --- a/py4DSTEM/process/diffraction/crystal.py +++ b/py4DSTEM/process/diffraction/crystal.py @@ -34,7 +34,6 @@ class Crystal: save_ang_file, symmetry_reduce_directions, orientation_map_to_orix_CrystalMap, - save_ang_file, ) from py4DSTEM.process.diffraction.crystal_viz import ( @@ -433,41 +432,31 @@ def from_unitcell_parameters( elif lattice_type == "hexagonal": assert ( len(latt_params) == 2 - ), "2 lattice parametere are expected for hexagonal: a, c, but given {len(latt_params)}".format( - len(latt_params) - ) + ), f"2 lattice parametere are expected for hexagonal: a, c, but given {len(latt_params)}" lattice = mg.core.Lattice.hexagonal(latt_params[0], latt_params[1]) elif lattice_type == "tetragonal": assert ( len(latt_params) == 2 - ), "2 lattice parametere are expected for tetragonal: a, c, but given {len(latt_params)}".format( - len(latt_params) - ) + ), f"2 lattice parametere are expected for tetragonal: a, c, but given {len(latt_params)}" lattice = mg.core.Lattice.tetragonal(latt_params[0], latt_params[1]) elif lattice_type == "orthorhombic": assert ( len(latt_params) == 3 - ), "3 lattice parametere are expected for orthorhombic: a, b, c, but given {len(latt_params)}".format( - len(latt_params) - ) + ), f"3 lattice parametere are expected for orthorhombic: a, b, c, but given {len(latt_params)}" lattice = mg.core.Lattice.orthorhombic( latt_params[0], latt_params[1], latt_params[2] ) elif lattice_type == "monoclinic": assert ( len(latt_params) == 4 - ), "4 lattice parametere are expected for monoclinic: a, b, c, beta, but given {len(latt_params)}".format( - len(latt_params) - ) + ), f"4 lattice parametere are expected for monoclinic: a, b, c, beta, but given {len(latt_params)}" lattice = mg.core.Lattice.monoclinic( latt_params[0], latt_params[1], latt_params[2], latt_params[3] ) else: assert ( len(latt_params) == 6 - ), "all 6 lattice parametere are expected: a, b, c, alpha, beta, gamma, but given {len(latt_params)}".format( - len(latt_params) - ) + ), f"all 6 lattice parametere are expected: a, b, c, alpha, beta, gamma, but given {len(latt_params)}" lattice = mg.core.Lattice.from_parameters( latt_params[0], latt_params[1], @@ -659,9 +648,6 @@ def generate_diffraction_pattern( print("Accelerating voltage not set. Assuming 300 keV!") self.setup_diffraction(300e3) - # Tolerance for angular tests - tol = 1e-6 - # Parse orientation inputs if orientation is not None: if ind_orientation is None: @@ -720,9 +706,9 @@ def generate_diffraction_pattern( gy_proj = g_diff[1, keep_int] # Diffracted peak labels - h = hkl[0, keep_int] - k = hkl[1, keep_int] - l = hkl[2, keep_int] + h = hkl[0, keep_int] # noqa: E741 + k = hkl[1, keep_int] # noqa: E741 + l = hkl[2, keep_int] # noqa: E741 # Output as PointList if keep_qz: @@ -815,9 +801,7 @@ def generate_ring_pattern( ) # check accelerating voltage - if hasattr(self, "accel_voltage"): - accelerating_voltage = self.accel_voltage - else: + if not hasattr(self, "accel_voltage"): self.accel_voltage = 300e3 print("Accelerating voltage not set. Assuming 300 keV!")