Skip to content

Commit

Permalink
Fixes skupperproject#1258: Modified python install to use pip install…
Browse files Browse the repository at this point in the history
… via a pyproject.toml instead of calling setup.py which is deprecated.
  • Loading branch information
ganeshmurthy committed Oct 13, 2023
1 parent 3d81fb8 commit e7d3a26
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 94 deletions.
20 changes: 10 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,34 +152,34 @@ if(NOT DEFINED VERSION)
# Git succeeded, we will use the DEFAULT_VERSION as the QPID_DISPATCH_VERSION
set(QPID_DISPATCH_VERSION ${DEFAULT_VERSION})
else()
# The git command failed, set QPID_DISPATCH_VERSION to "UNKNOWN"
set(QPID_DISPATCH_VERSION "UNKNOWN")
# The git command failed, set QPID_DISPATCH_VERSION to "0.0.0"
set(QPID_DISPATCH_VERSION "0.0.0")
endif(GIT_RESULT EQUAL 0)
else(BRANCH_NAME STREQUAL "HEAD")
# If the BRANCH_NAME is not HEAD, get the commit sha of the latest commit and
# set that as the version.
# If the BRANCH_NAME is not HEAD (means you are on a branch, get the commit sha of the latest commit and
# set the version as 0.0.0+<latest-commit-sha>-branch name. This is PEP 440 compliant.
# For example, if you are on the main branch and the most recent commit is 68df4e1346b9238ef8f71b9ae0dcdd49eec73c9a,
# the router version will print as 68df4e1346b9238ef8f71b9ae0dcdd49eec73c9a(main)
# the router version will print as 0.0.0+68df4e1346b9238ef8f71b9ae0dcdd49eec73c9a-main
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
OUTPUT_VARIABLE COMMIT_SHA
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "COMMIT_SHA is ${COMMIT_SHA}")
set(QPID_DISPATCH_VERSION "${COMMIT_SHA}(${BRANCH_NAME})")
set(QPID_DISPATCH_VERSION "0.0.0+${COMMIT_SHA}-${BRANCH_NAME}")
endif(BRANCH_NAME STREQUAL "HEAD")
else(Git_FOUND)
# Git executable was not available, we will not be able to determine the version, just set it to "UNKNOWN"
set(QPID_DISPATCH_VERSION "UNKNOWN")
# Git executable was not available, we will not be able to determine the version, just set it to "0.0.0"
set(QPID_DISPATCH_VERSION "0.0.0")
endif(Git_FOUND)

else(NOT DEFINED VERSION)

# What if VERSION is defined but someone passed in an empty value for VERSION? Deal with that case here.
if (VERSION STREQUAL "")
set(QPID_DISPATCH_VERSION "UNKNOWN")
set(QPID_DISPATCH_VERSION "0.0.0")
else()
string(STRIP ${VERSION} VERSION)
if (VERSION STREQUAL "")
set(QPID_DISPATCH_VERSION "UNKNOWN")
set(QPID_DISPATCH_VERSION "0.0.0")
else()
set(QPID_DISPATCH_VERSION ${VERSION})
endif()
Expand Down
26 changes: 20 additions & 6 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,28 @@
# Private python modules, not in standard python site dir.
install(DIRECTORY skupper_router_internal DESTINATION ${QPID_DISPATCH_HOME}/python)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in
${CMAKE_CURRENT_BINARY_DIR}/setup.py)
# Copy the public python modules into a build/python/src folder.
# We do this because, pip install, by default, will look into a src folder
# and automatically figure out python packaging and installs the files
# in the appropriate location.

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/skupper_router_site.py.in
${CMAKE_CURRENT_BINARY_DIR}/skupper_router_site.py)
add_custom_target(NAME ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/python/skupper_router ${CMAKE_CURRENT_BINARY_DIR}/src/skupper_router
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/_skupper_router_site.py ${CMAKE_CURRENT_BINARY_DIR}/src/skupper_router)

# Install script for public python modules
install(CODE "execute_process(COMMAND ${Python_EXECUTABLE} setup.py -v install --single-version-externally-managed --record=/dev/null --prefix=${CMAKE_INSTALL_PREFIX} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
configure_file(${CMAKE_SOURCE_DIR}/python/skupper_router/_skupper_router_site.py.in
${CMAKE_CURRENT_BINARY_DIR}/_skupper_router_site.py)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pyproject.toml.in
${CMAKE_CURRENT_BINARY_DIR}/pyproject.toml)

