Skip to content

Add automatic code formatting #825

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/pseewald/fprettify
rev: v0.3.7
hooks:
- id: fprettify
args: [-i4, -r]
196 changes: 98 additions & 98 deletions app/main.f90
Original file line number Diff line number Diff line change
@@ -1,119 +1,119 @@
program main
use, intrinsic :: iso_fortran_env, only : error_unit, output_unit
use fpm_command_line, only: &
fpm_cmd_settings, &
fpm_new_settings, &
fpm_build_settings, &
fpm_run_settings, &
fpm_test_settings, &
fpm_install_settings, &
fpm_update_settings, &
fpm_clean_settings, &
get_command_line_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_cmd_install, only: cmd_install
use fpm_cmd_new, only: cmd_new
use fpm_cmd_update, only : cmd_update
use fpm_os, only: change_directory, get_current_directory

implicit none

class(fpm_cmd_settings), allocatable :: cmd_settings
type(error_t), allocatable :: error
character(len=:), allocatable :: pwd_start, pwd_working, working_dir, project_root

call get_command_line_settings(cmd_settings)

call get_current_directory(pwd_start, error)
call handle_error(error)

call get_working_dir(cmd_settings, working_dir)
if (allocated(working_dir)) then
use, intrinsic :: iso_fortran_env, only: error_unit, output_unit
use fpm_command_line, only: &
fpm_cmd_settings, &
fpm_new_settings, &
fpm_build_settings, &
fpm_run_settings, &
fpm_test_settings, &
fpm_install_settings, &
fpm_update_settings, &
fpm_clean_settings, &
get_command_line_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_cmd_install, only: cmd_install
use fpm_cmd_new, only: cmd_new
use fpm_cmd_update, only: cmd_update
use fpm_os, only: change_directory, get_current_directory

implicit none

class(fpm_cmd_settings), allocatable :: cmd_settings
type(error_t), allocatable :: error
character(len=:), allocatable :: pwd_start, pwd_working, working_dir, project_root

call get_command_line_settings(cmd_settings)

call get_current_directory(pwd_start, error)
call handle_error(error)

call get_working_dir(cmd_settings, working_dir)
if (allocated(working_dir)) then
! Change working directory if requested
if (len_trim(working_dir) > 0) then
call change_directory(working_dir, error)
call handle_error(error)
call change_directory(working_dir, error)
call handle_error(error)

call get_current_directory(pwd_working, error)
call handle_error(error)
write(output_unit, '(*(a))') "fpm: Entering directory '"//pwd_working//"'"
call get_current_directory(pwd_working, error)
call handle_error(error)
write (output_unit, '(*(a))') "fpm: Entering directory '"//pwd_working//"'"
else
pwd_working = pwd_start
pwd_working = pwd_start
end if
else
else
pwd_working = pwd_start
end if

select type (settings => cmd_settings)
type is (fpm_new_settings)
class default
if (.not.has_manifest(pwd_working)) then
project_root = pwd_working
do while(.not.has_manifest(project_root))
working_dir = parent_dir(project_root)
if (len(working_dir) == 0) exit
project_root = working_dir
end do

if (has_manifest(project_root)) then
call change_directory(project_root, error)
call handle_error(error)
write(output_unit, '(*(a))') "fpm: Entering directory '"//project_root//"'"
end if
end if

select type (settings => cmd_settings)
type is (fpm_new_settings)
class default
if (.not. has_manifest(pwd_working)) then
project_root = pwd_working
do while (.not. has_manifest(project_root))
working_dir = parent_dir(project_root)
if (len(working_dir) == 0) exit
project_root = working_dir
end do

if (has_manifest(project_root)) then
call change_directory(project_root, error)
call handle_error(error)
write (output_unit, '(*(a))') "fpm: Entering directory '"//project_root//"'"
end if
end if
end select
end select

select type(settings=>cmd_settings)
type is (fpm_new_settings)
select type (settings => cmd_settings)
type is (fpm_new_settings)
call cmd_new(settings)
type is (fpm_build_settings)
type is (fpm_build_settings)
call cmd_build(settings)
type is (fpm_run_settings)
call cmd_run(settings,test=.false.)
type is (fpm_test_settings)
call cmd_run(settings,test=.true.)
type is (fpm_install_settings)
type is (fpm_run_settings)
call cmd_run(settings, test=.false.)
type is (fpm_test_settings)
call cmd_run(settings, test=.true.)
type is (fpm_install_settings)
call cmd_install(settings)
type is (fpm_update_settings)
type is (fpm_update_settings)
call cmd_update(settings)
type is (fpm_clean_settings)
type is (fpm_clean_settings)
call cmd_clean(settings)
end select
end select

if (allocated(project_root)) then
write(output_unit, '(*(a))') "fpm: Leaving directory '"//project_root//"'"
end if
if (allocated(project_root)) then
write (output_unit, '(*(a))') "fpm: Leaving directory '"//project_root//"'"
end if

if (pwd_start /= pwd_working) then
write(output_unit, '(*(a))') "fpm: Leaving directory '"//pwd_working//"'"
end if
if (pwd_start /= pwd_working) then
write (output_unit, '(*(a))') "fpm: Leaving directory '"//pwd_working//"'"
end if

contains

function has_manifest(dir)
character(len=*), intent(in) :: dir
logical :: has_manifest

