Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 0 additions & 53 deletions .appveyor.yml

This file was deleted.

2 changes: 0 additions & 2 deletions .bandit

This file was deleted.

8 changes: 0 additions & 8 deletions .coveragerc.in

This file was deleted.

55 changes: 55 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: CI

on: [ push, pull_request ]

jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.9" ]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v3
name: Configure pip caching
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
pip install -e '.[dev]'
- name: Run lint
run: |
pre-commit run --all-files --show-diff-on-failure

test:
strategy:
matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11" ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v3
name: Configure pip caching
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
pip install -e '.[dev]'
- name: Run tests
run: |
pytest
2 changes: 1 addition & 1 deletion .github/workflows/renovate-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '12'
node-version: '16'
- name: Install Dependencies
run: npm install -g renovate
- name: Test
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ __pycache__/
*.egg-info
/build
/dist
/flake8_executable/_version.py
/tests/.pytest_cache/
3 changes: 0 additions & 3 deletions .mypy.ini

This file was deleted.

41 changes: 41 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
repos:
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-executable
- bandit
- flake8-bugbear
- flake8-comprehensions
- flake8-simplify
args: [ "--max-line-length", "120" ]
exclude: "tests/to-be-tested/"
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.991'
hooks:
- id: mypy
args: ["--disallow-untyped-defs", "--show-error-codes"]
exclude: "tests/"
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
exclude: "tests/to-be-tested/"
- repo: https://github.com/pycqa/isort
rev: 5.11.4
hooks:
- id: isort
args: [ "--profile", "black", "-w", "88" ]
exclude: "tests/to-be-tested/"
- repo: https://github.com/asottile/yesqa
rev: v1.4.0
hooks:
- id: yesqa
exclude: "tests/to-be-tested/"
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [ "--py37-plus" ]
exclude: "tests/to-be-tested/"
14 changes: 5 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
# Contributing

To start developing, first create a virtual environment. Inside the virtual environment, install all development
dependencies:

pip install -U -r requirements-dev.txt

Alternatively, install `tox` first. Then, let tox create the virtual environment for you:

pip install -U --user tox
tox -e dev
. .tox/dev/bin/activate # activate the virtual environment
pip install -U .[dev]

To run lint:

tox -e lint
pre-commit run --all-files

To run runtime tests:

tox --skip-missing-interpreters
pytest
37 changes: 34 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
[![Pyversions](https://img.shields.io/pypi/pyversions/flake8-executable.svg?style=flat-square)](https://pypi.python.org/pypi/flake8-executable)
![PyPI](https://img.shields.io/pypi/v/flake8-executable.svg)
![PyPI - Downloads](https://img.shields.io/pypi/dm/flake8-executable)
[![Build Status](https://ci.appveyor.com/api/projects/status/h6mucl894w6dx7d0?svg=true)](https://ci.appveyor.com/project/xuhdev/flake8-executable)
[![Build Status](https://github.com/sbrugman/flake8-executable/actions/workflows/ci.yml/badge.svg)](https://github.com/sbrugman/flake8-executable/actions/workflows/ci.yml)

Very often, developers mess up the executable permissions and shebangs of Python files. For example,
sometimes the executable permission was accidentally granted, sometimes it is forgotten.
sometimes the executable permission was accidentally granted, sometimes it is forgotten. Moreover,
this should be consistent with [Top-level code environment][] checks.

This is a [Flake8][] plugin that ensures the executable permissions and shebangs of Python files are
correctly set. Specifically, it checks the following errors:
Expand All @@ -16,21 +17,50 @@ correctly set. Specifically, it checks the following errors:
- EXE003: Shebang is present but does not contain "python".
- EXE004: There is whitespace before shebang.
- EXE005: There are blank or comment lines before shebang.
- EXE006: Found shebang, but no \_\_name\_\_ == '\_\_main\_\_' or \_\_main\_\_.py.
- EXE007: The file is executable, but no \_\_name\_\_ == '\_\_main\_\_' or \_\_main\_\_.py.

## Error codes overview

| Shebang | Executable* | \_\_main\_\_ | Error code |
|---------|-------------|--------------|-------------------------------------|
| ✅ | ✅ | ✅ | Complete, no issues |
| ✅ | ✅ | ❌ | EXE007 |
| ✅ | ❌ | ✅ | EXE001 |
| ✅ | ❌ | ❌ | EXE001, EXE006 |
| ❌ | ✅ | ✅ | EXE002 |
| ❌ | ✅ | ❌ | EXE002, EXE007 |
| ❌ | ❌ | ✅ | Shebang and executable are optional |
| ❌ | ❌ | ❌ | No issue |

(*) Executable bit is ignored on Windows

## Installation

Run:

pip install flake8-executable

Or through `pre-commit` with the `.pre-commit-config.yaml`:

```yaml
repos:
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0 # replace with the latest flake8 release
hooks:
- id: flake8
additional_dependencies:
- flake8-executable
```

## Usage

Normally, after flake8-executable is installed, invoking flake8 will also run this plugin. For more
details, check out the [Flake8 plugin page][].

## Copyright and License

Copyright (c) 2019 Hong Xu <hong@topbug.net>
Copyright (c) 2019 Hong Xu <hong@topbug.net>, 2023 Simon Brugman

flake8-executable is free software: you can redistribute it and/or modify it under the terms of the
GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of
Expand All @@ -47,3 +77,4 @@ flake8-executable. If not, see <https://www.gnu.org/licenses/>.

[Flake8]: https://flake8.pycqa.org/
[Flake8 plugin page]: https://flake8.pycqa.org/en/latest/user/using-plugins.html
[Top-level code environment]: https://docs.python.org/3/library/__main__.html
Loading