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 3bf56d698..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@v4 - - name: Set up Python 3.10 - uses: actions/setup-python@v5 - 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 deleted file mode 100644 index 550998606..000000000 --- a/.github/workflows/linter.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Check for errors with flake8 - -on: - push: - branches: [ "dev" ] - pull_request: - branches: [ "dev" ] - -jobs: - run-lint: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - # Full git history is needed to get a proper list of changed files within `super-linter` - fetch-depth: 0 - - - name: Lint Code Base - uses: github/super-linter@v6 - env: - VALIDATE_ALL_CODEBASE: false - VALIDATE_PYTHON_FLAKE8: true - DEFAULT_BRANCH: "dev" - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml new file mode 100644 index 000000000..fb71c3bae --- /dev/null +++ b/.github/workflows/ruff.yml @@ -0,0 +1,40 @@ +name: Ruff Check + +on: + push: + pull_request: + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Get all commits + + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v35 + with: + files: '**/*.py' # Adjust pattern for your file types + + - name: Setup Python environment + uses: actions/setup-python@v3 + + - name: Install Ruff + run: pip install ruff + + - name: Run Ruff on changed files + env: + ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} + run: | + - run: | + if [ -n "${ALL_CHANGED_FILES}" ]; then + # for file in ${ALL_CHANGED_FILES}; do + # echo "$file was changed" + # done + ruff check ${ALL_CHANGED_FILES} + else + echo "No files changed" + fi + diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a90d54b54..bedc2082e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: hooks: - id: black language_version: python3.9 - - repo: https://github.com/pycqa/flake8 - rev: '6.1.0' + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.5.0 hooks: - - id: flake8 \ No newline at end of file + - id: ruff \ No newline at end of file diff --git a/py4DSTEM/__init__.py b/py4DSTEM/__init__.py index d5df63f5e..429ef8d84 100644 --- a/py4DSTEM/__init__.py +++ b/py4DSTEM/__init__.py @@ -1,7 +1,6 @@ from py4DSTEM.version import __version__ from emdfile import tqdmnd - ### io # substructure diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 000000000..237ab5039 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,51 @@ +required-version = ">=0.5.0" +target-version = "py311" +[lint] +# From Flake8 config +# select = [ +# # "F402", # module level import not at top of file +# # "F404", # future import not at top of file +# # # "F812", # list comprehension redefines name from outer scope +# # "F823", # local variable name referenced before assignment +# # # "F831", # duplicate argument name in function definition +# # "F821", # undefined name +# # "F822", # undefined name in __all__ +# # "E112", # expected an indented block +# # "E902", # IOError +# # # "E999", # SyntaxError deprecated since +# ] + +ignore = [ + "E501", # line-too-long + "F401", # unused import + + # exisiting errors in code base + # "E721", # do not compare types, use 'isinstance()' + # "F841", # local variable is assigned to but never used + # "E741", # ambiguous variable name + # "F541", # f-string is missing placeholders + # "E731", # do not assign a lambda expression, use a def + # "E714", # test for object identity should be 'is not' + # "F811", # redefinition of unused name + # "E722", # do not use bare except + # "F405", # name may be undefined, or defined from star imports + # "F523", # string-dot-format-extra-positional-argument + # "F403", # unable to detect undefined names + # "F524", # string-dot-format-missing-arguments + # "E402", # module level import not at top of file + # "E713", # test for membership should be 'not in' + # "E743", # ambiguous function name + # "E712", # true-false-comparison + +] + +exclude = ["test/**/*.py"] # ignore test files + +[lint.per-file-ignores] +# Ignore specific lint errors for __init__.py files +"**/__init__.py" = [ + "F401", # Unspecified import + "F403", # Unable to detect undefined names + "E402" # Module level import not at top of file +] +# "./test/**/*.py" = ["E501", "F401", "E402"] # line-too-long, unused import, import not at top of file