Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added: Possibility to specify extension modules. #640

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
8ed363c
Added: Possibility to specify extension modules.
Aug 8, 2019
d044794
Added: Integration test for the extension module functionality.
margru Aug 8, 2019
c6e9e45
Adapted: Some unit tests to pass with extension modules parameter.
margru Aug 8, 2019
2b58c96
Fixed: Code-style breaking the build.
margru Aug 9, 2019
842d1c0
Added possibility to build Cython extensions
margru Aug 27, 2019
497ba24
Fixed Cython extension rendering in setup.py
margru Aug 27, 2019
593690f
Minor fixes
margru Aug 27, 2019
c20e39b
Unpinned pip and setuptools dependencies
margru Aug 27, 2019
e1d9387
Merge branch 'dev'
margru Aug 28, 2019
8dde5e6
Improved Cython extension modules handling
margru Nov 4, 2019
5ef5f67
Added support for include_package_data
margru Mar 11, 2020
ac944e9
Minor fixes
margru Jun 11, 2021
5dcc1f8
Discard pip options from the requirements file
margru Jun 11, 2021
a94bf4a
Merge branch 'margu/master' into 'upstream/master'
chylek Mar 4, 2022
168a57a
Change default value when ext_modules are empty
chylek Mar 10, 2022
e7ccffb
Fix Cython dependency for cython_ext_modules
chylek Mar 10, 2022
301ef9b
Merge pull request #1 from chylek/ext_modules
margru Aug 3, 2022
3d9f6d7
Merge remote-tracking branch 'upstream/master' into ext_modules
chylek Aug 23, 2022
6c96c06
Fix ext modules test
chylek Aug 24, 2022
d6f6f65
Improve Cython dependency check
chylek Aug 24, 2022
5a50a10
Fix ext modules test
chylek Aug 25, 2022
9380b35
Add lazy Cython import in setup.py
chylek Aug 25, 2022
bdecc1d
Fix missing import for cythonization
chylek Aug 26, 2022
bc9f019
Add cythonization integration test
chylek Aug 26, 2022
b4d4644
Remove comments from test file
chylek Aug 26, 2022
deadc83
Merge remote-tracking branch 'upstream/master'
chylek Apr 25, 2023
c372e36
Fix integration test
chylek Apr 25, 2023
d1771b2
Add support for cython's compiler_directives
chylek Apr 25, 2023
f45b8db
Merge pull request #3 from chylek/update_upstream
margru Jun 16, 2023
45bf3ba
Merge pull request #4 from chylek/cython_in_setup
margru Jun 16, 2023
95cbd38
Merge branch 'master' into feature/compiler_directives
margru Jun 16, 2023
b70a141
Merge pull request #5 from chylek/feature/compiler_directives
margru Jun 16, 2023
0cc08a8
Add necessary setup_requires
margru Jun 23, 2023
2d071d7
FIX integration tests
margru Jun 23, 2023
809442d
Minor fix
margru Jun 23, 2023
9565af3
Add pyproject.toml creation if not exist
margru Jun 23, 2023
d01363d
Merge remote-tracking branch 'origin/ext_modules' into master-fix
chylek Aug 24, 2023
ec6fe88
Merge remote-tracking branch 'origin/cython_in_setup' into master-fix
chylek Aug 24, 2023
18cf168
Add support for cython's compiler_directives
chylek Apr 25, 2023
0164015
Add necessary setup_requires
chylek Aug 24, 2023
d1470c4
Add pyproject.toml creation if not exist
margru Jun 23, 2023
c4b168e
Add pyproject.toml merging
chylek Aug 23, 2023
0e26825
Fix linting issue
chylek Aug 23, 2023
71722fe
Fix lazy cythonization
chylek Aug 24, 2023
2c35dfa
Merge remote-tracking branch 'chylek/master-fixed'
margru Aug 25, 2023
46bea10
Fix incorrect merge
chylek Aug 28, 2023
dc444d8
Merge pull request #6 from chylek/master
margru May 28, 2024
41b6792
Merge tag 'v0.13.11'
margru May 28, 2024
05aa208
Merge branch 'master' into master
arcivanov May 29, 2024
dab1233
Minor fix causing error during build
margru May 29, 2024
0fe2c92
FIX cython version for cythonization for > 3.8
margru May 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ target/

