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
17 changes: 17 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ jobs:
actions: read

steps:
- name: Check the tag against the version in pyproject.toml
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.ref_name }}
run: |
version=$(gh api -H "Accept: application/vnd.github.raw+json" \
"repos/${GITHUB_REPOSITORY}/contents/pyproject.toml?ref=${GITHUB_SHA}" \
| sed -n 's/^version = "\(.*\)"$/\1/p' | head -n1)
if [ -z "$version" ]; then
echo "::error::Could not read the version from pyproject.toml at ${GITHUB_SHA}."
exit 1
fi
if [ "v$version" != "$TAG" ]; then
echo "::error::The tag $TAG does not match the version $version in pyproject.toml. Bump the version before tagging."
exit 1
fi

- name: Find main-branch build runs for this commit
id: find_runs
env:
Expand Down
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
cmake_minimum_required(VERSION 3.15)

project(monero VERSION 0.9.10 LANGUAGES CXX)
# The version is declared only in pyproject.toml, which also gives it to the wheel
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/pyproject.toml" MONERO_PYTHON_PYPROJECT)
string(REGEX MATCH "(^|\n)version = \"([0-9]+\\.[0-9]+\\.[0-9]+)\"" MONERO_PYTHON_VERSION_MATCH "${MONERO_PYTHON_PYPROJECT}")
if(NOT MONERO_PYTHON_VERSION_MATCH)
message(FATAL_ERROR "Could not read the version from pyproject.toml")
endif()
set(MONERO_PYTHON_VERSION "${CMAKE_MATCH_2}")
# configure again when the version changes
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/pyproject.toml")

project(monero VERSION ${MONERO_PYTHON_VERSION} LANGUAGES CXX)
message(STATUS "monero-python version ${PROJECT_VERSION}")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down Expand Up @@ -274,6 +285,10 @@ set(LIBRARY_SRC_FILES
src/cpp/py_monero.cpp
)

# only this file reports the version, so a new version does not rebuild the others
set_source_files_properties(src/cpp/utils/py_monero_utils.cpp PROPERTIES
COMPILE_DEFINITIONS "MONERO_PYTHON_VERSION=\"${PROJECT_VERSION}\"")

pybind11_add_module(monero ${LIBRARY_SRC_FILES})

if (WIN32)
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion debian/jammy/control → debian/DEBIAN/control
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Package: python3-monero
Architecture: all
Description: Python bindings for monero-cpp
This package provides Python 3 bindings for the monero-cpp library using pybind11.
Version: 0.9.10
Version: @VERSION@
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions debian/bookworm/changelog

This file was deleted.

14 changes: 0 additions & 14 deletions debian/bookworm/control

This file was deleted.

3 changes: 0 additions & 3 deletions debian/jammy/changelog

This file was deleted.

1 change: 0 additions & 1 deletion debian/jammy/compat

This file was deleted.

6 changes: 0 additions & 6 deletions debian/jammy/copyright

This file was deleted.

1 change: 0 additions & 1 deletion debian/jammy/format

This file was deleted.

4 changes: 0 additions & 4 deletions debian/jammy/rules

This file was deleted.

1 change: 0 additions & 1 deletion debian/noble/compat

This file was deleted.

14 changes: 0 additions & 14 deletions debian/noble/control

This file was deleted.

6 changes: 0 additions & 6 deletions debian/noble/copyright

This file was deleted.

1 change: 0 additions & 1 deletion debian/noble/format

This file was deleted.

4 changes: 0 additions & 4 deletions debian/noble/rules

This file was deleted.

4 changes: 0 additions & 4 deletions debian/trixie/changelog

This file was deleted.

1 change: 0 additions & 1 deletion debian/trixie/compat

This file was deleted.

14 changes: 0 additions & 14 deletions debian/trixie/control

This file was deleted.

6 changes: 0 additions & 6 deletions debian/trixie/copyright

This file was deleted.

1 change: 0 additions & 1 deletion debian/trixie/format

This file was deleted.

4 changes: 0 additions & 4 deletions debian/trixie/rules

This file was deleted.

15 changes: 12 additions & 3 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
set -e

DISTRO_CODENAME=$(grep VERSION_CODENAME /etc/os-release | cut -d'=' -f2)
DEFAULT_VERSION="0.9.10"

# the version is declared only in pyproject.toml
VERSION=$(sed -n 's/^version = "\(.*\)"$/\1/p' pyproject.toml | head -n 1)
if [ -z "$VERSION" ]; then
echo "ERROR: could not read the version from pyproject.toml" >&2
exit 1
fi

