Skip to content
Merged
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
12 changes: 11 additions & 1 deletion .ciscripts/build-deploy-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ set -o pipefail
set -u
set -v

# Set the version for both vp and n3fit
gitroot=$(git rev-parse --show-toplevel)
gitversion=$(git describe --long --tags)
tag=$(git describe --abbrev=0 --tags)
gitversion=${gitversion/${tag}-/${tag}.}
githash=$(git rev-parse --short HEAD)
gitversion=${gitversion/-g${githash}/+g${githash}}
echo "build_version=\"${gitversion}\"" > ${gitroot}/n3fit/src/n3fit/version.py
echo "build_version=\"${gitversion}\"" > ${gitroot}/validphys2/src/validphys/version.py

#Set up netrc file for uploading/downloading
echo "$NETRC_FILE" | base64 --decode > ~/.netrc

Expand Down Expand Up @@ -41,4 +51,4 @@ if [ $? == 0 ]; then
else
echo "Conda package upload failed"
exit 1
fi
fi
10 changes: 10 additions & 0 deletions .ciscripts/build-deploy-osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ set -v
#Set up netrc file for uploading/downloading
echo "$NETRC_FILE" | base64 --decode > ~/.netrc

# Set the version for both vp and n3fit
gitroot=$(git rev-parse --show-toplevel)
gitversion=$(git describe --long --tags)
tag=$(git describe --abbrev=0 --tags)
gitversion=${gitversion/${tag}-/${tag}.}
githash=$(git rev-parse --short HEAD)
gitversion=${gitversion/-g${githash}/+g${githash}}
echo "build_version=\"${gitversion}\"" > ${gitroot}/n3fit/src/n3fit/version.py
echo "build_version=\"${gitversion}\"" > ${gitroot}/validphys2/src/validphys/version.py

conda build -q conda-recipe
if [ $? != 0 ]; then
echo failed to build
Expand Down
43 changes: 41 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ option(ENABLE_ASAN "Enable ASAN" OFF)
option(ENABLE_DEAD_STRIP "Enable use of flag `-dead_strip-dylibs`" OFF)
option(VP_DEV "validphys in developer mode" ON)
option(N3_DEV "n3fit in developer mode" ON)
option(BURN_TAG "burn down the git tag in vp and n3fit (only local non-dev installation)" ON)
set(PROFILE_PREFIX "" CACHE STRING "Where you store the 'data' folder. Default empty uses CMAKE_INSTALL_PREFIX/share/NNPDF.")

if (PROFILE_PREFIX)
Expand Down Expand Up @@ -147,16 +148,54 @@ add_subdirectory(nnpdfcpp)
# evolven3fit
add_subdirectory(n3fit/evolven3fit)

if((BURN_TAG) AND (NOT (VP_DEV) OR NOT (N3_DEV)))
# Find out where is the root of the git repository (if available) and finds the correct tag to burn down
# in the package. This just sets the variable, the actual burning is done down below by the validphys
# or n3fit installation and is found in the version.cmake file as it needs to be done post-installation
set(GIT_DIR "--git-dir=${PROJECT_SOURCE_DIR}/.git")
# get the current tag (ex: 3.4) and check at the same time whether git is available and the .git folder found
execute_process(COMMAND git ${GIT_DIR} describe --abbrev=0 --tags OUTPUT_VARIABLE GIT_TAG ERROR_VARIABLE GIT_ERROR)
if(GIT_ERROR STREQUAL "")
string(STRIP ${GIT_TAG} GIT_TAG)
# get the number of revisions since tag happened
execute_process(COMMAND git ${GIT_DIR} rev-list ${GIT_TAG}..HEAD --count OUTPUT_VARIABLE GIT_REVN)
string(STRIP ${GIT_REVN} GIT_REVN)
# get the shortname for the hash
execute_process(COMMAND git ${GIT_DIR} rev-parse --short HEAD OUTPUT_VARIABLE GIT_HASH)
string(STRIP ${GIT_HASH} GIT_HASH)
# find out whether the repository is in a dirty state
# (this returns ${GIT_TAG}-dev so we have to remove the tag)
execute_process(COMMAND git ${GIT_DIR} describe --abbrev=0 --tags --dirty=-dev OUTPUT_VARIABLE GIT_DIRTY)
string(STRIP ${GIT_DIRTY} GIT_DIRTY)
string(REPLACE "${GIT_TAG}" "" GIT_DIRTY ${GIT_DIRTY})
# now concatenate everything
# with the format ex: 3.4.1880+g00b1741c-dev
set(GIT_VERSION "build_version='${GIT_TAG}.${GIT_REVN}+g${GIT_HASH}${GIT_DIRTY}'")
# now set the variable at install time
install(CODE "set(GIT_VERSION \"${GIT_VERSION}\")")
else(GIT_ERROR STREQUAL "")
set(BURN_TAG OFF)
endif(GIT_ERROR STREQUAL "")
endif()

