From 947c024c8069fff18b1d9bc0f6fd369aee8cfa45 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 24 Jun 2026 12:50:41 +0200 Subject: [PATCH 1/2] Modernize setup.py and drop legacy Python 2 --- .github/workflows/ci.yml | 40 ++++++++++++++++++++++++++++++++++++++++ setup.py | 31 ++++++++++--------------------- 2 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..20ecec04 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,40 @@ +name: ci +on: + push: + pull_request: + workflow_dispatch: +jobs: + ci: + strategy: + fail-fast: false # https://github.com/actions/runner-images#available-images + matrix: # https://www.lua.org/versions.html + os: [macos-26, macos-26-intel, ubuntu-26.04, ubuntu-26.04-arm] + runs-on: ${{ matrix.os }} + steps: + - run: echo "${{ runner.os }} on ${{ runner.arch }}" + - if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt-get install -y luarocks + - if: runner.os == 'macOS' + run: brew install luarocks + - uses: actions/checkout@v7 + - uses: actions/setup-python@v6 + with: + python-version: 3.x + pip-install: --editable . + # Dependencies installed. Start testing. + - shell: python # Sanity check + run: | + import lua + lg = lua.globals() + print(f"{lg = }") + print(f"{lg.string = }") + print(f"{lg.string.lower = }") + print(f"{lg.string.lower('Hello world!') = }") + assert lg.string.lower('Hello world!') != 'Hello world!' + assert lg.string.lower('Hello world!') == 'hello world!' + - run: python -m doctest tests/test_lua.py || true + - run: pip install pytest + - run: pytest || true + - run: pytest --doctest-modules || true diff --git a/setup.py b/setup.py index 93d6cf0f..5ee3013a 100755 --- a/setup.py +++ b/setup.py @@ -1,28 +1,21 @@ -#!/usr/bin/python +#!/usr/bin/env python -import sys import os +import sys +from distutils.sysconfig import get_python_lib +from subprocess import getstatusoutput +from sysconfig import get_config_var, get_python_version -if sys.version > '3': - PY3 = True -else: - PY3 = False - -if PY3: - import subprocess as commands -else: - import commands -from distutils.core import setup, Extension -from distutils.sysconfig import get_config_var, get_python_lib, get_python_version +from setuptools import Extension, setup if os.path.isfile("MANIFEST"): os.unlink("MANIFEST") -lua_versions = ["5.5", "5.4", "5.3", "5.2", "5.1"] +lua_versions = ("5.5", "5.4", "5.3", "5.2", "5.1") LUAVERSION = None for version in lua_versions: - presult, poutput = commands.getstatusoutput("pkg-config --exists lua" + str(version)) + presult, poutput = getstatusoutput("pkg-config --exists lua" + str(version)) if presult == 0: LUAVERSION = version break @@ -43,7 +36,7 @@ def pkgconfig(*packages): combined_pcoutput = '' for package in packages: - (pcstatus, pcoutput) = commands.getstatusoutput( + (pcstatus, pcoutput) = getstatusoutput( "pkg-config --libs --cflags %s" % package) if pcstatus == 0: combined_pcoutput += ' ' + pcoutput @@ -59,11 +52,7 @@ def pkgconfig(*packages): else: # throw others to extra_link_args kwargs.setdefault('extra_link_args', []).append(token) - if PY3: - items = kwargs.items() - else: - items = kwargs.iteritems() - for k, v in items: # remove duplicated + for k, v in kwargs.items(): # remove duplicated kwargs[k] = list(set(v)) return kwargs From b4a0d3707e75af45a2e737c8dae390500f3525e6 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 24 Jun 2026 16:09:17 +0200 Subject: [PATCH 2/2] Modernize the imports of setup.py --- setup.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 5ee3013a..302de90e 100755 --- a/setup.py +++ b/setup.py @@ -1,17 +1,27 @@ -#!/usr/bin/env python +#!/usr/bin/python import os import sys from distutils.sysconfig import get_python_lib -from subprocess import getstatusoutput -from sysconfig import get_config_var, get_python_version -from setuptools import Extension, setup +if sys.version > '3': + PY3 = True +else: + PY3 = False + +if PY3: + from setuptools import Extension, setup + from subprocess import getstatusoutput + from sysconfig import get_config_var, get_python_version +else: + from commands import getstatusoutput + from distutils.core import setup, Extension + from distutils.sysconfig import get_config_var, get_python_version if os.path.isfile("MANIFEST"): os.unlink("MANIFEST") -lua_versions = ("5.5", "5.4", "5.3", "5.2", "5.1") +lua_versions = ["5.5", "5.4", "5.3", "5.2", "5.1"] LUAVERSION = None for version in lua_versions: @@ -52,7 +62,11 @@ def pkgconfig(*packages): else: # throw others to extra_link_args kwargs.setdefault('extra_link_args', []).append(token) - for k, v in kwargs.items(): # remove duplicated + if PY3: + items = kwargs.items() + else: + items = kwargs.iteritems() + for k, v in items: # remove duplicated kwargs[k] = list(set(v)) return kwargs