Skip to content

Commit

Permalink
python: Remove code referring to CMakeLists.txt version
Browse files Browse the repository at this point in the history
Python build was reading and parsing CMakeLists.txt from the parent dir
to get the project name and version. Although this reduces one point
that can fall out of sync during a release, it caused python builds to
break when built/installed from pip.

This commit fixes this issue by hard coding the version in python/setup.py
and then extends the release tooling to also update this file.

Related-to: #160
Signed-off-by: Marco Nilsson <[email protected]>
Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha committed Feb 13, 2024
1 parent a0f8968 commit 42399bb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
14 changes: 3 additions & 11 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,12 @@
import shutil
import subprocess

current_dir = os.environ.get("PWD")
project_name = "libosdp"
project_version = "2.4.0"
current_dir = os.path.dirname(os.path.realpath(__file__))
build_dir = os.path.abspath(os.path.join(current_dir, "build"))
root_dir = os.path.abspath(os.path.join(current_dir, ".."))

def read_version():
with open(os.path.join(root_dir, "CMakeLists.txt")) as f:
for line in f.readlines():
m = re.match(r"^project\((.+) VERSION (\d+\.\d+\.\d+)\)$", line)
if (m):
return m.groups()
raise RuntimeError("Failed to parse package name and version")

project_name, project_version = read_version()

def map_prefix(src_list, path, check_files=False):
paths = [ os.path.join(path, src) for src in src_list ]
for path in paths:
Expand Down
31 changes: 24 additions & 7 deletions scripts/make-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ usage() {
---
}

function setup_py_inc_version() {
dir=$1
inc=$2
perl -pi -se '
if (/^project_version = "(\d+)\.(\d+)\.(\d+)"$/) {
$maj=$1; $min=$2; $pat=$3;
if ($major) { $maj+=1; $min=0; $pat=0; }
if ($minor) { $min+=1; $pat=0; }
$pat+=1 if $patch;
$_="project_version = \"$maj.$min.$pat\"\n"
}' -- -$inc $dir/setup.py
}

function cmake_inc_version() {
dir=$1
inc=$2
Expand All @@ -22,8 +35,8 @@ function cmake_inc_version() {
if ($major) { $maj+=1; $min=0; $pat=0; }
if ($minor) { $min+=1; $pat=0; }
$pat+=1 if $patch;
$_="project($1 VERSION $maj.$min.$pat)\n"
}' -- -$inc $dir/CmakeLists.txt
$_="project($1 VERSION $maj.$min.$pat)\n"
}' -- -$inc $dir/CMakeLists.txt
}

function caro_inc_version() {
Expand All @@ -35,7 +48,7 @@ function caro_inc_version() {
if ($major) { $maj+=1; $min=0; $pat=0; }
if ($minor) { $min+=1; $pat=0; }
$pat+=1 if $patch;
$_="version = \"$maj.$min.$pat\"\n"
$_="version = \"$maj.$min.$pat\"\n"
}' -- -$inc $dir/Cargo.toml
}

Expand Down Expand Up @@ -80,6 +93,7 @@ function generate_change_log() {

function prepare_libosdp_release() {
cmake_inc_version "." $1
setup_py_inc_version "python" $1
generate_change_log > /tmp/rel.txt
printf '%s\n\n\n%s\n' "$(cat /tmp/rel.txt)" "$(cat CHANGELOG)" > CHANGELOG
}
Expand All @@ -90,11 +104,14 @@ function do_libosdp_release() {
exit 0
fi
git diff --cached --name-status | while read status file; do
if [[ "$file" != "CHANGELOG" ]] && [[ "$file" != "CMakeLists.txt" ]]; then
if [[ "$file" != "CHANGELOG" ]] && \
[[ "$file" != "CMakeLists.txt" ]] && \
[[ "$file" != "python/setup.py" ]]
then
echo "ERROR:"
echo " Only CHANGELOG and CMakeLists.txt must be modified to make a"
echo " release commit. To prepare a new release, run this script on a"
echo " clean git tree."
echo " Only CHANGELOG CMakeLists.txt python/setup.py must be modified"
echo " to make a release commit. To prepare a new release, run this"
echo " script on a clean git tree."
exit 1
fi
done
Expand Down

0 comments on commit 42399bb

Please sign in to comment.