# install validphys2
if(VP_DEV)
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install -e ${PROJECT_SOURCE_DIR}/validphys2)")
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install -e ${PROJECT_SOURCE_DIR}/validphys2)")
else(VP_DEV)
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install --no-deps --ignore-installed ${PROJECT_SOURCE_DIR}/validphys2)")
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install --no-deps --ignore-installed ${PROJECT_SOURCE_DIR}/validphys2)")
if(BURN_TAG)
install(CODE "set(LIBRARY \"validphys\")")
install(SCRIPT ${PROJECT_SOURCE_DIR}/version.cmake)
endif(BURN_TAG)
endif(VP_DEV)

# install n3fit
if(N3_DEV)
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install -e ${PROJECT_SOURCE_DIR}/n3fit)")
else(N3_DEV)
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install --no-deps --ignore-installed ${PROJECT_SOURCE_DIR}/n3fit)")
if(BURN_TAG)
install(CODE "set(LIBRARY \"n3fit\")")
install(SCRIPT ${PROJECT_SOURCE_DIR}/version.cmake)
endif(BURN_TAG)
endif(N3_DEV)
4 changes: 2 additions & 2 deletions conda-recipe/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=${PREFIX} -DVP_DEV=OFF -DN3_DEV=OFF
cmake .. -DCMAKE_INSTALL_PREFIX=${PREFIX} -DVP_DEV=OFF -DN3_DEV=OFF -DBURN_TAG=OFF
make -j${CPU_COUNT}
make install
make install
2 changes: 1 addition & 1 deletion conda-recipe/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pytest --pyargs n3fit

mkdir bldtest
cd bldtest
cmake .. -DENABLE_TESTS=ON
cmake .. -DENABLE_TESTS=ON -DBURN_TAG=OFF
make catch_test -j
./libnnpdf/tests/catch_test

Expand Down
2 changes: 2 additions & 0 deletions n3fit/src/n3fit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from n3fit.version import build_version
__version__ = build_version
41 changes: 41 additions & 0 deletions n3fit/src/n3fit/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This file gets overwritten on deployemt, don't modify
def __give_git():
# Get the path to this file
from pathlib import Path

file_dir = Path(__file__).parent
from subprocess import run, CalledProcessError

try:
result = run(
["git", "describe", "--tags", "--long", "--dirty=-dev"],
capture_output=True,
text=True,
check=True,
cwd=file_dir,
).stdout.strip()
tag = run(
["git", "describe", "--abbrev=0", "--tags"],
capture_output=True,
text=True,
check=True,
cwd=file_dir,
).stdout.strip()
githash = run(
["git", "rev-parse", "--short", "HEAD"],
capture_output=True,
text=True,
check=True,
cwd=file_dir,
).stdout.strip()
version = result.replace(f"-g{githash}", f"+g{githash}").replace(
f"{tag}-", f"{tag}."
)
except CalledProcessError:
# In principle this function should not exist on an installed version
# but who knows. Also maybe git doesn't work on the machine or whatever
version = "unknown"
return version


build_version = __give_git()
4 changes: 3 additions & 1 deletion validphys2/src/validphys/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#We don't want to import stuff here that could slow down the import times
#We don't want to import stuff here that could slow down the import times
from validphys.version import build_version
__version__ = build_version
41 changes: 41 additions & 0 deletions validphys2/src/validphys/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This file gets overwritten on deployemt, don't modify
def __give_git():
# Get the path to this file
from pathlib import Path

file_dir = Path(__file__).parent
from subprocess import run, CalledProcessError

try:
result = run(
["git", "describe", "--tags", "--long", "--dirty=-dev"],
capture_output=True,
text=True,
check=True,
cwd=file_dir,
).stdout.strip()
tag = run(
["git", "describe", "--abbrev=0", "--tags"],
capture_output=True,
text=True,
check=True,
cwd=file_dir,
).stdout.strip()
githash = run(
["git", "rev-parse", "--short", "HEAD"],
capture_output=True,
text=True,
check=True,
cwd=file_dir,
).stdout.strip()
version = result.replace(f"-g{githash}", f"+g{githash}").replace(
f"{tag}-", f"{tag}."
)
except CalledProcessError:
# In principle this function should not exist on an installed version
# but who knows. Also maybe git doesn't work on the machine or whatever
version = "unknown"
return version


build_version = __give_git()
3 changes: 3 additions & 0 deletions version.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
execute_process(COMMAND python -c "import ${LIBRARY}.version ; print(${LIBRARY}.version.__file__)" OUTPUT_VARIABLE VERSION_PATH)
STRING(STRIP ${VERSION_PATH} VERSION_PATH)
file(WRITE ${VERSION_PATH} ${GIT_VERSION})