From 71f94ffca337ffea33a88fdd56ca712c08cf521d Mon Sep 17 00:00:00 2001 From: gnikit Date: Tue, 10 May 2022 11:31:12 +0100 Subject: [PATCH 1/9] Add pre-commit Fixes #106 --- .pre-commit-config.yaml | 18 ++++++++++++++++++ setup.cfg | 1 + 2 files changed, 19 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..01a8925b --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,18 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files +- repo: https://github.com/psf/black + rev: 22.3.0 + hooks: + - id: black +- repo: https://gitlab.com/pycqa/flake8 + rev: 4.0.1 + hooks: + - id: flake8 diff --git a/setup.cfg b/setup.cfg index 03b6d826..15fafecb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -56,6 +56,7 @@ dev = pytest-cov >= 2.12.1 black isort + pre-commit docs = sphinx >= 4.0.0 sphinx_rtd_theme From 47b638aebcf8a3aa700dff9312e127a225ff754c Mon Sep 17 00:00:00 2001 From: gnikit Date: Tue, 10 May 2022 11:31:46 +0100 Subject: [PATCH 2/9] Run `pre-commit run --all-files` --- .coveragerc | 4 ++-- .gitignore | 4 ++-- CONTRIBUTING.md | 2 +- docs/Makefile | 2 +- docs/editor_integration.rst | 2 -- docs/options.rst | 4 ++-- test/test_source/.fortls | 2 +- test/test_source/diag/test_contains.f90 | 2 +- test/test_source/diag/test_external.f90 | 2 +- test/test_source/diag/test_implicit_none.f90 | 2 +- test/test_source/diag/test_lines.f90 | 2 +- test/test_source/diag/test_scope_end_name_var.f90 | 2 +- test/test_source/diag/test_semicolon.f90 | 2 +- test/test_source/diag/test_visibility.f90 | 2 +- test/test_source/docs/test_doxygen.f90 | 4 ++-- test/test_source/docs/test_ford.f90 | 2 +- test/test_source/excldir/sub1/tmp.f90 | 4 ++-- test/test_source/hover/associate_block.f90 | 2 +- test/test_source/hover/parameters.f90 | 2 +- test/test_source/hover/pointers.f90 | 2 +- test/test_source/hover/recursive.f90 | 2 +- test/test_source/hover/spaced_keywords.f90 | 2 +- test/test_source/pp/include/petscpc.h | 4 ++-- test/test_source/pp/preproc.F90 | 2 +- test/test_source/pp/preproc_keywords.F90 | 4 ++-- test/test_source/rename/test_rename_intrinsic.f90 | 2 +- test/test_source/subdir/test_rename.F90 | 2 +- test/test_source/subdir/test_vis.f90 | 2 +- 28 files changed, 34 insertions(+), 36 deletions(-) diff --git a/.coveragerc b/.coveragerc index b3c2823f..4109acf6 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,6 +1,6 @@ [run] dynamic_context = test_function -omit = +omit = fortls/__init__.py fortls/version.py @@ -9,4 +9,4 @@ exclude_lines = if debug: log.debug except: - if not PY3K: \ No newline at end of file + if not PY3K: diff --git a/.gitignore b/.gitignore index 241dc003..b32c18d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ *.pyc .vscode -*.egg-info +*.egg-info dist/ build/ docs/_build/ @@ -14,4 +14,4 @@ fortls/_version.py *.smod *.log -.coverage \ No newline at end of file +.coverage diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 97945037..435847a7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -40,7 +40,7 @@ pytest -v ``` This will run the entire unit test suite. You can also run this to verify that you haven't broken anything in the code. -👉 **Tip!** You can run individual tests by selecting the path to the Python file and the method +👉 **Tip!** You can run individual tests by selecting the path to the Python file and the method ```sh pytest test/test_interface.py::test_version_update_pypi ``` diff --git a/docs/Makefile b/docs/Makefile index aaa17963..bbc97288 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -6,7 +6,7 @@ SPHINXOPTS ?= SPHINXBUILD ?= sphinx-build SPHINXAPIDOC ?= sphinx-apidoc -PANDOC ?= pandoc +PANDOC ?= pandoc SOURCEDIR = . BUILDDIR = _build diff --git a/docs/editor_integration.rst b/docs/editor_integration.rst index 31e1241e..80b18f0c 100644 --- a/docs/editor_integration.rst +++ b/docs/editor_integration.rst @@ -120,5 +120,3 @@ Edit your kakrc config to enable kak-lsp, adding fortran as a filetype: hook global WinSetOption filetype=(fortran) %{ lsp-enable-window } - - diff --git a/docs/options.rst b/docs/options.rst index 153b7952..42e8ed53 100644 --- a/docs/options.rst +++ b/docs/options.rst @@ -108,7 +108,7 @@ incl_suffixes .F .f .F03 .f03 .F05 .f05 .F08 .f08 .F18 .f18 .F77 .f77 .F90 .f90 .F95 .f95 .FOR .for .FPP .fpp. Additional source file extensions can be defined in ``incl_suffixes``. -.. note:: The default file extensions cannot be overwritten. ``incl_suffixes`` will only append to the default extensions. +.. note:: The default file extensions cannot be overwritten. ``incl_suffixes`` will only append to the default extensions. excl_suffixes @@ -187,7 +187,7 @@ pp_defs } } -Additional **preprocessor definitions** from what are specified in files found in +Additional **preprocessor definitions** from what are specified in files found in ``include_dirs`` can be defined in ``pp_defs``. .. note:: Definitions in ``pp_defs`` will override definitions from ``include_dirs`` diff --git a/test/test_source/.fortls b/test/test_source/.fortls index 06f03f00..9bf0936d 100644 --- a/test/test_source/.fortls +++ b/test/test_source/.fortls @@ -9,4 +9,4 @@ "rename" ] -} \ No newline at end of file +} diff --git a/test/test_source/diag/test_contains.f90 b/test/test_source/diag/test_contains.f90 index 27aacf6e..34e46e4f 100644 --- a/test/test_source/diag/test_contains.f90 +++ b/test/test_source/diag/test_contains.f90 @@ -3,4 +3,4 @@ program test_contains contains contains end program test_contains -contains \ No newline at end of file +contains diff --git a/test/test_source/diag/test_external.f90 b/test/test_source/diag/test_external.f90 index f7d91abe..1634920a 100644 --- a/test/test_source/diag/test_external.f90 +++ b/test/test_source/diag/test_external.f90 @@ -8,4 +8,4 @@ program test_external EXTERNAL VAR_B ! throw error REAL VAR_A ! throw error EXTERNAL VAR_C -end program test_external \ No newline at end of file +end program test_external diff --git a/test/test_source/diag/test_implicit_none.f90 b/test/test_source/diag/test_implicit_none.f90 index d45309ed..0c9af40e 100644 --- a/test/test_source/diag/test_implicit_none.f90 +++ b/test/test_source/diag/test_implicit_none.f90 @@ -1,5 +1,5 @@ program test_imp implicit none - + end program test_imp implicit none diff --git a/test/test_source/diag/test_lines.f90 b/test/test_source/diag/test_lines.f90 index b7838893..01711bc0 100644 --- a/test/test_source/diag/test_lines.f90 +++ b/test/test_source/diag/test_lines.f90 @@ -2,4 +2,4 @@ program test_lines implicit none character(len=123) :: val = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sodales imperdiet dolor, sit amet venenatis magna dictum id." ! Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sodales imperdiet dolor, sit amet venenatis magna dictum id. -end program test_lines \ No newline at end of file +end program test_lines diff --git a/test/test_source/diag/test_scope_end_name_var.f90 b/test/test_source/diag/test_scope_end_name_var.f90 index de5790cb..d5692bec 100644 --- a/test/test_source/diag/test_scope_end_name_var.f90 +++ b/test/test_source/diag/test_scope_end_name_var.f90 @@ -4,4 +4,4 @@ program scope_end_named_var if (.true.) then end = 10 end if -end program scope_end_named_var \ No newline at end of file +end program scope_end_named_var diff --git a/test/test_source/diag/test_semicolon.f90 b/test/test_source/diag/test_semicolon.f90 index 146f624d..72318bcf 100644 --- a/test/test_source/diag/test_semicolon.f90 +++ b/test/test_source/diag/test_semicolon.f90 @@ -16,4 +16,4 @@ program test_semicolon print*, "one"; print*, str2 print*, a; print*, p; ! a; comment; that;contains; semi-colons -end program test_semicolon \ No newline at end of file +end program test_semicolon diff --git a/test/test_source/diag/test_visibility.f90 b/test/test_source/diag/test_visibility.f90 index 03f2064f..543d988a 100644 --- a/test/test_source/diag/test_visibility.f90 +++ b/test/test_source/diag/test_visibility.f90 @@ -1,4 +1,4 @@ program test_visibility implicit none end program test_visibility -public \ No newline at end of file +public diff --git a/test/test_source/docs/test_doxygen.f90 b/test/test_source/docs/test_doxygen.f90 index aa242491..3d96cc49 100644 --- a/test/test_source/docs/test_doxygen.f90 +++ b/test/test_source/docs/test_doxygen.f90 @@ -1,6 +1,6 @@ module test_doxygen implicit none - + contains !> @brief inserts a value into an ordered array @@ -32,4 +32,4 @@ pure function calc_angle(v, w) result (theta) real :: theta end function calc_angle -end module test_doxygen \ No newline at end of file +end module test_doxygen diff --git a/test/test_source/docs/test_ford.f90 b/test/test_source/docs/test_ford.f90 index b5424d41..452a7e4a 100644 --- a/test/test_source/docs/test_ford.f90 +++ b/test/test_source/docs/test_ford.f90 @@ -19,4 +19,4 @@ subroutine feed_pets(cats, dogs, food, angry) return end subroutine feed_pets -end module test_fortd \ No newline at end of file +end module test_fortd diff --git a/test/test_source/excldir/sub1/tmp.f90 b/test/test_source/excldir/sub1/tmp.f90 index e3bb39ba..9a2422a5 100644 --- a/test/test_source/excldir/sub1/tmp.f90 +++ b/test/test_source/excldir/sub1/tmp.f90 @@ -9,7 +9,7 @@ module oumods FINAL :: del_ex_type PROCEDURE :: sub => ex_sub END TYPE ex_type - + contains subroutine zI12(t,c,alpha,beta,r) complex(c_double_complex) c,r, x,y,z @@ -19,4 +19,4 @@ subroutine zI12(t,c,alpha,beta,r) & /2._c_double )) / (c / exp((z + cmplx(0._c_double,3.14159265358979324_c_double,kind(1._c_double)))/2._c_double)) r = beta*r+alpha*((t*y - x)/c) end subroutine -end module \ No newline at end of file +end module diff --git a/test/test_source/hover/associate_block.f90 b/test/test_source/hover/associate_block.f90 index ef4a6507..30994308 100644 --- a/test/test_source/hover/associate_block.f90 +++ b/test/test_source/hover/associate_block.f90 @@ -10,4 +10,4 @@ PROGRAM test_associate_block ASSOCIATE (ARRAY => B(:,1)) ARRAY (3) = ARRAY (1) + ARRAY (2) END ASSOCIATE -END PROGRAM test_associate_block \ No newline at end of file +END PROGRAM test_associate_block diff --git a/test/test_source/hover/parameters.f90 b/test/test_source/hover/parameters.f90 index 7ede3436..e60f5cbc 100644 --- a/test/test_source/hover/parameters.f90 +++ b/test/test_source/hover/parameters.f90 @@ -9,4 +9,4 @@ program params logical(kind=8), parameter :: long_bool = .true. character(len=5), parameter :: sq_str = '12345' character(len=5), parameter :: dq_str = "12345" -end program params \ No newline at end of file +end program params diff --git a/test/test_source/hover/pointers.f90 b/test/test_source/hover/pointers.f90 index 9beef061..f19f4748 100644 --- a/test/test_source/hover/pointers.f90 +++ b/test/test_source/hover/pointers.f90 @@ -1,3 +1,3 @@ program pointers INTEGER, POINTER :: val1 -end program \ No newline at end of file +end program diff --git a/test/test_source/hover/recursive.f90 b/test/test_source/hover/recursive.f90 index 50730816..fa9171ff 100644 --- a/test/test_source/hover/recursive.f90 +++ b/test/test_source/hover/recursive.f90 @@ -20,4 +20,4 @@ recursive subroutine recursive_assign_descending(node, vector, current_loc) end if return end subroutine recursive_assign_descending -end module tree \ No newline at end of file +end module tree diff --git a/test/test_source/hover/spaced_keywords.f90 b/test/test_source/hover/spaced_keywords.f90 index c7b60aa6..3342dee4 100644 --- a/test/test_source/hover/spaced_keywords.f90 +++ b/test/test_source/hover/spaced_keywords.f90 @@ -1,4 +1,4 @@ subroutine spaced_keywords(arg1, arg2) real, dimension (:, :), intent (in) :: arg1 real, dimension ( size(arg1, 1), maxval([size(arg1, 2), size(arg1, 1)]) ), intent (out) :: arg2 -end subroutine spaced_keywords \ No newline at end of file +end subroutine spaced_keywords diff --git a/test/test_source/pp/include/petscpc.h b/test/test_source/pp/include/petscpc.h index b57881b3..d6f9899b 100644 --- a/test/test_source/pp/include/petscpc.h +++ b/test/test_source/pp/include/petscpc.h @@ -5,9 +5,9 @@ #define PC type(tPC) #define PCType character*(80) -#define ewrite(priority, format) if (priority <= 3) write((priority), format) +#define ewrite(priority, format) if (priority <= 3) write((priority), format) #define ewrite2(priority, format) \ - if (priority <= 3) write((priority), format) + if (priority <= 3) write((priority), format) #define varVar \ 55 #endif diff --git a/test/test_source/pp/preproc.F90 b/test/test_source/pp/preproc.F90 index 5ed849c1..265bff68 100644 --- a/test/test_source/pp/preproc.F90 +++ b/test/test_source/pp/preproc.F90 @@ -11,4 +11,4 @@ program preprocessor print*, SUCCESS #endif -end program preprocessor \ No newline at end of file +end program preprocessor diff --git a/test/test_source/pp/preproc_keywords.F90 b/test/test_source/pp/preproc_keywords.F90 index c216b51e..1748456f 100644 --- a/test/test_source/pp/preproc_keywords.F90 +++ b/test/test_source/pp/preproc_keywords.F90 @@ -3,8 +3,8 @@ program test_preproc_keywords #ifdef HAVE_CONTIGUOUS , CONTIGUOUS & #endif -, POINTER :: & +, POINTER :: & var1(:), & var2(:) -end program test_preproc_keywords \ No newline at end of file +end program test_preproc_keywords diff --git a/test/test_source/rename/test_rename_intrinsic.f90 b/test/test_source/rename/test_rename_intrinsic.f90 index 4870b0dd..77e69b34 100644 --- a/test/test_source/rename/test_rename_intrinsic.f90 +++ b/test/test_source/rename/test_rename_intrinsic.f90 @@ -22,4 +22,4 @@ program driver integer :: sz call size(val, sz) ! This is fortran_sub and should be renamed print*, size(val) ! This is an intrinsic, should be skipped in renaming -end program driver \ No newline at end of file +end program driver diff --git a/test/test_source/subdir/test_rename.F90 b/test/test_source/subdir/test_rename.F90 index 8868e34f..52bc0911 100644 --- a/test/test_source/subdir/test_rename.F90 +++ b/test/test_source/subdir/test_rename.F90 @@ -12,5 +12,5 @@ subroutine test_rename_sub() implicit none ! localname = 4 -renamed_var2 = 4 +renamed_var2 = 4 end subroutine test_rename_sub diff --git a/test/test_source/subdir/test_vis.f90 b/test/test_source/subdir/test_vis.f90 index 4e50ec84..40144d2c 100644 --- a/test/test_source/subdir/test_vis.f90 +++ b/test/test_source/subdir/test_vis.f90 @@ -11,4 +11,4 @@ module test_vis_mod contains subroutine some_sub end subroutine some_sub -end module test_vis_mod \ No newline at end of file +end module test_vis_mod From cdec6d119c312b019ad798709f312b3386add40b Mon Sep 17 00:00:00 2001 From: gnikit Date: Tue, 10 May 2022 11:39:34 +0100 Subject: [PATCH 3/9] Adds pyupgrade in pre-commit --- .pre-commit-config.yaml | 12 ++++++--- fortls/__init__.py | 54 ++++++++++++++++++-------------------- fortls/helper_functions.py | 4 +-- fortls/objects.py | 2 +- test/test_interface.py | 18 ++++++------- 5 files changed, 45 insertions(+), 45 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 01a8925b..f4f6199c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,11 +8,15 @@ repos: - id: end-of-file-fixer - id: check-yaml - id: check-added-large-files -- repo: https://github.com/psf/black - rev: 22.3.0 - hooks: - - id: black - repo: https://gitlab.com/pycqa/flake8 rev: 4.0.1 hooks: - id: flake8 +- repo: https://github.com/asottile/pyupgrade + rev: v2.32.1 + hooks: + - id: pyupgrade +- repo: https://github.com/psf/black + rev: 22.3.0 + hooks: + - id: black diff --git a/fortls/__init__.py b/fortls/__init__.py index fd559ff0..6558f80c 100644 --- a/fortls/__init__.py +++ b/fortls/__init__.py @@ -86,18 +86,18 @@ def debug_server_general(args, settings): "Specified 'debug_rootpath' does not exist or is not a directory" ) print('\nTesting "initialize" request:') - print(' Root = "{0}"'.format(args.debug_rootpath)) + print(' Root = "{}"'.format(args.debug_rootpath)) s.serve_initialize({"params": {"rootPath": args.debug_rootpath}}) if len(s.post_messages) == 0: print(" Successful!") else: print(" Successful with errors:") for message in s.post_messages: - print(" {0}".format(message[1])) + print(" {}".format(message[1])) # Print module directories print("\n Source directories:") for source_dir in s.source_dirs: - print(" {0}".format(source_dir)) + print(" {}".format(source_dir)) # if args.debug_diagnostics: print('\nTesting "textDocument/publishDiagnostics" notification:') @@ -117,7 +117,7 @@ def debug_server_general(args, settings): sline = diag["range"]["start"]["line"] message = diag["message"] sev = sev_map[diag["severity"] - 1] - print(' {0:5d}:{1} "{2}"'.format(sline, sev, message)) + print(' {:5d}:{} "{}"'.format(sline, sev, message)) # if args.debug_symbols: print('\nTesting "textDocument/documentSymbol" request:') @@ -192,7 +192,7 @@ def debug_server_general(args, settings): else: for obj in completion_results: print( - " {0}: {1} -> {2}".format( + " {}: {} -> {}".format( obj["kind"], obj["label"], obj["detail"] ) ) @@ -220,11 +220,11 @@ def debug_server_general(args, settings): print(json.dumps(signature_results, indent=2)) else: active_param = signature_results.get("activeParameter", 0) - print(" Active param = {0}".format(active_param)) + print(" Active param = {}".format(active_param)) active_signature = signature_results.get("activeSignature", 0) - print(" Active sig = {0}".format(active_signature)) + print(" Active sig = {}".format(active_signature)) for i, signature in enumerate(signature_results["signatures"]): - print(" {0}".format(signature["label"])) + print(" {}".format(signature["label"])) for j, obj in enumerate(signature["parameters"]): if (i == active_signature) and (j == active_param): active_mark = "*" @@ -278,14 +278,14 @@ def debug_server_general(args, settings): if args.debug_full_result: print(json.dumps(definition_results, indent=2)) else: - print(' URI = "{0}"'.format(definition_results["uri"])) + print(' URI = "{}"'.format(definition_results["uri"])) print( - " Line = {0}".format( + " Line = {}".format( definition_results["range"]["start"]["line"] + 1 ) ) print( - " Char = {0}".format( + " Char = {}".format( definition_results["range"]["start"]["character"] + 1 ) ) @@ -345,7 +345,7 @@ def debug_server_general(args, settings): print("=======") for result in ref_results: print( - " {0} ({1}, {2})".format( + " {} ({}, {})".format( result["uri"], result["range"]["start"]["line"] + 1, result["range"]["start"]["character"] + 1, @@ -379,7 +379,7 @@ def debug_server_general(args, settings): print("=======") for uri, result in ref_results["changes"].items(): path = path_from_uri(uri) - print('File: "{0}"'.format(path)) + print('File: "{}"'.format(path)) file_obj = s.workspace.get(path) if file_obj is not None: file_contents = file_obj.contents_split @@ -388,11 +388,11 @@ def debug_server_general(args, settings): end_line = change["range"]["end"]["line"] start_col = change["range"]["start"]["character"] end_col = change["range"]["end"]["character"] - print(" {0}, {1}".format(start_line + 1, end_line + 1)) + print(" {}, {}".format(start_line + 1, end_line + 1)) new_contents = [] for i in range(start_line, end_line + 1): line = file_contents[i] - print(" - {0}".format(line)) + print(" - {}".format(line)) if i == start_line: new_contents.append( line[:start_col] + change["newText"] @@ -400,10 +400,10 @@ def debug_server_general(args, settings): if i == end_line: new_contents[-1] += line[end_col:] for line in new_contents: - print(" + {0}".format(line)) + print(" + {}".format(line)) print() else: - print('Unknown file: "{0}"'.format(path)) + print('Unknown file: "{}"'.format(path)) print("=======") # if args.debug_actions: @@ -434,12 +434,10 @@ def debug_server_general(args, settings): else: for result in action_results: print( - "Kind = '{0}', Title = '{1}'".format( - result["kind"], result["title"] - ) + "Kind = '{}', Title = '{}'".format(result["kind"], result["title"]) ) for editUri, editChange in result["edit"]["changes"].items(): - print("\nChange: URI = '{0}'".format(editUri)) + print("\nChange: URI = '{}'".format(editUri)) pp.pprint(editChange) print() tmpout.close() @@ -485,7 +483,7 @@ def debug_server_parser(args): print(f"Error while parsing '{args.config}' settings file") # print("\nTesting parser") - print(' File = "{0}"'.format(args.debug_filepath)) + print(' File = "{}"'.format(args.debug_filepath)) file_obj = fortran_file(args.debug_filepath, pp_suffixes) err_str, _ = file_obj.load_from_disk() if err_str: @@ -495,11 +493,11 @@ def debug_server_parser(args): file_ast = file_obj.parse(debug=True, pp_defs=pp_defs, include_dirs=include_dirs) print("\n=========\nObject Tree\n=========\n") for obj in file_ast.get_scopes(): - print("{0}: {1}".format(obj.get_type(), obj.FQSN)) + print("{}: {}".format(obj.get_type(), obj.FQSN)) print_children(obj) print("\n=========\nExportable Objects\n=========\n") for _, obj in file_ast.global_dict.items(): - print("{0}: {1}".format(obj.get_type(), obj.FQSN)) + print("{}: {}".format(obj.get_type(), obj.FQSN)) def check_request_params(args, loc_needed=True): @@ -508,17 +506,17 @@ def check_request_params(args, loc_needed=True): file_exists = os.path.isfile(args.debug_filepath) if file_exists is False: error_exit("Specified 'debug_filepath' does not exist") - print(' File = "{0}"'.format(args.debug_filepath)) + print(' File = "{}"'.format(args.debug_filepath)) if loc_needed: if args.debug_line is None: error_exit("'debug_line' not specified for debug request") - print(" Line = {0}".format(args.debug_line)) + print(" Line = {}".format(args.debug_line)) if args.debug_char is None: error_exit("'debug_char' not specified for debug request") - print(" Char = {0}\n".format(args.debug_char)) + print(" Char = {}\n".format(args.debug_char)) def print_children(obj, indent=""): for child in obj.get_children(): - print(" {0}{1}: {2}".format(indent, child.get_type(), child.FQSN)) + print(" {}{}: {}".format(indent, child.get_type(), child.FQSN)) print_children(child, indent + " ") diff --git a/fortls/helper_functions.py b/fortls/helper_functions.py index 6ba6b6d6..d2485afe 100644 --- a/fortls/helper_functions.py +++ b/fortls/helper_functions.py @@ -107,10 +107,10 @@ def strip_strings(in_line: str, maintain_len: bool = False) -> str: """ def repl_sq(m): - return "'{0}'".format(" " * (len(m.group()) - 2)) + return "'{}'".format(" " * (len(m.group()) - 2)) def repl_dq(m): - return '"{0}"'.format(" " * (len(m.group()) - 2)) + return '"{}"'.format(" " * (len(m.group()) - 2)) if maintain_len: out_line = FRegex.SQ_STRING.sub(repl_sq, in_line) diff --git a/fortls/objects.py b/fortls/objects.py index 05b01884..64cf0a00 100644 --- a/fortls/objects.py +++ b/fortls/objects.py @@ -1666,7 +1666,7 @@ def get_hover(self, long=False, include_doc=True, drop_arg=-1): if self.is_parameter() and self.param_val: hover_str += f" :: {self.name} = {self.param_val}" if include_doc and (doc_str is not None): - hover_str += "\n {0}".format("\n ".join(doc_str.splitlines())) + hover_str += "\n {}".format("\n ".join(doc_str.splitlines())) return hover_str, True def get_keywords(self): diff --git a/test/test_interface.py b/test/test_interface.py index 0d205d8d..db7137bd 100644 --- a/test/test_interface.py +++ b/test/test_interface.py @@ -28,10 +28,10 @@ def test_command_line_file_parsing_options(): "--source_dirs tmp ./local /usr/include/** --incl_suffixes .FF .fpc .h f20" " --excl_suffixes _tmp.f90 _h5hut_tests.F90 --excl_paths exclude tests".split() ) - assert args.source_dirs == set(["tmp", "./local", "/usr/include/**"]) + assert args.source_dirs == {"tmp", "./local", "/usr/include/**"} assert args.incl_suffixes == [".FF", ".fpc", ".h", "f20"] - assert args.excl_suffixes == set(["_tmp.f90", "_h5hut_tests.F90"]) - assert args.excl_paths == set(["exclude", "tests"]) + assert args.excl_suffixes == {"_tmp.f90", "_h5hut_tests.F90"} + assert args.excl_paths == {"exclude", "tests"} def test_command_line_autocomplete_options(): @@ -69,7 +69,7 @@ def test_command_line_preprocessor_options(): ' {"HAVE_PETSC":"","HAVE_ZOLTAN":"","Mat":"type(tMat)"}'.split() ) assert args.pp_suffixes == [".h", ".fh"] - assert args.include_dirs == set(["/usr/include/**", "./local/incl"]) + assert args.include_dirs == {"/usr/include/**", "./local/incl"} assert args.pp_defs == {"HAVE_PETSC": "", "HAVE_ZOLTAN": "", "Mat": "type(tMat)"} @@ -109,12 +109,10 @@ def test_config_file_general_options(): def test_config_file_dir_parsing_options(): server, r = unittest_server_init() # File parsing - assert server.source_dirs == set( - [f'{r/"subdir"}', f'{r/"pp"}', f'{r/"pp"/"include"}'] - ) + assert server.source_dirs == {f'{r/"subdir"}', f'{r/"pp"}', f'{r/"pp"/"include"}'} assert server.incl_suffixes == [".FF", ".fpc", ".h", "f20"] - assert server.excl_suffixes == set(["_tmp.f90", "_h5hut_tests.F90"]) - assert server.excl_paths == set([f'{r/"excldir"}', f'{r/"hover"}']) + assert server.excl_suffixes == {"_tmp.f90", "_h5hut_tests.F90"} + assert server.excl_paths == {f'{r/"excldir"}', f'{r/"hover"}'} def test_config_file_autocomplete_options(): @@ -146,7 +144,7 @@ def test_config_file_preprocessor_options(): server, root = unittest_server_init() # Preprocessor options assert server.pp_suffixes == [".h", ".fh"] - assert server.include_dirs == set([f'{root/"include"}']) + assert server.include_dirs == {f'{root/"include"}'} assert server.pp_defs == { "HAVE_PETSC": "", "HAVE_ZOLTAN": "", From 711ee5c406018171759f25ca5c221aec3a1bfb2a Mon Sep 17 00:00:00 2001 From: gnikit Date: Tue, 10 May 2022 11:44:13 +0100 Subject: [PATCH 4/9] Updated CONTRIBUTING to include pre-commit --- CONTRIBUTING.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 435847a7..7bd660c3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -38,15 +38,27 @@ To verify that your cloning of the GitHub repository work as expected open a ter ```sh pytest -v ``` + This will run the entire unit test suite. You can also run this to verify that you haven't broken anything in the code. 👉 **Tip!** You can run individual tests by selecting the path to the Python file and the method + ```sh pytest test/test_interface.py::test_version_update_pypi ``` ### Developing & Debugging 🐞️ +❗️ Before you start developing, open a terminal inside `fortls` and run: + +```sh +pre-commit install +``` + +This will ensure that all you commits meet the formatting standards of the project. + +---- + You can now start writing code! Your local `fortls` version will be updated with every code change you make, so you can use your normal code editor to checkout the `fortls` features that you have implemented. It is however considerably easier to create compact unittests to check if your changes have worked. @@ -54,10 +66,8 @@ A `fortls` test normally involves writing a Python function which sends a JSONRP Often times small bits of Fortran source code also have to be submited to be used by the test. You can find varisous test examples in the `tests` directory. - 👉 **Tip!** You can attach a debugger to the main `fortls` source code during unittesting which should allow you to pause, break, step into, etc. while testing, thus making it easier to find mistakes. - ### Merging To merge your changes to the main `fortls` repository push your branch on GitHub and open a [Pull Request](https://github.com/gnikit/fortls/pulls). Ping `@gnikit` to review your PR. From d7d179834157bc0e7825170111a75418755f8310 Mon Sep 17 00:00:00 2001 From: gnikit Date: Tue, 10 May 2022 11:47:25 +0100 Subject: [PATCH 5/9] Added isort in pre-commit --- .pre-commit-config.yaml | 5 +++++ test/test_interface.py | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f4f6199c..6000fcfd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,6 +16,11 @@ repos: rev: v2.32.1 hooks: - id: pyupgrade +- repo: https://github.com/pycqa/isort + rev: 5.10.1 + hooks: + - id: isort + name: isort (python) - repo: https://github.com/psf/black rev: 22.3.0 hooks: diff --git a/test/test_interface.py b/test/test_interface.py index db7137bd..b4837969 100644 --- a/test/test_interface.py +++ b/test/test_interface.py @@ -165,9 +165,10 @@ def test_config_file_codeactions_options(): def test_version_update_pypi(): + from packaging import version + from fortls.jsonrpc import JSONRPC2Connection, ReadWriter from fortls.langserver import LangServer - from packaging import version parser = commandline_args("fortls") args = parser.parse_args("-c f90_config.json".split()) From b1ae33faef0107974e985aa4511801d5693c4b97 Mon Sep 17 00:00:00 2001 From: gnikit Date: Tue, 10 May 2022 11:56:21 +0100 Subject: [PATCH 6/9] Set isort profile to --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 4aa5b93d..553da76c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,3 +9,6 @@ build-backend = "setuptools.build_meta" [tool.setuptools_scm] write_to = "fortls/_version.py" + +[tool.isort] +profile = "black" From 320a30fc7b0956fbd0cb785609d320cd7501fab8 Mon Sep 17 00:00:00 2001 From: gnikit Date: Tue, 10 May 2022 13:59:46 +0100 Subject: [PATCH 7/9] Add coverage for variable + documentation --- test/test_server_documentation.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/test_server_documentation.py b/test/test_server_documentation.py index 0682d715..634f6d99 100644 --- a/test/test_server_documentation.py +++ b/test/test_server_documentation.py @@ -88,6 +88,17 @@ def test_doc_type_bound_procedure_sub_implementation(): check_return(results[1], ((1, "!! Doc 4"), (4, " !! Doc 5"))) +def test_doc_variable(): + string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)}) + file_path = test_dir / "subdir" / "test_free.f90" + # n !! Doc 5 + # Test that a variable can carry over documentation + string += hover_request(file_path, 37, 26) + errcode, results = run_request(string) + assert errcode == 0 + check_return(results[1], ((1, " !! Doc 5"),)) + + def test_doc_overwrite_type_bound_procedure_fun(): string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)}) file_path = test_dir / "subdir" / "test_free.f90" From b29ebfaca224a52163a57045f4b2ecadba73caa7 Mon Sep 17 00:00:00 2001 From: gnikit Date: Tue, 10 May 2022 14:02:13 +0100 Subject: [PATCH 8/9] chore: Update pre-commit config --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6000fcfd..e36d622d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,14 +2,14 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.2.0 + rev: v4.2.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml - id: check-added-large-files - repo: https://gitlab.com/pycqa/flake8 - rev: 4.0.1 + rev: 3.9.2 hooks: - id: flake8 - repo: https://github.com/asottile/pyupgrade From 50b370d16d6c1b6f762ff600e417e54c7bb7a29e Mon Sep 17 00:00:00 2001 From: gnikit Date: Tue, 10 May 2022 14:20:46 +0100 Subject: [PATCH 9/9] Updated CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23f4ede3..4c5eaf05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,10 +6,16 @@ ### Added +- Added `pre-commit` hook to the project + ([#106](https://github.com/gnikit/fortls/issues/106)) - Added Code of Conduct - Added basic support for hovering over `ASSOCIATE` blocks ([#62](https://github.com/gnikit/fortls/issues/62)) +### Changed + +- Formatted all files with `pre-commit` + ## 2.3.1 ### Fixed