From 7d5a99d4e7d067214a506b842ad4115f823e301b Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Wed, 27 Mar 2024 18:01:59 +0530 Subject: [PATCH 01/51] fix: url bug --- src/fpm/dependency.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fpm/dependency.f90 b/src/fpm/dependency.f90 index 6cc87e4212..bc5aebde77 100644 --- a/src/fpm/dependency.f90 +++ b/src/fpm/dependency.f90 @@ -695,7 +695,7 @@ subroutine get_from_registry(self, target_dir, global_settings, error, downloade end if ! Include namespace and package name in the target url and download package data. - target_url = global_settings%registry_settings%url//'packages/'//self%namespace//'/'//self%name + target_url = global_settings%registry_settings%url//'/packages/'//self%namespace//'/'//self%name call downloader%get_pkg_data(target_url, self%requested_version, tmp_file, json, error) close (unit, status='delete') if (allocated(error)) return From 94fdf25abd2a78a8f21c6ec0bd6875523f48d472 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 19 May 2024 10:44:22 +0530 Subject: [PATCH 02/51] add: search functionality for fpm registry --- src/fpm/search.f90 | 127 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 src/fpm/search.f90 diff --git a/src/fpm/search.f90 b/src/fpm/search.f90 new file mode 100644 index 0000000000..1c070f2308 --- /dev/null +++ b/src/fpm/search.f90 @@ -0,0 +1,127 @@ +module fpm_search + use fpm_error, only: error_t, fatal_error + use fpm_filesystem, only: which, run + use fpm_versioning, only: version_t + use jonquil, only: json_object, json_value, json_error, json_load, cast_to_object + use fpm_strings, only: string_t + + implicit none + private + + public :: search_t + + !> This type could be entirely avoided but it is quite practical because it can be mocked for testing. + type search_t + contains + procedure, nopass :: get_pkgs + end type + + contains + + !> Perform an http get request, save output to file, and parse json. + subroutine get_pkgs_data(query, url, json, error) + character(*), intent(in) :: url + character(*), intent(in) :: query + type(json_object), intent(out) :: json + type(error_t), allocatable, intent(out) :: error + + class(json_value), allocatable :: j_value + type(json_object), pointer :: ptr + type(json_error), allocatable :: j_error + + + call get_file(url, tmp_pkg_file, error) + if (allocated(error)) return + + call json_load(j_value, tmp_pkg_file, error=j_error) + if (allocated(j_error)) then + allocate (error); call move_alloc(j_error%message, error%message); call json%destroy(); return + end if + + ptr => cast_to_object(j_value) + if (.not. associated(ptr)) then + call fatal_error(error, "Error parsing JSON from '"//url//"'."); return + end if + + json = ptr + end + + !> Download a file from a url using either curl or wget. + subroutine get_(url, tmp_pkg_file, error) + character(*), intent(in) :: url + character(*), intent(in) :: tmp_pkg_file + type(error_t), allocatable, intent(out) :: error + + integer :: stat + + if (which('curl') /= '') then + print *, "Downloading '"//url//"' -> '"//tmp_pkg_file//"'" + call execute_command_line('curl '//url//' -s -o '//tmp_pkg_file, exitstat=stat) + else if (which('wget') /= '') then + print *, "Downloading '"//url//"' -> '"//tmp_pkg_file//"'" + call execute_command_line('wget '//url//' -q -O '//tmp_pkg_file, exitstat=stat) + else + call fatal_error(error, "Neither 'curl' nor 'wget' installed."); return + end if + + if (stat /= 0) then + call fatal_error(error, "Error downloading package from '"//url//"'."); return + end if + end + + !> Perform an http post request with form data. + subroutine upload_form(endpoint, form_data, verbose, error) + !> Endpoint to upload to. + character(len=*), intent(in) :: endpoint + !> Form data to upload. + type(string_t), intent(in) :: form_data(:) + !> Print additional information if true. + logical, intent(in) :: verbose + !> Error handling. + type(error_t), allocatable, intent(out) :: error + + integer :: stat, i + character(len=:), allocatable :: form_data_str + + form_data_str = '' + do i = 1, size(form_data) + form_data_str = form_data_str//"-F '"//form_data(i)%s//"' " + end do + + if (which('curl') /= '') then + print *, 'Uploading package ...' + call run('curl -X POST -H "Content-Type: multipart/form-data" '// & + & form_data_str//endpoint, exitstat=stat, echo=verbose) + else + call fatal_error(error, "'curl' not installed."); return + end if + + if (stat /= 0) then + call fatal_error(error, "Error uploading package to registry."); return + end if + end + + !> Unpack a tarball to a destination. + subroutine unpack(tmp_pkg_file, destination, error) + !> Path to tarball. + character(*), intent(in) :: tmp_pkg_file + !> Destination to unpack to. + character(*), intent(in) :: destination + !> Error handling. + type(error_t), allocatable, intent(out) :: error + + integer :: stat + + if (which('tar') == '') then + call fatal_error(error, "'tar' not installed."); return + end if + + print *, "Unpacking '"//tmp_pkg_file//"' to '"//destination//"' ..." + call execute_command_line('tar -zxf '//tmp_pkg_file//' -C '//destination, exitstat=stat) + + if (stat /= 0) then + call fatal_error(error, "Error unpacking '"//tmp_pkg_file//"'."); return + end if + end + end + \ No newline at end of file From 0a4f91007f6479772090ac91bf01f0ed24fc79a7 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 19 May 2024 15:53:35 +0530 Subject: [PATCH 03/51] add: search --- app/main.f90 | 7 ++- src/fpm.f90 | 79 ++++++++++++++++++++++-- src/fpm/search.f90 | 127 --------------------------------------- src/fpm_command_line.f90 | 21 ++++++- 4 files changed, 98 insertions(+), 136 deletions(-) delete mode 100644 src/fpm/search.f90 diff --git a/app/main.f90 b/app/main.f90 index 4bd3ac5e33..063a531299 100644 --- a/app/main.f90 +++ b/app/main.f90 @@ -11,10 +11,11 @@ program main fpm_update_settings, & fpm_clean_settings, & fpm_publish_settings, & - get_command_line_settings + get_command_line_settings, & + fpm_search_settings use fpm_error, only: error_t use fpm_filesystem, only: exists, parent_dir, join_path -use fpm, only: cmd_build, cmd_run, cmd_clean +use fpm, only: cmd_build, cmd_run, cmd_clean, cmd_search use fpm_cmd_install, only: cmd_install use fpm_cmd_export, only: cmd_export use fpm_cmd_new, only: cmd_new @@ -86,6 +87,8 @@ program main call cmd_update(settings) type is (fpm_clean_settings) call cmd_clean(settings) +type is (fpm_search_settings) + call cmd_search(settings) type is (fpm_publish_settings) call cmd_publish(settings) end select diff --git a/src/fpm.f90 b/src/fpm.f90 index 37cf069c9c..03085137b3 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -5,10 +5,10 @@ module fpm use fpm_backend, only: build_package use fpm_command_line, only: fpm_build_settings, fpm_new_settings, & fpm_run_settings, fpm_install_settings, fpm_test_settings, & - fpm_clean_settings + fpm_clean_settings, fpm_search_settings use fpm_dependency, only : new_dependency_tree use fpm_filesystem, only: is_dir, join_path, list_files, exists, & - basename, filewrite, mkdir, run, os_delete_dir + basename, filewrite, mkdir, run, os_delete_dir, get_temp_filename use fpm_model, only: fpm_model_t, srcfile_t, show_model, fortran_features_t, & FPM_SCOPE_UNKNOWN, FPM_SCOPE_LIB, FPM_SCOPE_DEP, & FPM_SCOPE_APP, FPM_SCOPE_EXAMPLE, FPM_SCOPE_TEST @@ -21,17 +21,23 @@ module fpm use fpm_manifest, only : get_package_data, package_config_t use fpm_meta, only : resolve_metapackages use fpm_error, only : error_t, fatal_error, fpm_stop -use fpm_toml, only: name_is_json +use fpm_toml, only: name_is_json, get_value +use fpm_downloader, only: downloader_t +use fpm_versioning, only: version_t +use tomlf, only : toml_array use, intrinsic :: iso_fortran_env, only : stdin => input_unit, & & stdout => output_unit, & & stderr => error_unit use iso_c_binding, only: c_char, c_ptr, c_int, c_null_char, c_associated, c_f_pointer use fpm_environment, only: os_is_unix -use fpm_settings, only: fpm_global_settings, get_global_settings +use fpm_toml, only: toml_table, toml_key, toml_error, toml_serialize, & + get_value +use jonquil, only : json_object!, json_loads, json_object, json_error +use fpm_settings, only: fpm_global_settings, get_global_settings, official_registry_base_url implicit none private -public :: cmd_build, cmd_run, cmd_clean +public :: cmd_build, cmd_run, cmd_clean, cmd_search public :: build_model, check_modules_for_duplicates contains @@ -716,6 +722,69 @@ subroutine cmd_clean(settings) end if end subroutine cmd_clean +!> Search the fpm registry for a package +subroutine cmd_search(settings) + !> Settings for the search command. + class(fpm_search_settings), intent(in) :: settings + + ! character :: user_response + type(fpm_global_settings) :: global_settings + character(:), allocatable :: cache_path, target_url, tmp_file + integer :: stat, unit, i + type(json_object) :: json, packages + !> Error handling. + type(error_t), allocatable :: error + ! type(toml_array), pointer :: array + type(version_t), allocatable :: version + + !> Downloader instance. + class(downloader_t), allocatable :: downloader + allocate (downloader) + + tmp_file = get_temp_filename() + open (newunit=unit, file=tmp_file, action='readwrite', iostat=stat) + if (stat /= 0) then + call fatal_error(error, "Error creating temporary file for downloading package."); return + end if + + ! Clear registry cache + call get_global_settings(global_settings, error) + if (allocated(error)) return + call downloader%get_pkg_data(official_registry_base_url//'/packages?query='//settings%query, version, tmp_file, json, error) + close (unit) + if (allocated(error)) return + print *, tmp_file + print *, settings%query + ! call get_value(json, 'packages', packages, stat=stat) + + + ! if (json%has_key("packages")) then + ! ! call get_value(packages, "packages", error=error) + ! call get_value(json, 'packages', packages, error=error) + ! if (allocated(error)) return + ! do i = 1, size(packages) + ! print *, packages%get_keys() + ! end do + ! end if + + ! print *, json%get_keys() + ! call get_value(json,"packages", array) + ! do i =1, size(array) + ! call json_loads(packages, array(i) , error=error) + ! if (allocated(error)) return + ! print *, packages%get_keys() + ! end do + ! print *, array + + ! Verify package data and read relevant information. + ! call check_and_read_pkg_data(json, self, target_url, version, error) + ! if (allocated(error)) return + ! call get_pkg_data(global_settings%official_registry_base_url//'/packages?query=c', settings%query) + ! subroutine get_pkg_data(url, version, tmp_pkg_file, json, error) + ! call os_delete_dir(os_is_unix(), global_settings%registry_settings%cache_path) + ! end if +end subroutine cmd_search + !> Sort executables by namelist ID, and trim unused values pure subroutine sort_executables(target_ID,executables) integer, allocatable, intent(inout) :: target_ID(:) diff --git a/src/fpm/search.f90 b/src/fpm/search.f90 deleted file mode 100644 index 1c070f2308..0000000000 --- a/src/fpm/search.f90 +++ /dev/null @@ -1,127 +0,0 @@ -module fpm_search - use fpm_error, only: error_t, fatal_error - use fpm_filesystem, only: which, run - use fpm_versioning, only: version_t - use jonquil, only: json_object, json_value, json_error, json_load, cast_to_object - use fpm_strings, only: string_t - - implicit none - private - - public :: search_t - - !> This type could be entirely avoided but it is quite practical because it can be mocked for testing. - type search_t - contains - procedure, nopass :: get_pkgs - end type - - contains - - !> Perform an http get request, save output to file, and parse json. - subroutine get_pkgs_data(query, url, json, error) - character(*), intent(in) :: url - character(*), intent(in) :: query - type(json_object), intent(out) :: json - type(error_t), allocatable, intent(out) :: error - - class(json_value), allocatable :: j_value - type(json_object), pointer :: ptr - type(json_error), allocatable :: j_error - - - call get_file(url, tmp_pkg_file, error) - if (allocated(error)) return - - call json_load(j_value, tmp_pkg_file, error=j_error) - if (allocated(j_error)) then - allocate (error); call move_alloc(j_error%message, error%message); call json%destroy(); return - end if - - ptr => cast_to_object(j_value) - if (.not. associated(ptr)) then - call fatal_error(error, "Error parsing JSON from '"//url//"'."); return - end if - - json = ptr - end - - !> Download a file from a url using either curl or wget. - subroutine get_(url, tmp_pkg_file, error) - character(*), intent(in) :: url - character(*), intent(in) :: tmp_pkg_file - type(error_t), allocatable, intent(out) :: error - - integer :: stat - - if (which('curl') /= '') then - print *, "Downloading '"//url//"' -> '"//tmp_pkg_file//"'" - call execute_command_line('curl '//url//' -s -o '//tmp_pkg_file, exitstat=stat) - else if (which('wget') /= '') then - print *, "Downloading '"//url//"' -> '"//tmp_pkg_file//"'" - call execute_command_line('wget '//url//' -q -O '//tmp_pkg_file, exitstat=stat) - else - call fatal_error(error, "Neither 'curl' nor 'wget' installed."); return - end if - - if (stat /= 0) then - call fatal_error(error, "Error downloading package from '"//url//"'."); return - end if - end - - !> Perform an http post request with form data. - subroutine upload_form(endpoint, form_data, verbose, error) - !> Endpoint to upload to. - character(len=*), intent(in) :: endpoint - !> Form data to upload. - type(string_t), intent(in) :: form_data(:) - !> Print additional information if true. - logical, intent(in) :: verbose - !> Error handling. - type(error_t), allocatable, intent(out) :: error - - integer :: stat, i - character(len=:), allocatable :: form_data_str - - form_data_str = '' - do i = 1, size(form_data) - form_data_str = form_data_str//"-F '"//form_data(i)%s//"' " - end do - - if (which('curl') /= '') then - print *, 'Uploading package ...' - call run('curl -X POST -H "Content-Type: multipart/form-data" '// & - & form_data_str//endpoint, exitstat=stat, echo=verbose) - else - call fatal_error(error, "'curl' not installed."); return - end if - - if (stat /= 0) then - call fatal_error(error, "Error uploading package to registry."); return - end if - end - - !> Unpack a tarball to a destination. - subroutine unpack(tmp_pkg_file, destination, error) - !> Path to tarball. - character(*), intent(in) :: tmp_pkg_file - !> Destination to unpack to. - character(*), intent(in) :: destination - !> Error handling. - type(error_t), allocatable, intent(out) :: error - - integer :: stat - - if (which('tar') == '') then - call fatal_error(error, "'tar' not installed."); return - end if - - print *, "Unpacking '"//tmp_pkg_file//"' to '"//destination//"' ..." - call execute_command_line('tar -zxf '//tmp_pkg_file//' -C '//destination, exitstat=stat) - - if (stat /= 0) then - call fatal_error(error, "Error unpacking '"//tmp_pkg_file//"'."); return - end if - end - end - \ No newline at end of file diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 6035130eb4..77b3d1d1c8 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -52,7 +52,8 @@ module fpm_command_line fpm_update_settings, & fpm_clean_settings, & fpm_publish_settings, & - get_command_line_settings + get_command_line_settings, & + fpm_search_settings type, abstract :: fpm_cmd_settings character(len=:), allocatable :: working_dir @@ -132,6 +133,10 @@ module fpm_command_line logical :: registry_cache = .false. end type +type, extends(fpm_cmd_settings) :: fpm_search_settings + character(len=:),allocatable :: query +end type + type, extends(fpm_build_settings) :: fpm_publish_settings logical :: show_package_version = .false. logical :: show_upload_data = .false. @@ -238,7 +243,7 @@ subroutine get_command_line_settings(cmd_settings) type(fpm_export_settings) , allocatable :: export_settings type(version_t) :: version character(len=:), allocatable :: common_args, compiler_args, run_args, working_dir, & - & c_compiler, cxx_compiler, archiver, version_s, token_s + & c_compiler, cxx_compiler, archiver, version_s, token_s, query character(len=*), parameter :: fc_env = "FC", cc_env = "CC", ar_env = "AR", & & fflags_env = "FFLAGS", cflags_env = "CFLAGS", cxxflags_env = "CXXFLAGS", ldflags_env = "LDFLAGS", & @@ -701,6 +706,18 @@ subroutine get_command_line_settings(cmd_settings) & clean_all=clean_all) end block + case('search') + call set_args(common_args // & + & ' --query', & + help_clean, version_text) + query = sget('query') + + block + allocate(fpm_search_settings :: cmd_settings) + cmd_settings = fpm_search_settings( & + & query=query) + end block + case('publish') call set_args(common_args // compiler_args //'& & --show-package-version F & From 7a4bdb53bba8c5beed71e6509d7b152b1ab73061 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 19 May 2024 16:06:49 +0530 Subject: [PATCH 04/51] add: search --- src/fpm.f90 | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/fpm.f90 b/src/fpm.f90 index 03085137b3..d1a142a93f 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -30,9 +30,7 @@ module fpm & stderr => error_unit use iso_c_binding, only: c_char, c_ptr, c_int, c_null_char, c_associated, c_f_pointer use fpm_environment, only: os_is_unix -use fpm_toml, only: toml_table, toml_key, toml_error, toml_serialize, & - get_value -use jonquil, only : json_object!, json_loads, json_object, json_error +use jonquil, only : json_object use fpm_settings, only: fpm_global_settings, get_global_settings, official_registry_base_url implicit none @@ -730,7 +728,7 @@ subroutine cmd_search(settings) ! character :: user_response type(fpm_global_settings) :: global_settings character(:), allocatable :: cache_path, target_url, tmp_file - integer :: stat, unit, i + integer :: stat, unit, ii type(json_object) :: json, packages !> Error handling. type(error_t), allocatable :: error @@ -755,10 +753,22 @@ subroutine cmd_search(settings) if (allocated(error)) return print *, tmp_file print *, settings%query - ! call get_value(json, 'packages', packages, stat=stat) - - - ! if (json%has_key("packages")) then + call get_value(json, 'packages', packages, stat=stat) + ! do ii = 1, size(list) + ! call get_value(table, list(ii)%key, ptr) + ! call get_value(ptr, "version", version) + ! call get_value(ptr, "proj-dir", proj_dir) + ! call get_value(ptr, "git", url) + + + if (json%has_key("packages")) then + print *, "Found packages" + call get_value(json, 'packages', packages) + do ii = 1, size(packages) + ! print *, json%get("packages")%get(i)%get("name")%get_string() + print *,"hi" + end do + end if ! ! call get_value(packages, "packages", error=error) ! call get_value(json, 'packages', packages, error=error) ! if (allocated(error)) return From cc9bd57490a331ba3b268785e678d91ca1902330 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 19 May 2024 17:34:54 +0530 Subject: [PATCH 05/51] add: search --- src/fpm.f90 | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/src/fpm.f90 b/src/fpm.f90 index d1a142a93f..d80e652c20 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -21,7 +21,8 @@ module fpm use fpm_manifest, only : get_package_data, package_config_t use fpm_meta, only : resolve_metapackages use fpm_error, only : error_t, fatal_error, fpm_stop -use fpm_toml, only: name_is_json, get_value +use fpm_toml, only: name_is_json, get_value, toml_table, toml_key, toml_error, toml_serialize, & + set_value, add_table, toml_load, toml_stat, set_string use fpm_downloader, only: downloader_t use fpm_versioning, only: version_t use tomlf, only : toml_array @@ -727,13 +728,15 @@ subroutine cmd_search(settings) ! character :: user_response type(fpm_global_settings) :: global_settings - character(:), allocatable :: cache_path, target_url, tmp_file + character(:), allocatable :: cache_path, target_url, tmp_file,name integer :: stat, unit, ii - type(json_object) :: json, packages + type(json_object) :: json + type(json_object), pointer :: p, q !> Error handling. type(error_t), allocatable :: error - ! type(toml_array), pointer :: array + type(toml_array), pointer :: array type(version_t), allocatable :: version + ! type(toml_array), pointer :: packages !> Downloader instance. class(downloader_t), allocatable :: downloader @@ -745,38 +748,23 @@ subroutine cmd_search(settings) call fatal_error(error, "Error creating temporary file for downloading package."); return end if - ! Clear registry cache - call get_global_settings(global_settings, error) - if (allocated(error)) return + !> Get the package data from the registry. call downloader%get_pkg_data(official_registry_base_url//'/packages?query='//settings%query, version, tmp_file, json, error) - close (unit) + close (unit, status='delete') if (allocated(error)) return print *, tmp_file print *, settings%query - call get_value(json, 'packages', packages, stat=stat) - ! do ii = 1, size(list) - ! call get_value(table, list(ii)%key, ptr) - ! call get_value(ptr, "version", version) - ! call get_value(ptr, "proj-dir", proj_dir) - ! call get_value(ptr, "git", url) - if (json%has_key("packages")) then print *, "Found packages" - call get_value(json, 'packages', packages) - do ii = 1, size(packages) - ! print *, json%get("packages")%get(i)%get("name")%get_string() - print *,"hi" - end do + call get_value(json, 'packages', array) + call get_value(array, 2, p) + ! print *, size(array) + call get_value(p, 'name', name) + print *, name + end if - ! ! call get_value(packages, "packages", error=error) - ! call get_value(json, 'packages', packages, error=error) - ! if (allocated(error)) return - ! do i = 1, size(packages) - ! print *, packages%get_keys() - ! end do - ! end if - + ! print *, json%get_keys() ! call get_value(json,"packages", array) ! do i =1, size(array) From 0a99d4a009cf792ace8e6c6de90d48f0f20f7853 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 19 May 2024 17:47:33 +0530 Subject: [PATCH 06/51] add: search --- src/fpm.f90 | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/fpm.f90 b/src/fpm.f90 index d80e652c20..f45cb77d03 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -759,28 +759,14 @@ subroutine cmd_search(settings) print *, "Found packages" call get_value(json, 'packages', array) call get_value(array, 2, p) - ! print *, size(array) - call get_value(p, 'name', name) - print *, name + ! print *, len(p) + do ii=1, 100 + call get_value(array, ii, p) + call get_value(p, 'name', name) + print *, name + end do end if - - ! print *, json%get_keys() - ! call get_value(json,"packages", array) - ! do i =1, size(array) - ! call json_loads(packages, array(i) , error=error) - ! if (allocated(error)) return - ! print *, packages%get_keys() - ! end do - ! print *, array - - ! Verify package data and read relevant information. - ! call check_and_read_pkg_data(json, self, target_url, version, error) - ! if (allocated(error)) return - ! call get_pkg_data(global_settings%official_registry_base_url//'/packages?query=c', settings%query) - ! subroutine get_pkg_data(url, version, tmp_pkg_file, json, error) - ! call os_delete_dir(os_is_unix(), global_settings%registry_settings%cache_path) - ! end if end subroutine cmd_search !> Sort executables by namelist ID, and trim unused values From b0484512638abb1f7d6513a4daa335d218f6a9c7 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 19 May 2024 18:16:31 +0530 Subject: [PATCH 07/51] add: search --- src/fpm.f90 | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/fpm.f90 b/src/fpm.f90 index f45cb77d03..c1b6cd9a9f 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -21,11 +21,11 @@ module fpm use fpm_manifest, only : get_package_data, package_config_t use fpm_meta, only : resolve_metapackages use fpm_error, only : error_t, fatal_error, fpm_stop -use fpm_toml, only: name_is_json, get_value, toml_table, toml_key, toml_error, toml_serialize, & +use fpm_toml, only: name_is_json, toml_table, toml_key, toml_error, toml_serialize, & set_value, add_table, toml_load, toml_stat, set_string use fpm_downloader, only: downloader_t use fpm_versioning, only: version_t -use tomlf, only : toml_array +use tomlf, only : toml_array, get_value, len,toml_key use, intrinsic :: iso_fortran_env, only : stdin => input_unit, & & stdout => output_unit, & & stderr => error_unit @@ -728,15 +728,15 @@ subroutine cmd_search(settings) ! character :: user_response type(fpm_global_settings) :: global_settings - character(:), allocatable :: cache_path, target_url, tmp_file,name - integer :: stat, unit, ii + character(:), allocatable :: tmp_file,name, version_p, description + type(toml_key), allocatable :: list(:) + integer :: stat, unit, ii,ikey type(json_object) :: json type(json_object), pointer :: p, q !> Error handling. type(error_t), allocatable :: error type(toml_array), pointer :: array type(version_t), allocatable :: version - ! type(toml_array), pointer :: packages !> Downloader instance. class(downloader_t), allocatable :: downloader @@ -758,14 +758,16 @@ subroutine cmd_search(settings) if (json%has_key("packages")) then print *, "Found packages" call get_value(json, 'packages', array) - call get_value(array, 2, p) - ! print *, len(p) - do ii=1, 100 + do ii=1, len(array) call get_value(array, ii, p) call get_value(p, 'name', name) - print *, name + call get_value(p, 'version', version_p) + call get_value(p, 'description', description) + print *, "Name: ", name + print *, "Version: ", version_p + print *, "Description: ", description + print *, "\n" end do - end if end subroutine cmd_search From 0b66b853e493c496e82fa1c54c06d6a251ac99c7 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 19 May 2024 18:22:46 +0530 Subject: [PATCH 08/51] add: search --- src/fpm.f90 | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/fpm.f90 b/src/fpm.f90 index c1b6cd9a9f..24c426f682 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -21,8 +21,7 @@ module fpm use fpm_manifest, only : get_package_data, package_config_t use fpm_meta, only : resolve_metapackages use fpm_error, only : error_t, fatal_error, fpm_stop -use fpm_toml, only: name_is_json, toml_table, toml_key, toml_error, toml_serialize, & - set_value, add_table, toml_load, toml_stat, set_string +use fpm_toml, only: name_is_json use fpm_downloader, only: downloader_t use fpm_versioning, only: version_t use tomlf, only : toml_array, get_value, len,toml_key @@ -726,11 +725,10 @@ subroutine cmd_search(settings) !> Settings for the search command. class(fpm_search_settings), intent(in) :: settings - ! character :: user_response type(fpm_global_settings) :: global_settings character(:), allocatable :: tmp_file,name, version_p, description type(toml_key), allocatable :: list(:) - integer :: stat, unit, ii,ikey + integer :: stat, unit, ii type(json_object) :: json type(json_object), pointer :: p, q !> Error handling. @@ -752,7 +750,6 @@ subroutine cmd_search(settings) call downloader%get_pkg_data(official_registry_base_url//'/packages?query='//settings%query, version, tmp_file, json, error) close (unit, status='delete') if (allocated(error)) return - print *, tmp_file print *, settings%query if (json%has_key("packages")) then @@ -764,10 +761,12 @@ subroutine cmd_search(settings) call get_value(p, 'version', version_p) call get_value(p, 'description', description) print *, "Name: ", name - print *, "Version: ", version_p + ! print *, "Version: ", version_p print *, "Description: ", description - print *, "\n" + print *, "" end do + else + call fatal_error(error, "Error Searching Packages"); return end if end subroutine cmd_search From d2b173abdbeefb0af9d7ce484837492f3619c3df Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 19 May 2024 19:00:32 +0530 Subject: [PATCH 09/51] fix search --- src/fpm.f90 | 9 +++++---- src/fpm_command_line.f90 | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/fpm.f90 b/src/fpm.f90 index 24c426f682..61c94198b8 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -726,7 +726,7 @@ subroutine cmd_search(settings) class(fpm_search_settings), intent(in) :: settings type(fpm_global_settings) :: global_settings - character(:), allocatable :: tmp_file,name, version_p, description + character(:), allocatable :: tmp_file,name, namespace, description type(toml_key), allocatable :: list(:) integer :: stat, unit, ii type(json_object) :: json @@ -740,13 +740,14 @@ subroutine cmd_search(settings) class(downloader_t), allocatable :: downloader allocate (downloader) + !> Generate a temporary file to store the downloaded package search data tmp_file = get_temp_filename() open (newunit=unit, file=tmp_file, action='readwrite', iostat=stat) if (stat /= 0) then call fatal_error(error, "Error creating temporary file for downloading package."); return end if - !> Get the package data from the registry. + !> Get the package data from the registry call downloader%get_pkg_data(official_registry_base_url//'/packages?query='//settings%query, version, tmp_file, json, error) close (unit, status='delete') if (allocated(error)) return @@ -758,10 +759,10 @@ subroutine cmd_search(settings) do ii=1, len(array) call get_value(array, ii, p) call get_value(p, 'name', name) - call get_value(p, 'version', version_p) + call get_value(p, 'namespace', namespace) call get_value(p, 'description', description) print *, "Name: ", name - ! print *, "Version: ", version_p + print *, "namespace: ", namespace print *, "Description: ", description print *, "" end do diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 77b3d1d1c8..413e00cfa6 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -707,15 +707,15 @@ subroutine get_command_line_settings(cmd_settings) end block case('search') - call set_args(common_args // & - & ' --query', & - help_clean, version_text) + call set_args(common_args //'& + & --query " " & + & --', help_clean, version_text) query = sget('query') block allocate(fpm_search_settings :: cmd_settings) cmd_settings = fpm_search_settings( & - & query=query) + & query=query) end block case('publish') From 6d5c44b2712dacbf99d923525745518bd1245580 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 19 May 2024 19:17:58 +0530 Subject: [PATCH 10/51] add: search --- src/fpm.f90 | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/fpm.f90 b/src/fpm.f90 index 61c94198b8..f2a3df9bae 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -24,7 +24,7 @@ module fpm use fpm_toml, only: name_is_json use fpm_downloader, only: downloader_t use fpm_versioning, only: version_t -use tomlf, only : toml_array, get_value, len,toml_key +use tomlf, only : toml_array, get_value, len, toml_key use, intrinsic :: iso_fortran_env, only : stdin => input_unit, & & stdout => output_unit, & & stderr => error_unit @@ -724,13 +724,11 @@ end subroutine cmd_clean subroutine cmd_search(settings) !> Settings for the search command. class(fpm_search_settings), intent(in) :: settings - - type(fpm_global_settings) :: global_settings - character(:), allocatable :: tmp_file,name, namespace, description + character(:), allocatable :: tmp_file, name, namespace, description type(toml_key), allocatable :: list(:) integer :: stat, unit, ii type(json_object) :: json - type(json_object), pointer :: p, q + type(json_object), pointer :: p !> Error handling. type(error_t), allocatable :: error type(toml_array), pointer :: array @@ -751,11 +749,10 @@ subroutine cmd_search(settings) call downloader%get_pkg_data(official_registry_base_url//'/packages?query='//settings%query, version, tmp_file, json, error) close (unit, status='delete') if (allocated(error)) return - print *, settings%query if (json%has_key("packages")) then - print *, "Found packages" call get_value(json, 'packages', array) + print '(A,I0,A)', ' Found ', len(array), ' packages:' do ii=1, len(array) call get_value(array, ii, p) call get_value(p, 'name', name) From 354fda1fbdcff37d8e42513ae7ea2d1eea455d6f Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 19 May 2024 19:59:46 +0530 Subject: [PATCH 11/51] fix: get file and add page --- src/fpm.f90 | 8 +++++--- src/fpm/downloader.f90 | 4 ++-- src/fpm_command_line.f90 | 9 ++++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/fpm.f90 b/src/fpm.f90 index f2a3df9bae..908bcaac16 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -724,7 +724,7 @@ end subroutine cmd_clean subroutine cmd_search(settings) !> Settings for the search command. class(fpm_search_settings), intent(in) :: settings - character(:), allocatable :: tmp_file, name, namespace, description + character(:), allocatable :: tmp_file, name, namespace, description, query_url type(toml_key), allocatable :: list(:) integer :: stat, unit, ii type(json_object) :: json @@ -745,9 +745,11 @@ subroutine cmd_search(settings) call fatal_error(error, "Error creating temporary file for downloading package."); return end if + query_url = official_registry_base_url//'/packages?query='//settings%query//'&page='//settings%page + !> Get the package data from the registry - call downloader%get_pkg_data(official_registry_base_url//'/packages?query='//settings%query, version, tmp_file, json, error) - close (unit, status='delete') + call downloader%get_pkg_data(query_url, version, tmp_file, json, error) + close (unit) if (allocated(error)) return if (json%has_key("packages")) then diff --git a/src/fpm/downloader.f90 b/src/fpm/downloader.f90 index 39a3314ccf..45b7bc24c2 100644 --- a/src/fpm/downloader.f90 +++ b/src/fpm/downloader.f90 @@ -62,10 +62,10 @@ subroutine get_file(url, tmp_pkg_file, error) if (which('curl') /= '') then print *, "Downloading '"//url//"' -> '"//tmp_pkg_file//"'" - call execute_command_line('curl '//url//' -s -o '//tmp_pkg_file, exitstat=stat) + call execute_command_line('curl "'//url//'" -s -o '//tmp_pkg_file, exitstat=stat) else if (which('wget') /= '') then print *, "Downloading '"//url//"' -> '"//tmp_pkg_file//"'" - call execute_command_line('wget '//url//' -q -O '//tmp_pkg_file, exitstat=stat) + call execute_command_line('wget "'//url//'" -q -O '//tmp_pkg_file, exitstat=stat) else call fatal_error(error, "Neither 'curl' nor 'wget' installed."); return end if diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 413e00cfa6..75f1c7ddff 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -135,6 +135,7 @@ module fpm_command_line type, extends(fpm_cmd_settings) :: fpm_search_settings character(len=:),allocatable :: query + character(len=:),allocatable :: page end type type, extends(fpm_build_settings) :: fpm_publish_settings @@ -243,7 +244,7 @@ subroutine get_command_line_settings(cmd_settings) type(fpm_export_settings) , allocatable :: export_settings type(version_t) :: version character(len=:), allocatable :: common_args, compiler_args, run_args, working_dir, & - & c_compiler, cxx_compiler, archiver, version_s, token_s, query + & c_compiler, cxx_compiler, archiver, version_s, token_s, query, page character(len=*), parameter :: fc_env = "FC", cc_env = "CC", ar_env = "AR", & & fflags_env = "FFLAGS", cflags_env = "CFLAGS", cxxflags_env = "CXXFLAGS", ldflags_env = "LDFLAGS", & @@ -709,13 +710,15 @@ subroutine get_command_line_settings(cmd_settings) case('search') call set_args(common_args //'& & --query " " & + & --page " " & & --', help_clean, version_text) - query = sget('query') + query = sget('query') + page = sget('page') block allocate(fpm_search_settings :: cmd_settings) cmd_settings = fpm_search_settings( & - & query=query) + & query=query, page=page) end block case('publish') From baed1f57b39fd71070ff8aa31a69361fe2113372 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 19 May 2024 20:43:09 +0530 Subject: [PATCH 12/51] fix: if no page number is provided --- src/fpm.f90 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/fpm.f90 b/src/fpm.f90 index 908bcaac16..865a603a3a 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -723,7 +723,7 @@ end subroutine cmd_clean !> Search the fpm registry for a package subroutine cmd_search(settings) !> Settings for the search command. - class(fpm_search_settings), intent(in) :: settings + class(fpm_search_settings), intent(inout) :: settings character(:), allocatable :: tmp_file, name, namespace, description, query_url type(toml_key), allocatable :: list(:) integer :: stat, unit, ii @@ -744,7 +744,10 @@ subroutine cmd_search(settings) if (stat /= 0) then call fatal_error(error, "Error creating temporary file for downloading package."); return end if - + + if (settings%page == ' ') then + settings%page = '1' + end if query_url = official_registry_base_url//'/packages?query='//settings%query//'&page='//settings%page !> Get the package data from the registry From 3456c3934636629fa25ac6d55c40ae578efa3319 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 26 May 2024 20:15:07 +0530 Subject: [PATCH 13/51] add: search functionality support registry, namespaces,packages --- app/main.f90 | 3 +- src/fpm.f90 | 65 ++--------------- src/fpm/cmd/search.f90 | 151 +++++++++++++++++++++++++++++++++++++++ src/fpm/dependency.f90 | 2 +- src/fpm/downloader.f90 | 9 ++- src/fpm_command_line.f90 | 59 +++++++++++++-- 6 files changed, 221 insertions(+), 68 deletions(-) create mode 100644 src/fpm/cmd/search.f90 diff --git a/app/main.f90 b/app/main.f90 index 063a531299..bf11e72a9e 100644 --- a/app/main.f90 +++ b/app/main.f90 @@ -15,12 +15,13 @@ program main fpm_search_settings use fpm_error, only: error_t use fpm_filesystem, only: exists, parent_dir, join_path -use fpm, only: cmd_build, cmd_run, cmd_clean, cmd_search +use fpm, only: cmd_build, cmd_run, cmd_clean use fpm_cmd_install, only: cmd_install use fpm_cmd_export, only: cmd_export use fpm_cmd_new, only: cmd_new use fpm_cmd_update, only : cmd_update use fpm_cmd_publish, only: cmd_publish +use fpm_cmd_search, only: cmd_search use fpm_os, only: change_directory, get_current_directory implicit none diff --git a/src/fpm.f90 b/src/fpm.f90 index 865a603a3a..636ec21509 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -5,10 +5,10 @@ module fpm use fpm_backend, only: build_package use fpm_command_line, only: fpm_build_settings, fpm_new_settings, & fpm_run_settings, fpm_install_settings, fpm_test_settings, & - fpm_clean_settings, fpm_search_settings + fpm_clean_settings use fpm_dependency, only : new_dependency_tree use fpm_filesystem, only: is_dir, join_path, list_files, exists, & - basename, filewrite, mkdir, run, os_delete_dir, get_temp_filename + basename, filewrite, mkdir, run, os_delete_dir use fpm_model, only: fpm_model_t, srcfile_t, show_model, fortran_features_t, & FPM_SCOPE_UNKNOWN, FPM_SCOPE_LIB, FPM_SCOPE_DEP, & FPM_SCOPE_APP, FPM_SCOPE_EXAMPLE, FPM_SCOPE_TEST @@ -22,20 +22,18 @@ module fpm use fpm_meta, only : resolve_metapackages use fpm_error, only : error_t, fatal_error, fpm_stop use fpm_toml, only: name_is_json -use fpm_downloader, only: downloader_t -use fpm_versioning, only: version_t -use tomlf, only : toml_array, get_value, len, toml_key +use tomlf, only : len use, intrinsic :: iso_fortran_env, only : stdin => input_unit, & & stdout => output_unit, & & stderr => error_unit use iso_c_binding, only: c_char, c_ptr, c_int, c_null_char, c_associated, c_f_pointer use fpm_environment, only: os_is_unix use jonquil, only : json_object -use fpm_settings, only: fpm_global_settings, get_global_settings, official_registry_base_url +use fpm_settings, only: fpm_global_settings, get_global_settings implicit none private -public :: cmd_build, cmd_run, cmd_clean, cmd_search +public :: cmd_build, cmd_run, cmd_clean public :: build_model, check_modules_for_duplicates contains @@ -720,59 +718,6 @@ subroutine cmd_clean(settings) end if end subroutine cmd_clean -!> Search the fpm registry for a package -subroutine cmd_search(settings) - !> Settings for the search command. - class(fpm_search_settings), intent(inout) :: settings - character(:), allocatable :: tmp_file, name, namespace, description, query_url - type(toml_key), allocatable :: list(:) - integer :: stat, unit, ii - type(json_object) :: json - type(json_object), pointer :: p - !> Error handling. - type(error_t), allocatable :: error - type(toml_array), pointer :: array - type(version_t), allocatable :: version - - !> Downloader instance. - class(downloader_t), allocatable :: downloader - allocate (downloader) - - !> Generate a temporary file to store the downloaded package search data - tmp_file = get_temp_filename() - open (newunit=unit, file=tmp_file, action='readwrite', iostat=stat) - if (stat /= 0) then - call fatal_error(error, "Error creating temporary file for downloading package."); return - end if - - if (settings%page == ' ') then - settings%page = '1' - end if - query_url = official_registry_base_url//'/packages?query='//settings%query//'&page='//settings%page - - !> Get the package data from the registry - call downloader%get_pkg_data(query_url, version, tmp_file, json, error) - close (unit) - if (allocated(error)) return - - if (json%has_key("packages")) then - call get_value(json, 'packages', array) - print '(A,I0,A)', ' Found ', len(array), ' packages:' - do ii=1, len(array) - call get_value(array, ii, p) - call get_value(p, 'name', name) - call get_value(p, 'namespace', namespace) - call get_value(p, 'description', description) - print *, "Name: ", name - print *, "namespace: ", namespace - print *, "Description: ", description - print *, "" - end do - else - call fatal_error(error, "Error Searching Packages"); return - end if -end subroutine cmd_search - !> Sort executables by namelist ID, and trim unused values pure subroutine sort_executables(target_ID,executables) integer, allocatable, intent(inout) :: target_ID(:) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 new file mode 100644 index 0000000000..264a431238 --- /dev/null +++ b/src/fpm/cmd/search.f90 @@ -0,0 +1,151 @@ +!> Search a package from both local and remote registry using the `search` command. +!> +!> The package can be searched by packagename, namespace, query (description and README.md), and license from the registries (local and remote). +!> the remote registry URL can also be specified by the paramter --registry. +!> It can be used as `fpm search --query fortran --page 2 --name fortran --namespace fortran --license MIT --registry URL`. +module fpm_cmd_search + use fpm_command_line, only: fpm_search_settings + use fpm_manifest, only: package_config_t, get_package_data + use fpm_model, only: fpm_model_t + use fpm_error, only: error_t, fpm_stop + use fpm_versioning, only: version_t + use fpm_filesystem, only: exists, join_path, get_temp_filename, delete_file, basename, & + canon_path, dirname, list_files, is_hidden_file + use fpm_git, only: git_archive + use fpm_downloader, only: downloader_t + use fpm_strings, only: string_t, string_array_contains, split, str + use fpm, only: build_model + use fpm_error, only : error_t, fatal_error, fpm_stop + use jonquil, only : json_object + use tomlf, only : toml_array, get_value, len, toml_key + use fpm_settings, only: fpm_global_settings, get_global_settings, official_registry_base_url + + implicit none + private + public :: cmd_search + + contains + + !> Search the fpm registry for a package + subroutine cmd_search(settings) + !> Settings for the search command. + class(fpm_search_settings), intent(in) :: settings + type(fpm_global_settings) :: global_settings + character(:), allocatable :: tmp_file, name, namespace, description, query_url + type(toml_key), allocatable :: list(:) + integer :: stat, unit, ii + type(json_object) :: json + type(json_object), pointer :: p + !> Error handling. + type(error_t), allocatable :: error + type(toml_array), pointer :: array + type(version_t), allocatable :: version + + !> Downloader instance. + class(downloader_t), allocatable :: downloader + allocate (downloader) + + call get_global_settings(global_settings, error) + if (allocated(error)) then + call fpm_stop(1, "Error retrieving global settings"); return + end if + + print *,global_settings%registry_settings%cache_path + ! print *,global_settings%registry_settings%path + ! print *,global_settings%registry_settings%url + ! print *,global_settings%path_to_config_folder + + ! new function to search package names, namespace. + ! query general term for description (both toml and readme) + ! search by namespace, package, license + ! search by namespace , package. + ! from fpm.toml -> description and license + ! README.md -> description + + + !> Generate a temporary file to store the downloaded package search data + tmp_file = get_temp_filename() + open (newunit=unit, file=tmp_file, action='readwrite', iostat=stat) + if (stat /= 0) then + call fatal_error(error, "Error creating temporary file for downloading package."); return + end if + + query_url = settings%registry//'/packages?query='//settings%query//'&page='//settings%page + + !> Get the package data from the registry + call downloader%get_pkg_data(query_url, version, tmp_file, json, error) + close (unit) + if (allocated(error)) then + call fpm_stop(1, "Error retrieving package data from registry: "//settings%registry); return + end if + + call search_namespace(settings%namespace) + if (.not.json%has_key("packages")) then + call get_value(json, 'packages', array) + print '(A,I0,A)', ' Found ', len(array), ' packages:' + do ii=1, len(array) + call get_value(array, ii, p) + call get_value(p, 'name', name) + call get_value(p, 'namespace', namespace) + call get_value(p, 'description', description) + print *, "Name: ", name + print *, "namespace: ", namespace + print *, "Description: ", description + print *, "" + end do + else + call fpm_stop(1, "Invalid package data returned"); return + end if + end subroutine cmd_search + + subroutine search_namespace(namespace) + type(fpm_global_settings) :: global_settings + type(error_t), allocatable :: error + character(:), allocatable, intent(in) :: namespace + character(:), allocatable :: path + character(:), allocatable :: array(:) + type(string_t), allocatable :: file_names(:) + integer :: i,j + + + call get_global_settings(global_settings, error) + if (allocated(error)) then + call fpm_stop(1, "Error retrieving global settings"); return + end if + + ! print *,global_settings%registry_settings%cache_path + print *, "Searching for namespace: ", namespace + + if (exists(join_path(global_settings%registry_settings%cache_path, namespace))) then + ! print *, "Namespace: ", namespace + path = join_path(global_settings%registry_settings%cache_path, namespace) + + ! Scan directory for sources + call list_files(path, file_names,recurse=.false.) + print *, "Found "//str(size(file_names))//" package(s) in namespace in the local registry." + do i=1,size(file_names) + if (.not.is_hidden_file(file_names(i)%s)) then + call split(file_names(i)%s,array,'/') + print *,"Package: ", array(size(array)) + print *, "Add as Dependency: " + print *, array(size(array)), " = { namespace = '", namespace, "' }" + end if + end do + else + print *, "Namespace not found in local registry. Searching remote registry." + + end if + + end subroutine search_namespace + + ! subroutine print_upload_data(upload_data) + ! type(string_t), intent(in) :: upload_data(:) + ! integer :: i + + ! print *, 'Upload data:' + ! do i = 1, size(upload_data) + ! print *, upload_data(i)%s + ! end do + ! end + end + \ No newline at end of file diff --git a/src/fpm/dependency.f90 b/src/fpm/dependency.f90 index bc5aebde77..6cc87e4212 100644 --- a/src/fpm/dependency.f90 +++ b/src/fpm/dependency.f90 @@ -695,7 +695,7 @@ subroutine get_from_registry(self, target_dir, global_settings, error, downloade end if ! Include namespace and package name in the target url and download package data. - target_url = global_settings%registry_settings%url//'/packages/'//self%namespace//'/'//self%name + target_url = global_settings%registry_settings%url//'packages/'//self%namespace//'/'//self%name call downloader%get_pkg_data(target_url, self%requested_version, tmp_file, json, error) close (unit, status='delete') if (allocated(error)) return diff --git a/src/fpm/downloader.f90 b/src/fpm/downloader.f90 index 45b7bc24c2..c0568ef77f 100644 --- a/src/fpm/downloader.f90 +++ b/src/fpm/downloader.f90 @@ -116,7 +116,7 @@ subroutine unpack(tmp_pkg_file, destination, error) !> Error handling. type(error_t), allocatable, intent(out) :: error - integer :: stat + integer :: stat,unit if (which('tar') == '') then call fatal_error(error, "'tar' not installed."); return @@ -128,5 +128,12 @@ subroutine unpack(tmp_pkg_file, destination, error) if (stat /= 0) then call fatal_error(error, "Error unpacking '"//tmp_pkg_file//"'."); return end if + + open (newunit=unit, file=destination//'cache.data', action='readwrite', iostat=stat) + if (stat /= 0) then + call fatal_error(error, "Error creating temporary file for downloading package."); return + end if + write(unit, '(A)') destination + close(unit) end end diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 75f1c7ddff..3d70f17d07 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -32,6 +32,7 @@ module fpm_command_line string_t, glob use fpm_filesystem, only : basename, canon_path, which, run use fpm_environment, only : get_command_arguments_quoted +use fpm_settings, only : official_registry_base_url use fpm_error, only : fpm_stop, error_t use fpm_os, only : get_current_directory use fpm_release, only : fpm_version, version_t @@ -136,6 +137,10 @@ module fpm_command_line type, extends(fpm_cmd_settings) :: fpm_search_settings character(len=:),allocatable :: query character(len=:),allocatable :: page + character(len=:),allocatable :: registry + character(len=:),allocatable :: namespace + character(len=:),allocatable :: package + character(len=:),allocatable :: license end type type, extends(fpm_build_settings) :: fpm_publish_settings @@ -155,9 +160,9 @@ module fpm_command_line & help_test(:), help_build(:), help_usage(:), help_runner(:), & & help_text(:), help_install(:), help_help(:), help_update(:), & & help_list(:), help_list_dash(:), help_list_nodash(:), & - & help_clean(:), help_publish(:) + & help_clean(:), help_publish(:), help_search(:) character(len=20),parameter :: manual(*)=[ character(len=20) ::& -& ' ', 'fpm', 'new', 'build', 'run', 'clean', & +& ' ', 'fpm', 'new', 'build', 'run', 'clean', 'search', & & 'test', 'runner', 'install', 'update', 'list', 'help', 'version', 'publish' ] character(len=:), allocatable :: val_runner, val_compiler, val_flag, val_cflag, val_cxxflag, val_ldflag, & @@ -244,7 +249,8 @@ subroutine get_command_line_settings(cmd_settings) type(fpm_export_settings) , allocatable :: export_settings type(version_t) :: version character(len=:), allocatable :: common_args, compiler_args, run_args, working_dir, & - & c_compiler, cxx_compiler, archiver, version_s, token_s, query, page + & c_compiler, cxx_compiler, archiver, version_s, token_s, query, page, registry, & + & namespace, license, package character(len=*), parameter :: fc_env = "FC", cc_env = "CC", ar_env = "AR", & & fflags_env = "FFLAGS", cflags_env = "CFLAGS", cxxflags_env = "CXXFLAGS", ldflags_env = "LDFLAGS", & @@ -525,6 +531,8 @@ subroutine get_command_line_settings(cmd_settings) help_text=[character(len=widest) :: help_text, version_text] case('clean' ) help_text=[character(len=widest) :: help_text, help_clean] + case('search' ) + help_text=[character(len=widest) :: help_text, help_search] case('publish') help_text=[character(len=widest) :: help_text, help_publish] case default @@ -711,14 +719,34 @@ subroutine get_command_line_settings(cmd_settings) call set_args(common_args //'& & --query " " & & --page " " & + & --registry " " & + & --namespace " " & + & --package " " & + & --license " " & & --', help_clean, version_text) query = sget('query') page = sget('page') + registry = sget('registry') + namespace = sget('namespace') + package = sget('package') + license = sget('license') block + if (query=='') then + call fpm_stop(2, 'Query must be specified on the search subcommand.') + end if + if (page=='') page='1' + if (.not. registry=='') then + print *, 'Using custom registry for seaching packages: ', registry + registry = trim(adjustl(registry)) + else + registry = official_registry_base_url + end if allocate(fpm_search_settings :: cmd_settings) cmd_settings = fpm_search_settings( & - & query=query, page=page) + & query=query, page=page, registry=registry, & + & namespace=namespace, package=package, & + & license=license) end block case('publish') @@ -739,7 +767,8 @@ subroutine get_command_line_settings(cmd_settings) archiver = sget('archiver') token_s = sget('token') - allocate(fpm_publish_settings :: cmd_settings) + allocate(fpm_publish_settings :: cmd_settings) ! Use local registry if it was specified in the global config file. + cmd_settings = fpm_publish_settings( & & show_package_version = lget('show-package-version'), & & show_upload_data = lget('show-upload-data'), & @@ -839,6 +868,7 @@ subroutine set_help() ' update Update and manage project dependencies ', & ' install Install project ', & ' clean Delete the build ', & + ' search Search for the packages in local registry and fpm-registry ', & ' publish Publish package to the registry ', & ' ', & ' Enter "fpm --list" for a brief list of subcommand options. Enter ', & @@ -860,6 +890,7 @@ subroutine set_help() ' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] ', & ' [options] ', & ' clean [--skip] [--all] [--registry-cache] ', & + ' search [--query] [--page] ', & ' publish [--token TOKEN] [--show-package-version] [--show-upload-data] ', & ' [--dry-run] [--verbose] ', & ' '] @@ -970,6 +1001,7 @@ subroutine set_help() ' + install Install project. ', & ' + clean Delete directories in the "build/" directory, except ', & ' dependencies. Prompts for confirmation to delete. ', & + ' + search Search for packages in local and fpm-registry ', & ' + publish Publish package to the registry. ', & ' ', & ' Their syntax is ', & @@ -989,6 +1021,7 @@ subroutine set_help() ' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] ', & ' [options] ', & ' clean [--skip] [--all] [--registry-cache] ', & + ' search [--query] [--page] ', & ' publish [--token TOKEN] [--show-package-version] [--show-upload-data] ', & ' [--dry-run] [--verbose] ', & ' ', & @@ -1060,6 +1093,7 @@ subroutine set_help() ' fpm run myprogram --profile release -- -x 10 -y 20 --title "my title" ', & ' fpm install --prefix ~/.local ', & ' fpm clean --all ', & + ' fpm search --query fortran --page 2 ', & ' ', & 'SEE ALSO ', & ' ', & @@ -1479,6 +1513,21 @@ subroutine set_help() ' --all Delete the build without prompting including dependencies.', & ' --registry-cache Delete registry cache.', & '' ] + help_search=[character(len=80) :: & + 'NAME', & + ' search(1) - search for the package in local and fpm - registry.', & + '', & + 'SYNOPSIS', & + ' fpm search', & + '', & + 'DESCRIPTION', & + ' Prompts the user to search deletion of the build. If affirmative,', & + ' directories in the build/ directory are deleted, except dependencies.', & + ' Use the --registry-cache option to delete the registry cache.', & + '', & + 'OPTIONS', & + ' --registry-cache Delete registry cache.', & + '' ] help_publish=[character(len=80) :: & 'NAME', & ' publish(1) - publish package to the registry', & From 384ef9397e4169b979f10e045b5429f56b5eddde Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 26 May 2024 20:30:55 +0530 Subject: [PATCH 14/51] clean --- src/fpm/downloader.f90 | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/fpm/downloader.f90 b/src/fpm/downloader.f90 index c0568ef77f..327cef8a70 100644 --- a/src/fpm/downloader.f90 +++ b/src/fpm/downloader.f90 @@ -129,11 +129,5 @@ subroutine unpack(tmp_pkg_file, destination, error) call fatal_error(error, "Error unpacking '"//tmp_pkg_file//"'."); return end if - open (newunit=unit, file=destination//'cache.data', action='readwrite', iostat=stat) - if (stat /= 0) then - call fatal_error(error, "Error creating temporary file for downloading package."); return - end if - write(unit, '(A)') destination - close(unit) end end From ea021d3d2d6687499d6d1910bf9e8ac13564e8d3 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 26 May 2024 20:31:36 +0530 Subject: [PATCH 15/51] clean --- src/fpm/downloader.f90 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/fpm/downloader.f90 b/src/fpm/downloader.f90 index 327cef8a70..45b7bc24c2 100644 --- a/src/fpm/downloader.f90 +++ b/src/fpm/downloader.f90 @@ -116,7 +116,7 @@ subroutine unpack(tmp_pkg_file, destination, error) !> Error handling. type(error_t), allocatable, intent(out) :: error - integer :: stat,unit + integer :: stat if (which('tar') == '') then call fatal_error(error, "'tar' not installed."); return @@ -128,6 +128,5 @@ subroutine unpack(tmp_pkg_file, destination, error) if (stat /= 0) then call fatal_error(error, "Error unpacking '"//tmp_pkg_file//"'."); return end if - end end From 7dbd3f77389dca3866830b08cdb2b1c394c52323 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 26 May 2024 20:32:45 +0530 Subject: [PATCH 16/51] clean --- src/fpm.f90 | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/fpm.f90 b/src/fpm.f90 index 636ec21509..37cf069c9c 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -22,13 +22,11 @@ module fpm use fpm_meta, only : resolve_metapackages use fpm_error, only : error_t, fatal_error, fpm_stop use fpm_toml, only: name_is_json -use tomlf, only : len use, intrinsic :: iso_fortran_env, only : stdin => input_unit, & & stdout => output_unit, & & stderr => error_unit use iso_c_binding, only: c_char, c_ptr, c_int, c_null_char, c_associated, c_f_pointer use fpm_environment, only: os_is_unix -use jonquil, only : json_object use fpm_settings, only: fpm_global_settings, get_global_settings implicit none From 11c05cba1728c5107b8caf87026d9e48abb8ed09 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 26 May 2024 20:42:22 +0530 Subject: [PATCH 17/51] clean --- src/fpm/cmd/search.f90 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index 264a431238..5463848f20 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -126,14 +126,13 @@ subroutine search_namespace(namespace) do i=1,size(file_names) if (.not.is_hidden_file(file_names(i)%s)) then call split(file_names(i)%s,array,'/') - print *,"Package: ", array(size(array)) + print *, "Package: ", array(size(array)) print *, "Add as Dependency: " print *, array(size(array)), " = { namespace = '", namespace, "' }" end if end do else print *, "Namespace not found in local registry. Searching remote registry." - end if end subroutine search_namespace From 762b78e6caef0259815ce4cd2f5105be163eab38 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 26 May 2024 23:11:20 +0530 Subject: [PATCH 18/51] clean --- src/fpm/cmd/search.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index 5463848f20..63ba101434 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -80,7 +80,7 @@ subroutine cmd_search(settings) end if call search_namespace(settings%namespace) - if (.not.json%has_key("packages")) then + if (json%has_key("packages")) then call get_value(json, 'packages', array) print '(A,I0,A)', ' Found ', len(array), ' packages:' do ii=1, len(array) From 08f0171094d05c69688ade582b8e6a9c5dc10cea Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 26 May 2024 23:12:54 +0530 Subject: [PATCH 19/51] clean --- src/fpm/cmd/search.f90 | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index 63ba101434..c9bbc3c8fa 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -136,15 +136,5 @@ subroutine search_namespace(namespace) end if end subroutine search_namespace - - ! subroutine print_upload_data(upload_data) - ! type(string_t), intent(in) :: upload_data(:) - ! integer :: i - - ! print *, 'Upload data:' - ! do i = 1, size(upload_data) - ! print *, upload_data(i)%s - ! end do - ! end end \ No newline at end of file From a87b4720739454355cc5c76242ca17aced825773 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Mon, 27 May 2024 16:53:25 +0530 Subject: [PATCH 20/51] fix --- example_packages/many_examples/demo1.txt | 1 + example_packages/many_examples/demo2.txt | 1 + src/fpm_command_line.f90 | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 example_packages/many_examples/demo1.txt create mode 100644 example_packages/many_examples/demo2.txt diff --git a/example_packages/many_examples/demo1.txt b/example_packages/many_examples/demo1.txt new file mode 100644 index 0000000000..5b5013d6f4 --- /dev/null +++ b/example_packages/many_examples/demo1.txt @@ -0,0 +1 @@ +DEMO1 diff --git a/example_packages/many_examples/demo2.txt b/example_packages/many_examples/demo2.txt new file mode 100644 index 0000000000..a7390b4791 --- /dev/null +++ b/example_packages/many_examples/demo2.txt @@ -0,0 +1 @@ +DEMO2 diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 3d70f17d07..25e9e56912 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -723,7 +723,7 @@ subroutine get_command_line_settings(cmd_settings) & --namespace " " & & --package " " & & --license " " & - & --', help_clean, version_text) + & --', help_search, version_text) query = sget('query') page = sget('page') registry = sget('registry') From 5f3a18d5923acb12e4b5688565ee8b9cf9564bb4 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Mon, 27 May 2024 16:57:04 +0530 Subject: [PATCH 21/51] fix --- test/help_test/help_test.f90 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/help_test/help_test.f90 b/test/help_test/help_test.f90 index 8112b81a37..b0745eaf0b 100644 --- a/test/help_test/help_test.f90 +++ b/test/help_test/help_test.f90 @@ -34,6 +34,7 @@ program help_test 'help list >> fpm_scratch_help.txt',& 'help help >> fpm_scratch_help.txt',& 'help clean >> fpm_scratch_help.txt',& +'help search >> fpm_scratch_help.txt',& 'help publish >> fpm_scratch_help.txt',& '--version >> fpm_scratch_help.txt',& ! generate manual @@ -43,7 +44,7 @@ program help_test !'fpm run -- --list >> fpm_scratch_help.txt',& !'fpm run -- list --list >> fpm_scratch_help.txt',& character(len=*),parameter :: names(*)=[character(len=10) ::& - 'fpm','new','update','build','run','test','runner','install','list','help','clean'] + 'fpm','new','update','build','run','test','runner','install','list','help','clean','search'] character(len=:), allocatable :: prog integer :: length From 334eeb5bb573dc9fc3f8a85ffeede5fe3603e4d5 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Mon, 27 May 2024 20:15:51 +0530 Subject: [PATCH 22/51] add: new search paramters --- src/fpm/cmd/search.f90 | 2 +- src/fpm_command_line.f90 | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index c9bbc3c8fa..9c01b032c7 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -70,7 +70,7 @@ subroutine cmd_search(settings) call fatal_error(error, "Error creating temporary file for downloading package."); return end if - query_url = settings%registry//'/packages?query='//settings%query//'&page='//settings%page + query_url = settings%registry//'/packages_cli?query='//settings%query//'&page='//settings%page !> Get the package data from the registry call downloader%get_pkg_data(query_url, version, tmp_file, json, error) diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 25e9e56912..6b5934cdbb 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -141,6 +141,9 @@ module fpm_command_line character(len=:),allocatable :: namespace character(len=:),allocatable :: package character(len=:),allocatable :: license + character(len=:),allocatable :: limit + character(len=:),allocatable :: sort_by + character(len=:),allocatable :: sort end type type, extends(fpm_build_settings) :: fpm_publish_settings @@ -250,7 +253,7 @@ subroutine get_command_line_settings(cmd_settings) type(version_t) :: version character(len=:), allocatable :: common_args, compiler_args, run_args, working_dir, & & c_compiler, cxx_compiler, archiver, version_s, token_s, query, page, registry, & - & namespace, license, package + & namespace, license, package, limit, sort_by, sort character(len=*), parameter :: fc_env = "FC", cc_env = "CC", ar_env = "AR", & & fflags_env = "FFLAGS", cflags_env = "CFLAGS", cxxflags_env = "CXXFLAGS", ldflags_env = "LDFLAGS", & @@ -723,6 +726,9 @@ subroutine get_command_line_settings(cmd_settings) & --namespace " " & & --package " " & & --license " " & + & --limit " " & + & --sort-by " " & + & --sort " " & & --', help_search, version_text) query = sget('query') page = sget('page') @@ -730,12 +736,15 @@ subroutine get_command_line_settings(cmd_settings) namespace = sget('namespace') package = sget('package') license = sget('license') + limit = sget('limit') + sort_by = sget('sort-by') + sort= sget('sort') block if (query=='') then call fpm_stop(2, 'Query must be specified on the search subcommand.') end if - if (page=='') page='1' + if (page=='') page='0' if (.not. registry=='') then print *, 'Using custom registry for seaching packages: ', registry registry = trim(adjustl(registry)) @@ -746,7 +755,8 @@ subroutine get_command_line_settings(cmd_settings) cmd_settings = fpm_search_settings( & & query=query, page=page, registry=registry, & & namespace=namespace, package=package, & - & license=license) + & license=license, limit=limit, sort_by=sort_by, & + & sort=sort) end block case('publish') From a0dbf40a6bc1be809ba870e0bde47e14c3a3a24e Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Mon, 27 May 2024 22:24:26 +0530 Subject: [PATCH 23/51] add: new search paramters --- src/fpm/cmd/search.f90 | 10 +++++++++- src/fpm_command_line.f90 | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index 9c01b032c7..73cdc5e57c 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -70,7 +70,15 @@ subroutine cmd_search(settings) call fatal_error(error, "Error creating temporary file for downloading package."); return end if - query_url = settings%registry//'/packages_cli?query='//settings%query//'&page='//settings%page + query_url = settings%registry//'/packages_cli' & + // '?query='//settings%query & + // '&page='//settings%page & + // '&package='//settings%package & + // '&namespace='//settings%namespace & + // '&license='//settings%license & + // '&limit='//settings%limit & + // '&sort_by='//settings%sort_by & + // '&sort='//settings%sort !> Get the package data from the registry call downloader%get_pkg_data(query_url, version, tmp_file, json, error) diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 6b5934cdbb..0c8b78f90b 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -744,7 +744,11 @@ subroutine get_command_line_settings(cmd_settings) if (query=='') then call fpm_stop(2, 'Query must be specified on the search subcommand.') end if - if (page=='') page='0' + if (page=='') page='1' + if (package==' ') package='' + if (license==' ') license='' + if (sort_by==' ') sort_by='name' + if (sort==' ') sort='asc' if (.not. registry=='') then print *, 'Using custom registry for seaching packages: ', registry registry = trim(adjustl(registry)) From 494194fad83ec5f15c424528cd26b8a6f450834f Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Mon, 27 May 2024 22:25:51 +0530 Subject: [PATCH 24/51] add: new search paramters --- example_packages/many_examples/demo1.txt | 1 - example_packages/many_examples/demo2.txt | 1 - 2 files changed, 2 deletions(-) delete mode 100644 example_packages/many_examples/demo1.txt delete mode 100644 example_packages/many_examples/demo2.txt diff --git a/example_packages/many_examples/demo1.txt b/example_packages/many_examples/demo1.txt deleted file mode 100644 index 5b5013d6f4..0000000000 --- a/example_packages/many_examples/demo1.txt +++ /dev/null @@ -1 +0,0 @@ -DEMO1 diff --git a/example_packages/many_examples/demo2.txt b/example_packages/many_examples/demo2.txt deleted file mode 100644 index a7390b4791..0000000000 --- a/example_packages/many_examples/demo2.txt +++ /dev/null @@ -1 +0,0 @@ -DEMO2 From 5eb04a5748917cf919bdb3f92af4ec755a5544e8 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Mon, 27 May 2024 22:40:20 +0530 Subject: [PATCH 25/51] add: new search paramters --- src/fpm/cmd/search.f90 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index 73cdc5e57c..dd05b805a9 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -87,7 +87,7 @@ subroutine cmd_search(settings) call fpm_stop(1, "Error retrieving package data from registry: "//settings%registry); return end if - call search_namespace(settings%namespace) + ! call search_namespace(settings%namespace) if (json%has_key("packages")) then call get_value(json, 'packages', array) print '(A,I0,A)', ' Found ', len(array), ' packages:' @@ -104,6 +104,7 @@ subroutine cmd_search(settings) else call fpm_stop(1, "Invalid package data returned"); return end if + print *, "Searching in local registry is not implemented yet for all parameters." end subroutine cmd_search subroutine search_namespace(namespace) From 034051d77031b046550c206c30688c51e4294657 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Wed, 29 May 2024 13:18:54 +0530 Subject: [PATCH 26/51] add: version functionality --- src/fpm/cmd/search.f90 | 26 +++++++++++++++++--------- src/fpm_command_line.f90 | 9 ++++++--- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index dd05b805a9..a8400e8aab 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -65,20 +65,28 @@ subroutine cmd_search(settings) !> Generate a temporary file to store the downloaded package search data tmp_file = get_temp_filename() - open (newunit=unit, file=tmp_file, action='readwrite', iostat=stat) + open (newunit=unit, file=tmp_file, action='readwrite', iostat=stat,status='write') if (stat /= 0) then call fatal_error(error, "Error creating temporary file for downloading package."); return end if query_url = settings%registry//'/packages_cli' & - // '?query='//settings%query & - // '&page='//settings%page & - // '&package='//settings%package & - // '&namespace='//settings%namespace & - // '&license='//settings%license & - // '&limit='//settings%limit & - // '&sort_by='//settings%sort_by & - // '&sort='//settings%sort + & // '?query='//settings%query & + & // '&page='//settings%page & + & // '&package='//settings%package & + & // '&namespace='//settings%namespace & + & // '&version='//settings%version & + & // '&license='//settings%license & + & // '&limit='//settings%limit & + & // '&sort_by='//settings%sort_by & + & // '&sort='//settings%sort + + ! also add version + !> name,license,version, description1 from fpm.toml + !> description2 from README.md + !> manipulation parameters: page, sort, sort_by, limit + !> search parameters: name, namespace, license, query -> (description1, description2) + !> Get the package data from the registry call downloader%get_pkg_data(query_url, version, tmp_file, json, error) diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 0c8b78f90b..aa14978efa 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -140,6 +140,7 @@ module fpm_command_line character(len=:),allocatable :: registry character(len=:),allocatable :: namespace character(len=:),allocatable :: package + character(len=:),allocatable :: version character(len=:),allocatable :: license character(len=:),allocatable :: limit character(len=:),allocatable :: sort_by @@ -253,7 +254,7 @@ subroutine get_command_line_settings(cmd_settings) type(version_t) :: version character(len=:), allocatable :: common_args, compiler_args, run_args, working_dir, & & c_compiler, cxx_compiler, archiver, version_s, token_s, query, page, registry, & - & namespace, license, package, limit, sort_by, sort + & namespace, license, package, package_version, limit, sort_by, sort character(len=*), parameter :: fc_env = "FC", cc_env = "CC", ar_env = "AR", & & fflags_env = "FFLAGS", cflags_env = "CFLAGS", cxxflags_env = "CXXFLAGS", ldflags_env = "LDFLAGS", & @@ -734,11 +735,12 @@ subroutine get_command_line_settings(cmd_settings) page = sget('page') registry = sget('registry') namespace = sget('namespace') + package_version = sget('version') package = sget('package') license = sget('license') limit = sget('limit') sort_by = sget('sort-by') - sort= sget('sort') + sort = sget('sort') block if (query=='') then @@ -749,6 +751,7 @@ subroutine get_command_line_settings(cmd_settings) if (license==' ') license='' if (sort_by==' ') sort_by='name' if (sort==' ') sort='asc' + if (package_version==' ') package_version='' if (.not. registry=='') then print *, 'Using custom registry for seaching packages: ', registry registry = trim(adjustl(registry)) @@ -758,7 +761,7 @@ subroutine get_command_line_settings(cmd_settings) allocate(fpm_search_settings :: cmd_settings) cmd_settings = fpm_search_settings( & & query=query, page=page, registry=registry, & - & namespace=namespace, package=package, & + & namespace=namespace, package=package, version=package_version, & & license=license, limit=limit, sort_by=sort_by, & & sort=sort) end block From 373155ca4b91f8407709a0eefc60ab0daafef47f Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Wed, 29 May 2024 13:38:36 +0530 Subject: [PATCH 27/51] add: docs --- src/fpm/cmd/search.f90 | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index a8400e8aab..8ded0aa6cb 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -62,7 +62,6 @@ subroutine cmd_search(settings) ! from fpm.toml -> description and license ! README.md -> description - !> Generate a temporary file to store the downloaded package search data tmp_file = get_temp_filename() open (newunit=unit, file=tmp_file, action='readwrite', iostat=stat,status='write') @@ -70,7 +69,7 @@ subroutine cmd_search(settings) call fatal_error(error, "Error creating temporary file for downloading package."); return end if - query_url = settings%registry//'/packages_cli' & + query_url = settings%registry//'/packages_cli' & & // '?query='//settings%query & & // '&page='//settings%page & & // '&package='//settings%package & @@ -80,13 +79,11 @@ subroutine cmd_search(settings) & // '&limit='//settings%limit & & // '&sort_by='//settings%sort_by & & // '&sort='//settings%sort - - ! also add version - !> name,license,version, description1 from fpm.toml - !> description2 from README.md - !> manipulation parameters: page, sort, sort_by, limit - !> search parameters: name, namespace, license, query -> (description1, description2) - + + !> search parameters: name, namespace, version, license, query -> (description1, description2) + !> name, license, version, description1 from fpm.toml + !> description2 from README.md (if exists) + !> order manipulation parameters: page, sort, sort_by, limit !> Get the package data from the registry call downloader%get_pkg_data(query_url, version, tmp_file, json, error) @@ -97,18 +94,19 @@ subroutine cmd_search(settings) ! call search_namespace(settings%namespace) if (json%has_key("packages")) then - call get_value(json, 'packages', array) - print '(A,I0,A)', ' Found ', len(array), ' packages:' - do ii=1, len(array) - call get_value(array, ii, p) - call get_value(p, 'name', name) - call get_value(p, 'namespace', namespace) - call get_value(p, 'description', description) - print *, "Name: ", name - print *, "namespace: ", namespace - print *, "Description: ", description - print *, "" - end do + !> Better method to display the package data + ! call get_value(json, 'packages', array) + ! print '(A,I0,A)', ' Found ', len(array), ' packages:' + ! do ii=1, len(array) + ! call get_value(array, ii, p) + ! call get_value(p, 'name', name) + ! call get_value(p, 'namespace', namespace) + ! call get_value(p, 'description', description) + ! print *, "Name: ", name + ! print *, "namespace: ", namespace + ! print *, "Description: ", description + ! print *, "" + ! end do else call fpm_stop(1, "Invalid package data returned"); return end if From 18c3975bcacf2e7096826718fd4ecc860f6b03f2 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Wed, 29 May 2024 21:51:59 +0530 Subject: [PATCH 28/51] search in local registry --- src/fpm/cmd/search.f90 | 48 +++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index 8ded0aa6cb..e49b689d29 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -50,7 +50,7 @@ subroutine cmd_search(settings) call fpm_stop(1, "Error retrieving global settings"); return end if - print *,global_settings%registry_settings%cache_path + ! print *,global_settings%registry_settings%cache_path ! print *,global_settings%registry_settings%path ! print *,global_settings%registry_settings%url ! print *,global_settings%path_to_config_folder @@ -68,7 +68,6 @@ subroutine cmd_search(settings) if (stat /= 0) then call fatal_error(error, "Error creating temporary file for downloading package."); return end if - query_url = settings%registry//'/packages_cli' & & // '?query='//settings%query & & // '&page='//settings%page & @@ -84,29 +83,32 @@ subroutine cmd_search(settings) !> name, license, version, description1 from fpm.toml !> description2 from README.md (if exists) !> order manipulation parameters: page, sort, sort_by, limit + !> show page number and total_pages !> Get the package data from the registry + ! print *, settings%namespace call downloader%get_pkg_data(query_url, version, tmp_file, json, error) close (unit) if (allocated(error)) then call fpm_stop(1, "Error retrieving package data from registry: "//settings%registry); return end if + - ! call search_namespace(settings%namespace) + call search_namespace(settings%namespace) if (json%has_key("packages")) then !> Better method to display the package data - ! call get_value(json, 'packages', array) - ! print '(A,I0,A)', ' Found ', len(array), ' packages:' - ! do ii=1, len(array) - ! call get_value(array, ii, p) - ! call get_value(p, 'name', name) - ! call get_value(p, 'namespace', namespace) - ! call get_value(p, 'description', description) - ! print *, "Name: ", name - ! print *, "namespace: ", namespace - ! print *, "Description: ", description - ! print *, "" - ! end do + call get_value(json, 'packages', array) + print '(A,I0,A)', ' Found ', len(array), ' packages:' + do ii=1, len(array) + call get_value(array, ii, p) + call get_value(p, 'name', name) + call get_value(p, 'namespace', namespace) + call get_value(p, 'description', description) + print *, "Name: ", name + print *, "namespace: ", namespace + print *, "Description: ", description + print *, "" + end do else call fpm_stop(1, "Invalid package data returned"); return end if @@ -127,6 +129,7 @@ subroutine search_namespace(namespace) if (allocated(error)) then call fpm_stop(1, "Error retrieving global settings"); return end if + print *, "called search_namespace" ! print *,global_settings%registry_settings%cache_path print *, "Searching for namespace: ", namespace @@ -136,14 +139,21 @@ subroutine search_namespace(namespace) path = join_path(global_settings%registry_settings%cache_path, namespace) ! Scan directory for sources - call list_files(path, file_names,recurse=.false.) + call list_files(path, file_names,recurse=.true.) print *, "Found "//str(size(file_names))//" package(s) in namespace in the local registry." do i=1,size(file_names) if (.not.is_hidden_file(file_names(i)%s)) then call split(file_names(i)%s,array,'/') - print *, "Package: ", array(size(array)) - print *, "Add as Dependency: " - print *, array(size(array)), " = { namespace = '", namespace, "' }" + if (array(size(array)) == "fpm.toml") then + print *, "Package: ", array(size(array)-1) + print *, array(size(array)-2) + end if + ! print *, "Add as Dependency: " + ! print *, array(size(array)-1), " = { namespace = '", namespace, "' }" + ! end if + ! print *, "Package: ", array(size(array)) + ! print *, "Add as Dependency: " + ! print *, array(size(array)), " = { namespace = '", namespace, "' }" end if end do else From 606c20a39baed4aa05b8e56206716e1c58780d3f Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Wed, 29 May 2024 22:11:10 +0530 Subject: [PATCH 29/51] add: search --- src/fpm/cmd/search.f90 | 36 ++++++++++++++++++------------------ src/fpm_command_line.f90 | 2 ++ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index e49b689d29..203d40c7df 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -64,7 +64,7 @@ subroutine cmd_search(settings) !> Generate a temporary file to store the downloaded package search data tmp_file = get_temp_filename() - open (newunit=unit, file=tmp_file, action='readwrite', iostat=stat,status='write') + open (newunit=unit, file=tmp_file, action='readwrite', iostat=stat) if (stat /= 0) then call fatal_error(error, "Error creating temporary file for downloading package."); return end if @@ -97,18 +97,18 @@ subroutine cmd_search(settings) call search_namespace(settings%namespace) if (json%has_key("packages")) then !> Better method to display the package data - call get_value(json, 'packages', array) - print '(A,I0,A)', ' Found ', len(array), ' packages:' - do ii=1, len(array) - call get_value(array, ii, p) - call get_value(p, 'name', name) - call get_value(p, 'namespace', namespace) - call get_value(p, 'description', description) - print *, "Name: ", name - print *, "namespace: ", namespace - print *, "Description: ", description - print *, "" - end do + ! call get_value(json, 'packages', array) + ! print '(A,I0,A)', ' Found ', len(array), ' packages:' + ! do ii=1, len(array) + ! call get_value(array, ii, p) + ! call get_value(p, 'name', name) + ! call get_value(p, 'namespace', namespace) + ! call get_value(p, 'description', description) + ! print *, "Name: ", name + ! print *, "namespace: ", namespace + ! print *, "Description: ", description + ! print *, "" + ! end do else call fpm_stop(1, "Invalid package data returned"); return end if @@ -129,24 +129,24 @@ subroutine search_namespace(namespace) if (allocated(error)) then call fpm_stop(1, "Error retrieving global settings"); return end if - print *, "called search_namespace" ! print *,global_settings%registry_settings%cache_path print *, "Searching for namespace: ", namespace if (exists(join_path(global_settings%registry_settings%cache_path, namespace))) then ! print *, "Namespace: ", namespace - path = join_path(global_settings%registry_settings%cache_path, namespace) + ! path = join_path(global_settings%registry_settings%cache_path, namespace) + path = global_settings%registry_settings%cache_path ! Scan directory for sources call list_files(path, file_names,recurse=.true.) - print *, "Found "//str(size(file_names))//" package(s) in namespace in the local registry." + ! print *, "Found "//str(size(file_names))//" package(s) in namespace in the local registry." do i=1,size(file_names) if (.not.is_hidden_file(file_names(i)%s)) then call split(file_names(i)%s,array,'/') if (array(size(array)) == "fpm.toml") then - print *, "Package: ", array(size(array)-1) - print *, array(size(array)-2) + print *, "Package: ", array(size(array)-3), array(size(array)-2), array(size(array)-1) + !> read the toml file from the path file_names(i)%s end if ! print *, "Add as Dependency: " ! print *, array(size(array)-1), " = { namespace = '", namespace, "' }" diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index aa14978efa..88a4e0b2ec 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -751,6 +751,8 @@ subroutine get_command_line_settings(cmd_settings) if (license==' ') license='' if (sort_by==' ') sort_by='name' if (sort==' ') sort='asc' + if (limit==' ') limit='10' + if (namespace==' ') namespace='' if (package_version==' ') package_version='' if (.not. registry=='') then print *, 'Using custom registry for seaching packages: ', registry From c1216f0f25fb93439476b4e51e711b780f293d09 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Wed, 29 May 2024 23:27:05 +0530 Subject: [PATCH 30/51] add: search --- src/fpm/cmd/search.f90 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index 203d40c7df..be8853f168 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -145,11 +145,9 @@ subroutine search_namespace(namespace) if (.not.is_hidden_file(file_names(i)%s)) then call split(file_names(i)%s,array,'/') if (array(size(array)) == "fpm.toml") then - print *, "Package: ", array(size(array)-3), array(size(array)-2), array(size(array)-1) + print *, "Package: ", array(size(array)-3), array(size(array)-2), array(size(array)-1), file_names(i)%s !> read the toml file from the path file_names(i)%s end if - ! print *, "Add as Dependency: " - ! print *, array(size(array)-1), " = { namespace = '", namespace, "' }" ! end if ! print *, "Package: ", array(size(array)) ! print *, "Add as Dependency: " From fc62c32ebd6dcab35aec1f203caff41601cffa9e Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Fri, 31 May 2024 11:09:19 +0530 Subject: [PATCH 31/51] add: local registry search functionality for all parameters --- src/fpm/cmd/search.f90 | 77 +++++++++++++++++++++++----------------- src/fpm_command_line.f90 | 3 +- 2 files changed, 47 insertions(+), 33 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index be8853f168..016b7b66bb 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -13,7 +13,7 @@ module fpm_cmd_search canon_path, dirname, list_files, is_hidden_file use fpm_git, only: git_archive use fpm_downloader, only: downloader_t - use fpm_strings, only: string_t, string_array_contains, split, str + use fpm_strings, only: string_t, string_array_contains, split, str,glob use fpm, only: build_model use fpm_error, only : error_t, fatal_error, fpm_stop use jonquil, only : json_object @@ -80,6 +80,8 @@ subroutine cmd_search(settings) & // '&sort='//settings%sort !> search parameters: name, namespace, version, license, query -> (description1, description2) + !> namespace,version,package from url. + !> description1 from fpm.toml and description2 from README.md !> name, license, version, description1 from fpm.toml !> description2 from README.md (if exists) !> order manipulation parameters: page, sort, sort_by, limit @@ -92,9 +94,9 @@ subroutine cmd_search(settings) if (allocated(error)) then call fpm_stop(1, "Error retrieving package data from registry: "//settings%registry); return end if - + ! print *, settings%version - call search_namespace(settings%namespace) + call search_package(settings%namespace, settings%package, settings%version) if (json%has_key("packages")) then !> Better method to display the package data ! call get_value(json, 'packages', array) @@ -112,17 +114,18 @@ subroutine cmd_search(settings) else call fpm_stop(1, "Invalid package data returned"); return end if - print *, "Searching in local registry is not implemented yet for all parameters." + ! print *, "Searching in local registry is not implemented yet for all parameters." end subroutine cmd_search - subroutine search_namespace(namespace) + subroutine search_package(namespace,package,version) type(fpm_global_settings) :: global_settings type(error_t), allocatable :: error - character(:), allocatable, intent(in) :: namespace - character(:), allocatable :: path - character(:), allocatable :: array(:) + character(:), allocatable, intent(in) :: namespace,package,version + character(:), allocatable :: path,array(:) + character(:), allocatable :: wild type(string_t), allocatable :: file_names(:) integer :: i,j + logical :: result call get_global_settings(global_settings, error) @@ -131,33 +134,43 @@ subroutine search_namespace(namespace) end if ! print *,global_settings%registry_settings%cache_path - print *, "Searching for namespace: ", namespace - - if (exists(join_path(global_settings%registry_settings%cache_path, namespace))) then - ! print *, "Namespace: ", namespace - ! path = join_path(global_settings%registry_settings%cache_path, namespace) - path = global_settings%registry_settings%cache_path + path = global_settings%registry_settings%cache_path - ! Scan directory for sources - call list_files(path, file_names,recurse=.true.) - ! print *, "Found "//str(size(file_names))//" package(s) in namespace in the local registry." - do i=1,size(file_names) - if (.not.is_hidden_file(file_names(i)%s)) then - call split(file_names(i)%s,array,'/') - if (array(size(array)) == "fpm.toml") then - print *, "Package: ", array(size(array)-3), array(size(array)-2), array(size(array)-1), file_names(i)%s - !> read the toml file from the path file_names(i)%s - end if - ! end if - ! print *, "Package: ", array(size(array)) - ! print *, "Add as Dependency: " - ! print *, array(size(array)), " = { namespace = '", namespace, "' }" - end if - end do + if (namespace /= "") then + wild = path//"/"//namespace + else + wild = path//"/*" + end if + if (package /= "") then + wild = wild//"/"//package + else + wild = wild//"/*" + end if + if (version /= "") then + wild = wild//"/"//version else - print *, "Namespace not found in local registry. Searching remote registry." + wild = wild//"/?.?.?" end if + wild = wild//"/fpm.toml" + ! print *, "Path: ", wild - end subroutine search_namespace + ! Scan directory for sources + call list_files(path, file_names,recurse=.true.) + do i=1,size(file_names) + if (.not.is_hidden_file(file_names(i)%s)) then + call split(file_names(i)%s,array,'/') + if (array(size(array)) == "fpm.toml") then + result = glob(file_names(i)%s,wild) + if (result) then + ! print *, "Matched results" !> add count + print *, "Package: ", array(size(array)-3), array(size(array)-2), array(size(array)-1) + end if + !> read the toml file from the path file_names(i)%s for data and path + end if + ! print *, "Add as Dependency: " + ! print *, array(size(array)), " = { namespace = '", namespace, "' }" + end if + end do + end subroutine search_package end \ No newline at end of file diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 88a4e0b2ec..e8ccedee45 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -726,6 +726,7 @@ subroutine get_command_line_settings(cmd_settings) & --registry " " & & --namespace " " & & --package " " & + & --package_version " " & & --license " " & & --limit " " & & --sort-by " " & @@ -735,7 +736,7 @@ subroutine get_command_line_settings(cmd_settings) page = sget('page') registry = sget('registry') namespace = sget('namespace') - package_version = sget('version') + package_version = sget('package_version') package = sget('package') license = sget('license') limit = sget('limit') From ced681ec043b1fa3e1d9322e98095cd3727da501 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Fri, 31 May 2024 11:24:48 +0530 Subject: [PATCH 32/51] clean --- src/fpm/cmd/search.f90 | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index 016b7b66bb..370fe4f996 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -133,7 +133,6 @@ subroutine search_package(namespace,package,version) call fpm_stop(1, "Error retrieving global settings"); return end if - ! print *,global_settings%registry_settings%cache_path path = global_settings%registry_settings%cache_path if (namespace /= "") then @@ -152,9 +151,8 @@ subroutine search_package(namespace,package,version) wild = wild//"/?.?.?" end if wild = wild//"/fpm.toml" - ! print *, "Path: ", wild - ! Scan directory for sources + ! Scan directory for packages call list_files(path, file_names,recurse=.true.) do i=1,size(file_names) if (.not.is_hidden_file(file_names(i)%s)) then @@ -163,12 +161,10 @@ subroutine search_package(namespace,package,version) result = glob(file_names(i)%s,wild) if (result) then ! print *, "Matched results" !> add count - print *, "Package: ", array(size(array)-3), array(size(array)-2), array(size(array)-1) + print *, "Package Found: ", array(size(array)-3), array(size(array)-2), array(size(array)-1) end if !> read the toml file from the path file_names(i)%s for data and path end if - ! print *, "Add as Dependency: " - ! print *, array(size(array)), " = { namespace = '", namespace, "' }" end if end do end subroutine search_package From 52b0d79b2a599adc3dedb8ed1bdd895e40606387 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Fri, 31 May 2024 11:27:57 +0530 Subject: [PATCH 33/51] add: enable global search --- src/fpm/cmd/search.f90 | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index 370fe4f996..84bdc53eac 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -99,18 +99,19 @@ subroutine cmd_search(settings) call search_package(settings%namespace, settings%package, settings%version) if (json%has_key("packages")) then !> Better method to display the package data - ! call get_value(json, 'packages', array) - ! print '(A,I0,A)', ' Found ', len(array), ' packages:' - ! do ii=1, len(array) - ! call get_value(array, ii, p) - ! call get_value(p, 'name', name) - ! call get_value(p, 'namespace', namespace) - ! call get_value(p, 'description', description) - ! print *, "Name: ", name - ! print *, "namespace: ", namespace - ! print *, "Description: ", description - ! print *, "" - ! end do + call get_value(json, 'packages', array) + print *, "" + print '(A,I0,A)', ' Found ', len(array), ' packages:' + do ii=1, len(array) + call get_value(array, ii, p) + call get_value(p, 'name', name) + call get_value(p, 'namespace', namespace) + call get_value(p, 'description', description) + print *, "Name: ", name + print *, "namespace: ", namespace + print *, "Description: ", description + print *, "" + end do else call fpm_stop(1, "Invalid package data returned"); return end if From 0ca0eae2fc8e5bef56d753fb126c4ca7fa7d6191 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Fri, 31 May 2024 11:42:36 +0530 Subject: [PATCH 34/51] fix: bugs --- src/fpm/cmd/search.f90 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index 84bdc53eac..0af666b645 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -31,7 +31,7 @@ subroutine cmd_search(settings) !> Settings for the search command. class(fpm_search_settings), intent(in) :: settings type(fpm_global_settings) :: global_settings - character(:), allocatable :: tmp_file, name, namespace, description, query_url + character(:), allocatable :: tmp_file, name, namespace, description, query_url,package_version type(toml_key), allocatable :: list(:) integer :: stat, unit, ii type(json_object) :: json @@ -81,6 +81,9 @@ subroutine cmd_search(settings) !> search parameters: name, namespace, version, license, query -> (description1, description2) !> namespace,version,package from url. + !> add to search only in the local/global registry + !> for description search + !> fix all the version search in global and add docs for parameters. !> description1 from fpm.toml and description2 from README.md !> name, license, version, description1 from fpm.toml !> description2 from README.md (if exists) @@ -88,7 +91,6 @@ subroutine cmd_search(settings) !> show page number and total_pages !> Get the package data from the registry - ! print *, settings%namespace call downloader%get_pkg_data(query_url, version, tmp_file, json, error) close (unit) if (allocated(error)) then @@ -107,9 +109,11 @@ subroutine cmd_search(settings) call get_value(p, 'name', name) call get_value(p, 'namespace', namespace) call get_value(p, 'description', description) + call get_value(p, 'version', package_version) print *, "Name: ", name print *, "namespace: ", namespace print *, "Description: ", description + print *, "version: ", package_version print *, "" end do else @@ -152,6 +156,8 @@ subroutine search_package(namespace,package,version) wild = wild//"/?.?.?" end if wild = wild//"/fpm.toml" + ! print *, wild + print *, "Package Search in Local Registry:" ! Scan directory for packages call list_files(path, file_names,recurse=.true.) From 4a4c6ce958442dd98673803f3f996edc5e96a54a Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Fri, 31 May 2024 12:34:23 +0530 Subject: [PATCH 35/51] clean --- src/fpm/cmd/search.f90 | 7 +++---- src/fpm_command_line.f90 | 12 ++++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index 0af666b645..c685230efc 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -84,6 +84,7 @@ subroutine cmd_search(settings) !> add to search only in the local/global registry !> for description search !> fix all the version search in global and add docs for parameters. + !> add globbing support for global search !> description1 from fpm.toml and description2 from README.md !> name, license, version, description1 from fpm.toml !> description2 from README.md (if exists) @@ -119,13 +120,12 @@ subroutine cmd_search(settings) else call fpm_stop(1, "Invalid package data returned"); return end if - ! print *, "Searching in local registry is not implemented yet for all parameters." end subroutine cmd_search subroutine search_package(namespace,package,version) type(fpm_global_settings) :: global_settings type(error_t), allocatable :: error - character(:), allocatable, intent(in) :: namespace,package,version + character(:), allocatable, intent(in) :: namespace, package, version character(:), allocatable :: path,array(:) character(:), allocatable :: wild type(string_t), allocatable :: file_names(:) @@ -156,8 +156,7 @@ subroutine search_package(namespace,package,version) wild = wild//"/?.?.?" end if wild = wild//"/fpm.toml" - ! print *, wild - print *, "Package Search in Local Registry:" + print *, "Searching packages in Local Registry:" ! Scan directory for packages call list_files(path, file_names,recurse=.true.) diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index e8ccedee45..7a6049f27b 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -732,21 +732,21 @@ subroutine get_command_line_settings(cmd_settings) & --sort-by " " & & --sort " " & & --', help_search, version_text) + query = sget('query') - page = sget('page') - registry = sget('registry') namespace = sget('namespace') - package_version = sget('package_version') package = sget('package') + package_version = sget('package_version') license = sget('license') + registry = sget('registry') + page = sget('page') limit = sget('limit') sort_by = sget('sort-by') sort = sget('sort') block - if (query=='') then - call fpm_stop(2, 'Query must be specified on the search subcommand.') - end if + + if (query==' ') query='' if (page=='') page='1' if (package==' ') package='' if (license==' ') license='' From 880092558f0dad88d07a04fa56bf718f566f8bf0 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Fri, 31 May 2024 22:15:06 +0530 Subject: [PATCH 36/51] clean --- src/fpm/cmd/search.f90 | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index c685230efc..0c515d3d13 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -19,6 +19,7 @@ module fpm_cmd_search use jonquil, only : json_object use tomlf, only : toml_array, get_value, len, toml_key use fpm_settings, only: fpm_global_settings, get_global_settings, official_registry_base_url + use fpm_versioning, only: version_t, new_version implicit none private @@ -100,7 +101,7 @@ subroutine cmd_search(settings) ! print *, settings%version call search_package(settings%namespace, settings%package, settings%version) - if (json%has_key("packages")) then + if (.not.json%has_key("packages")) then !> Better method to display the package data call get_value(json, 'packages', array) print *, "" @@ -125,6 +126,8 @@ end subroutine cmd_search subroutine search_package(namespace,package,version) type(fpm_global_settings) :: global_settings type(error_t), allocatable :: error + ! type(version_t) :: version_check + ! type(new_version) :: version_check character(:), allocatable, intent(in) :: namespace, package, version character(:), allocatable :: path,array(:) character(:), allocatable :: wild @@ -158,6 +161,8 @@ subroutine search_package(namespace,package,version) wild = wild//"/fpm.toml" print *, "Searching packages in Local Registry:" + !> globbing breaks for 2digit version numbers 2.10.1 + ! Scan directory for packages call list_files(path, file_names,recurse=.true.) do i=1,size(file_names) @@ -165,6 +170,11 @@ subroutine search_package(namespace,package,version) call split(file_names(i)%s,array,'/') if (array(size(array)) == "fpm.toml") then result = glob(file_names(i)%s,wild) + ! call new_version_from_string(version_check,array(size(array)-1), error) + ! call version_check%new_version_from_string(array(size(array)-1), error) + if (allocated(error)) then + call fpm_stop(1, "Error parsing version"); return + end if if (result) then ! print *, "Matched results" !> add count print *, "Package Found: ", array(size(array)-3), array(size(array)-2), array(size(array)-1) From b02bd7298b10d713c49177e021f8d26ff07425e3 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Thu, 6 Jun 2024 10:16:00 +0530 Subject: [PATCH 37/51] search description --- src/fpm/cmd/search.f90 | 117 ++++++++++++++++++++++------------------- 1 file changed, 62 insertions(+), 55 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index 0c515d3d13..8fb3c0a431 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -17,9 +17,10 @@ module fpm_cmd_search use fpm, only: build_model use fpm_error, only : error_t, fatal_error, fpm_stop use jonquil, only : json_object - use tomlf, only : toml_array, get_value, len, toml_key + use tomlf, only : toml_array, get_value, len, toml_key, toml_loads, toml_table, & + toml_serializer,toml_value + use tomlf_utils_io, only : read_whole_file use fpm_settings, only: fpm_global_settings, get_global_settings, official_registry_base_url - use fpm_versioning, only: version_t, new_version implicit none private @@ -32,7 +33,7 @@ subroutine cmd_search(settings) !> Settings for the search command. class(fpm_search_settings), intent(in) :: settings type(fpm_global_settings) :: global_settings - character(:), allocatable :: tmp_file, name, namespace, description, query_url,package_version + character(:), allocatable :: tmp_file, name, namespace, description, query_url, package_version type(toml_key), allocatable :: list(:) integer :: stat, unit, ii type(json_object) :: json @@ -80,61 +81,55 @@ subroutine cmd_search(settings) & // '&sort_by='//settings%sort_by & & // '&sort='//settings%sort - !> search parameters: name, namespace, version, license, query -> (description1, description2) - !> namespace,version,package from url. + !> search parameters: name, namespace, version, license, query -> description !> add to search only in the local/global registry - !> for description search - !> fix all the version search in global and add docs for parameters. - !> add globbing support for global search - !> description1 from fpm.toml and description2 from README.md - !> name, license, version, description1 from fpm.toml - !> description2 from README.md (if exists) + !> add docs for parameters. + !> add globbing support for global search + !> name, license, version, description from fpm.toml !> order manipulation parameters: page, sort, sort_by, limit !> show page number and total_pages !> Get the package data from the registry - call downloader%get_pkg_data(query_url, version, tmp_file, json, error) - close (unit) - if (allocated(error)) then - call fpm_stop(1, "Error retrieving package data from registry: "//settings%registry); return - end if + ! call downloader%get_pkg_data(query_url, version, tmp_file, json, error) + ! close (unit) + ! if (allocated(error)) then + ! call fpm_stop(1, "Error retrieving package data from registry: "//settings%registry); return + ! end if ! print *, settings%version - call search_package(settings%namespace, settings%package, settings%version) - if (.not.json%has_key("packages")) then - !> Better method to display the package data - call get_value(json, 'packages', array) - print *, "" - print '(A,I0,A)', ' Found ', len(array), ' packages:' - do ii=1, len(array) - call get_value(array, ii, p) - call get_value(p, 'name', name) - call get_value(p, 'namespace', namespace) - call get_value(p, 'description', description) - call get_value(p, 'version', package_version) - print *, "Name: ", name - print *, "namespace: ", namespace - print *, "Description: ", description - print *, "version: ", package_version - print *, "" - end do - else - call fpm_stop(1, "Invalid package data returned"); return - end if + call search_package(settings%query, settings%namespace, settings%package, settings%version) + ! if (.not.json%has_key("packages")) then + ! !> Better method to display the package data + ! call get_value(json, 'packages', array) + ! print *, "" + ! print '(A,I0,A)', ' Found ', len(array), ' packages:' + ! do ii=1, len(array) + ! call get_value(array, ii, p) + ! call get_value(p, 'name', name) + ! call get_value(p, 'namespace', namespace) + ! call get_value(p, 'description', description) + ! call get_value(p, 'version', package_version) + ! print *, "Name: ", name + ! print *, "namespace: ", namespace + ! print *, "Description: ", description + ! print *, "version: ", package_version + ! print *, "" + ! end do + ! else + ! call fpm_stop(1, "Invalid package data returned"); return + ! end if end subroutine cmd_search - subroutine search_package(namespace,package,version) + subroutine search_package(query,namespace,package,version) type(fpm_global_settings) :: global_settings type(error_t), allocatable :: error - ! type(version_t) :: version_check - ! type(new_version) :: version_check - character(:), allocatable, intent(in) :: namespace, package, version - character(:), allocatable :: path,array(:) - character(:), allocatable :: wild + character(:), allocatable, intent(in) :: namespace, package, version, query + character(:), allocatable :: path,array(:), versioncheck(:), toml_package_data + character(:), allocatable :: description, wild type(string_t), allocatable :: file_names(:) - integer :: i,j + type(toml_table), allocatable :: table + integer :: i, j, unit, stat logical :: result - call get_global_settings(global_settings, error) if (allocated(error)) then @@ -161,8 +156,6 @@ subroutine search_package(namespace,package,version) wild = wild//"/fpm.toml" print *, "Searching packages in Local Registry:" - !> globbing breaks for 2digit version numbers 2.10.1 - ! Scan directory for packages call list_files(path, file_names,recurse=.true.) do i=1,size(file_names) @@ -170,16 +163,30 @@ subroutine search_package(namespace,package,version) call split(file_names(i)%s,array,'/') if (array(size(array)) == "fpm.toml") then result = glob(file_names(i)%s,wild) - ! call new_version_from_string(version_check,array(size(array)-1), error) - ! call version_check%new_version_from_string(array(size(array)-1), error) - if (allocated(error)) then - call fpm_stop(1, "Error parsing version"); return - end if - if (result) then - ! print *, "Matched results" !> add count + call split(array(size(array)-1),versioncheck,'.') + if (size(versioncheck) > 2) then print *, "Package Found: ", array(size(array)-3), array(size(array)-2), array(size(array)-1) + + !> query search for description + call read_whole_file(file_names(i)%s, toml_package_data, stat) + if (stat /= 0) then + call fatal_error(error, "Error reading file: "//file_names(i)%s); return + end if + ! Load TOML data into a table + call toml_loads(table,toml_package_data) + if (allocated(error)) then + call fpm_stop(1, "Error loading toml file"); return + end if + if (allocated(table)) then + call get_value(table, 'description', description) + print *, "Description: ", description + if (query /="") then + + end if + else + call fpm_stop(1, "Error Searching for the query"); return + end if end if - !> read the toml file from the path file_names(i)%s for data and path end if end if end do From e05e51d2a234c43ab6d2430e5d68413bc9d30455 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Thu, 6 Jun 2024 10:18:11 +0530 Subject: [PATCH 38/51] search query matching --- src/fpm/cmd/search.f90 | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index 8fb3c0a431..ce2b2de650 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -165,7 +165,7 @@ subroutine search_package(query,namespace,package,version) result = glob(file_names(i)%s,wild) call split(array(size(array)-1),versioncheck,'.') if (size(versioncheck) > 2) then - print *, "Package Found: ", array(size(array)-3), array(size(array)-2), array(size(array)-1) + ! print *, "Package Found: ", array(size(array)-3), array(size(array)-2), array(size(array)-1) !> query search for description call read_whole_file(file_names(i)%s, toml_package_data, stat) @@ -179,9 +179,16 @@ subroutine search_package(query,namespace,package,version) end if if (allocated(table)) then call get_value(table, 'description', description) - print *, "Description: ", description + ! print *, "Description: ", description if (query /="") then - + result = glob(description,query) + if (result) then + print *, "Package Found: ", array(size(array)-3), array(size(array)-2), array(size(array)-1) + print *, "Description: ", description + end if + else + print *, "Package Found: ", array(size(array)-3), array(size(array)-2), array(size(array)-1) + print *, "Description: ", description end if else call fpm_stop(1, "Error Searching for the query"); return From 469051faa26def0795ad48b88541786dae8e43c8 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Thu, 6 Jun 2024 10:29:24 +0530 Subject: [PATCH 39/51] fix: search and clean --- src/fpm/cmd/search.f90 | 68 ++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 42 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index ce2b2de650..c1de696ef2 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -52,18 +52,6 @@ subroutine cmd_search(settings) call fpm_stop(1, "Error retrieving global settings"); return end if - ! print *,global_settings%registry_settings%cache_path - ! print *,global_settings%registry_settings%path - ! print *,global_settings%registry_settings%url - ! print *,global_settings%path_to_config_folder - - ! new function to search package names, namespace. - ! query general term for description (both toml and readme) - ! search by namespace, package, license - ! search by namespace , package. - ! from fpm.toml -> description and license - ! README.md -> description - !> Generate a temporary file to store the downloaded package search data tmp_file = get_temp_filename() open (newunit=unit, file=tmp_file, action='readwrite', iostat=stat) @@ -90,34 +78,33 @@ subroutine cmd_search(settings) !> show page number and total_pages !> Get the package data from the registry - ! call downloader%get_pkg_data(query_url, version, tmp_file, json, error) - ! close (unit) - ! if (allocated(error)) then - ! call fpm_stop(1, "Error retrieving package data from registry: "//settings%registry); return - ! end if - ! print *, settings%version + call downloader%get_pkg_data(query_url, version, tmp_file, json, error) + close (unit) + if (allocated(error)) then + call fpm_stop(1, "Error retrieving package data from registry: "//settings%registry); return + end if call search_package(settings%query, settings%namespace, settings%package, settings%version) - ! if (.not.json%has_key("packages")) then - ! !> Better method to display the package data - ! call get_value(json, 'packages', array) - ! print *, "" - ! print '(A,I0,A)', ' Found ', len(array), ' packages:' - ! do ii=1, len(array) - ! call get_value(array, ii, p) - ! call get_value(p, 'name', name) - ! call get_value(p, 'namespace', namespace) - ! call get_value(p, 'description', description) - ! call get_value(p, 'version', package_version) - ! print *, "Name: ", name - ! print *, "namespace: ", namespace - ! print *, "Description: ", description - ! print *, "version: ", package_version - ! print *, "" - ! end do - ! else - ! call fpm_stop(1, "Invalid package data returned"); return - ! end if + if (json%has_key("packages")) then + !> Shift to better method to display the package data + call get_value(json, 'packages', array) + print *, "" + print '(A,I0,A)', ' Found ', len(array), ' packages:' + do ii=1, len(array) + call get_value(array, ii, p) + call get_value(p, 'name', name) + call get_value(p, 'namespace', namespace) + call get_value(p, 'description', description) + ! call get_value(p, 'version', package_version) + print *, "Name: ", name + print *, "namespace: ", namespace + print *, "Description: ", description + ! print *, "version: ", package_version + print *, "" + end do + else + call fpm_stop(1, "Invalid package data returned"); return + end if end subroutine cmd_search subroutine search_package(query,namespace,package,version) @@ -164,9 +151,7 @@ subroutine search_package(query,namespace,package,version) if (array(size(array)) == "fpm.toml") then result = glob(file_names(i)%s,wild) call split(array(size(array)-1),versioncheck,'.') - if (size(versioncheck) > 2) then - ! print *, "Package Found: ", array(size(array)-3), array(size(array)-2), array(size(array)-1) - + if (size(versioncheck) > 2) then !> query search for description call read_whole_file(file_names(i)%s, toml_package_data, stat) if (stat /= 0) then @@ -179,7 +164,6 @@ subroutine search_package(query,namespace,package,version) end if if (allocated(table)) then call get_value(table, 'description', description) - ! print *, "Description: ", description if (query /="") then result = glob(description,query) if (result) then From c1b0c183d2aa593ef9acf94f876b7cfca927e768 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Thu, 6 Jun 2024 10:45:40 +0530 Subject: [PATCH 40/51] seach local registry functionality with all parameters --- src/fpm/cmd/search.f90 | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index c1de696ef2..4a98b4d9f9 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -88,19 +88,20 @@ subroutine cmd_search(settings) if (json%has_key("packages")) then !> Shift to better method to display the package data call get_value(json, 'packages', array) - print *, "" - print '(A,I0,A)', ' Found ', len(array), ' packages:' + print * + print '(A,I0,A)', ' Found ', len(array), ' packages in fpm - registry:' + print * do ii=1, len(array) call get_value(array, ii, p) call get_value(p, 'name', name) call get_value(p, 'namespace', namespace) call get_value(p, 'description', description) - ! call get_value(p, 'version', package_version) + call get_value(p, 'version', package_version) print *, "Name: ", name print *, "namespace: ", namespace print *, "Description: ", description - ! print *, "version: ", package_version - print *, "" + print *, "version: ", package_version + print * end do else call fpm_stop(1, "Invalid package data returned"); return @@ -141,7 +142,9 @@ subroutine search_package(query,namespace,package,version) wild = wild//"/?.?.?" end if wild = wild//"/fpm.toml" + print * print *, "Searching packages in Local Registry:" + print * ! Scan directory for packages call list_files(path, file_names,recurse=.true.) @@ -162,22 +165,29 @@ subroutine search_package(query,namespace,package,version) if (allocated(error)) then call fpm_stop(1, "Error loading toml file"); return end if + if (allocated(table)) then call get_value(table, 'description', description) if (query /="") then result = glob(description,query) if (result) then - print *, "Package Found: ", array(size(array)-3), array(size(array)-2), array(size(array)-1) + print *, "Name: ", array(size(array)-2) + print *, "Namespace: ", array(size(array)-3) print *, "Description: ", description + print *, "Version: ", array(size(array)-1) end if else - print *, "Package Found: ", array(size(array)-3), array(size(array)-2), array(size(array)-1) + print *, "Name: ", array(size(array)-2) + print *, "Namespace: ", array(size(array)-3) print *, "Description: ", description + print *, "Version: ", array(size(array)-1) end if + print * else call fpm_stop(1, "Error Searching for the query"); return end if end if + end if end if end do From 8496b5c72cae8511b6b86852141a0cb9fdf22a5f Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 9 Jun 2024 18:07:51 +0530 Subject: [PATCH 41/51] clean --- src/fpm/cmd/search.f90 | 51 +++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index 4a98b4d9f9..2e7d555809 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -83,7 +83,9 @@ subroutine cmd_search(settings) if (allocated(error)) then call fpm_stop(1, "Error retrieving package data from registry: "//settings%registry); return end if - + print * + print *, "Searching packages in Local Registry:" + print * call search_package(settings%query, settings%namespace, settings%package, settings%version) if (json%has_key("packages")) then !> Shift to better method to display the package data @@ -91,6 +93,7 @@ subroutine cmd_search(settings) print * print '(A,I0,A)', ' Found ', len(array), ' packages in fpm - registry:' print * + ! call print_packages(array) do ii=1, len(array) call get_value(array, ii, p) call get_value(p, 'name', name) @@ -124,27 +127,8 @@ subroutine search_package(query,namespace,package,version) call fpm_stop(1, "Error retrieving global settings"); return end if - path = global_settings%registry_settings%cache_path - - if (namespace /= "") then - wild = path//"/"//namespace - else - wild = path//"/*" - end if - if (package /= "") then - wild = wild//"/"//package - else - wild = wild//"/*" - end if - if (version /= "") then - wild = wild//"/"//version - else - wild = wild//"/?.?.?" - end if - wild = wild//"/fpm.toml" - print * - print *, "Searching packages in Local Registry:" - print * + path = global_settings%registry_settings%cache_path + wild = package_search_wild(path,namespace,package,version) ! Scan directory for packages call list_files(path, file_names,recurse=.true.) @@ -187,10 +171,31 @@ subroutine search_package(query,namespace,package,version) call fpm_stop(1, "Error Searching for the query"); return end if end if - end if end if end do end subroutine search_package + + function package_search_wild(path,namespace,package,version) result(wild) + character(:), allocatable, intent(in) :: namespace, package, version, path + character(:), allocatable :: wild + character(:), allocatable :: array(:) + if (namespace /= "") then + wild = path//"/"//namespace + else + wild = path//"/*" + end if + if (package /= "") then + wild = wild//"/"//package + else + wild = wild//"/*" + end if + if (version /= "") then + wild = wild//"/"//version + else + wild = wild//"/?.?.?" + end if + wild = wild//"/fpm.toml" + end function package_search_wild end \ No newline at end of file From 5c259a4de65280ebf145d54082c04ee09928e558 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 23 Jun 2024 00:07:35 +0530 Subject: [PATCH 42/51] refactor --- src/fpm/cmd/search.f90 | 102 +++++++++++++++++---------------------- src/fpm_command_line.f90 | 6 +-- 2 files changed, 47 insertions(+), 61 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index 2e7d555809..3098ac5020 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -127,75 +127,61 @@ subroutine search_package(query,namespace,package,version) call fpm_stop(1, "Error retrieving global settings"); return end if - path = global_settings%registry_settings%cache_path - wild = package_search_wild(path,namespace,package,version) + path = global_settings%registry_settings%cache_path ! Scan directory for packages call list_files(path, file_names,recurse=.true.) do i=1,size(file_names) - if (.not.is_hidden_file(file_names(i)%s)) then - call split(file_names(i)%s,array,'/') - if (array(size(array)) == "fpm.toml") then - result = glob(file_names(i)%s,wild) - call split(array(size(array)-1),versioncheck,'.') - if (size(versioncheck) > 2) then - !> query search for description - call read_whole_file(file_names(i)%s, toml_package_data, stat) - if (stat /= 0) then - call fatal_error(error, "Error reading file: "//file_names(i)%s); return - end if - ! Load TOML data into a table - call toml_loads(table,toml_package_data) - if (allocated(error)) then - call fpm_stop(1, "Error loading toml file"); return - end if + result = package_search_wild(namespace,package,version,file_names(i)%s) + call split(file_names(i)%s,array,'/') + if (result) then + !> query search for description + call read_whole_file(file_names(i)%s, toml_package_data, stat) + if (stat /= 0) then + call fatal_error(error, "Error reading file: "//file_names(i)%s); return + end if + ! Load TOML data into a table + call toml_loads(table,toml_package_data) + if (allocated(error)) then + call fpm_stop(1, "Error loading toml file"); return + end if - if (allocated(table)) then - call get_value(table, 'description', description) - if (query /="") then - result = glob(description,query) - if (result) then - print *, "Name: ", array(size(array)-2) - print *, "Namespace: ", array(size(array)-3) - print *, "Description: ", description - print *, "Version: ", array(size(array)-1) - end if - else - print *, "Name: ", array(size(array)-2) - print *, "Namespace: ", array(size(array)-3) - print *, "Description: ", description - print *, "Version: ", array(size(array)-1) - end if - print * - else - call fpm_stop(1, "Error Searching for the query"); return + if (allocated(table)) then + call get_value(table, 'description', description) + if (query /="") then + result = glob(description,query) + if (result) then + print *, "Name: ", array(size(array)-2) + print *, "Namespace: ", array(size(array)-3) + print *, "Description: ", description + print *, "Version: ", array(size(array)-1) end if + else + print *, "Name: ", array(size(array)-2) + print *, "Namespace: ", array(size(array)-3) + print *, "Description: ", description + print *, "Version: ", array(size(array)-1) end if + print * + else + call fpm_stop(1, "Error Searching for the query"); return end if - end if + endif end do end subroutine search_package - function package_search_wild(path,namespace,package,version) result(wild) - character(:), allocatable, intent(in) :: namespace, package, version, path - character(:), allocatable :: wild - character(:), allocatable :: array(:) - if (namespace /= "") then - wild = path//"/"//namespace - else - wild = path//"/*" - end if - if (package /= "") then - wild = wild//"/"//package - else - wild = wild//"/*" - end if - if (version /= "") then - wild = wild//"/"//version - else - wild = wild//"/?.?.?" - end if - wild = wild//"/fpm.toml" + function package_search_wild(namespace,package,version, file_name) result(result) + character(:), allocatable, intent(in) :: namespace, package, version, file_name + character(:), allocatable :: array(:), versioncheck(:) + logical :: result + + call split(file_name,array,'/') + call split(array(size(array)-1),versioncheck,'.') + result = array(size(array)) == "fpm.toml" + result = result .and. glob(array(size(array)-2),package) + result = result .and. glob(array(size(array)-3),namespace) + result = result .and. glob(array(size(array)-1),version) + result = result .and. size(versioncheck) > 2 end function package_search_wild end \ No newline at end of file diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 7a6049f27b..5e707345df 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -748,13 +748,13 @@ subroutine get_command_line_settings(cmd_settings) if (query==' ') query='' if (page=='') page='1' - if (package==' ') package='' + if (package==' ') package='*' if (license==' ') license='' if (sort_by==' ') sort_by='name' if (sort==' ') sort='asc' if (limit==' ') limit='10' - if (namespace==' ') namespace='' - if (package_version==' ') package_version='' + if (namespace==' ') namespace='*' + if (package_version==' ') package_version='*' if (.not. registry=='') then print *, 'Using custom registry for seaching packages: ', registry registry = trim(adjustl(registry)) From 1c86fdf7c30d543da27658289f66356f10a7e89f Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 23 Jun 2024 01:09:25 +0530 Subject: [PATCH 43/51] refactor and clean --- src/fpm/cmd/search.f90 | 48 ++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index 3098ac5020..750a3df33e 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -33,7 +33,7 @@ subroutine cmd_search(settings) !> Settings for the search command. class(fpm_search_settings), intent(in) :: settings type(fpm_global_settings) :: global_settings - character(:), allocatable :: tmp_file, name, namespace, description, query_url, package_version + character(:), allocatable :: tmp_file, name, namespace, description, query_url, package_version, package_array(:) type(toml_key), allocatable :: list(:) integer :: stat, unit, ii type(json_object) :: json @@ -93,18 +93,24 @@ subroutine cmd_search(settings) print * print '(A,I0,A)', ' Found ', len(array), ' packages in fpm - registry:' print * - ! call print_packages(array) + do ii=1, len(array) call get_value(array, ii, p) call get_value(p, 'name', name) call get_value(p, 'namespace', namespace) call get_value(p, 'description', description) call get_value(p, 'version', package_version) - print *, "Name: ", name - print *, "namespace: ", namespace - print *, "Description: ", description - print *, "version: ", package_version - print * + + ! package_array = [name, namespace, package_version] + + ! call print_package_data(package_array,description) + + ! print *, "Name: ", name + ! print *, "namespace: ", namespace + ! print *, "Description: ", description + ! print *, "version: ", package_version + ! print * + end do else call fpm_stop(1, "Invalid package data returned"); return @@ -115,7 +121,7 @@ subroutine search_package(query,namespace,package,version) type(fpm_global_settings) :: global_settings type(error_t), allocatable :: error character(:), allocatable, intent(in) :: namespace, package, version, query - character(:), allocatable :: path,array(:), versioncheck(:), toml_package_data + character(:), allocatable :: path, array(:), versioncheck(:), toml_package_data, print_package(:) character(:), allocatable :: description, wild type(string_t), allocatable :: file_names(:) type(toml_table), allocatable :: table @@ -150,19 +156,10 @@ subroutine search_package(query,namespace,package,version) call get_value(table, 'description', description) if (query /="") then result = glob(description,query) - if (result) then - print *, "Name: ", array(size(array)-2) - print *, "Namespace: ", array(size(array)-3) - print *, "Description: ", description - print *, "Version: ", array(size(array)-1) - end if + if (result) call print_package_data(array,description) else - print *, "Name: ", array(size(array)-2) - print *, "Namespace: ", array(size(array)-3) - print *, "Description: ", description - print *, "Version: ", array(size(array)-1) + call print_package_data(array,description) end if - print * else call fpm_stop(1, "Error Searching for the query"); return end if @@ -178,10 +175,21 @@ function package_search_wild(namespace,package,version, file_name) result(result call split(file_name,array,'/') call split(array(size(array)-1),versioncheck,'.') result = array(size(array)) == "fpm.toml" - result = result .and. glob(array(size(array)-2),package) result = result .and. glob(array(size(array)-3),namespace) + result = result .and. glob(array(size(array)-2),package) result = result .and. glob(array(size(array)-1),version) result = result .and. size(versioncheck) > 2 end function package_search_wild + + subroutine print_package_data(package_array,description) + character(:), allocatable, intent(in) :: package_array(:) + character(*), intent(in) :: description + + print *, "Name: ", package_array(size(package_array)-2) + print *, "Namespace: ", package_array(size(package_array)-3) + print *, "Version: ", package_array(size(package_array)-1) + print *, "Description: ", description + print * + end subroutine print_package_data end \ No newline at end of file From 4a1975f7c32240fcb028bdba9697e65637377654 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 23 Jun 2024 11:18:32 +0530 Subject: [PATCH 44/51] clean --- src/fpm/cmd/search.f90 | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/src/fpm/cmd/search.f90 b/src/fpm/cmd/search.f90 index 750a3df33e..68169e3fd7 100644 --- a/src/fpm/cmd/search.f90 +++ b/src/fpm/cmd/search.f90 @@ -1,8 +1,7 @@ -!> Search a package from both local and remote registry using the `search` command. -!> +!> Search a package from both local and remote registry using the `search` subcommand. !> The package can be searched by packagename, namespace, query (description and README.md), and license from the registries (local and remote). !> the remote registry URL can also be specified by the paramter --registry. -!> It can be used as `fpm search --query fortran --page 2 --name fortran --namespace fortran --license MIT --registry URL`. +!> It can be used as `fpm search --query q* --page 1 --registry URL --namespace n* --package p* --package_version v* --license l* --limit 10 --sort-by [name] --sort [asc/desc]` module fpm_cmd_search use fpm_command_line, only: fpm_search_settings use fpm_manifest, only: package_config_t, get_package_data @@ -33,8 +32,7 @@ subroutine cmd_search(settings) !> Settings for the search command. class(fpm_search_settings), intent(in) :: settings type(fpm_global_settings) :: global_settings - character(:), allocatable :: tmp_file, name, namespace, description, query_url, package_version, package_array(:) - type(toml_key), allocatable :: list(:) + character(:), allocatable :: tmp_file, name, namespace, description, query_url, package_version integer :: stat, unit, ii type(json_object) :: json type(json_object), pointer :: p @@ -68,14 +66,6 @@ subroutine cmd_search(settings) & // '&limit='//settings%limit & & // '&sort_by='//settings%sort_by & & // '&sort='//settings%sort - - !> search parameters: name, namespace, version, license, query -> description - !> add to search only in the local/global registry - !> add docs for parameters. - !> add globbing support for global search - !> name, license, version, description from fpm.toml - !> order manipulation parameters: page, sort, sort_by, limit - !> show page number and total_pages !> Get the package data from the registry call downloader%get_pkg_data(query_url, version, tmp_file, json, error) @@ -88,12 +78,10 @@ subroutine cmd_search(settings) print * call search_package(settings%query, settings%namespace, settings%package, settings%version) if (json%has_key("packages")) then - !> Shift to better method to display the package data call get_value(json, 'packages', array) print * print '(A,I0,A)', ' Found ', len(array), ' packages in fpm - registry:' print * - do ii=1, len(array) call get_value(array, ii, p) call get_value(p, 'name', name) @@ -101,16 +89,11 @@ subroutine cmd_search(settings) call get_value(p, 'description', description) call get_value(p, 'version', package_version) - ! package_array = [name, namespace, package_version] - - ! call print_package_data(package_array,description) - - ! print *, "Name: ", name - ! print *, "namespace: ", namespace - ! print *, "Description: ", description - ! print *, "version: ", package_version - ! print * - + print *, "Name: ", name + print *, "namespace: ", namespace + print *, "Description: ", description + print *, "version: ", package_version + print * end do else call fpm_stop(1, "Invalid package data returned"); return From 0f668a5ec00ca9fd501cf1b90fc8599db8b483f5 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 23 Jun 2024 12:10:40 +0530 Subject: [PATCH 45/51] fix --- src/fpm_command_line.f90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 5e707345df..9dcb9d0833 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -747,7 +747,7 @@ subroutine get_command_line_settings(cmd_settings) block if (query==' ') query='' - if (page=='') page='1' + if (page==' ') page='1' if (package==' ') package='*' if (license==' ') license='' if (sort_by==' ') sort_by='name' @@ -852,7 +852,7 @@ subroutine check_build_vals() val_cxxflag = " "// sget('cxx-flag') val_ldflag = " " // sget('link-flag') val_profile = sget('profile') - + ! conda = sget('conda') end subroutine check_build_vals !> Print help text and stop From dad1f49090d0337a135cbae37073cc35f0f40f9e Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 23 Jun 2024 12:23:05 +0530 Subject: [PATCH 46/51] add docs --- src/fpm_command_line.f90 | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 9dcb9d0833..65a81c0ed0 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -910,7 +910,9 @@ subroutine set_help() ' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] ', & ' [options] ', & ' clean [--skip] [--all] [--registry-cache] ', & - ' search [--query] [--page] ', & + ' search [--query query] [--page page] [--registry URL] [--namespace namespace] ', & + ' [--package package] [--package_version version] [--license license] ', & + ' [--limit <10>] [--sort-by ] [--sort ] ', & ' publish [--token TOKEN] [--show-package-version] [--show-upload-data] ', & ' [--dry-run] [--verbose] ', & ' '] @@ -1041,7 +1043,9 @@ subroutine set_help() ' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] ', & ' [options] ', & ' clean [--skip] [--all] [--registry-cache] ', & - ' search [--query] [--page] ', & + ' search [--query query] [--page page] [--registry URL] [--namespace namespace] ', & + ' [--package package] [--package_version version] [--license license] ', & + ' [--limit <10>] [--sort-by ] [--sort ] ', & ' publish [--token TOKEN] [--show-package-version] [--show-upload-data] ', & ' [--dry-run] [--verbose] ', & ' ', & @@ -1541,12 +1545,21 @@ subroutine set_help() ' fpm search', & '', & 'DESCRIPTION', & - ' Prompts the user to search deletion of the build. If affirmative,', & - ' directories in the build/ directory are deleted, except dependencies.', & - ' Use the --registry-cache option to delete the registry cache.', & + ' Search for packages in the local directory and the fpm-registry, ', & + ' supports package search by name, namespace, query (description and README.md)' & + ' and license from the registries (local and remote).', & '', & 'OPTIONS', & - ' --registry-cache Delete registry cache.', & + ' --query Search query (supports wildcard).', & + ' --page Page number for results.', & + ' --registry URL of the registry to query.', & + ' --namespace Namespace to filter results.', & + ' --package Package name to filter results.', & + ' --package_version Version of the package to filter results.', & + ' --license License type to filter results.', & + ' --limit Maximum number of results to return.', & + ' --sort-by Field to sort results by (e.g., name).', & + ' --sort Sort order (asc for ascending, desc for descending).', & '' ] help_publish=[character(len=80) :: & 'NAME', & From c3f27ba198defb78f1f8f8d75931c5d9206a5dca Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 23 Jun 2024 12:24:39 +0530 Subject: [PATCH 47/51] fix --- src/fpm_command_line.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 65a81c0ed0..aba557e1b1 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -1546,7 +1546,7 @@ subroutine set_help() '', & 'DESCRIPTION', & ' Search for packages in the local directory and the fpm-registry, ', & - ' supports package search by name, namespace, query (description and README.md)' & + ' supports package search by name, namespace, query (description and README.md)', & ' and license from the registries (local and remote).', & '', & 'OPTIONS', & From 81ea75bb3895294fbcb7cdea25ef7e9f1a9686f3 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sun, 23 Jun 2024 12:28:04 +0530 Subject: [PATCH 48/51] clean --- src/fpm_command_line.f90 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index aba557e1b1..cc1cca305e 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -787,7 +787,7 @@ subroutine get_command_line_settings(cmd_settings) archiver = sget('archiver') token_s = sget('token') - allocate(fpm_publish_settings :: cmd_settings) ! Use local registry if it was specified in the global config file. + allocate(fpm_publish_settings :: cmd_settings) cmd_settings = fpm_publish_settings( & & show_package_version = lget('show-package-version'), & @@ -852,7 +852,6 @@ subroutine check_build_vals() val_cxxflag = " "// sget('cxx-flag') val_ldflag = " " // sget('link-flag') val_profile = sget('profile') - ! conda = sget('conda') end subroutine check_build_vals !> Print help text and stop @@ -1553,9 +1552,9 @@ subroutine set_help() ' --query Search query (supports wildcard).', & ' --page Page number for results.', & ' --registry URL of the registry to query.', & - ' --namespace Namespace to filter results.', & + ' --namespace Namespace of the package', & ' --package Package name to filter results.', & - ' --package_version Version of the package to filter results.', & + ' --package_version Version of the package', & ' --license License type to filter results.', & ' --limit Maximum number of results to return.', & ' --sort-by Field to sort results by (e.g., name).', & From a62162a63dc9758f47d7c7935e23898be895a71a Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Fri, 28 Jun 2024 20:36:24 +0530 Subject: [PATCH 49/51] fix --- src/fpm_command_line.f90 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index ebe141329e..452942e31d 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -54,11 +54,8 @@ module fpm_command_line fpm_clean_settings, & fpm_publish_settings, & get_command_line_settings, & -<<<<<<< fpm-search - fpm_search_settings -======= + fpm_search_settings, & get_fpm_env ->>>>>>> main type, abstract :: fpm_cmd_settings character(len=:), allocatable :: working_dir From ad779ec8954e0ddfdaab339deb6ef85fa58c311a Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Tue, 2 Jul 2024 17:57:47 +0530 Subject: [PATCH 50/51] add: comments --- src/fpm_command_line.f90 | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 452942e31d..5c2d50e376 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -135,17 +135,18 @@ module fpm_command_line logical :: registry_cache = .false. end type +!> Settings for searching for packages in local and remote registries type, extends(fpm_cmd_settings) :: fpm_search_settings - character(len=:),allocatable :: query - character(len=:),allocatable :: page - character(len=:),allocatable :: registry - character(len=:),allocatable :: namespace - character(len=:),allocatable :: package - character(len=:),allocatable :: version - character(len=:),allocatable :: license - character(len=:),allocatable :: limit - character(len=:),allocatable :: sort_by - character(len=:),allocatable :: sort + character(len=:),allocatable :: query !> search for packages with a specific query (globbing supported) + character(len=:),allocatable :: page !> return in a specific page of results of remote registry (default: 1) + character(len=:),allocatable :: registry !> search in a specific registry (default: official registry), stores the URL of the registry + character(len=:),allocatable :: namespace !> search for packages with a specific namespace (globbing supported) + character(len=:),allocatable :: package !> search for packages with a specific name (globbing supported) + character(len=:),allocatable :: version !> search for packages with version (globbing supported) + character(len=:),allocatable :: license !> search for packages with a specific license (globbing supported) + character(len=:),allocatable :: limit !> limit the number of results returned (default: 10). + character(len=:),allocatable :: sort_by !> sort the results by name, author, createdat, updatedat, downloads (default: name) + character(len=:),allocatable :: sort !> sort the results in ascending or descending (asc or desc) order (default: asc). end type type, extends(fpm_build_settings) :: fpm_publish_settings @@ -1550,7 +1551,9 @@ subroutine set_help() ' and license from the registries (local and remote).', & '', & 'OPTIONS', & - ' --query Search query (supports wildcard).', & + ' --query Search for any term, can be used for searching across parameters like:', & + ' name, namespace, description, and license, version, keywords, ', & + ' README, maintainer, author. (supports globbing)', & ' --page Page number for results.', & ' --registry URL of the registry to query.', & ' --namespace Namespace of the package', & From 2d088aa96be7368f9d6514dfc47dbd51870724cb Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Mon, 26 Aug 2024 18:34:03 +0530 Subject: [PATCH 51/51] test commit --- src/fpm_command_line.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 5c2d50e376..23a7429812 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -1577,7 +1577,7 @@ subroutine set_help() 'DESCRIPTION', & ' Follow the steps to create a tarball and upload a package to the registry:', & '', & - ' 1. Register on the website (https://registry-phi.vercel.app/).', & + ' 1. Register on the website (TODO: registry url).', & ' 2. Create a namespace. Uploaded packages must be assigned to a unique', & ' namespace to avoid conflicts among packages with similar names. A', & ' namespace can accommodate multiple packages.', &