diff --git a/site_scons/site_init.py b/site_scons/site_init.py
index c80730e..e87ef33 100644
--- a/site_scons/site_init.py
+++ b/site_scons/site_init.py
@@ -1,126 +1,127 @@
# -*- 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 .
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')
+ output = bytes(e.output)
+ context.Log(output.decode() + '\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
diff --git a/site_scons/version.py b/site_scons/version.py
index f2e3dfc..6715a35 100644
--- a/site_scons/version.py
+++ b/site_scons/version.py
@@ -1,52 +1,52 @@
# -*- 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 .
import subprocess
import base64
from zlib import compress
def git(*args):
"""Run a git command"""
try:
return bytes(subprocess.check_output(["git"] + list(args)))
except subprocess.CalledProcessError:
- return ""
+ return bytes()
def get_git_subst():
"""Get info about state of git repository"""
branch = git("rev-parse", "--abbrev-ref", "@")[:-1]
commit = git("rev-parse", branch)[:-1]
diff = git("diff", "@")
remotes = git('remote', '-v')
if remotes != "":
remotes_string = remotes[:-1].decode().replace('\n', '\\\\n')
else:
remotes_string = '""'
return {
'@commit@': commit.decode(),
'@branch@': branch.decode(),
'@diff@': base64.b64encode(compress(diff, 9)).decode(),
'@remotes@': remotes_string,
}