You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2022/10/18 04:17:07 UTC

[buildstream] branch tristan/dont-distribute-generated-code created (now e72e4c36e)

This is an automated email from the ASF dual-hosted git repository.

tvb pushed a change to branch tristan/dont-distribute-generated-code
in repository https://gitbox.apache.org/repos/asf/buildstream.git


      at e72e4c36e setup.py: Stop including generated Cython code in source distributions.

This branch includes the following new commits:

     new e72e4c36e setup.py: Stop including generated Cython code in source distributions.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[buildstream] 01/01: setup.py: Stop including generated Cython code in source distributions.

Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch tristan/dont-distribute-generated-code
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit e72e4c36e2e83a1ab726d0d820ba0a8b1e04c17f
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Tue Oct 18 13:13:51 2022 +0900

    setup.py: Stop including generated Cython code in source distributions.
    
    Ensures that code will always be generated when building for a given
    target environment, this is because Cython generates code which accesses
    CPython internal symbols and we cannot guarantee that the C code we
    generated will be valid for the target CPython interpretor.
---
 MANIFEST.in |  1 -
 setup.py    | 55 ++++++++++++++++++-------------------------------------
 2 files changed, 18 insertions(+), 38 deletions(-)

diff --git a/MANIFEST.in b/MANIFEST.in
index 9c28ca355..047ceac43 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -9,7 +9,6 @@ include README.rst
 # Cython files
 recursive-include src/buildstream *.pyx
 recursive-include src/buildstream *.pxd
-recursive-include src/buildstream *.c
 
 # Data files required by BuildStream's generic source tests
 graft src/buildstream/_testing/_sourcetests/project
diff --git a/setup.py b/setup.py
index 8e1a11556..4b1b68493 100755
--- a/setup.py
+++ b/setup.py
@@ -315,23 +315,6 @@ with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), "README.rst"
 #####################################################
 #            Setup Cython and extensions            #
 #####################################################
-# We want to ensure that source distributions always
-# include the .c files, in order to allow users to
-# not need cython when building.
-def assert_cython_required():
-    if "sdist" not in sys.argv:
-        return
-
-    print(
-        "Cython is required when building 'sdist' in order to "
-        "ensure source distributions can be built without Cython. "
-        "Please install it using your package manager (usually 'python3-cython') "
-        "or pip (pip install cython).",
-        file=sys.stderr,
-    )
-
-    raise SystemExit(1)
-
 
 try:
     ENABLE_CYTHON_TRACE = int(os.environ.get("BST_CYTHON_TRACE", "0"))
@@ -344,29 +327,27 @@ extension_macros = [("CYTHON_TRACE", ENABLE_CYTHON_TRACE)]
 
 
 def cythonize(extensions, **kwargs):
+    # We want to make sure that generated Cython code is never
+    # included in the source distribution.
+    #
+    # This is because Cython will generate some code which accesses
+    # internal API from CPython, as such we cannot guarantee that
+    # the C code we generated when creating the distribution will
+    # be valid for the target CPython interpretor.
+    #
+    if "sdist" in sys.argv:
+        return extensions
+
     try:
         from Cython.Build import cythonize as _cythonize
     except ImportError:
-        assert_cython_required()
-
-        print("Cython not found. Using preprocessed c files instead")
-
-        missing_c_sources = []
-
-        for extension in extensions:
-            for source in extension.sources:
-                if source.endswith(".pyx"):
-                    c_file = source.replace(".pyx", ".c")
-
-                    if not os.path.exists(c_file):
-                        missing_c_sources.append((extension, c_file))
-
-        if missing_c_sources:
-            for extension, source in missing_c_sources:
-                print("Missing '{}' for building extension '{}'".format(source, extension.name))
-
-            raise SystemExit(1)
-        return extensions
+        print(
+            "Cython is required when building BuildStream from sources."
+            "Please install it using your package manager (usually 'python3-cython') "
+            "or pip (pip install cython).",
+            file=sys.stderr,
+        )
+        raise SystemExit(1)
 
     return _cythonize(extensions, **kwargs)