has_manifest = exists(join_path(dir, "fpm.toml"))
end function has_manifest

subroutine handle_error(error)
type(error_t), optional, intent(in) :: error
if (present(error)) then
write(error_unit, '("[Error]", 1x, a)') error%message
stop 1
end if
end subroutine handle_error

!> Save access to working directory in settings, in case setting have not been allocated
subroutine get_working_dir(settings, working_dir)
class(fpm_cmd_settings), optional, intent(in) :: settings
character(len=:), allocatable, intent(out) :: working_dir
if (present(settings)) then
working_dir = settings%working_dir
end if
end subroutine get_working_dir
function has_manifest(dir)
character(len=*), intent(in) :: dir
logical :: has_manifest

has_manifest = exists(join_path(dir, "fpm.toml"))
end function has_manifest

subroutine handle_error(error)
type(error_t), optional, intent(in) :: error
if (present(error)) then
write (error_unit, '("[Error]", 1x, a)') error%message
stop 1
end if
end subroutine handle_error

!> Save access to working directory in settings, in case setting have not been allocated
subroutine get_working_dir(settings, working_dir)
class(fpm_cmd_settings), optional, intent(in) :: settings
character(len=:), allocatable, intent(out) :: working_dir
if (present(settings)) then
working_dir = settings%working_dir
end if
end subroutine get_working_dir

end program main
46 changes: 23 additions & 23 deletions example_packages/app_with_c/app/main.f90
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
module with_c
use iso_c_binding, only: c_char, c_int, c_null_char
implicit none
use iso_c_binding, only: c_char, c_int, c_null_char
implicit none

contains

function system_isdir(dirname)
! Source (Public domain): https://github.com/urbanjost/M_system
!
implicit none
character(len=*), intent(in) :: dirname
logical :: system_isdir
function system_isdir(dirname)
! Source (Public domain): https://github.com/urbanjost/M_system
!
implicit none
character(len=*), intent(in) :: dirname
logical :: system_isdir

interface
function c_isdir(dirname) bind(C, name="my_isdir") result(c_ierr)
import c_char, c_int
character(kind=c_char, len=1), intent(in) :: dirname(*)
integer(kind=c_int) :: c_ierr
end function c_isdir
end interface
interface
function c_isdir(dirname) bind(C, name="my_isdir") result(c_ierr)
import c_char, c_int
character(kind=c_char, len=1), intent(in) :: dirname(*)
integer(kind=c_int) :: c_ierr
end function c_isdir
end interface

system_isdir = c_isdir(trim(dirname)//c_null_char) == 1
system_isdir = c_isdir(trim(dirname)//c_null_char) == 1

end function system_isdir
end function system_isdir

end module with_c

program with_c_app
use with_c
implicit none
use with_c
implicit none

write (*, *) "isdir('app') = ", system_isdir('app')
write (*, *) "isdir('src') = ", system_isdir('src')
write (*, *) "isdir('test') = ", system_isdir('test')
write (*, *) "isdir('bench') = ", system_isdir('bench')
write (*, *) "isdir('app') = ", system_isdir('app')
write (*, *) "isdir('src') = ", system_isdir('src')
write (*, *) "isdir('test') = ", system_isdir('test')
write (*, *) "isdir('bench') = ", system_isdir('bench')

end program with_c_app
18 changes: 9 additions & 9 deletions example_packages/app_with_submodule/app/app1/child1.f90
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
submodule(parent) child1
implicit none
implicit none

interface
module function my_fun() result (b)
integer :: b
interface
module function my_fun() result(b)
integer :: b
end function my_fun
end interface
end interface

contains

module procedure my_sub1
a = my_fun()
end procedure my_sub1
module procedure my_sub1
a = my_fun()
end procedure my_sub1

end submodule child1
end submodule child1
4 changes: 2 additions & 2 deletions example_packages/app_with_submodule/app/app1/grandchild.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
contains

module procedure my_fun
b = 1
b = 1
end procedure my_fun

end submodule grandchild
end submodule grandchild
16 changes: 8 additions & 8 deletions example_packages/app_with_submodule/app/app1/main1.f90
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
program test
use parent
implicit none
use parent
implicit none

integer :: a
integer :: a

call my_sub1(a)
call my_sub1(a)

if (a /= 1) then
write(*,*) 'FAILED: Unexpected value of a'
if (a /= 1) then
write (*, *) 'FAILED: Unexpected value of a'
stop 1
end if
end if

end program test
end program test
10 changes: 5 additions & 5 deletions example_packages/app_with_submodule/app/app2/child2.f90
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
submodule(parent) child2
implicit none
implicit none

contains

module procedure my_sub1
a = 2
end procedure my_sub1
module procedure my_sub1
a = 2
end procedure my_sub1

end submodule child2
end submodule child2
16 changes: 8 additions & 8 deletions example_packages/app_with_submodule/app/app2/main2.f90
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
program test
use parent
implicit none
use parent
implicit none

integer :: a
integer :: a

call my_sub1(a)
call my_sub1(a)

if (a /= 2) then
write(*,*) 'FAILED: Unexpected value of a'
if (a /= 2) then
write (*, *) 'FAILED: Unexpected value of a'
stop 1
end if
end if

end program test
end program test
Loading