Skip to content

Commit

Permalink
Remove use of setup.py by using a proxied build backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Nov 15, 2023
1 parent 12d3fd2 commit 7839190
Show file tree
Hide file tree
Showing 40 changed files with 226 additions and 133 deletions.
8 changes: 8 additions & 0 deletions android/builder.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion android/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,3 +17,6 @@ source = [
"src/toga_android",
"**/toga_android",
]

[tool.setuptools_scm]
root = ".."
3 changes: 3 additions & 0 deletions android/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions android/setup.py

This file was deleted.

8 changes: 8 additions & 0 deletions cocoa/builder.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion cocoa/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,3 +17,6 @@ source = [
"src/toga_cocoa",
"**/toga_cocoa",
]

[tool.setuptools_scm]
root = ".."
5 changes: 5 additions & 0 deletions cocoa/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions cocoa/setup.py

This file was deleted.

23 changes: 23 additions & 0 deletions demo/builder.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion demo/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -42,3 +43,6 @@ requires = [
requires = [
"../android",
]

[tool.setuptools_scm]
root = ".."
3 changes: 3 additions & 0 deletions demo/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions demo/setup.py

This file was deleted.

8 changes: 8 additions & 0 deletions dummy/builder.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion dummy/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = ".."
3 changes: 3 additions & 0 deletions dummy/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions dummy/setup.py

This file was deleted.

8 changes: 8 additions & 0 deletions gtk/builder.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion gtk/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,3 +17,6 @@ source = [
"src/toga_gtk",
"**/toga_gtk",
]

[tool.setuptools_scm]
root = ".."
6 changes: 6 additions & 0 deletions gtk/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions gtk/setup.py

This file was deleted.

8 changes: 8 additions & 0 deletions iOS/builder.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion iOS/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,3 +17,6 @@ source = [
"src/toga_iOS",
"**/toga_iOS",
]

[tool.setuptools_scm]
root = ".."
5 changes: 5 additions & 0 deletions iOS/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions iOS/setup.py

This file was deleted.

8 changes: 8 additions & 0 deletions textual/builder.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion textual/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,3 +17,6 @@ source = [
"src/toga_textual",
"**/toga_textual",
]

[tool.setuptools_scm]
root = ".."
4 changes: 4 additions & 0 deletions textual/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 0 additions & 12 deletions textual/setup.py

This file was deleted.

29 changes: 29 additions & 0 deletions toga/builder.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion toga/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = ".."
Loading

0 comments on commit 7839190

Please sign in to comment.