diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 5b69b416..748d2c2b 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -10,16 +10,11 @@ jobs: strategy: matrix: python-version: [3.5, 3.6, 3.7, 3.8, 3.9] - services: - mysql: - image: mysql:8.0 - ports: - - 3306:3306 - env: - MYSQL_DATABASE: mysqldb_test - MYSQL_ROOT_PASSWORD: secretsecret - options: --health-cmd "mysqladmin ping -h localhost" --health-interval 20s --health-timeout 10s --health-retries 10 steps: + - name: Start MySQL + run: | + sudo systemctl start mysql.service + mysql -uroot -proot -e "CREATE DATABASE mysqldb_test" - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 diff --git a/HISTORY.rst b/HISTORY.rst index 6ad6e148..16fcbd59 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,3 +1,14 @@ +====================== + What's new in 2.0.3 +====================== + +Release: 2021-01-01 + +* Add ``-std=c99`` option to cflags by default for ancient compilers that doesn't + accept C99 by default. +* You can customize cflags and ldflags by setting ``MYSQLCLIENT_CFLAGS`` and + ``MYSQLCLIENT_LDFLAGS``. It overrides ``mysql_config``. + ====================== What's new in 2.0.2 ====================== diff --git a/README.md b/README.md index 79af2573..f65329cf 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,20 @@ Then you can install mysqlclient via pip now: $ pip install mysqlclient ``` +### Customize build (POSIX) + +mysqlclient uses `mysql_config` or `mariadb_config` by default for finding +compiler/linker flags. + +You can use `MYSQLCLIENT_CFLAGS` and `MYSQLCLIENT_LDFLAGS` environment +variables to customize compiler/linker options. + +``` +$ export MYSQLCLIENT_CFLAGS=`pkg-config mysqlclient --cflags` +$ export MYSQLCLIENT_LDFLAGS=`pkg-config mysqlclient --libs` +$ pip install mysqlclient +``` + ### Documentation Documentation is hosted on [Read The Docs](https://mysqlclient.readthedocs.io/) diff --git a/metadata.cfg b/metadata.cfg index b0ee0db4..2a2e64fa 100644 --- a/metadata.cfg +++ b/metadata.cfg @@ -1,6 +1,6 @@ [metadata] -version: 2.0.2 -version_info: (2,0,2,'final',0) +version: 2.0.3 +version_info: (2,0,3,'final',0) description: Python interface to MySQL author: Inada Naoki author_email: songofacandy@gmail.com diff --git a/setup_posix.py b/setup_posix.py index 5602be84..e556f5c5 100644 --- a/setup_posix.py +++ b/setup_posix.py @@ -19,9 +19,9 @@ def dequote(s): def mysql_config(what): - from os import popen - - f = popen("{} --{}".format(_mysql_config_path, what)) + cmd = "{} --{}".format(_mysql_config_path, what) + print(cmd) + f = os.popen(cmd) data = f.read().strip().split() ret = f.close() if ret: @@ -29,6 +29,7 @@ def mysql_config(what): data = [] if ret / 256 > 1: raise OSError("{} not found".format(_mysql_config_path)) + print(data) return data @@ -62,26 +63,41 @@ def get_config(): static = True sys.argv.remove("--static") - libs = mysql_config("libs") + libs = os.environ.get("MYSQLCLIENT_LDFLAGS") + if libs: + libs = libs.strip().split() + else: + libs = mysql_config("libs") library_dirs = [dequote(i[2:]) for i in libs if i.startswith("-L")] libraries = [dequote(i[2:]) for i in libs if i.startswith("-l")] extra_link_args = [x for x in libs if not x.startswith(("-l", "-L"))] - removable_compile_args = ("-I", "-L", "-l") - extra_compile_args = [ - i.replace("%", "%%") - for i in mysql_config("cflags") - if i[:2] not in removable_compile_args - ] + cflags = os.environ.get("MYSQLCLIENT_CFLAGS") + if cflags: + use_mysqlconfig_cflags = False + cflags = cflags.strip().split() + else: + use_mysqlconfig_cflags = True + cflags = mysql_config("cflags") + + include_dirs = [] + extra_compile_args = ["-std=c99"] + + for a in cflags: + if a.startswith("-I"): + include_dirs.append(dequote(a[2:])) + elif a.startswith(("-L", "-l")): # This should be LIBS. + pass + else: + extra_compile_args.append(a.replace("%", "%%")) # Copy the arch flags for linking as well - for i in range(len(extra_compile_args)): - if extra_compile_args[i] == "-arch": + try: + i = extra_compile_args.index("-arch") + if "-arch" not in extra_link_args: extra_link_args += ["-arch", extra_compile_args[i + 1]] - - include_dirs = [ - dequote(i[2:]) for i in mysql_config("include") if i.startswith("-I") - ] + except ValueError: + pass if static: # properly handle mysql client libraries that are not called libmysqlclient @@ -109,11 +125,12 @@ def get_config(): if client in libraries: libraries.remove(client) else: - # mysql_config may have "-lmysqlclient -lz -lssl -lcrypto", but zlib and - # ssl is not used by _mysql. They are needed only for static build. - for L in ("crypto", "ssl", "z"): - if L in libraries: - libraries.remove(L) + if use_mysqlconfig_cflags: + # mysql_config may have "-lmysqlclient -lz -lssl -lcrypto", but zlib and + # ssl is not used by _mysql. They are needed only for static build. + for L in ("crypto", "ssl", "z"): + if L in libraries: + libraries.remove(L) name = "mysqlclient" metadata["name"] = name @@ -138,6 +155,10 @@ def get_config(): if static: ext_options["language"] = "c++" + print("ext_options:") + for k, v in ext_options.items(): + print(" {}: {}".format(k, v)) + return metadata, ext_options diff --git a/tests/actions.cnf b/tests/actions.cnf index 8918f031..d20296d6 100644 --- a/tests/actions.cnf +++ b/tests/actions.cnf @@ -7,5 +7,5 @@ host = 127.0.0.1 port = 3306 user = root database = mysqldb_test -password = secretsecret +password = root default-character-set = utf8mb4