# Idea
.idea
*.iml
206 changes: 206 additions & 0 deletions src/integrationtest/python/should_cythonize_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
# -*- coding: utf-8 -*-
#
# This file is part of PyBuilder
#
# Copyright 2011-2020 PyBuilder Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

from itest_support import IntegrationTestSupport


class Test(IntegrationTestSupport):
def test(self):
self.write_build_file("""
import os

from pybuilder.core import use_plugin, init

use_plugin("python.core")
use_plugin("python.install_dependencies")
use_plugin("python.distutils")
use_plugin("copy_resources")
use_plugin("filter_resources")

name = "integration-test"
default_task = "publish"

@init
def init (project):
project.depends_on("pyassert", url="https://github.com/downloads/halimath/pyassert/pyassert-0.2.2.tar.gz",
declaration_only = True)

project.set_property("filter_resources_target", "$dir_dist")
project.set_property("filter_resources_glob", [
os.path.join("**", "__init__.py")
])
project.set_property("distutils_cython_ext_modules", [{
"module_list": ["spam/**/*.py", "eggs/**/*.py"],
"exclude": ["**/__init__.py"],
"compiler_directives": {"language_level": "3"}
}])
project.set_property("distutils_cython_remove_python_sources", True)
project.set_property("copy_resources_target", "$dir_dist")
""")
self.create_directory("src/main/python/spam")
self.write_file("src/main/python/spam/__init__.py", "")
self.write_file("src/main/python/spam/eggs.py", """
def spam ():
pass
""")
self.create_directory("src/main/python/eggs")
self.write_file("src/main/python/eggs/__init__.py", "")
self.write_file("src/main/python/eggs/spam.py", """
def eggs ():
pass
""")

reactor = self.prepare_reactor()
reactor.build()

self.assert_directory_exists("target/dist/integration-test-1.0.dev0")
self.assert_directory_exists("target/dist/integration-test-1.0.dev0/spam")
self.assert_file_empty("target/dist/integration-test-1.0.dev0/spam/__init__.py")
self.assert_file_exists("target/dist/integration-test-1.0.dev0/spam/eggs.c")

setup_py = "target/dist/integration-test-1.0.dev0/setup.py"

self.assert_file_exists(setup_py)
self.assert_file_permissions(0o755, setup_py)

