Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F77980498
site_init.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Aug 17, 15:43
Size
4 KB
Mime Type
text/x-python
Expires
Mon, Aug 19, 15:43 (2 d)
Engine
blob
Format
Raw Data
Handle
19956263
Attached To
rTAMAAS tamaas
site_init.py
View Options
# -*- coding: utf-8 -*-
# @file
# @section LICENSE
#
# Copyright (©) 2016-2020 EPFL (École Polytechnique Fédérale de Lausanne),
# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import
subprocess
from
detect
import
FindPybind11
# ------------------------------------------------------------------------------
def
pybind11
(
env
):
"""A tool to configure pybind11"""
def
execute
(
command
):
return
[
line
for
line
in
subprocess
.
check_output
(
command
,
universal_newlines
=
True
)
.
split
(
'
\n
'
)
if
line
!=
""
]
# Create a clone so we do not modify env
clone
=
env
.
Clone
()
# Set variables for clone
FindPybind11
(
clone
)
includes
=
clone
[
'CPPPATH'
]
# Extension of shared library for python
try
:
extension
=
execute
(
'{}-config --extension-suffix'
.
format
(
env
[
'py_exec'
])
.
split
())[
0
]
except
subprocess
.
CalledProcessError
:
extension
=
".so"
def
pybind11_builder
(
env
,
target
,
source
,
**
kwargs
):
"""Create a pybind11 module"""
clone
=
env
.
Clone
()
clone
.
AppendUnique
(
CPPPATH
=
includes
)
clone
[
'SHLIBSUFFIX'
]
=
extension
clone
.
AppendUnique
(
SHLINKFLAGS
=
[
'-fvisibility=hidden'
])
return
clone
.
SharedLibrary
(
target
,
source
,
**
kwargs
)
# Add pseudo-builder to master environment
env
.
AddMethod
(
pybind11_builder
,
'Pybind11Module'
)
# ------------------------------------------------------------------------------
def
pretty_cmd_print
(
command
,
target
,
source
,
env
):
colors
=
env
[
'COLOR_DICT'
]
if
'Copy'
in
command
:
color
=
colors
[
'red'
]
action
=
'Copying'
elif
'Creating'
in
command
:
color
=
colors
[
'yellow'
]
action
=
'Generating'
else
:
print
(
command
)
return
print
(
"{color}[{action}] {end}{target}"
.
format
(
color
=
color
,
end
=
colors
[
'end'
],
target
=
target
[
0
],
action
=
action
))
# ------------------------------------------------------------------------------
def
CheckPythonModule
(
context
,
module
):
"""Checks the existence of a python module"""
context
.
Message
(
'Checking for Python module {}... '
.
format
(
module
))
env
=
context
.
sconf
.
env
command
=
[
env
.
subst
(
'${py_exec}'
),
'-c'
,
'import {}'
.
format
(
module
)]
context
.
Log
(
'Executing external command: {}
\n
'
.
format
(
command
))
try
:
subprocess
.
check_output
(
command
,
stderr
=
subprocess
.
STDOUT
)
result
=
True
except
subprocess
.
CalledProcessError
as
e
:
result
=
False
context
.
Log
(
e
.
output
+
'
\n
'
)
context
.
Result
(
result
)
return
result
# ------------------------------------------------------------------------------
def
dummy_command
(
env
,
command
,
error_msg
):
"""Creates a dummy scons command"""
def
print_error
(
*
args
,
**
kwargs
):
print
(
error_msg
)
def
print_cmd
(
*
args
,
**
kwargs
):
pass
comm
=
env
.
Command
(
'#.phony_{}'
.
format
(
command
),
''
,
print_error
,
PRINT_CMD_LINE_FUNC
=
print_cmd
)
env
.
Alias
(
command
,
comm
)
# ------------------------------------------------------------------------------
def
get_python_version
(
env
):
versions_script
=
"""
from __future__ import print_function
from sysconfig import get_python_version
print(get_python_version())"""
version
=
subprocess
.
check_output
([
env
[
'py_exec'
],
"-c"
,
versions_script
],
universal_newlines
=
True
)
.
replace
(
'
\n
'
,
''
)
print
(
version
)
return
version
Event Timeline
Log In to Comment