Commit 2145ae1b authored by Victor Yu's avatar Victor Yu
Browse files

Add a script to compute module dependencies

* Update all make.depend files
* Support `make -j`
* Todo: clean up unused module imports
parent e8d01ac9
......@@ -30,13 +30,13 @@ stages:
- cd QEDIR
- git describe --tags --always
- ./configure
- make -j8 pw
- make -j4 pw
- ls bin
- git clone -b $CI_COMMIT_REF_NAME $CI_REPOSITORY_URL West
- cd West
- git describe --tags --always
- make conf PYT=python3 PYT_LDFLAGS="`python3-config --ldflags --embed`"
- make all
- make -j4 all
- ls ../bin
.template_test:
......@@ -46,13 +46,13 @@ stages:
- cd QEDIR
- git describe --tags --always
- ./configure
- make -j8 pw
- make -j4 pw
- ls bin
- git clone -b $CI_COMMIT_REF_NAME $CI_REPOSITORY_URL West
- cd West
- git describe --tags --always
- make conf PYT=python3 PYT_LDFLAGS="`python3-config --ldflags --embed`"
- make all
- make -j4 all
- cd test-suite
- make NP=$CI_NP NI=$CI_NI NT=$CI_NT
artifacts:
......
store_sqvc.o : ../../Modules/cell_base.o
store_sqvc.o : ../../Modules/constants.o
store_sqvc.o : ../../Modules/io_global.o
store_sqvc.o : ../../Modules/kind.o
store_sqvc.o : ../../Modules/recvec.o
store_sqvc.o : ../Tools/class_bz_grid.o
store_sqvc.o : ../Tools/types_bz_grid.o
store_sqvc.o : ../../PW/src/exx.o
store_sqvc.o : ../../PW/src/pwcom.o
store_sqvc.o : ../../West/Modules/westcom.o
store_vspx.o : ../../Modules/cell_base.o
store_vspx.o : ../../Modules/constants.o
store_vspx.o : ../../Modules/kind.o
store_vspx.o : ../../Modules/recvec.o
store_vspx.o : ../../PW/src/exx.o
store_vspx.o : ../../PW/src/pwcom.o
class_coulomb.o : ../../Modules/cell_base.o
class_coulomb.o : ../../Modules/constants.o
class_coulomb.o : ../../Modules/control_flags.o
class_coulomb.o : ../../Modules/gvecw.o
class_coulomb.o : ../../Modules/io_global.o
class_coulomb.o : ../../Modules/kind.o
class_coulomb.o : ../../Modules/mp.o
class_coulomb.o : ../../Modules/mp_global.o
class_coulomb.o : ../../Modules/mp_world.o
class_coulomb.o : ../../Modules/random_numbers.o
class_coulomb.o : ../../Modules/recvec.o
class_coulomb.o : ../Modules/westcom.o
class_coulomb.o : ../Tools/types_bz_grid.o
types_coulomb.o : ../../Modules/kind.o
types_coulomb.o : class_coulomb.o
apply_sternheimerop_to_m_wfcs.o : ../../Modules/becmod.o
apply_sternheimerop_to_m_wfcs.o : ../../Modules/control_flags.o
apply_sternheimerop_to_m_wfcs.o : ../../Modules/kind.o
apply_sternheimerop_to_m_wfcs.o : ../../Modules/mp.o
apply_sternheimerop_to_m_wfcs.o : ../../Modules/mp_global.o
......@@ -7,34 +6,39 @@ apply_sternheimerop_to_m_wfcs.o : ../../Modules/noncol.o
apply_sternheimerop_to_m_wfcs.o : ../../Modules/uspp.o
apply_sternheimerop_to_m_wfcs.o : ../../Modules/wavefunctions.o
apply_sternheimerop_to_m_wfcs.o : ../../PW/src/pwcom.o
apply_sternheimerop_to_m_wfcs.o : ../../West/Modules/westcom.o
dfpt.o : ../../Modules/constants.o
dfpt.o : ../../Modules/control_flags.o
dfpt.o : ../../Modules/fft_base.o
dfpt.o : ../../Modules/io_files.o
dfpt.o : ../../Modules/io_global.o
dfpt.o : ../../Modules/kind.o
dfpt.o : ../../Modules/mp.o
dfpt.o : ../../Modules/mp_global.o
dfpt.o : ../../Modules/noncol.o
dfpt.o : ../../Modules/recvec.o
dfpt.o : ../../Modules/uspp.o
dfpt.o : ../../Modules/wavefunctions.o
dfpt.o : ../../PW/src/buffers.o
dfpt.o : ../../PW/src/pwcom.o
dfpt.o : ../../West/FFT_kernel/fft_at_gamma.o
dfpt.o : ../../West/FFT_kernel/fft_at_k.o
dfpt.o : ../../West/Modules/westcom.o
dfpt.o : ../../West/Tools/bar.o
dfpt.o : ../../West/Tools/io_push.o
dfpt.o : ../../West/Tools/types_bz_grid.o
dfpt.o : ../../PW/src/exx.o
apply_sternheimerop_to_m_wfcs.o : ../Modules/westcom.o
dfpt_module.o : ../../FFTXlib/fft_interfaces.o
dfpt_module.o : ../../Modules/cell_base.o
dfpt_module.o : ../../Modules/constants.o
dfpt_module.o : ../../Modules/control_flags.o
dfpt_module.o : ../../Modules/fft_base.o
dfpt_module.o : ../../Modules/gvecw.o
dfpt_module.o : ../../Modules/io_files.o
dfpt_module.o : ../../Modules/io_global.o
dfpt_module.o : ../../Modules/kind.o
dfpt_module.o : ../../Modules/mp.o
dfpt_module.o : ../../Modules/mp_global.o
dfpt_module.o : ../../Modules/mp_world.o
dfpt_module.o : ../../Modules/noncol.o
dfpt_module.o : ../../Modules/recvec.o
dfpt_module.o : ../../Modules/uspp.o
dfpt_module.o : ../../Modules/wavefunctions.o
dfpt_module.o : ../../PW/src/buffers.o
dfpt_module.o : ../../PW/src/pwcom.o
dfpt_module.o : ../FFT_kernel/fft_at_gamma.o
dfpt_module.o : ../FFT_kernel/fft_at_k.o
dfpt_module.o : ../Modules/westcom.o
dfpt_module.o : ../Tools/bar.o
dfpt_module.o : ../Tools/io_push.o
dfpt_module.o : ../Tools/types_bz_grid.o
linsolve_sternheimer_m_wfcts.o : ../../Modules/control_flags.o
linsolve_sternheimer_m_wfcts.o : ../../Modules/kind.o
linsolve_sternheimer_m_wfcts.o : ../../Modules/mp.o
linsolve_sternheimer_m_wfcts.o : ../../Modules/mp_global.o
linsolve_sternheimer_m_wfcts.o : ../../Modules/noncol.o
linsolve_sternheimer_m_wfcts.o : ../../Modules/recvec.o
linsolve_sternheimer_m_wfcts.o : ../../Modules/wavefunctions.o
linsolve_sternheimer_m_wfcts.o : ../../PW/src/pwcom.o
linsolve_sternheimer_m_wfcts.o : ../../West/Modules/westcom.o
linsolve_sternheimer_m_wfcts.o : ../Modules/westcom.o
precondition_m_wfcts.o : ../../Modules/kind.o
precondition_m_wfcts.o : ../../Modules/noncol.o
precondition_m_wfcts.o : ../../PW/src/pwcom.o
fft_at_gamma.o : ../../Modules/fft_base.o
fft_at_gamma.o : ../../FFTXlib/fft_interfaces.o
fft_at_gamma.o : ../../FFTXlib/fft_types.o
fft_at_gamma.o : ../../Modules/kind.o
fft_at_gamma.o : ../../Modules/recvec.o
fft_at_k.o : ../../Modules/fft_base.o
fft_at_k.o : ../../FFTXlib/fft_interfaces.o
fft_at_k.o : ../../FFTXlib/fft_types.o
fft_at_k.o : ../../Modules/kind.o
fft_at_k.o : ../../Modules/recvec.o
fft_at_k.o : ../../PW/src/pwcom.o
fft_interpolation.o : ../../FFTXlib/fft_interfaces.o
fft_interpolation.o : ../../FFTXlib/fft_types.o
fft_interpolation.o : ../../Modules/cell_base.o
fft_interpolation.o : ../../Modules/kind.o
fft_interpolation.o : ../../Modules/recvec.o
......@@ -3,7 +3,6 @@ apply_alpha_pc_to_m_wfcs.o : ../../Modules/kind.o
apply_alpha_pc_to_m_wfcs.o : ../../Modules/mp.o
apply_alpha_pc_to_m_wfcs.o : ../../Modules/mp_global.o
apply_alpha_pc_to_m_wfcs.o : ../../Modules/noncol.o
apply_alpha_pc_to_m_wfcs.o : ../../Modules/recvec.o
apply_alpha_pc_to_m_wfcs.o : ../../Modules/wavefunctions.o
apply_alpha_pc_to_m_wfcs.o : ../../PW/src/pwcom.o
apply_alpha_pv_to_m_wfcs.o : ../../Modules/control_flags.o
......@@ -11,7 +10,6 @@ apply_alpha_pv_to_m_wfcs.o : ../../Modules/kind.o
apply_alpha_pv_to_m_wfcs.o : ../../Modules/mp.o
apply_alpha_pv_to_m_wfcs.o : ../../Modules/mp_global.o
apply_alpha_pv_to_m_wfcs.o : ../../Modules/noncol.o
apply_alpha_pv_to_m_wfcs.o : ../../Modules/recvec.o
apply_alpha_pv_to_m_wfcs.o : ../../Modules/wavefunctions.o
apply_alpha_pv_to_m_wfcs.o : ../../PW/src/pwcom.o
commutator_Hx_psi.o : ../../Modules/becmod.o
......@@ -24,17 +22,10 @@ commutator_Hx_psi.o : ../../Modules/noncol.o
commutator_Hx_psi.o : ../../Modules/recvec.o
commutator_Hx_psi.o : ../../Modules/uspp.o
commutator_Hx_psi.o : ../../PW/src/pwcom.o
k_psi.o : ../../Modules/becmod.o
glbrak.o : ../../Modules/kind.o
glbrak.o : ../../Modules/recvec.o
k_psi.o : ../../Modules/control_flags.o
k_psi.o : ../../Modules/fft_base.o
k_psi.o : ../../Modules/funct.o
k_psi.o : ../../Modules/kind.o
k_psi.o : ../../Modules/noncol.o
k_psi.o : ../../Modules/recvec.o
k_psi.o : ../../Modules/uspp.o
k_psi.o : ../../PW/src/bp_mod.o
k_psi.o : ../../PW/src/exx.o
k_psi.o : ../../PW/src/ldaU.o
k_psi.o : ../../PW/src/pwcom.o
k_psi.o : ../../PW/src/realus.o
k_psi.o : ../../PW/src/scf_mod.o
fetch_namelist.o : ../../Modules/io_files.o
fetch_namelist.o : ../../Modules/io_global.o
fetch_namelist.o : ../../Modules/mp.o
fetch_namelist.o : ../../Modules/mp_global.o
fetch_namelist.o : ../../PW/src/pwcom.o
fetch_namelist.o : ../../West/Modules/westcom.o
fetch_namelist.o : ../../West/Tools/io_push.o
cubefile.o : ../../FFTXlib/fft_types.o
cubefile.o : ../../FFTXlib/scatter_mod.o
cubefile.o : ../../Modules/cell_base.o
cubefile.o : ../../Modules/ions_base.o
cubefile.o : ../../Modules/kind.o
function3d.o : ../../FFTXlib/fft_types.o
function3d.o : ../../FFTXlib/scatter_mod.o
function3d.o : ../../Modules/cell_base.o
function3d.o : ../../Modules/control_flags.o
function3d.o : ../../Modules/kind.o
function3d.o : ../../Modules/mp_bands.o
function3d.o : ../Libraries/Base64/base64module.o
function3d.o : ../Libraries/Forpy/forpy_mod.o
function3d.o : ../Tools/conversions.o
mod_west_io.o : ../../Modules/kind.o
mod_west_io.o : ../../Modules/parallel_include.o
pdep_db.o : ../../Modules/io_files.o
mpiio.o : ../../Modules/kind.o
mpiio.o : ../../Modules/mp.o
mpiio.o : ../../Modules/mp_bands.o
mpiio.o : ../../Modules/mp_global.o
mpiio.o : ../../Modules/mp_images.o
mpiio.o : ../../Modules/mp_world.o
mpiio.o : ../../Modules/parallel_include.o
pdep_db.o : ../../Modules/cell_base.o
pdep_db.o : ../../Modules/gvecw.o
pdep_db.o : ../../Modules/io_global.o
pdep_db.o : ../../Modules/kind.o
pdep_db.o : ../../Modules/mp.o
pdep_db.o : ../../Modules/mp_global.o
pdep_db.o : ../../Modules/xml_io_base.o
pdep_db.o : ../../PW/src/pwcom.o
pdep_db.o : ../../West/Modules/westcom.o
pdep_db.o : ../../West/Tools/io_push.o
pdep_db.o : ../../iotk/src/iotk_module.o
pdep_db.o : ../../Modules/mp_world.o
pdep_db.o : ../../Modules/recvec.o
pdep_db.o : ../Libraries/Json/json_module.o
pdep_db.o : ../Modules/westcom.o
pdep_db.o : ../Para_kernel/distribution_center.o
pdep_db.o : ../Tools/io_push.o
pdep_db.o : ../Tools/types_bz_grid.o
pdep_db.o : pdep_io.o
pdep_io.o : ../../Modules/control_flags.o
pdep_io.o : ../../Modules/kind.o
pdep_io.o : ../../Modules/mp.o
pdep_io.o : ../../Modules/mp_global.o
pdep_io.o : ../../Modules/mp_wave.o
pdep_io.o : ../../PW/src/pwcom.o
pdep_io.o : ../../West/Modules/westcom.o
pdep_io.o : ../../iotk/src/iotk_module.o
pdep_restart.o : ../../Modules/io_files.o
pdep_restart.o : ../../Modules/io_global.o
pdep_restart.o : ../../Modules/kind.o
pdep_restart.o : ../../Modules/mp.o
pdep_restart.o : ../../Modules/mp_global.o
pdep_restart.o : ../../Modules/wrappers.o
pdep_restart.o : ../../Modules/xml_io_base.o
pdep_restart.o : ../../PW/src/pwcom.o
pdep_restart.o : ../../West/Modules/westcom.o
pdep_restart.o : ../../iotk/src/iotk_module.o
pdep_restart.o : pdep_io.o
pdep_io.o : ../../Modules/recvec.o
pdep_io.o : ../Libraries/Base64/base64module.o
pdep_io.o : ../Libraries/Json/json_module.o
pdep_io.o : ../Modules/westcom.o
wfreq_db.o : ../../Modules/constants.o
wfreq_db.o : ../../Modules/io_global.o
wfreq_db.o : ../../Modules/kind.o
wfreq_db.o : ../../Modules/mp.o
wfreq_db.o : ../../Modules/mp_global.o
wfreq_db.o : ../../Modules/mp_world.o
wfreq_db.o : ../../PW/src/pwcom.o
wfreq_db.o : ../Libraries/Json/json_module.o
wfreq_db.o : ../Modules/westcom.o
wfreq_db.o : ../Tools/io_push.o
wfreq_db.o : ../Tools/types_bz_grid.o
wfreq_io.o : ../../Modules/control_flags.o
wfreq_io.o : ../../Modules/kind.o
wfreq_io.o : ../../Modules/mp.o
wfreq_io.o : ../../Modules/mp_global.o
wfreq_io.o : ../../Modules/mp_images.o
wfreq_io.o : ../../Modules/mp_world.o
wfreq_io.o : ../../iotk/src/iotk_module.o
wfreq_io.o : ../Modules/westcom.o
wfreq_io.o : ../Para_kernel/class_idistribute.o
wfreq_io.o : mpiio.o
wfreq_restart.o : ../../Modules/io_files.o
wfreq_restart.o : ../../Modules/io_global.o
wfreq_restart.o : ../../Modules/kind.o
wfreq_restart.o : ../../Modules/mp.o
wfreq_restart.o : ../../Modules/mp_global.o
wfreq_restart.o : ../../Modules/mp_world.o
wfreq_restart.o : ../../iotk/src/iotk_module.o
wfreq_restart.o : ../Modules/westcom.o
wfreq_restart.o : ../Para_kernel/distribution_center.o
wfreq_restart.o : ../Tools/types_bz_grid.o
wfreq_restart.o : mod_west_io.o
......@@ -3,8 +3,7 @@
include ../../../make.inc
# location of needed modules
MODFLAGS= $(MOD_FLAG).
IFLAGS=
MODFLAGS = $(MOD_FLAG).
BASE64_OBJS = \
cbase64.o \
......@@ -26,4 +25,3 @@ title :
@echo "### Base64 ###"
@echo "##############"
@echo " "
fetch_namelist.o : ../../Modules/io_files.o
fetch_namelist.o : ../../Modules/io_global.o
fetch_namelist.o : ../../Modules/mp.o
fetch_namelist.o : ../../Modules/mp_global.o
fetch_namelist.o : ../../PW/src/pwcom.o
fetch_namelist.o : ../../West/Modules/westcom.o
fetch_namelist.o : ../../West/Tools/io_push.o
mod_west_io.o : ../../Modules/kind.o
mod_west_io.o : ../../Modules/parallel_include.o
pdep_db.o : ../../Modules/io_files.o
pdep_db.o : ../../Modules/io_global.o
pdep_db.o : ../../Modules/kind.o
pdep_db.o : ../../Modules/mp.o
pdep_db.o : ../../Modules/mp_global.o
pdep_db.o : ../../Modules/xml_io_base.o
pdep_db.o : ../../PW/src/pwcom.o
pdep_db.o : ../../West/Modules/westcom.o
pdep_db.o : ../../West/Tools/io_push.o
pdep_db.o : ../../iotk/src/iotk_module.o
pdep_db.o : pdep_io.o
pdep_io.o : ../../Modules/kind.o
pdep_io.o : ../../Modules/mp.o
pdep_io.o : ../../Modules/mp_global.o
pdep_io.o : ../../Modules/mp_wave.o
pdep_io.o : ../../PW/src/pwcom.o
pdep_io.o : ../../West/Modules/westcom.o
pdep_io.o : ../../iotk/src/iotk_module.o
pdep_restart.o : ../../Modules/io_files.o
pdep_restart.o : ../../Modules/io_global.o
pdep_restart.o : ../../Modules/kind.o
pdep_restart.o : ../../Modules/mp.o
pdep_restart.o : ../../Modules/mp_global.o
pdep_restart.o : ../../Modules/wrappers.o
pdep_restart.o : ../../Modules/xml_io_base.o
pdep_restart.o : ../../PW/src/pwcom.o
pdep_restart.o : ../../West/Modules/westcom.o
pdep_restart.o : ../../iotk/src/iotk_module.o
pdep_restart.o : pdep_io.o
......@@ -2,26 +2,14 @@
include ../../../make.inc
.SUFFIXES : .o .c .f .f90 .F90
.F90.o:
$(MPIF90) $(F90FLAGS) -c $<
# location of needed modules
MODFLAGS= $(MOD_FLAG).
IFLAGS=
MODFLAGS = $(MOD_FLAG).
FORPY_OBJS = \
forpy_mod.o
#TLDEPS= bindir mods libs pw
#all : title tldeps libjson.a
all : title libforpy.a
#tldeps:
# test -n "$(TLDEPS)" && ( cd ../.. ; $(MAKE) $(MFLAGS) $(TLDEPS) || exit 1) || :
libforpy.a : $(FORPY_OBJS)
$(AR) $(ARFLAGS) $@ $?
$(RANLIB) $@
......@@ -36,4 +24,3 @@ title :
@echo "### Forpy ####"
@echo "##############"
@echo " "
! Copyright (C) 2017-2018 Elias Rabel
! Copyright (C) 2017-2020 Elias Rabel
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU Lesser General Public License as published by
......@@ -50,7 +50,7 @@ tuple_create, list_create, dict_create, bytes_create, str_create, &
unicode_create, NoneType_create, ndarray_create, ndarray_create_nocopy, &
ndarray_create_empty, ndarray_create_zeros, ndarray_create_ones, &
import_py, call_py, call_py_noret, assign_py, cast, cast_nonstrict, &
PythonMethodTable, PythonModule, forpy_initialize, forpy_initialize_ext, &
PythonMethodTable, PythonModule, forpy_initialize, &
forpy_finalize, is_long, is_list, is_tuple, is_bytes, is_dict, &
is_float, is_complex, is_bool, is_unicode, is_int, is_str, is_none, &
is_null, is_ndarray, exception_matches, err_clear, err_print, have_exception, &
......@@ -72,6 +72,7 @@ PRIVATE
! These global variables shall be set in
! forpy_initialize only and never changed afterwards!
integer, private, save :: global_forpy_initialized = 0
type(c_ptr), private, save :: global_numpy_mod = C_NULL_PTR
type(c_ptr), private, save :: global_numpy_asarray_method = C_NULL_PTR
! the location of the singleton Python Py_NoneStruct method
......@@ -247,6 +248,11 @@ interface
subroutine Py_Initialize() bind(c, name="Py_Initialize")
end subroutine
function Py_IsInitialized() bind(c, name="Py_IsInitialized") result(r)
import C_INT
integer(kind=C_INT) :: r
end function
subroutine Py_Finalize() bind(c, name="Py_Finalize")
end subroutine
......@@ -612,6 +618,19 @@ interface
end function
#endif
!PyObject* PyUnicode_AsUTF8String(PyObject *unicode)
#ifdef PYTHON2
#ifdef PYTHON2_NARROW
function PyUnicode_AsUTF8String(unicode) bind(c, name="PyUnicodeUCS2_AsUTF8String") result(r)
#else
function PyUnicode_AsUTF8String(unicode) bind(c, name="PyUnicodeUCS4_AsUTF8String") result(r)
#endif
import c_ptr
type(c_ptr), value :: unicode
type(c_ptr) :: r
end function
#endif
function PyEval_GetBuiltins() bind(c, name="PyEval_GetBuiltins") result(r)
import c_ptr
type(c_ptr) :: r
......@@ -826,7 +845,11 @@ interface unbox_value
module procedure unbox_value_complex_real32
module procedure unbox_value_complex_real64
module procedure unbox_value_logical
#ifdef PYTHON2
module procedure unbox_value_chars_py2
#else
module procedure unbox_value_chars
#endif
module procedure unbox_value_char_1d
end interface
......@@ -837,11 +860,6 @@ end interface
!--------- High-level API to Python's datastructures -------------------
!> Type to represent an arbitrary Python object
type object
private
......@@ -952,7 +970,6 @@ type, abstract, extends(object) :: Sequence
!> Get item at a certain index
generic, public :: getitem => sequence_getitem_int64_chars
!> Checks if a given item is contained in the sequence.
procedure, public :: contains => sequence_contains
end type
......@@ -1513,6 +1530,7 @@ end type
interface str_create
module procedure str_create_chars
module procedure str_create_char_1d
module procedure str_create_object
end interface
!> Type corresponding to Python 2 'unicode' or Python 3 'str'.
......@@ -1772,10 +1790,15 @@ interface cast
module procedure cast_to_tuple
module procedure cast_to_NoneType
module procedure cast_to_ndarray
module procedure cast_to_str
module procedure cast_to_bytes
module procedure cast_to_unicode
module procedure cast_to_object
module procedure cast_to_char_1d
module procedure cast_to_chars
module procedure cast_from_char_1d
module procedure cast_from_chars
module procedure cast_to_int32
module procedure cast_to_int32_flex
......@@ -1821,6 +1844,7 @@ end interface
interface cast_nonstrict
module procedure cast_nonstrict_to_list
module procedure cast_nonstrict_to_tuple
module procedure cast_nonstrict_to_str
! no cast_nonstrict_to_char_1d, because one can
! not always return a pointer to a character buffer
......@@ -1953,42 +1977,35 @@ function forpy_initialize(use_numpy) result(ierror)
integer(kind=C_INT) :: ierror
logical :: numpy_flag
if (present(use_numpy)) then
numpy_flag = use_numpy
else
numpy_flag = .true.
endif
ierror = forpy_initialize_helper(.false., numpy_flag)
end function
!> Deprecated: use forpy_initialize instead
function forpy_initialize_ext(use_numpy) result(ierror)
!> Set to .false., if you do not need the array features of forpy powered by numpy. (Default: .true.)
logical, optional, intent(in) :: use_numpy
integer(kind=C_INT) :: ierror
ierror = 1_C_INT
if (Py_IsInitialized() == 0_C_INT) then
call Py_Initialize()
endif
logical :: numpy_flag
if (present(use_numpy)) then
numpy_flag = use_numpy
else
numpy_flag = .true.
ierror = 0_C_INT
if (global_forpy_initialized == 0) then
ierror = forpy_initialize_forpy_globals()
if (ierror == 0_C_INT) then
global_forpy_initialized = 1
endif
endif
ierror = forpy_initialize_helper(.true., numpy_flag)
if (ierror == 0_C_INT .and. numpy_flag &
.and. .not. c_associated(global_numpy_mod)) then
ierror = forpy_initialize_numpy()
endif
end function
function forpy_initialize_helper(is_extension, use_numpy) result(ierror)
logical, intent(in) :: is_extension
logical, intent(in) :: use_numpy
function forpy_initialize_forpy_globals() result(ierror)
integer(kind=C_INT) :: ierror
! might remove this in the future, since it is required that
! calling Py_Initialize multiple times is safe
if (.not. is_extension) then
call Py_Initialize()
endif
! Initialise Python's None object
ierror = forpy_initialize_none()
if (ierror /= 0) then
......@@ -2020,11 +2037,25 @@ function forpy_initialize_helper(is_extension, use_numpy) result(ierror)
return
endif
if (use_numpy) then
ierror = forpy_initialize_numpy()
ierror = forpy_initialize_sys_argv()
if (ierror /= 0) then
return
endif
end function
!> Sets sys.argv = [''], since some 3rd party Python modules require
!> sys.argv[0] - before Python 3.8 sys.argv does not exist in embedded Python,
!> see https://bugs.python.org/issue32573
function forpy_initialize_sys_argv() result(ierror)
integer(kind=C_INT) :: ierror
! there also exist C-API functions to set sys.argv, but they involve wchar_t
! which iso_c_binding does not support and that has platform dep. size
ierror = PyRun_SimpleString("import sys" // C_NEW_LINE // &
"if not hasattr(sys, 'argv') or sys.argv==[]:" // C_NEW_LINE // &
" sys.argv=['']" // C_NEW_LINE // C_NULL_CHAR)
end function
function forpy_initialize_numpy() result(ierror)
integer(kind=C_INT) :: ierror
......@@ -2386,7 +2417,7 @@ end function
!> Frees resources used by Python interpreter. Call when finished using forpy.
subroutine forpy_finalize()
global_forpy_initialized = 0
call Py_Decref(global_numpy_asarray_method)
call Py_Decref(global_numpy_mod)
global_numpy_asarray_method = C_NULL_PTR
......@@ -2395,7 +2426,6 @@ subroutine forpy_finalize()
call Py_Finalize()
end subroutine
!-------------------------------------------------------------------------------------
! Functions to check type
!> Checks if object is a Python long.
......@@ -2438,7 +2468,6 @@ logical function is_dict(obj)
is_dict = (check_tp_flags(obj%py_object, ishft(1_C_LONG, 29)) /= 0)
end function
!> Checks if object is a Python float.
logical function is_float(obj)
!> The object to check.
......@@ -2511,7 +2540,6 @@ logical function is_unicode(obj)
endif
end function
#ifdef PYTHON2
logical function is_short_int(obj)
class(object), intent(in) :: obj
......@@ -2684,7 +2712,6 @@ function tuple_create_int64(r, len) result(ierror)
endif
end function
function tuple_create_object(r, obj) result(ierror)
!> the created tuple
type(tuple), intent(out) :: r
......@@ -2924,7 +2951,6 @@ function list_append_chars(self, item) result(ierror)
endif
end function
function list_copy(self, dest) result(ierror)
class(list), intent(in) :: self
type(list), intent(out) :: dest
......@@ -3007,7 +3033,6 @@ function list_delitem_int64(self, ind) result(ierror)
ierror = PySequence_DelItem(self%py_object, ind_tmp)
end function
function sequence_getitem_int32_object(self, item, ind) result(ierror)
class(Sequence), intent(inout) :: self
type(object), intent(out) :: item
......@@ -3438,7 +3463,6 @@ function sequence_getitem_int64_chars(self, item, ind) result(ierror)
endif
end function