Skip to content

Commit 8d59876

Browse files
authored
Merge pull request #2796 from cclauss/remove-lint-logic-from-setup.py
Remove lint logic from setup.py
2 parents 569b91a + 06533f6 commit 8d59876

File tree

2 files changed

+5
-97
lines changed

2 files changed

+5
-97
lines changed

.github/workflows/format-lint.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: python3 setup.py lint
22

33
# Run lint CI on changes to main branch, or any PR to main. Do not run CI on
44
# any other branch.
5-
# run only if there are changes on files that are linted (C, python and rst files)
5+
# Run only if there are changes on files that are linted (C, Python and rst files)
66
on:
77
push:
88
branches: main
@@ -43,10 +43,10 @@ jobs:
4343
- uses: actions/[email protected]
4444

4545
- name: Install deps
46-
run: python3 -m pip install pylint black clang-format sphinx"<7.2.0"
46+
run: python3 -m pip install pylint sphinx"<7.2.0"
4747

48-
- name: Check code Formatting and Linting
49-
run: python3 setup.py lint
48+
- name: Check code linting
49+
run: pylint src_py docs
5050

5151
- name: Check docs changes are checked in
5252
run: |

setup.py

Lines changed: 1 addition & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def consume_arg(name):
273273
if cython_only:
274274
sys.exit(0)
275275

276-
no_compilation = any(x in ['lint', 'format', 'docs'] for x in sys.argv)
276+
no_compilation = 'docs' in sys.argv
277277
AUTO_CONFIG = not os.path.isfile('Setup') and not no_compilation
278278
if consume_arg('-auto'):
279279
AUTO_CONFIG = True
@@ -779,98 +779,6 @@ def run(self):
779779
return subprocess.call([sys.executable, os.path.join('test', '__main__.py')])
780780

781781

782-
class LintFormatCommand(Command):
783-
""" Used for formatting or linting. See Lint and Format Sub classes.
784-
"""
785-
user_options = []
786-
lint = False
787-
format = False
788-
789-
def initialize_options(self):
790-
pass
791-
792-
def finalize_options(self):
793-
pass
794-
795-
def run(self):
796-
"""Check the existence and launch linters."""
797-
import subprocess
798-
import sys
799-
import warnings
800-
import pathlib
801-
802-
def check_linter_exists(linter):
803-
if shutil.which(linter) is None:
804-
msg = "Please install '%s' in your environment. (hint: 'python3 -m pip install %s')"
805-
warnings.warn(msg % (linter, linter))
806-
sys.exit(1)
807-
808-
def filter_files(path_obj, all_files, allowed_files, disallowed_files):
809-
files = []
810-
for file in all_files:
811-
for disallowed in disallowed_files:
812-
if file.match(str(path_obj / disallowed)):
813-
break
814-
else: # no-break
815-
files.append(str(file))
816-
continue
817-
818-
for allowed in allowed_files:
819-
if file.match(str(path_obj / allowed)):
820-
files.append(str(file))
821-
break
822-
823-
return files
824-
825-
path_obj = pathlib.Path(path, "src_c")
826-
c_files_unfiltered = path_obj.glob("**/*.[ch]")
827-
c_file_disallow = [
828-
"_sdl2/**",
829-
"pypm.c",
830-
"**/sse2neon.h",
831-
"doc/**",
832-
]
833-
c_file_allow = ["_sdl2/touch.c"]
834-
c_files = filter_files(path_obj, c_files_unfiltered, c_file_allow, c_file_disallow)
835-
836-
837-
# Other files have too many issues for now. setup.py, buildconfig, etc
838-
python_directories = ["src_py", "test", "examples", "docs", "--exclude", "docs/reST"]
839-
if self.lint:
840-
commands = {
841-
"clang-format": ["--dry-run", "--Werror", "-i"] + c_files,
842-
"black": ["--check", "--diff"] + python_directories,
843-
# Test directory has too much pylint warning for now
844-
"pylint": ["src_py", "docs"],
845-
}
846-
else:
847-
commands = {
848-
"clang-format": ["-i"] + c_files,
849-
"black": python_directories,
850-
}
851-
852-
formatters = ["black", "clang-format"]
853-
for linter, option in commands.items():
854-
print(" ".join([linter] + option))
855-
check_linter_exists(linter)
856-
result = subprocess.run([linter] + option)
857-
if result.returncode:
858-
msg = f"'{linter}' failed."
859-
msg += " Please run: python setup.py format" if linter in formatters else ""
860-
msg += f" Do you have the latest version of {linter}?"
861-
raise SystemExit(msg)
862-
863-
864-
@add_command("lint")
865-
class LintCommand(LintFormatCommand):
866-
lint = True
867-
868-
869-
@add_command("format")
870-
class FormatCommand(LintFormatCommand):
871-
format = True
872-
873-
874782
@add_command('docs')
875783
class DocsCommand(Command):
876784
""" For building the pygame-ce documentation with `python setup.py docs`.

0 commit comments

Comments
 (0)