self.assert_file_content(setup_py, """#!/usr/bin/env python
# -*- coding: utf-8 -*-

from setuptools import setup, Extension
from setuptools.command.install import install as _install

from setuptools.command.build_py import build_py as _build_py
import glob

class LazyCythonize(list):
def __init__(self, ext_modules, cythonize_modules_kwargs):
self.ext_modules = ext_modules if ext_modules is not None else []
self.cythonize_modules_kwargs = cythonize_modules_kwargs if cythonize_modules_kwargs is not None else []
self.cythonized_modules = []

def _cythonize(self):
if self.cythonized_modules:
return

from Cython.Build import cythonize

for kwargs in self.cythonize_modules_kwargs:
self.cythonized_modules.extend(cythonize(**kwargs))
self.cythonized_modules.extend(self.ext_modules)

def __iter__(self):
self._cythonize()
return iter(self.cythonized_modules)

def __getitem__(self, key):
self._cythonize()
if 0<=key<len(self.cythonized_modules):
return self.cythonized_modules[key]
else:
raise IndexError("Index out of range")

def __len__(self):
self._cythonize()
return len(self.cythonized_modules)


class install(_install):
def pre_install_script(self):
pass

def post_install_script(self):
pass

def run(self):
self.pre_install_script()

_install.run(self)

self.post_install_script()


cython_module_list = ['spam/**/*.py', 'eggs/**/*.py']
cython_excludes = ['**/__init__.py']
def not_cythonized(tup):
(package, module, filepath) = tup
return any(
[filepath in glob.iglob(pattern, recursive=True) for pattern in cython_excludes]
) or not any(
[filepath in glob.iglob(pattern, recursive=True) for pattern in cython_module_list]
)

class build_py(_build_py):
def find_modules(self):
modules = super().find_modules()
return list(filter(not_cythonized, modules))

def find_package_modules(self, package, package_dir):
modules = super().find_package_modules(package, package_dir)
return list(filter(not_cythonized, modules))


if __name__ == '__main__':
setup(
name = 'integration-test',
version = '1.0.dev0',
description = '',
long_description = 'integration-test',
long_description_content_type = None,
classifiers = [
'Development Status :: 3 - Alpha',
'Programming Language :: Python'
],
keywords = '',

author = '',
author_email = '',
maintainer = '',
maintainer_email = '',

license = '',

url = '',
project_urls = {},

scripts = [],
packages = [
'eggs',
'spam'
],
namespace_packages = [],
py_modules = [],
ext_modules = LazyCythonize([],[{"module_list":['spam/**/*.py', 'eggs/**/*.py'],"exclude":['**/__init__.py'],"compiler_directives":{'language_level': '3'}}]),
entry_points = {},
data_files = [],
package_data = {},
include_package_data = False,
install_requires = [],
dependency_links = ['https://github.com/downloads/halimath/pyassert/pyassert-0.2.2.tar.gz'],
zip_safe = True,
cmdclass = {'install': install,'build_py': build_py},
python_requires = '',
obsoletes = [],
setup_requires = ["cython~=0.29.0; python_version <= '3.7'", "cython~=3.0.10; python_version > '3.7'"],
)
""") # noqa: E501


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ def spam ():
self.assert_file_content(setup_py, """#!/usr/bin/env python
# -*- coding: utf-8 -*-

from setuptools import setup
from setuptools import setup, Extension
from setuptools.command.install import install as _install


class install(_install):
def pre_install_script(self):
pass
Expand All @@ -90,6 +91,8 @@ def run(self):

self.post_install_script()



if __name__ == '__main__':
setup(
name = 'integration-test',
Expand Down Expand Up @@ -117,9 +120,11 @@ def run(self):
packages = ['spam'],
namespace_packages = ['spam'],
py_modules = ['standalone_module'],
ext_modules = [],
entry_points = {},
data_files = [],
package_data = {},
include_package_data = False,
install_requires = [
'eggs==0.2.3',
'spam'
Expand All @@ -129,6 +134,7 @@ def run(self):
cmdclass = {'install': install},
python_requires = '',
obsoletes = [],
setup_requires = [],
)
""")

Expand Down
8 changes: 7 additions & 1 deletion src/integrationtest/python/should_write_setup_file_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ def spam ():
self.assert_file_content(setup_py, """#!/usr/bin/env python
# -*- coding: utf-8 -*-

from setuptools import setup
from setuptools import setup, Extension
from setuptools.command.install import install as _install


class install(_install):
def pre_install_script(self):
pass
Expand All @@ -98,6 +99,8 @@ def run(self):

self.post_install_script()



if __name__ == '__main__':
setup(
name = 'integration-test',
Expand Down Expand Up @@ -129,12 +132,14 @@ def run(self):
],
namespace_packages = [],
py_modules = ['standalone_module'],
ext_modules = [],
entry_points = {},
data_files = [],
package_data = {
'project': ['descriptors/*/*'],
'project.calendars': ['2018.yml', 'acc/2018.yml']
},
include_package_data = False,
install_requires = [
'eggs==0.2.3',
'spam'
Expand All @@ -144,6 +149,7 @@ def run(self):
cmdclass = {'install': install},
python_requires = '',
obsoletes = [],
setup_requires = [],
)
""")

Expand Down
Loading
Loading