From e7d7ac88c956c69a912c6faf97b9f85d76fe039e Mon Sep 17 00:00:00 2001 From: minhqdao Date: Sat, 27 May 2023 16:57:32 +0700 Subject: [PATCH 1/8] Clean up fpm help new and add --help and --version to fpm help publish --- src/fpm_command_line.f90 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index f7a0b1380d..9e1a8e50d1 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -1125,13 +1125,15 @@ subroutine set_help() help_new=[character(len=80) :: & 'NAME ', & ' new(1) - the fpm(1) subcommand to initialize a new project ', & + ' ', & 'SYNOPSIS ', & - ' fpm new NAME [[--lib|--src] [--app] [--test] [--example]]| ', & - ' [--full|--bare][--backfill] ', & + ' fpm new NAME [[--lib|--src] [--app] [--test] [--example]]| ', & + ' [--full|--bare][--backfill] ', & ' fpm new --help|--version ', & ' ', & 'DESCRIPTION ', & ' "fpm new" creates and populates a new programming project directory. ', & + ' ', & ' It ', & ' o creates a directory with the specified name ', & ' o runs the command "git init" in that directory ', & @@ -1361,6 +1363,8 @@ subroutine set_help() 'SYNOPSIS', & ' fpm publish [--token TOKEN]', & '', & + ' fpm publish --help|--version', & + '', & 'DESCRIPTION', & ' Collect relevant source files and upload package to the registry.', & ' It is mandatory to provide a token. The token can be generated on the', & @@ -1369,6 +1373,8 @@ subroutine set_help() 'OPTIONS', & ' --show-package-version show package version without publishing', & ' --show-form-data show sent form data without publishing', & + ' --help print this help and exit', & + ' --version print program version information and exit', & '' ] end subroutine set_help From 17fb88c9c0f692be06cba325358d7391bfc23fea Mon Sep 17 00:00:00 2001 From: minhqdao Date: Sat, 27 May 2023 17:12:03 +0700 Subject: [PATCH 2/8] Rename --show-form-data to --show-upload-data --- src/fpm/cmd/publish.f90 | 16 ++++++++-------- src/fpm_command_line.f90 | 12 ++++++------ test/cli_test/cli_test.f90 | 16 ++++++++-------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/fpm/cmd/publish.f90 b/src/fpm/cmd/publish.f90 index dc83880f14..97b1e6d0d8 100644 --- a/src/fpm/cmd/publish.f90 +++ b/src/fpm/cmd/publish.f90 @@ -30,7 +30,7 @@ subroutine cmd_publish(settings) type(fpm_model_t) :: model type(error_t), allocatable :: error type(version_t), allocatable :: version - type(string_t), allocatable :: form_data(:) + type(string_t), allocatable :: upload_data(:) character(len=:), allocatable :: tmp_file type(downloader_t) :: downloader integer :: i @@ -61,22 +61,22 @@ subroutine cmd_publish(settings) end if end do - form_data = [ & + upload_data = [ & string_t('package_name="'//package%name//'"'), & string_t('package_license="'//package%license//'"'), & string_t('package_version="'//version%s()//'"') & & ] - if (allocated(settings%token)) form_data = [form_data, string_t('upload_token="'//settings%token//'"')] + if (allocated(settings%token)) upload_data = [upload_data, string_t('upload_token="'//settings%token//'"')] tmp_file = get_temp_filename() call git_archive('.', tmp_file, error) if (allocated(error)) call fpm_stop(1, '*cmd_publish* Pack error: '//error%message) - form_data = [form_data, string_t('tarball=@"'//tmp_file//'"')] + upload_data = [upload_data, string_t('tarball=@"'//tmp_file//'"')] - if (settings%show_form_data) then - do i = 1, size(form_data) - print *, form_data(i)%s + if (settings%show_upload_data) then + do i = 1, size(upload_data) + print *, upload_data(i)%s end do return end if @@ -84,7 +84,7 @@ subroutine cmd_publish(settings) ! Make sure a token is provided for publishing. if (.not. allocated(settings%token)) call fpm_stop(1, 'No token provided.') - call downloader%upload_form(official_registry_base_url//'/packages', form_data, error) + call downloader%upload_form(official_registry_base_url//'/packages', upload_data, error) if (allocated(error)) call fpm_stop(1, '*cmd_publish* Upload error: '//error%message) end end diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 9e1a8e50d1..9141e36741 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -120,7 +120,7 @@ module fpm_command_line type, extends(fpm_build_settings) :: fpm_publish_settings logical :: show_package_version = .false. - logical :: show_form_data = .false. + logical :: show_upload_data = .false. character(len=:), allocatable :: token end type @@ -620,7 +620,7 @@ subroutine get_command_line_settings(cmd_settings) case('publish') call set_args(common_args // compiler_args //'& & --show-package-version F & - & --show-form-data F & + & --show-upload-data F & & --token " " & & --list F & & --show-model F & @@ -637,7 +637,7 @@ subroutine get_command_line_settings(cmd_settings) allocate(fpm_publish_settings :: cmd_settings) cmd_settings = fpm_publish_settings( & & show_package_version = lget('show-package-version'), & - & show_form_data = lget('show-form-data'), & + & show_upload_data = lget('show-upload-data'), & & profile=val_profile,& & prune=.not.lget('no-prune'), & & compiler=val_compiler, & @@ -754,7 +754,7 @@ subroutine set_help() ' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] ', & ' [options] ', & ' clean [--skip] [--all] ', & - ' publish [--show-package-version] [--show-form-data] [--token TOKEN] ', & + ' publish [--show-package-version] [--show-upload-data] [--token TOKEN] ', & ' '] help_usage=[character(len=80) :: & '' ] @@ -878,7 +878,7 @@ subroutine set_help() ' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] ', & ' [options] ', & ' clean [--skip] [--all] ', & - ' publish [--show-package-version] [--show-form-data] [--token TOKEN] ', & + ' publish [--show-package-version] [--show-upload-data] [--token TOKEN] ', & ' ', & 'SUBCOMMAND OPTIONS ', & ' -C, --directory PATH', & @@ -1372,7 +1372,7 @@ subroutine set_help() '', & 'OPTIONS', & ' --show-package-version show package version without publishing', & - ' --show-form-data show sent form data without publishing', & + ' --show-upload-data show uploaded data without publishing', & ' --help print this help and exit', & ' --version print program version information and exit', & '' ] diff --git a/test/cli_test/cli_test.f90 b/test/cli_test/cli_test.f90 index dfc94d4daa..ca24b12122 100644 --- a/test/cli_test/cli_test.f90 +++ b/test/cli_test/cli_test.f90 @@ -30,12 +30,12 @@ program main logical :: c_s,act_c_s ; namelist/act_cli/act_c_s logical :: c_a,act_c_a ; namelist/act_cli/act_c_a logical :: show_v,act_show_v ; namelist/act_cli/act_show_v -logical :: show_f_d,act_show_f_d; namelist/act_cli/act_show_f_d +logical :: show_u_d,act_show_u_d; namelist/act_cli/act_show_u_d character(len=:), allocatable :: token, act_token ; namelist/act_cli/act_token character(len=:), allocatable :: profile,act_profile ; namelist/act_cli/act_profile character(len=:), allocatable :: args,act_args ; namelist/act_cli/act_args -namelist/expected/cmd,cstat,estat,w_e,w_t,c_s,c_a,name,profile,args,show_v,show_f_d,token +namelist/expected/cmd,cstat,estat,w_e,w_t,c_s,c_a,name,profile,args,show_v,show_u_d,token integer :: lun logical,allocatable :: tally(:) logical,allocatable :: subtally(:) @@ -75,7 +75,7 @@ program main 'CMD="clean --skip", C_S=T, NAME=, ARGS="",', & 'CMD="clean --all", C_A=T, NAME=, ARGS="",', & 'CMD="publish --token abc --show-package-version", SHOW_V=T, NAME=, token="abc",ARGS="",', & -'CMD="publish --token abc --show-form-data", SHOW_F_D=T, NAME=, token="abc",ARGS="",', & +'CMD="publish --token abc --show-upload-data", SHOW_U_D=T, NAME=, token="abc",ARGS="",', & 'CMD="publish --token abc", NAME=, token="abc",ARGS="",', & ' ' ] character(len=256) :: readme(3) @@ -110,7 +110,7 @@ program main c_s=.false. ! --skip c_a=.false. ! --all show_v=.false. ! --show-package-version - show_f_d=.false. ! --show-form-data + show_u_d=.false. ! --show-upload-data token='' ! --token TOKEN args=repeat(' ',132) ! -- ARGS cmd=repeat(' ',132) ! the command line arguments to test @@ -132,7 +132,7 @@ program main act_c_s=.false. act_c_a=.false. act_show_v=.false. - act_show_f_d=.false. + act_show_u_d=.false. act_token='' act_args=repeat(' ',132) read(lun,nml=act_cli,iostat=ios,iomsg=message) @@ -148,7 +148,7 @@ program main call test_test('WITH_TESTED',act_w_t.eqv.w_t) call test_test('WITH_TEST',act_w_t.eqv.w_t) call test_test('SHOW-PACKAGE-VERSION',act_show_v.eqv.show_v) - call test_test('SHOW-FORM-DATA',act_show_f_d.eqv.show_f_d) + call test_test('SHOW-UPLOAD-DATA',act_show_u_d.eqv.show_u_d) call test_test('TOKEN',act_token==token) call test_test('ARGS',act_args==args) if(all(subtally))then @@ -237,7 +237,7 @@ subroutine parse() act_c_s=.false. act_c_a=.false. act_show_v=.false. -act_show_f_d=.false. +act_show_u_d=.false. act_token='' act_profile='' @@ -262,7 +262,7 @@ subroutine parse() type is (fpm_install_settings) type is (fpm_publish_settings) act_show_v=settings%show_package_version - act_show_f_d=settings%show_form_data + act_show_u_d=settings%show_upload_data act_token=settings%token end select From 4aed890ec51b0ce289aeb02665f586df43313988 Mon Sep 17 00:00:00 2001 From: minhqdao Date: Sat, 27 May 2023 17:17:30 +0700 Subject: [PATCH 3/8] Clean up fpm help list --- 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 9141e36741..d40e66d5ba 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -958,7 +958,7 @@ subroutine set_help() ' list(1) - list summary of fpm(1) subcommands ', & ' ', & 'SYNOPSIS ', & - ' fpm list [-list] ', & + ' fpm list ', & ' ', & ' fpm list --help|--version ', & ' ', & From 2f2e4717d61124d225a6153b83763b233c70527d Mon Sep 17 00:00:00 2001 From: minhqdao Date: Sun, 28 May 2023 09:21:17 +0700 Subject: [PATCH 4/8] Include steps in help --- src/fpm/cmd/publish.f90 | 8 ++++---- src/fpm_command_line.f90 | 26 ++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/fpm/cmd/publish.f90 b/src/fpm/cmd/publish.f90 index 97b1e6d0d8..8ff3a7d7da 100644 --- a/src/fpm/cmd/publish.f90 +++ b/src/fpm/cmd/publish.f90 @@ -44,16 +44,16 @@ subroutine cmd_publish(settings) print *, version%s(); return end if - ! Build model to obtain dependency tree. - call build_model(model, settings%fpm_build_settings, package, error) - if (allocated(error)) call fpm_stop(1, '*cmd_build* Model error: '//error%message) - !> Checks before uploading the package. if (.not. allocated(package%license)) call fpm_stop(1, 'No license specified in fpm.toml.') if (.not. allocated(version)) call fpm_stop(1, 'No version specified in fpm.toml.') if (version%s() == '0') call fpm_stop(1, 'Invalid version: "'//version%s()//'".') if (.not. exists('fpm.toml')) call fpm_stop(1, "Cannot find 'fpm.toml' file. Are you in the project root?") + ! Build model to obtain dependency tree. + call build_model(model, settings%fpm_build_settings, package, error) + if (allocated(error)) call fpm_stop(1, '*cmd_build* Model error: '//error%message) + ! Check if package contains git dependencies. Only publish packages without git dependencies. do i = 1, model%deps%ndep if (allocated(model%deps%dep(i)%git)) then diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index d40e66d5ba..15e93d685c 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -1361,20 +1361,38 @@ subroutine set_help() ' publish(1) - publish package to the registry', & '', & 'SYNOPSIS', & - ' fpm publish [--token TOKEN]', & + ' fpm publish [--token TOKEN] [--show-package-version] [--show-upload-data]', & '', & ' fpm publish --help|--version', & '', & 'DESCRIPTION', & - ' Collect relevant source files and upload package to the registry.', & - ' It is mandatory to provide a token. The token can be generated on the', & - ' registry website and will be linked to your username and namespace.', & + ' Follow the steps to create a tarball and upload the package to the registry:', & + '', & + ' 1. Register on the website (https://registry-frontend.vercel.app/).', & + ' 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.', & + ' 3. Create a token for that namespace. A token is linked to your username', & + ' and is used to authenticate you during the upload process. Do not share', & + ' the token with others.', & + ' 4. Run fpm publish --token TOKEN to upload the package to the registry.', & + ' But be aware that the upload is permanent. An uploaded package cannot be', & + ' deleted.', & + '', & + ' See documentation (https://fpm.fortran-lang.org/en/spec/publish.html) for', & + ' more information regarding the package upload.', & '', & 'OPTIONS', & ' --show-package-version show package version without publishing', & ' --show-upload-data show uploaded data without publishing', & ' --help print this help and exit', & ' --version print program version information and exit', & + '', & + 'EXAMPLES', & + '', & + ' fpm publish --show-package-version # show package version without publishing', & + ' fpm publish --show-upload-data # show upload data without publishing', & + ' fpm publish --token TOKEN # upload package to the registry using TOKEN', & '' ] end subroutine set_help From c3823ce9c377aae6b9dd69729dfa30df4486bf4e Mon Sep 17 00:00:00 2001 From: minhqdao Date: Sun, 28 May 2023 10:19:21 +0700 Subject: [PATCH 5/8] Check for non-empty token --- src/fpm/cmd/publish.f90 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/fpm/cmd/publish.f90 b/src/fpm/cmd/publish.f90 index 8ff3a7d7da..80cb3d82e9 100644 --- a/src/fpm/cmd/publish.f90 +++ b/src/fpm/cmd/publish.f90 @@ -82,7 +82,11 @@ subroutine cmd_publish(settings) end if ! Make sure a token is provided for publishing. - if (.not. allocated(settings%token)) call fpm_stop(1, 'No token provided.') + if (allocated(settings%token)) then + if (settings%token == '') call fpm_stop(1, 'No token provided.') + else + call fpm_stop(1, 'No token provided.') + end if call downloader%upload_form(official_registry_base_url//'/packages', upload_data, error) if (allocated(error)) call fpm_stop(1, '*cmd_publish* Upload error: '//error%message) From a7097ae005ecec348d7c219859e125ee4cddaae6 Mon Sep 17 00:00:00 2001 From: minhqdao Date: Sun, 28 May 2023 10:31:06 +0700 Subject: [PATCH 6/8] Improve error message for git dependencies --- src/fpm/cmd/publish.f90 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fpm/cmd/publish.f90 b/src/fpm/cmd/publish.f90 index 80cb3d82e9..e149c3075e 100644 --- a/src/fpm/cmd/publish.f90 +++ b/src/fpm/cmd/publish.f90 @@ -57,7 +57,8 @@ subroutine cmd_publish(settings) ! Check if package contains git dependencies. Only publish packages without git dependencies. do i = 1, model%deps%ndep if (allocated(model%deps%dep(i)%git)) then - call fpm_stop(1, "Do not publish packages containing git dependencies. '"//model%deps%dep(i)%name//"' is a git dependency.") + call fpm_stop(1, 'Do not publish packages containing git dependencies. '// & + & "Please upload '"//model%deps%dep(i)%name//"' to the registry first.") end if end do From 41166f8b95d879f047835e64ace5b3883e0018af Mon Sep 17 00:00:00 2001 From: minhqdao Date: Sun, 28 May 2023 12:03:52 +0700 Subject: [PATCH 7/8] Add link to documentation for package usage --- src/fpm_command_line.f90 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 15e93d685c..57e804035b 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -1366,7 +1366,7 @@ subroutine set_help() ' fpm publish --help|--version', & '', & 'DESCRIPTION', & - ' Follow the steps to create a tarball and upload the package to the registry:', & + ' Follow the steps to create a tarball and upload a package to the registry:', & '', & ' 1. Register on the website (https://registry-frontend.vercel.app/).', & ' 2. Create a namespace. Uploaded packages must be assigned to a unique', & @@ -1379,8 +1379,13 @@ subroutine set_help() ' But be aware that the upload is permanent. An uploaded package cannot be', & ' deleted.', & '', & - ' See documentation (https://fpm.fortran-lang.org/en/spec/publish.html) for', & - ' more information regarding the package upload.', & + ' See documentation for more information regarding the package upload and usage:', & + '', & + ' Package upload:', & + ' https://fpm.fortran-lang.org/en/spec/publish.html', & + '', & + ' Package usage:', & + ' https://fpm.fortran-lang.org/en/spec/manifest.html#dependencies-from-a-registry', & '', & 'OPTIONS', & ' --show-package-version show package version without publishing', & From c5ab931e173fe34c787d17e53b99e7f0ecc74af7 Mon Sep 17 00:00:00 2001 From: minhqdao Date: Sun, 28 May 2023 12:47:30 +0700 Subject: [PATCH 8/8] Require module-naming --- src/fpm/cmd/publish.f90 | 2 ++ src/fpm_command_line.f90 | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fpm/cmd/publish.f90 b/src/fpm/cmd/publish.f90 index e149c3075e..b84fba640a 100644 --- a/src/fpm/cmd/publish.f90 +++ b/src/fpm/cmd/publish.f90 @@ -46,6 +46,8 @@ subroutine cmd_publish(settings) !> Checks before uploading the package. if (.not. allocated(package%license)) call fpm_stop(1, 'No license specified in fpm.toml.') + if (.not. package%build%module_naming) call fpm_stop(1, 'The package does not meet the module naming requirements. '// & + & 'Please set "module_naming = true" in fpm.toml [build] or specify a custom module prefix.') if (.not. allocated(version)) call fpm_stop(1, 'No version specified in fpm.toml.') if (version%s() == '0') call fpm_stop(1, 'Invalid version: "'//version%s()//'".') if (.not. exists('fpm.toml')) call fpm_stop(1, "Cannot find 'fpm.toml' file. Are you in the project root?") diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 57e804035b..22ba9c0843 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -754,7 +754,7 @@ subroutine set_help() ' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] ', & ' [options] ', & ' clean [--skip] [--all] ', & - ' publish [--show-package-version] [--show-upload-data] [--token TOKEN] ', & + ' publish [--show-package-version] [--show-upload-data] [--token TOKEN] ', & ' '] help_usage=[character(len=80) :: & '' ]