From 54696194be70bc662a9e6803cacc95d970e13768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Warnier?= Date: Mon, 27 Apr 2026 18:20:43 +0200 Subject: [PATCH 1/2] Depend on PyMySQL by default (rather than MySQLdb) #152 --- docker/Dockerfile | 21 +++++---------------- docker/Makefile | 3 ++- docs/INSTALLATION.md | 12 ++++++------ docs/modules/database.md | 6 +++--- opensipscli/defaults.py | 4 ++-- packaging/debian/control | 4 ++-- packaging/redhat_fedora/opensips-cli.spec | 6 +++++- pyproject.toml | 2 +- setup.py | 4 ++-- test/alltests.py | 18 +++++++++--------- test/test-database.sh | 2 +- 11 files changed, 38 insertions(+), 44 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 76e51f1..d353468 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,27 +1,16 @@ FROM python:slim-trixie LABEL maintainer="Razvan Crainea " -USER root - # Set Environment Variables ENV DEBIAN_FRONTEND noninteractive -#install basic components -RUN apt-get -y update -qq && \ - apt-get -y install git default-libmysqlclient-dev gcc - -#add keyserver, repository -RUN git clone https://github.com/OpenSIPS/opensips-cli.git /usr/src/opensips-cli && \ - cd /usr/src/opensips-cli && \ - python3 -m pip install . && \ +COPY . /usr/src/opensips-cli +RUN cd /usr/src/opensips-cli && \ + python3 -m pip install --no-cache-dir . && \ cd / && rm -rf /usr/src/opensips-cli -RUN apt-get purge -y git gcc && \ - apt-get autoremove -y && \ - apt-get clean - -ADD "run.sh" "/run.sh" +ADD "docker/run.sh" "/run.sh" ENV PYTHONPATH /usr/lib/python3/dist-packages -ENTRYPOINT ["/run.sh", "-o", "communication_type=http"] +ENTRYPOINT [ "/run.sh", "-o", "communication_type=http" ] diff --git a/docker/Makefile b/docker/Makefile index bb406f0..8f562c2 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -5,7 +5,8 @@ all: build start .PHONY: build start build: - docker build \ + cd .. ; \ + docker build -f docker/Dockerfile \ --tag="opensips/opensips-cli:$(OPENSIPS_DOCKER_TAG)" \ . diff --git a/docs/INSTALLATION.md b/docs/INSTALLATION.md index 742df83..dcd5c23 100644 --- a/docs/INSTALLATION.md +++ b/docs/INSTALLATION.md @@ -56,12 +56,12 @@ will vary on every supported operating system. ``` # required OS packages -sudo apt install python3 python3-pip python3-dev gcc default-libmysqlclient-dev \ - python3-mysqldb python3-sqlalchemy python3-sqlalchemy-utils \ +sudo apt install python3 python3-pip python3-dev \ + python3-pymysql python3-sqlalchemy python3-sqlalchemy-utils \ python3-openssl # alternatively, you can build the requirements from source -sudo pip3 install mysqlclient sqlalchemy sqlalchemy-utils pyOpenSSL +sudo pip3 install pymysql sqlalchemy sqlalchemy-utils pyOpenSSL ``` #### Red Hat / CentOS @@ -72,11 +72,11 @@ sudo yum install python36 python36-pip python36-devel gcc mysql-devel \ python36-mysql python36-sqlalchemy python36-pyOpenSSL # required CentOS 8 packages -sudo yum install python3 python3-pip python3-devel gcc mysql-devel \ - python3-mysqlclient python3-sqlalchemy python3-pyOpenSSL +sudo yum install python3 python3-pip python3-devel \ + python3-pymysql python3-sqlalchemy python3-pyOpenSSL # alternatively, you can build the requirements from source -sudo pip3 install mysqlclient sqlalchemy sqlalchemy-utils pyOpenSSL +sudo pip3 install pymysql sqlalchemy sqlalchemy-utils pyOpenSSL ``` ### Download, Build & Install diff --git a/docs/modules/database.md b/docs/modules/database.md index fe7f097..9cbe79a 100644 --- a/docs/modules/database.md +++ b/docs/modules/database.md @@ -41,10 +41,10 @@ are using the OpenSIPS source tree. Default: `/usr/share/opensips` (administrator) access level which will be used to create/drop databases, as well as to create or ensure access for the non-privileged DB access user provided via `database_url`. The URL combines schema, username, password, host -and port. Default: `mysql://root@localhost`. +and port. Default: `mysql+pymysql://root@localhost`. * `database_url` (optional) - the connection string to the database. A good practice would be to use a non-administrator access user for this URL. Default: -`mysql://opensips:opensipsrw@localhost`. +`mysql+pymysql://opensips:opensipsrw@localhost`. * `database_name` (optional) - the name of the database. Modules may be separately added to this database if you choose not to install all of them. Default: `opensips`. * `database_modules` (optional) - accepts the `ALL` keyword that indicates all the @@ -68,7 +68,7 @@ Consider the following configuration file: database_modules: ALL #database_admin_url: postgresql://root@localhost -database_admin_url: mysql://root@localhost +database_admin_url: mysql+pymysql://root@localhost ``` The following command will create the `opensips` database and all possible diff --git a/opensipscli/defaults.py b/opensipscli/defaults.py index e29417b..45ba967 100644 --- a/opensipscli/defaults.py +++ b/opensipscli/defaults.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 ## ## This file is part of OpenSIPS CLI ## (see https://github.com/OpenSIPS/opensips-cli). @@ -71,7 +71,7 @@ "datagram_buffer_size": "65535", # database module - "database_url": "mysql://opensips:opensipsrw@localhost", + "database_url": "mysql+pymysql://opensips:opensipsrw@localhost", "database_name": "opensips", "database_schema_path": "/usr/share/opensips", diff --git a/packaging/debian/control b/packaging/debian/control index 2c9136d..7ad2352 100644 --- a/packaging/debian/control +++ b/packaging/debian/control @@ -2,14 +2,14 @@ Source: opensips-cli Section: python Priority: optional Maintainer: Razvan Crainea -Build-Depends: debhelper (>= 9), dh-python, python3-setuptools, python3-dev, default-libmysqlclient-dev | libmysqlclient-dev, python3-sqlalchemy, python3-opensips +Build-Depends: debhelper (>= 9), dh-python, python3-setuptools, python3-dev, python3-sqlalchemy, python3-opensips Standards-Version: 3.9.8 Homepage: https://github.com/OpenSIPS/opensips-cli Package: opensips-cli Architecture: all Multi-Arch: foreign -Depends: python3, ${misc:Depends}, ${python3:Depends}, python3-sqlalchemy, python3-sqlalchemy-utils, python3-openssl, python3-mysqldb, python3-pymysql, python3-opensips +Depends: python3, ${misc:Depends}, ${python3:Depends}, python3-sqlalchemy, python3-sqlalchemy-utils, python3-openssl, python3-pymysql, python3-opensips Description: Interactive command-line tool for OpenSIPS 3.0+ This package contains the OpenSIPS CLI tool, an interactive command line tool that can be used to control and monitor OpenSIPS 3.0+ servers. diff --git a/packaging/redhat_fedora/opensips-cli.spec b/packaging/redhat_fedora/opensips-cli.spec index 7a73791..4873fec 100644 --- a/packaging/redhat_fedora/opensips-cli.spec +++ b/packaging/redhat_fedora/opensips-cli.spec @@ -12,7 +12,9 @@ BuildArch: noarch BuildRequires: python3-devel BuildRequires: python3-setuptools BuildRequires: python3-rpm-macros +%if 0%{?rhel} == 7 BuildRequires: mysql-devel +%endif BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) AutoReqProv: no @@ -24,7 +26,7 @@ Requires: python36-mysql Requires: python36-pyOpenSSL %else Requires: python3-sqlalchemy -Requires: python3-mysqlclient +Requires: python3-pymysql Requires: python3-pyOpenSSL %endif Requires: python3-opensips @@ -69,6 +71,8 @@ rm -rf $RPM_BUILD_ROOT %license LICENSE %changelog +* Mon Apr 27 2026 Jérôme Warnier - 0.1-3 +- Use PyMySQL rather than MySQLdb on recent distros. * Thu Aug 27 2020 Liviu Chircu - 0.1-2 - Update package summary. * Fri Jan 3 2020 Nick Altmann - 0.1-1 diff --git a/pyproject.toml b/pyproject.toml index 444bde1..5426248 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ maintainers = [ ] dependencies = [ "opensips", - "mysqlclient<1.4.0rc1", + "pymysql", "sqlalchemy>=1.3.3,<2", "sqlalchemy-utils", ] diff --git a/setup.py b/setup.py index 9645094..eae6549 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 ## ## This file is part of OpenSIPS CLI ## (see https://github.com/OpenSIPS/opensips-cli). @@ -46,7 +46,7 @@ packages=find_packages(include=("opensipscli", "opensipscli.*")), install_requires=[ "opensips", - "mysqlclient<1.4.0rc1", + "pymysql", "sqlalchemy>=1.3.3,<2", "sqlalchemy-utils", ], diff --git a/test/alltests.py b/test/alltests.py index 25bcf1e..8a88dcc 100644 --- a/test/alltests.py +++ b/test/alltests.py @@ -26,17 +26,17 @@ def testMakeURL(self): assert repr(u) == 'x://user:***@host:12/db' assert str(u) == 'x://user:pass@host:12/db' - u = make_url('mysql://opensips:opensipsrw@localhost/opensips') - assert repr(u) == 'mysql://opensips:***@localhost/opensips' - assert str(u) == 'mysql://opensips:opensipsrw@localhost/opensips' + u = make_url('mysql+pymysql://opensips:opensipsrw@localhost/opensips') + assert repr(u) == 'mysql+pymysql://opensips:***@localhost/opensips' + assert str(u) == 'mysql+pymysql://opensips:opensipsrw@localhost/opensips' - u = make_url('mysql://opensips:opensipsrw@localhost') - assert repr(u) == 'mysql://opensips:***@localhost' - assert str(u) == 'mysql://opensips:opensipsrw@localhost' + u = make_url('mysql+pymysql://opensips:opensipsrw@localhost') + assert repr(u) == 'mysql+pymysql://opensips:***@localhost' + assert str(u) == 'mysql+pymysql://opensips:opensipsrw@localhost' - u = make_url('mysql://root@localhost') - assert repr(u) == 'mysql://root@localhost' - assert str(u) == 'mysql://root@localhost' + u = make_url('mysql+pymysql://root@localhost') + assert repr(u) == 'mysql+pymysql://root@localhost' + assert str(u) == 'mysql+pymysql://root@localhost' if __name__ == "__main__": diff --git a/test/test-database.sh b/test/test-database.sh index 596c2a2..9ba119d 100644 --- a/test/test-database.sh +++ b/test/test-database.sh @@ -20,7 +20,7 @@ CLI_CFG=/tmp/.__cli.cfg DB_NAME=_opensips_cli_test -MYSQL_URL=mysql://opensips:opensipsrw@localhost +MYSQL_URL=mysql+pymysql://opensips:opensipsrw@localhost PGSQL_URL=postgresql://opensips:opensipsrw@localhost TESTS=( From ab4a3c20d3c5297a03ba2fd2560c0cadf25f8585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Warnier?= Date: Mon, 27 Apr 2026 18:36:11 +0200 Subject: [PATCH 2/2] Update docker.md doc accordingly --- docker/docker.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/docker.md b/docker/docker.md index f689daf..e35837b 100644 --- a/docker/docker.md +++ b/docker/docker.md @@ -9,8 +9,8 @@ You can build the docker image by running: make build ``` -This command will build a docker image with OpenSIPS CLI master version taken from -the git repository +This command will build a docker image with OpenSIPS CLI code taken from +the parent directory. ## Parameters