Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: fpm search #1054

Open
wants to merge 57 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
7d5a99d
fix: url bug
henilp105 Mar 27, 2024
06d353c
Merge branch 'fortran-lang:main' into fpm-search
henilp105 May 18, 2024
94fdf25
add: search functionality for fpm registry
henilp105 May 19, 2024
0a4f910
add: search
henilp105 May 19, 2024
7a4bdb5
add: search
henilp105 May 19, 2024
cc9bd57
add: search
henilp105 May 19, 2024
0a99d4a
add: search
henilp105 May 19, 2024
b048451
add: search
henilp105 May 19, 2024
0b66b85
add: search
henilp105 May 19, 2024
d2b173a
fix search
henilp105 May 19, 2024
6d5c44b
add: search
henilp105 May 19, 2024
354fda1
fix: get file and add page
henilp105 May 19, 2024
baed1f5
fix: if no page number is provided
henilp105 May 19, 2024
3456c39
add: search functionality support registry, namespaces,packages
henilp105 May 26, 2024
384ef93
clean
henilp105 May 26, 2024
ea021d3
clean
henilp105 May 26, 2024
7dbd3f7
clean
henilp105 May 26, 2024
11c05cb
clean
henilp105 May 26, 2024
762b78e
clean
henilp105 May 26, 2024
08f0171
clean
henilp105 May 26, 2024
511a107
Merge branch 'fortran-lang:main' into fpm-search
henilp105 May 26, 2024
a87b472
fix
henilp105 May 27, 2024
5f3a18d
fix
henilp105 May 27, 2024
334eeb5
add: new search paramters
henilp105 May 27, 2024
a0dbf40
add: new search paramters
henilp105 May 27, 2024
494194f
add: new search paramters
henilp105 May 27, 2024
5eb04a5
add: new search paramters
henilp105 May 27, 2024
034051d
add: version functionality
henilp105 May 29, 2024
373155c
add: docs
henilp105 May 29, 2024
18c3975
search in local registry
henilp105 May 29, 2024
606c20a
add: search
henilp105 May 29, 2024
e9822d9
Merge branch 'fortran-lang:main' into fpm-search
henilp105 May 29, 2024
c1216f0
add: search
henilp105 May 29, 2024
fc62c32
add: local registry search functionality for all parameters
henilp105 May 31, 2024
ced681e
clean
henilp105 May 31, 2024
52b0d79
add: enable global search
henilp105 May 31, 2024
0ca0eae
fix: bugs
henilp105 May 31, 2024
4a4c6ce
clean
henilp105 May 31, 2024
8800925
clean
henilp105 May 31, 2024
b02bd72
search description
henilp105 Jun 6, 2024
e05e51d
search query matching
henilp105 Jun 6, 2024
469051f
fix: search and clean
henilp105 Jun 6, 2024
c1b0c18
seach local registry functionality with all parameters
henilp105 Jun 6, 2024
aa1112b
Merge branch 'fortran-lang:main' into fpm-search
henilp105 Jun 7, 2024
8496b5c
clean
henilp105 Jun 9, 2024
4beb573
Merge branch 'fortran-lang:main' into fpm-search
henilp105 Jun 22, 2024
5c259a4
refactor
henilp105 Jun 22, 2024
1c86fdf
refactor and clean
henilp105 Jun 22, 2024
4a1975f
clean
henilp105 Jun 23, 2024
0f668a5
fix
henilp105 Jun 23, 2024
dad1f49
add docs
henilp105 Jun 23, 2024
c3f27ba
fix
henilp105 Jun 23, 2024
81ea75b
clean
henilp105 Jun 23, 2024
805f1e5
Merge branch 'main' into fpm-search
henilp105 Jun 28, 2024
a62162a
fix
henilp105 Jun 28, 2024
ad779ec
add: comments
henilp105 Jul 2, 2024
2d088aa
test commit
henilp105 Aug 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add: search functionality support registry, namespaces,packages
henilp105 committed May 26, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 3456c3934636629fa25ac6d55c40ae578efa3319
3 changes: 2 additions & 1 deletion app/main.f90
Original file line number Diff line number Diff line change
@@ -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
65 changes: 5 additions & 60 deletions src/fpm.f90
Original file line number Diff line number Diff line change
@@ -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(:)
151 changes: 151 additions & 0 deletions src/fpm/cmd/search.f90
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion src/fpm/dependency.f90
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion src/fpm/downloader.f90
Original file line number Diff line number Diff line change
@@ -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
59 changes: 54 additions & 5 deletions src/fpm_command_line.f90
Original file line number Diff line number Diff line change
@@ -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', &