@@ -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
277277AUTO_CONFIG = not os .path .isfile ('Setup' ) and not no_compilation
278278if 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' )
875783class DocsCommand (Command ):
876784 """ For building the pygame-ce documentation with `python setup.py docs`.
0 commit comments