Skip to content

Commit 757e003

Browse files
authored
Merge pull request #915 from fortran-lang/add-publish-to-fpm-help
Add more infos to `fpm help publish`
2 parents a3d689f + c5ab931 commit 757e003

File tree

3 files changed

+71
-35
lines changed

3 files changed

+71
-35
lines changed

src/fpm/cmd/publish.f90

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ subroutine cmd_publish(settings)
3030
type(fpm_model_t) :: model
3131
type(error_t), allocatable :: error
3232
type(version_t), allocatable :: version
33-
type(string_t), allocatable :: form_data(:)
33+
type(string_t), allocatable :: upload_data(:)
3434
character(len=:), allocatable :: tmp_file
3535
type(downloader_t) :: downloader
3636
integer :: i
@@ -44,47 +44,54 @@ subroutine cmd_publish(settings)
4444
print *, version%s(); return
4545
end if
4646

47-
! Build model to obtain dependency tree.
48-
call build_model(model, settings%fpm_build_settings, package, error)
49-
if (allocated(error)) call fpm_stop(1, '*cmd_build* Model error: '//error%message)
50-
5147
!> Checks before uploading the package.
5248
if (.not. allocated(package%license)) call fpm_stop(1, 'No license specified in fpm.toml.')
49+
if (.not. package%build%module_naming) call fpm_stop(1, 'The package does not meet the module naming requirements. '// &
50+
& 'Please set "module_naming = true" in fpm.toml [build] or specify a custom module prefix.')
5351
if (.not. allocated(version)) call fpm_stop(1, 'No version specified in fpm.toml.')
5452
if (version%s() == '0') call fpm_stop(1, 'Invalid version: "'//version%s()//'".')
5553
if (.not. exists('fpm.toml')) call fpm_stop(1, "Cannot find 'fpm.toml' file. Are you in the project root?")
5654

55+
! Build model to obtain dependency tree.
56+
call build_model(model, settings%fpm_build_settings, package, error)
57+
if (allocated(error)) call fpm_stop(1, '*cmd_build* Model error: '//error%message)
58+
5759
! Check if package contains git dependencies. Only publish packages without git dependencies.
5860
do i = 1, model%deps%ndep
5961
if (allocated(model%deps%dep(i)%git)) then
60-
call fpm_stop(1, "Do not publish packages containing git dependencies. '"//model%deps%dep(i)%name//"' is a git dependency.")
62+
call fpm_stop(1, 'Do not publish packages containing git dependencies. '// &
63+
& "Please upload '"//model%deps%dep(i)%name//"' to the registry first.")
6164
end if
6265
end do
6366

64-
form_data = [ &
67+
upload_data = [ &
6568
string_t('package_name="'//package%name//'"'), &
6669
string_t('package_license="'//package%license//'"'), &
6770
string_t('package_version="'//version%s()//'"') &
6871
& ]
6972

70-
if (allocated(settings%token)) form_data = [form_data, string_t('upload_token="'//settings%token//'"')]
73+
if (allocated(settings%token)) upload_data = [upload_data, string_t('upload_token="'//settings%token//'"')]
7174

7275
tmp_file = get_temp_filename()
7376
call git_archive('.', tmp_file, error)
7477
if (allocated(error)) call fpm_stop(1, '*cmd_publish* Pack error: '//error%message)
75-
form_data = [form_data, string_t('tarball=@"'//tmp_file//'"')]
78+
upload_data = [upload_data, string_t('tarball=@"'//tmp_file//'"')]
7679

77-
if (settings%show_form_data) then
78-
do i = 1, size(form_data)
79-
print *, form_data(i)%s
80+
if (settings%show_upload_data) then
81+
do i = 1, size(upload_data)
82+
print *, upload_data(i)%s
8083
end do
8184
return
8285
end if
8386

8487
! Make sure a token is provided for publishing.
85-
if (.not. allocated(settings%token)) call fpm_stop(1, 'No token provided.')
88+
if (allocated(settings%token)) then
89+
if (settings%token == '') call fpm_stop(1, 'No token provided.')
90+
else
91+
call fpm_stop(1, 'No token provided.')
92+
end if
8693

87-
call downloader%upload_form(official_registry_base_url//'/packages', form_data, error)
94+
call downloader%upload_form(official_registry_base_url//'/packages', upload_data, error)
8895
if (allocated(error)) call fpm_stop(1, '*cmd_publish* Upload error: '//error%message)
8996
end
9097
end

src/fpm_command_line.f90

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ module fpm_command_line
120120

121121
type, extends(fpm_build_settings) :: fpm_publish_settings
122122
logical :: show_package_version = .false.
123-
logical :: show_form_data = .false.
123+
logical :: show_upload_data = .false.
124124
character(len=:), allocatable :: token
125125
end type
126126

@@ -620,7 +620,7 @@ subroutine get_command_line_settings(cmd_settings)
620620
case('publish')
621621
call set_args(common_args // compiler_args //'&
622622
& --show-package-version F &
623-
& --show-form-data F &
623+
& --show-upload-data F &
624624
& --token " " &
625625
& --list F &
626626
& --show-model F &
@@ -637,7 +637,7 @@ subroutine get_command_line_settings(cmd_settings)
637637
allocate(fpm_publish_settings :: cmd_settings)
638638
cmd_settings = fpm_publish_settings( &
639639
& show_package_version = lget('show-package-version'), &
640-
& show_form_data = lget('show-form-data'), &
640+
& show_upload_data = lget('show-upload-data'), &
641641
& profile=val_profile,&
642642
& prune=.not.lget('no-prune'), &
643643
& compiler=val_compiler, &
@@ -754,7 +754,7 @@ subroutine set_help()
754754
' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] ', &
755755
' [options] ', &
756756
' clean [--skip] [--all] ', &
757-
' publish [--show-package-version] [--show-form-data] [--token TOKEN] ', &
757+
' publish [--show-package-version] [--show-upload-data] [--token TOKEN] ', &
758758
' ']
759759
help_usage=[character(len=80) :: &
760760
'' ]
@@ -878,7 +878,7 @@ subroutine set_help()
878878
' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] ', &
879879
' [options] ', &
880880
' clean [--skip] [--all] ', &
881-
' publish [--show-package-version] [--show-form-data] [--token TOKEN] ', &
881+
' publish [--show-package-version] [--show-upload-data] [--token TOKEN] ', &
882882
' ', &
883883
'SUBCOMMAND OPTIONS ', &
884884
' -C, --directory PATH', &
@@ -958,7 +958,7 @@ subroutine set_help()
958958
' list(1) - list summary of fpm(1) subcommands ', &
959959
' ', &
960960
'SYNOPSIS ', &
961-
' fpm list [-list] ', &
961+
' fpm list ', &
962962
' ', &
963963
' fpm list --help|--version ', &
964964
' ', &
@@ -1125,13 +1125,15 @@ subroutine set_help()
11251125
help_new=[character(len=80) :: &
11261126
'NAME ', &
11271127
' new(1) - the fpm(1) subcommand to initialize a new project ', &
1128+
' ', &
11281129
'SYNOPSIS ', &
1129-
' fpm new NAME [[--lib|--src] [--app] [--test] [--example]]| ', &
1130-
' [--full|--bare][--backfill] ', &
1130+
' fpm new NAME [[--lib|--src] [--app] [--test] [--example]]| ', &
1131+
' [--full|--bare][--backfill] ', &
11311132
' fpm new --help|--version ', &
11321133
' ', &
11331134
'DESCRIPTION ', &
11341135
' "fpm new" creates and populates a new programming project directory. ', &
1136+
' ', &
11351137
' It ', &
11361138
' o creates a directory with the specified name ', &
11371139
' o runs the command "git init" in that directory ', &
@@ -1359,16 +1361,43 @@ subroutine set_help()
13591361
' publish(1) - publish package to the registry', &
13601362
'', &
13611363
'SYNOPSIS', &
1362-
' fpm publish [--token TOKEN]', &
1364+
' fpm publish [--token TOKEN] [--show-package-version] [--show-upload-data]', &
1365+
'', &
1366+
' fpm publish --help|--version', &
13631367
'', &
13641368
'DESCRIPTION', &
1365-
' Collect relevant source files and upload package to the registry.', &
1366-
' It is mandatory to provide a token. The token can be generated on the', &
1367-
' registry website and will be linked to your username and namespace.', &
1369+
' Follow the steps to create a tarball and upload a package to the registry:', &
1370+
'', &
1371+
' 1. Register on the website (https://registry-frontend.vercel.app/).', &
1372+
' 2. Create a namespace. Uploaded packages must be assigned to a unique', &
1373+
' namespace to avoid conflicts among packages with similar names. A', &
1374+
' namespace can accommodate multiple packages.', &
1375+
' 3. Create a token for that namespace. A token is linked to your username', &
1376+
' and is used to authenticate you during the upload process. Do not share', &
1377+
' the token with others.', &
1378+
' 4. Run fpm publish --token TOKEN to upload the package to the registry.', &
1379+
' But be aware that the upload is permanent. An uploaded package cannot be', &
1380+
' deleted.', &
1381+
'', &
1382+
' See documentation for more information regarding the package upload and usage:', &
1383+
'', &
1384+
' Package upload:', &
1385+
' https://fpm.fortran-lang.org/en/spec/publish.html', &
1386+
'', &
1387+
' Package usage:', &
1388+
' https://fpm.fortran-lang.org/en/spec/manifest.html#dependencies-from-a-registry', &
13681389
'', &
13691390
'OPTIONS', &
13701391
' --show-package-version show package version without publishing', &
1371-
' --show-form-data show sent form data without publishing', &
1392+
' --show-upload-data show uploaded data without publishing', &
1393+
' --help print this help and exit', &
1394+
' --version print program version information and exit', &
1395+
'', &
1396+
'EXAMPLES', &
1397+
'', &
1398+
' fpm publish --show-package-version # show package version without publishing', &
1399+
' fpm publish --show-upload-data # show upload data without publishing', &
1400+
' fpm publish --token TOKEN # upload package to the registry using TOKEN', &
13721401
'' ]
13731402
end subroutine set_help
13741403

test/cli_test/cli_test.f90

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ program main
3030
logical :: c_s,act_c_s ; namelist/act_cli/act_c_s
3131
logical :: c_a,act_c_a ; namelist/act_cli/act_c_a
3232
logical :: show_v,act_show_v ; namelist/act_cli/act_show_v
33-
logical :: show_f_d,act_show_f_d; namelist/act_cli/act_show_f_d
33+
logical :: show_u_d,act_show_u_d; namelist/act_cli/act_show_u_d
3434
character(len=:), allocatable :: token, act_token ; namelist/act_cli/act_token
3535

3636
character(len=:), allocatable :: profile,act_profile ; namelist/act_cli/act_profile
3737
character(len=:), allocatable :: args,act_args ; namelist/act_cli/act_args
38-
namelist/expected/cmd,cstat,estat,w_e,w_t,c_s,c_a,name,profile,args,show_v,show_f_d,token
38+
namelist/expected/cmd,cstat,estat,w_e,w_t,c_s,c_a,name,profile,args,show_v,show_u_d,token
3939
integer :: lun
4040
logical,allocatable :: tally(:)
4141
logical,allocatable :: subtally(:)
@@ -75,7 +75,7 @@ program main
7575
'CMD="clean --skip", C_S=T, NAME=, ARGS="",', &
7676
'CMD="clean --all", C_A=T, NAME=, ARGS="",', &
7777
'CMD="publish --token abc --show-package-version", SHOW_V=T, NAME=, token="abc",ARGS="",', &
78-
'CMD="publish --token abc --show-form-data", SHOW_F_D=T, NAME=, token="abc",ARGS="",', &
78+
'CMD="publish --token abc --show-upload-data", SHOW_U_D=T, NAME=, token="abc",ARGS="",', &
7979
'CMD="publish --token abc", NAME=, token="abc",ARGS="",', &
8080
' ' ]
8181
character(len=256) :: readme(3)
@@ -110,7 +110,7 @@ program main
110110
c_s=.false. ! --skip
111111
c_a=.false. ! --all
112112
show_v=.false. ! --show-package-version
113-
show_f_d=.false. ! --show-form-data
113+
show_u_d=.false. ! --show-upload-data
114114
token='' ! --token TOKEN
115115
args=repeat(' ',132) ! -- ARGS
116116
cmd=repeat(' ',132) ! the command line arguments to test
@@ -132,7 +132,7 @@ program main
132132
act_c_s=.false.
133133
act_c_a=.false.
134134
act_show_v=.false.
135-
act_show_f_d=.false.
135+
act_show_u_d=.false.
136136
act_token=''
137137
act_args=repeat(' ',132)
138138
read(lun,nml=act_cli,iostat=ios,iomsg=message)
@@ -148,7 +148,7 @@ program main
148148
call test_test('WITH_TESTED',act_w_t.eqv.w_t)
149149
call test_test('WITH_TEST',act_w_t.eqv.w_t)
150150
call test_test('SHOW-PACKAGE-VERSION',act_show_v.eqv.show_v)
151-
call test_test('SHOW-FORM-DATA',act_show_f_d.eqv.show_f_d)
151+
call test_test('SHOW-UPLOAD-DATA',act_show_u_d.eqv.show_u_d)
152152
call test_test('TOKEN',act_token==token)
153153
call test_test('ARGS',act_args==args)
154154
if(all(subtally))then
@@ -237,7 +237,7 @@ subroutine parse()
237237
act_c_s=.false.
238238
act_c_a=.false.
239239
act_show_v=.false.
240-
act_show_f_d=.false.
240+
act_show_u_d=.false.
241241
act_token=''
242242
act_profile=''
243243

@@ -262,7 +262,7 @@ subroutine parse()
262262
type is (fpm_install_settings)
263263
type is (fpm_publish_settings)
264264
act_show_v=settings%show_package_version
265-
act_show_f_d=settings%show_form_data
265+
act_show_u_d=settings%show_upload_data
266266
act_token=settings%token
267267
end select
268268

0 commit comments

Comments
 (0)