From 783919000207a4dea8caab6b86285968f7ed3698 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Wed, 15 Nov 2023 10:03:28 +0800 Subject: [PATCH] Remove use of setup.py by using a proxied build backend. --- android/builder.py | 8 ++++++++ android/pyproject.toml | 6 +++++- android/setup.cfg | 3 +++ android/setup.py | 11 ----------- cocoa/builder.py | 8 ++++++++ cocoa/pyproject.toml | 6 +++++- cocoa/setup.cfg | 5 +++++ cocoa/setup.py | 13 ------------- demo/builder.py | 23 +++++++++++++++++++++++ demo/pyproject.toml | 6 +++++- demo/setup.cfg | 3 +++ demo/setup.py | 11 ----------- dummy/builder.py | 8 ++++++++ dummy/pyproject.toml | 6 +++++- dummy/setup.cfg | 3 +++ dummy/setup.py | 11 ----------- gtk/builder.py | 8 ++++++++ gtk/pyproject.toml | 6 +++++- gtk/setup.cfg | 6 ++++++ gtk/setup.py | 14 -------------- iOS/builder.py | 8 ++++++++ iOS/pyproject.toml | 6 +++++- iOS/setup.cfg | 5 +++++ iOS/setup.py | 13 ------------- textual/builder.py | 8 ++++++++ textual/pyproject.toml | 6 +++++- textual/setup.cfg | 4 ++++ textual/setup.py | 12 ------------ toga/builder.py | 29 +++++++++++++++++++++++++++++ toga/pyproject.toml | 6 +++++- toga/setup.py | 15 --------------- toga_builder.py | 24 ++++++++++++++++++++++++ web/builder.py | 8 ++++++++ web/pyproject.toml | 6 +++++- web/setup.cfg | 3 +++ web/setup.py | 11 ----------- winforms/builder.py | 8 ++++++++ winforms/pyproject.toml | 6 +++++- winforms/setup.cfg | 4 ++++ winforms/setup.py | 12 ------------ 40 files changed, 226 insertions(+), 133 deletions(-) create mode 100644 android/builder.py delete mode 100644 android/setup.py create mode 100644 cocoa/builder.py delete mode 100644 cocoa/setup.py create mode 100644 demo/builder.py delete mode 100644 demo/setup.py create mode 100644 dummy/builder.py delete mode 100644 dummy/setup.py create mode 100644 gtk/builder.py delete mode 100644 gtk/setup.py create mode 100644 iOS/builder.py delete mode 100644 iOS/setup.py create mode 100644 textual/builder.py delete mode 100644 textual/setup.py create mode 100644 toga/builder.py delete mode 100644 toga/setup.py create mode 100644 toga_builder.py create mode 100644 web/builder.py delete mode 100644 web/setup.py create mode 100644 winforms/builder.py delete mode 100644 winforms/setup.py diff --git a/android/builder.py b/android/builder.py new file mode 100644 index 0000000000..db01945513 --- /dev/null +++ b/android/builder.py @@ -0,0 +1,8 @@ +# PEP517 doesn't allow ".." in a build backend's `backend-path` setting. +# To avoid duplicating the backend's code, insert ".." into sys.path, +# then import the toga_builder. +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)))) +from toga_builder import * # noqa: F401,E402,F403 diff --git a/android/pyproject.toml b/android/pyproject.toml index 9dae7f3704..c183e6a50b 100644 --- a/android/pyproject.toml +++ b/android/pyproject.toml @@ -1,6 +1,7 @@ [build-system] requires = ["setuptools==66.1.1", "setuptools_scm[toml]==7.0.5"] -build-backend = "setuptools.build_meta" +build-backend = "builder" +backend-path = ["."] [tool.coverage.run] parallel = true @@ -16,3 +17,6 @@ source = [ "src/toga_android", "**/toga_android", ] + +[tool.setuptools_scm] +root = ".." diff --git a/android/setup.cfg b/android/setup.cfg index e3ef915b3c..b74f0139b5 100644 --- a/android/setup.cfg +++ b/android/setup.cfg @@ -46,6 +46,9 @@ package_dir = python_requires = >= 3.8 zip_safe = False +# Build backend will inject a dependency on toga-core==VERSION +# install_requires = + [options.entry_points] toga.backends = android = toga_android diff --git a/android/setup.py b/android/setup.py deleted file mode 100644 index 117b407133..0000000000 --- a/android/setup.py +++ /dev/null @@ -1,11 +0,0 @@ -from setuptools import setup -from setuptools_scm import get_version - -version = get_version(root="..") - -setup( - version=version, - install_requires=[ - "toga-core==%s" % version, - ], -) diff --git a/cocoa/builder.py b/cocoa/builder.py new file mode 100644 index 0000000000..db01945513 --- /dev/null +++ b/cocoa/builder.py @@ -0,0 +1,8 @@ +# PEP517 doesn't allow ".." in a build backend's `backend-path` setting. +# To avoid duplicating the backend's code, insert ".." into sys.path, +# then import the toga_builder. +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)))) +from toga_builder import * # noqa: F401,E402,F403 diff --git a/cocoa/pyproject.toml b/cocoa/pyproject.toml index 68b490f89a..3c3d954a9f 100644 --- a/cocoa/pyproject.toml +++ b/cocoa/pyproject.toml @@ -1,6 +1,7 @@ [build-system] requires = ["setuptools==66.1.1", "setuptools_scm[toml]==7.0.5"] -build-backend = "setuptools.build_meta" +build-backend = "builder" +backend-path = ["."] [tool.coverage.run] parallel = true @@ -16,3 +17,6 @@ source = [ "src/toga_cocoa", "**/toga_cocoa", ] + +[tool.setuptools_scm] +root = ".." diff --git a/cocoa/setup.cfg b/cocoa/setup.cfg index 7b9f2cc29f..053876a68c 100644 --- a/cocoa/setup.cfg +++ b/cocoa/setup.cfg @@ -47,6 +47,11 @@ package_dir = python_requires = >= 3.8 zip_safe = False +# Build backend will inject a dependency on toga-core==VERSION +install_requires = + fonttools >= 4.42.1, < 5.0.0 + rubicon-objc >= 0.4.7, < 0.5.0 + [options.entry_points] toga.backends = macOS = toga_cocoa diff --git a/cocoa/setup.py b/cocoa/setup.py deleted file mode 100644 index 30217c2e40..0000000000 --- a/cocoa/setup.py +++ /dev/null @@ -1,13 +0,0 @@ -from setuptools import setup -from setuptools_scm import get_version - -version = get_version(root="..") - -setup( - version=version, - install_requires=[ - "fonttools >= 4.42.1, < 5.0.0", - "rubicon-objc >= 0.4.7, < 0.5.0", - f"toga-core == {version}", - ], -) diff --git a/demo/builder.py b/demo/builder.py new file mode 100644 index 0000000000..f9c8a523eb --- /dev/null +++ b/demo/builder.py @@ -0,0 +1,23 @@ +# A wrapper around setuptools that injects a dynamic dependency on toga. +# It presents as a PEP517 build backend with the same interface as +# setuptools.build_meta, but dynamically injects a modification to +# `parse_config_files` that injects the extra dependency, using the version +# number computed at runtime. +from setuptools import dist +from setuptools.build_meta import * # noqa: F401,F403 +from setuptools_scm import get_version + +TOGA_VERSION = get_version(root="..") + + +orig_parse_config_files = dist.Distribution.parse_config_files + + +def parse_config_files(self, filenames=None, ignore_option_errors=False): + orig_parse_config_files(self, filenames=None, ignore_option_errors=False) + + # Insert a dependency on toga at the same version as the repo. + self.install_requires.insert(0, f"toga=={TOGA_VERSION}") + + +dist.Distribution.parse_config_files = parse_config_files diff --git a/demo/pyproject.toml b/demo/pyproject.toml index b8e718c817..08d03c8e79 100644 --- a/demo/pyproject.toml +++ b/demo/pyproject.toml @@ -1,6 +1,7 @@ [build-system] requires = ["setuptools==66.1.1", "setuptools_scm[toml]==7.0.5"] -build-backend = "setuptools.build_meta" +build-backend = "builder" +backend-path = ["."] [tool.briefcase] project_name = "Toga Demo" @@ -42,3 +43,6 @@ requires = [ requires = [ "../android", ] + +[tool.setuptools_scm] +root = ".." diff --git a/demo/setup.cfg b/demo/setup.cfg index d35fa90721..1ead0a44a0 100644 --- a/demo/setup.cfg +++ b/demo/setup.cfg @@ -52,6 +52,9 @@ packages = find: python_requires = >= 3.7 zip_safe = False +# Build backend will inject a dependency on toga==VERSION +# install_requires = + [options.entry_points] console_scripts = toga-demo = toga_demo.__main__:run diff --git a/demo/setup.py b/demo/setup.py deleted file mode 100644 index 857372ef3e..0000000000 --- a/demo/setup.py +++ /dev/null @@ -1,11 +0,0 @@ -from setuptools import setup -from setuptools_scm import get_version - -version = get_version(root="..") - -setup( - version=version, - install_requires=[ - f"toga=={version}", - ], -) diff --git a/dummy/builder.py b/dummy/builder.py new file mode 100644 index 0000000000..db01945513 --- /dev/null +++ b/dummy/builder.py @@ -0,0 +1,8 @@ +# PEP517 doesn't allow ".." in a build backend's `backend-path` setting. +# To avoid duplicating the backend's code, insert ".." into sys.path, +# then import the toga_builder. +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)))) +from toga_builder import * # noqa: F401,E402,F403 diff --git a/dummy/pyproject.toml b/dummy/pyproject.toml index 884844b9a7..a909f09028 100644 --- a/dummy/pyproject.toml +++ b/dummy/pyproject.toml @@ -1,3 +1,7 @@ [build-system] requires = ["setuptools==66.1.1", "setuptools_scm[toml]==7.0.5"] -build-backend = "setuptools.build_meta" +build-backend = "builder" +backend-path = ["."] + +[tool.setuptools_scm] +root = ".." diff --git a/dummy/setup.cfg b/dummy/setup.cfg index b84bab24c0..315cc28251 100644 --- a/dummy/setup.cfg +++ b/dummy/setup.cfg @@ -45,6 +45,9 @@ package_dir = python_requires = >= 3.8 zip_safe = False +# Build backend will inject a dependency on toga==VERSION +# install_requires = + [options.entry_points] toga.backends = dummy = toga_dummy diff --git a/dummy/setup.py b/dummy/setup.py deleted file mode 100644 index 117b407133..0000000000 --- a/dummy/setup.py +++ /dev/null @@ -1,11 +0,0 @@ -from setuptools import setup -from setuptools_scm import get_version - -version = get_version(root="..") - -setup( - version=version, - install_requires=[ - "toga-core==%s" % version, - ], -) diff --git a/gtk/builder.py b/gtk/builder.py new file mode 100644 index 0000000000..db01945513 --- /dev/null +++ b/gtk/builder.py @@ -0,0 +1,8 @@ +# PEP517 doesn't allow ".." in a build backend's `backend-path` setting. +# To avoid duplicating the backend's code, insert ".." into sys.path, +# then import the toga_builder. +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)))) +from toga_builder import * # noqa: F401,E402,F403 diff --git a/gtk/pyproject.toml b/gtk/pyproject.toml index cc44825992..1febf1e791 100644 --- a/gtk/pyproject.toml +++ b/gtk/pyproject.toml @@ -1,6 +1,7 @@ [build-system] requires = ["setuptools==66.1.1", "setuptools_scm[toml]==7.0.5"] -build-backend = "setuptools.build_meta" +build-backend = "builder" +backend-path = ["."] [tool.coverage.run] parallel = true @@ -16,3 +17,6 @@ source = [ "src/toga_gtk", "**/toga_gtk", ] + +[tool.setuptools_scm] +root = ".." diff --git a/gtk/setup.cfg b/gtk/setup.cfg index cc09df2006..97e75d3d4d 100644 --- a/gtk/setup.cfg +++ b/gtk/setup.cfg @@ -48,6 +48,12 @@ package_dir = python_requires = >= 3.8 zip_safe = False +# Build backend will inject a dependency on toga-core==VERSION +install_requires = + gbulb >= 0.5.3 + pycairo >= 1.17.0 + pygobject >= 3.46.0 + [options.entry_points] toga.backends = linux = toga_gtk diff --git a/gtk/setup.py b/gtk/setup.py deleted file mode 100644 index c7ce5cbbdf..0000000000 --- a/gtk/setup.py +++ /dev/null @@ -1,14 +0,0 @@ -from setuptools import setup -from setuptools_scm import get_version - -version = get_version(root="..") - -setup( - version=version, - install_requires=[ - "toga-core==%s" % version, - "gbulb>=0.5.3", - "pycairo>=1.17.0", - "pygobject>=3.46.0", - ], -) diff --git a/iOS/builder.py b/iOS/builder.py new file mode 100644 index 0000000000..db01945513 --- /dev/null +++ b/iOS/builder.py @@ -0,0 +1,8 @@ +# PEP517 doesn't allow ".." in a build backend's `backend-path` setting. +# To avoid duplicating the backend's code, insert ".." into sys.path, +# then import the toga_builder. +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)))) +from toga_builder import * # noqa: F401,E402,F403 diff --git a/iOS/pyproject.toml b/iOS/pyproject.toml index 8066590905..b45f389ca1 100644 --- a/iOS/pyproject.toml +++ b/iOS/pyproject.toml @@ -1,6 +1,7 @@ [build-system] requires = ["setuptools==66.1.1", "setuptools_scm[toml]==7.0.5"] -build-backend = "setuptools.build_meta" +build-backend = "builder" +backend-path = ["."] [tool.coverage.run] parallel = true @@ -16,3 +17,6 @@ source = [ "src/toga_iOS", "**/toga_iOS", ] + +[tool.setuptools_scm] +root = ".." diff --git a/iOS/setup.cfg b/iOS/setup.cfg index 18d9fe6002..646d71388a 100644 --- a/iOS/setup.cfg +++ b/iOS/setup.cfg @@ -46,6 +46,11 @@ package_dir = python_requires = >= 3.8 zip_safe = False +# Build backend will inject a dependency on toga-core==VERSION +install_requires = + fonttools >= 4.42.1, < 5.0.0 + rubicon-objc >= 0.4.7, < 0.5.0 + [options.entry_points] toga.backends = iOS = toga_iOS diff --git a/iOS/setup.py b/iOS/setup.py deleted file mode 100644 index 30217c2e40..0000000000 --- a/iOS/setup.py +++ /dev/null @@ -1,13 +0,0 @@ -from setuptools import setup -from setuptools_scm import get_version - -version = get_version(root="..") - -setup( - version=version, - install_requires=[ - "fonttools >= 4.42.1, < 5.0.0", - "rubicon-objc >= 0.4.7, < 0.5.0", - f"toga-core == {version}", - ], -) diff --git a/textual/builder.py b/textual/builder.py new file mode 100644 index 0000000000..db01945513 --- /dev/null +++ b/textual/builder.py @@ -0,0 +1,8 @@ +# PEP517 doesn't allow ".." in a build backend's `backend-path` setting. +# To avoid duplicating the backend's code, insert ".." into sys.path, +# then import the toga_builder. +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)))) +from toga_builder import * # noqa: F401,E402,F403 diff --git a/textual/pyproject.toml b/textual/pyproject.toml index 32ff78706c..bf055b33f9 100644 --- a/textual/pyproject.toml +++ b/textual/pyproject.toml @@ -1,6 +1,7 @@ [build-system] requires = ["setuptools==66.1.1", "setuptools_scm[toml]==7.0.5"] -build-backend = "setuptools.build_meta" +build-backend = "builder" +backend-path = ["."] [tool.coverage.run] parallel = true @@ -16,3 +17,6 @@ source = [ "src/toga_textual", "**/toga_textual", ] + +[tool.setuptools_scm] +root = ".." diff --git a/textual/setup.cfg b/textual/setup.cfg index 2b98f712cb..c7d97f91e2 100644 --- a/textual/setup.cfg +++ b/textual/setup.cfg @@ -47,6 +47,10 @@ package_dir = python_requires = >= 3.8 zip_safe = False +# Build backend will inject a dependency on toga-core==VERSION +install_requires = + textual + [options.entry_points] toga.backends = # The textual backend is a candidate for use on every platform. diff --git a/textual/setup.py b/textual/setup.py deleted file mode 100644 index 1977b3cf11..0000000000 --- a/textual/setup.py +++ /dev/null @@ -1,12 +0,0 @@ -from setuptools import setup -from setuptools_scm import get_version - -version = get_version(root="..") - -setup( - version=version, - install_requires=[ - f"toga-core == {version}", - "textual", - ], -) diff --git a/toga/builder.py b/toga/builder.py new file mode 100644 index 0000000000..ddb87554fc --- /dev/null +++ b/toga/builder.py @@ -0,0 +1,29 @@ +# A wrapper around setuptools that injects a dynamic dependency on toga. +# +# It presents as a PEP517 build backend with the same interface as +# setuptools.build_meta, but dynamically injects a modification to +# `parse_config_files` that injects the extra dependencies, using the +# version number computed at runtime. +from setuptools import dist +from setuptools.build_meta import * # noqa: F401,F403 +from setuptools_scm import get_version + +TOGA_VERSION = get_version(root="..") + + +orig_parse_config_files = dist.Distribution.parse_config_files + + +def parse_config_files(self, filenames=None, ignore_option_errors=False): + orig_parse_config_files(self, filenames=None, ignore_option_errors=False) + + # Insert the per-platform extra dependencies with the same version as the + self.extras_require = { + ':sys_platform=="win32"': [f"toga-winforms=={TOGA_VERSION}"], + ':sys_platform=="linux"': [f"toga-gtk=={TOGA_VERSION}"], + ':"freebsd" in sys_platform': [f"toga-gtk=={TOGA_VERSION}"], + ':sys_platform=="darwin"': [f"toga-cocoa=={TOGA_VERSION}"], + } + + +dist.Distribution.parse_config_files = parse_config_files diff --git a/toga/pyproject.toml b/toga/pyproject.toml index 884844b9a7..a909f09028 100644 --- a/toga/pyproject.toml +++ b/toga/pyproject.toml @@ -1,3 +1,7 @@ [build-system] requires = ["setuptools==66.1.1", "setuptools_scm[toml]==7.0.5"] -build-backend = "setuptools.build_meta" +build-backend = "builder" +backend-path = ["."] + +[tool.setuptools_scm] +root = ".." diff --git a/toga/setup.py b/toga/setup.py deleted file mode 100644 index 240d3f7fb8..0000000000 --- a/toga/setup.py +++ /dev/null @@ -1,15 +0,0 @@ -from setuptools import setup -from setuptools_scm import get_version - -version = get_version(root="..") - -setup( - version=version, - extras_require={ - # Automatically installed platform backends - ':sys_platform=="win32"': ["toga-winforms==%s" % version], - ':sys_platform=="linux"': ["toga-gtk==%s" % version], - ':"freebsd" in sys_platform': ["toga-gtk==%s" % version], - ':sys_platform=="darwin"': ["toga-cocoa==%s" % version], - }, -) diff --git a/toga_builder.py b/toga_builder.py new file mode 100644 index 0000000000..1df1a776b1 --- /dev/null +++ b/toga_builder.py @@ -0,0 +1,24 @@ +# A wrapper around setuptools that injects a dynamic dependency on toga-core. +# +# It presents as a PEP517 build backend with the same interface as +# setuptools.build_meta, but dynamically injects a modification to +# `parse_config_files` that injects the extra dependency, using the +# version number computed at runtime. +from setuptools import dist +from setuptools.build_meta import * # noqa: F401,F403 +from setuptools_scm import get_version + +TOGA_VERSION = get_version(root="..") + + +orig_parse_config_files = dist.Distribution.parse_config_files + + +def parse_config_files(self, filenames=None, ignore_option_errors=False): + orig_parse_config_files(self, filenames=None, ignore_option_errors=False) + + # Insert a dependency on toga at the same version as the repo. + self.install_requires.insert(0, f"toga-core=={TOGA_VERSION}") + + +dist.Distribution.parse_config_files = parse_config_files diff --git a/web/builder.py b/web/builder.py new file mode 100644 index 0000000000..db01945513 --- /dev/null +++ b/web/builder.py @@ -0,0 +1,8 @@ +# PEP517 doesn't allow ".." in a build backend's `backend-path` setting. +# To avoid duplicating the backend's code, insert ".." into sys.path, +# then import the toga_builder. +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)))) +from toga_builder import * # noqa: F401,E402,F403 diff --git a/web/pyproject.toml b/web/pyproject.toml index 388c39d1e0..2d22600bd8 100644 --- a/web/pyproject.toml +++ b/web/pyproject.toml @@ -1,6 +1,7 @@ [build-system] requires = ["setuptools==66.1.1", "setuptools_scm[toml]==7.0.5"] -build-backend = "setuptools.build_meta" +build-backend = "builder" +backend-path = ["."] [tool.coverage.run] parallel = true @@ -16,3 +17,6 @@ source = [ "src/toga_web", "**/toga_web", ] + +[tool.setuptools_scm] +root = ".." diff --git a/web/setup.cfg b/web/setup.cfg index 3221e804e8..4b6fbedf8b 100644 --- a/web/setup.cfg +++ b/web/setup.cfg @@ -45,6 +45,9 @@ package_dir = python_requires = >= 3.8 zip_safe = False +# Build backend will inject a dependency on toga-core==VERSION +# install_requires = + [options.entry_points] toga.backends = web = toga_web diff --git a/web/setup.py b/web/setup.py deleted file mode 100644 index 117b407133..0000000000 --- a/web/setup.py +++ /dev/null @@ -1,11 +0,0 @@ -from setuptools import setup -from setuptools_scm import get_version - -version = get_version(root="..") - -setup( - version=version, - install_requires=[ - "toga-core==%s" % version, - ], -) diff --git a/winforms/builder.py b/winforms/builder.py new file mode 100644 index 0000000000..db01945513 --- /dev/null +++ b/winforms/builder.py @@ -0,0 +1,8 @@ +# PEP517 doesn't allow ".." in a build backend's `backend-path` setting. +# To avoid duplicating the backend's code, insert ".." into sys.path, +# then import the toga_builder. +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)))) +from toga_builder import * # noqa: F401,E402,F403 diff --git a/winforms/pyproject.toml b/winforms/pyproject.toml index 3fa806db1d..2545e72c8e 100644 --- a/winforms/pyproject.toml +++ b/winforms/pyproject.toml @@ -1,6 +1,7 @@ [build-system] requires = ["setuptools==66.1.1", "setuptools_scm[toml]==7.0.5"] -build-backend = "setuptools.build_meta" +build-backend = "builder" +backend-path = ["."] [tool.coverage.run] parallel = true @@ -16,3 +17,6 @@ source = [ "src/toga_winforms", "**/toga_winforms", ] + +[tool.setuptools_scm] +root = ".." diff --git a/winforms/setup.cfg b/winforms/setup.cfg index e4a72d66fa..54ccf4e2c1 100644 --- a/winforms/setup.cfg +++ b/winforms/setup.cfg @@ -47,6 +47,10 @@ package_dir = python_requires = >= 3.8 zip_safe = False +# Build backend will inject a dependency on toga-core==VERSION +install_requires = + pythonnet >= 3.0.0 + [options.package_data] toga_winforms = libs/WebView2/** diff --git a/winforms/setup.py b/winforms/setup.py deleted file mode 100644 index 052ef3d036..0000000000 --- a/winforms/setup.py +++ /dev/null @@ -1,12 +0,0 @@ -from setuptools import setup -from setuptools_scm import get_version - -version = get_version(root="..") - -setup( - version=version, - install_requires=[ - "pythonnet>=3.0.0", - "toga-core==%s" % version, - ], -)