# Use pip install to install the public python modules.
# --compile option compiles Python source files to bytecode
IF(DEFINED ENV{DESTDIR})
install(CODE "execute_process(COMMAND ${Python_EXECUTABLE} -m pip install ${CMAKE_CURRENT_BINARY_DIR} --verbose --compile --prefix=$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
else ()
install(CODE "execute_process(COMMAND ${Python_EXECUTABLE} -m pip install ${CMAKE_CURRENT_BINARY_DIR} --verbose --compile --prefix=${CMAKE_INSTALL_PREFIX} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
endif()

install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/skupper_router/management/skrouter.json
Expand Down
46 changes: 46 additions & 0 deletions python/pyproject.toml.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

[project]
name="skupper_router"
description = "Skupper Router tools and libraries"
version = '${QPID_DISPATCH_VERSION}'
authors = [
{ name = "Skupper Project", email = "[email protected]" }
]
requires-python = ">=3.9"

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[tool.skupper_router]
homepage = "https://skupper.io/"
repository = "https://github.com/skupperproject/skupper-router/"

[tool.setuptools]
# By default, include-package-data is true in pyproject.toml, so you do
# NOT have to specify this line.
include-package-data = true

[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools.package-data]
"*" = ["*.json"]
65 changes: 0 additions & 65 deletions python/setup.py.in

This file was deleted.

File renamed without changes.
4 changes: 2 additions & 2 deletions python/skupper_router_internal/management/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

from ctypes import c_void_p, py_object, c_long

import skupper_router_site
from skupper_router._skupper_router_site import SKIP_DELETE_HTTP_LISTENER
from skupper_router.management.entity import camelcase
from skupper_router.management.error import ManagementError, OK, CREATED, NO_CONTENT, STATUS_TEXT, \
BadRequestStatus, InternalServerErrorStatus, NotImplementedStatus, NotFoundStatus
Expand Down Expand Up @@ -424,7 +424,7 @@ def __str__(self):
return super(ListenerEntity, self).__str__().replace("Entity(", "ListenerEntity(")

def _delete(self):
if self.http and skupper_router_site.SKIP_DELETE_HTTP_LISTENER:
if self.http and SKIP_DELETE_HTTP_LISTENER:
raise BadRequestStatus("HTTP listeners cannot be deleted")
self._qd.qd_connection_manager_delete_listener(self._dispatch, self._implementations[0].key)

Expand Down
2 changes: 1 addition & 1 deletion python/skupper_router_internal/tools/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import argparse
import os

from skupper_router_site import VERSION
from skupper_router._skupper_router_site import VERSION
from proton import SSLDomain, Url


Expand Down
2 changes: 1 addition & 1 deletion run.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ run.py --sh # Print a shell script to set the run


extra_paths = [
"${CMAKE_BINARY_DIR}/python/src",
"${CMAKE_SOURCE_DIR}/python",
"${CMAKE_BINARY_DIR}/python",
"${CMAKE_SOURCE_DIR}/tests"
]

Expand Down
6 changes: 3 additions & 3 deletions tests/python-checker.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

set -exo pipefail
echo ----Starting flake8 checks----
flake8 --verbose --count --show-source ${CMAKE_SOURCE_DIR}/python/skupper_router ${CMAKE_SOURCE_DIR}/python/skupper_router_internal ${CMAKE_SOURCE_DIR}/docs ${CMAKE_SOURCE_DIR}/tests ${CMAKE_SOURCE_DIR}/tools ${CMAKE_SOURCE_DIR}/scripts ${CMAKE_BINARY_DIR}/python/skupper_router_site.py ${CMAKE_SOURCE_DIR}/tools/skstat ${CMAKE_SOURCE_DIR}/tools/skmanage
flake8 --verbose --count --show-source ${CMAKE_SOURCE_DIR}/python/skupper_router ${CMAKE_SOURCE_DIR}/python/skupper_router_internal ${CMAKE_SOURCE_DIR}/docs ${CMAKE_SOURCE_DIR}/tests ${CMAKE_SOURCE_DIR}/tools ${CMAKE_SOURCE_DIR}/scripts ${CMAKE_BINARY_DIR}/python/_skupper_router_site.py ${CMAKE_SOURCE_DIR}/tools/skstat ${CMAKE_SOURCE_DIR}/tools/skmanage
echo ----Starting pylint checks----
pylint --jobs 4 --rcfile ${CMAKE_BINARY_DIR}/tests/pylintrc --ignore friendship_server.py,friendship_pb2.py,friendship_pb2_grpc.py ${CMAKE_SOURCE_DIR}/python/skupper_router ${CMAKE_SOURCE_DIR}/python/skupper_router_internal ${CMAKE_SOURCE_DIR}/docs ${CMAKE_SOURCE_DIR}/tests ${CMAKE_SOURCE_DIR}/tools ${CMAKE_SOURCE_DIR}/scripts ${CMAKE_BINARY_DIR}/python/skupper_router_site.py ${CMAKE_SOURCE_DIR}/tools/skstat ${CMAKE_SOURCE_DIR}/tools/skmanage
pylint --jobs 4 --rcfile ${CMAKE_BINARY_DIR}/tests/pylintrc --ignore friendship_server.py,friendship_pb2.py,friendship_pb2_grpc.py ${CMAKE_SOURCE_DIR}/python/skupper_router ${CMAKE_SOURCE_DIR}/python/skupper_router_internal ${CMAKE_SOURCE_DIR}/docs ${CMAKE_SOURCE_DIR}/tests ${CMAKE_SOURCE_DIR}/tools ${CMAKE_SOURCE_DIR}/scripts ${CMAKE_BINARY_DIR}/python/_skupper_router_site.py ${CMAKE_SOURCE_DIR}/tools/skstat ${CMAKE_SOURCE_DIR}/tools/skmanage
echo ----Starting mypy checks----
#mypy --verbose --config-file ${CMAKE_BINARY_DIR}/tests/mypy.ini ${CMAKE_SOURCE_DIR}/python/skupper_router ${CMAKE_SOURCE_DIR}/python/skupper_router_internal ${CMAKE_SOURCE_DIR}/docs ${CMAKE_SOURCE_DIR}/tests ${CMAKE_SOURCE_DIR}/tools ${CMAKE_SOURCE_DIR}/scripts ${CMAKE_BINARY_DIR}/python/skupper_router_site.py
#mypy --verbose --config-file ${CMAKE_BINARY_DIR}/tests/mypy.ini ${CMAKE_SOURCE_DIR}/python/skupper_router ${CMAKE_SOURCE_DIR}/python/skupper_router_internal ${CMAKE_SOURCE_DIR}/docs ${CMAKE_SOURCE_DIR}/tests ${CMAKE_SOURCE_DIR}/tools ${CMAKE_SOURCE_DIR}/scripts ${CMAKE_BINARY_DIR}/python/_skupper_router_site.py

4 changes: 2 additions & 2 deletions tests/system_tests_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from urllib.request import urlopen, build_opener, HTTPSHandler
from urllib.error import HTTPError, URLError

import skupper_router_site
from skupper_router._skupper_router_site import SKIP_DELETE_HTTP_LISTENER
from system_test import Process, QdManager, retry
from system_test import TestCase, Qdrouterd, main_module, DIR
from system_test import unittest, AMQP_LISTENER_TYPE, ALLOCATOR_TYPE
Expand All @@ -46,7 +46,7 @@ def ssl_file(name):
def setUpClass(cls):
super(RouterTestHttp, cls).setUpClass()
# DISPATCH-1513, DISPATCH-2299: Http listener delete was broken in LWS v4 until v4.2.0
cls.skip_delete_http_listener_test = skupper_router_site.SKIP_DELETE_HTTP_LISTENER
cls.skip_delete_http_listener_test = SKIP_DELETE_HTTP_LISTENER

@classmethod
def get(cls, url, use_ca=True):
Expand Down
4 changes: 2 additions & 2 deletions tools/skmanage
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import json
import re
from collections.abc import Mapping, Sequence

import skupper_router_site
skupper_router_site.populate_pythonpath()
from skupper_router._skupper_router_site import populate_pythonpath
populate_pythonpath()

from skupper_router.management.client import Node
from skupper_router_internal.tools.command import (UsageError, _skmanage_parser, check_args,
Expand Down
4 changes: 2 additions & 2 deletions tools/skstat
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import sys
from datetime import datetime
from time import ctime, strftime, gmtime

import skupper_router_site
skupper_router_site.populate_pythonpath()
from skupper_router._skupper_router_site import populate_pythonpath
populate_pythonpath()

from skupper_router.management.client import Node
from skupper_router_internal.management.qdrouter import QdSchema
Expand Down

0 comments on commit e7d3a26

Please sign in to comment.