if [ -z "$DISTRO_CODENAME" ]; then
DISTRO_CODENAME=$(lsb_release -c -s 2>/dev/null || echo "unknown")
Expand All @@ -17,7 +23,7 @@ elif [[ "$ARCH" == armv7* || "$ARCH" == "armhf" ]]; then
ARCH="armhf"
fi

PACKAGE_NAME=${PACKAGE_NAME:-python3-monero_${DEFAULT_VERSION}-1${DISTRO_CODENAME}1_${ARCH}}
PACKAGE_NAME=${PACKAGE_NAME:-python3-monero_${VERSION}-1${DISTRO_CODENAME}1_${ARCH}}

echo "Building package: ${PACKAGE_NAME}"
echo "Distro codename: ${DISTRO_CODENAME}"
Expand Down Expand Up @@ -77,13 +83,16 @@ fi
cp -R src/python build/${PACKAGE_NAME}/usr/lib/python3/dist-packages/monero
rm -rf build/${PACKAGE_NAME}/usr/lib/python3/dist-packages/pybind11*
rm -rf build/${PACKAGE_NAME}/usr/lib/python3/dist-packages/bin
cp -R "debian/${DISTRO_CODENAME}" "build/${PACKAGE_NAME}/DEBIAN"
cp -R debian/DEBIAN "build/${PACKAGE_NAME}/DEBIAN"

CONTROL_FILE="build/${PACKAGE_NAME}/DEBIAN/control"
if [ -f "$CONTROL_FILE" ]; then
echo "Patching control file architecture to: ${ARCH}"
sed -i "s/^Architecture: .*/Architecture: ${ARCH}/" "$CONTROL_FILE"

echo "Patching control file version to: ${VERSION}"
sed -i "s/^Version: .*/Version: ${VERSION}/" "$CONTROL_FILE"

echo "Computing runtime library dependencies with dpkg-shlibdeps"
SO_FILES=$(find "build/${PACKAGE_NAME}/usr/lib/python3/dist-packages" -maxdepth 1 -name "*.so")
if [ -z "$SO_FILES" ]; then
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[project]
name = "monero"
# the only place where the version is declared: CMakeLists.txt, docker/build.sh and
# the release workflow read it from here
version = "0.9.10"
description = "A Python library for using Monero"
authors = [
Expand Down
18 changes: 0 additions & 18 deletions setup.py

This file was deleted.

7 changes: 7 additions & 0 deletions src/cpp/utils/py_monero_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "py_monero_utils.h"

#ifndef MONERO_PYTHON_VERSION
#error "MONERO_PYTHON_VERSION is defined by CMakeLists.txt from the version in pyproject.toml"
#endif

std::string PyMoneroUtils::get_version() {
return std::string(MONERO_PYTHON_VERSION);
}

void PyMoneroUtils::validate_payment_id_long(const std::string& payment_id_str) {
crypto::hash payment_id;
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/utils/py_monero_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class PyMoneroUtils {
public:

PyMoneroUtils() {};
static std::string get_version() { return std::string("0.9.10"); };
static std::string get_version();
static std::string json_to_binary(const std::string &json);
static std::string dict_to_binary(const py::dict &dictionary);
static py::dict binary_to_dict(const std::string& bin);
Expand Down
8 changes: 7 additions & 1 deletion tests/test_monero_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import subprocess
import sys
import gc
import re

if sys.platform != "win32":
import resource

from typing import Any
from pathlib import Path
from configparser import ConfigParser
from monero import (
MoneroNetworkType, MoneroIntegratedAddress, MoneroUtils, MoneroTxConfig,
Expand Down Expand Up @@ -604,11 +606,15 @@ def test_parse_payment_uri_unknown_parameter(self, config: TestMoneroUtils.Confi
parsed: MoneroTxConfig = MoneroUtils.parse_payment_uri(f"monero:{address}?foo=bar")
assert parsed.destinations[0].address == address

# Can get version
# Can get version, which is the one declared in pyproject.toml
def test_get_version(self) -> None:
version: str = MoneroUtils.get_version()
logger.debug(f"Testing monero-python version: {version}")
assert version != "", "Version is empty"
pyproject: str = (Path(__file__).resolve().parent.parent / "pyproject.toml").read_text(encoding="utf-8")
declared = re.search(r'^version = "(\d+\.\d+\.\d+)"$', pyproject, re.MULTILINE)
assert declared is not None, "Version not found in pyproject.toml"
assert version == declared.group(1)

# Can get ring size
def test_get_ring_size(self) -> None:
Expand Down
Loading