Các enscons package dường như được thiết kế để làm gì là câu hỏi. Ví dụ về việc sử dụng nó để tạo gói có phần mở rộng C là here.
Bạn có thể có một cấu trúc gói cơ bản như:
pkgroot/
pyproject.toml
setup.py
SConstruct
README.md
pkgname/
__init__.py
pkgname.py
cfile.c
Trong file pyproject.toml
có thể giống như thế:
[build-system]
requires = ["enscons"]
[tool.enscons]
name = "pkgname"
description = "My nice packahe"
version = "0.0.1"
author = "Me"
author_email = "[email protected]"
keywords = ["spam"]
url = "https://github.com/me/pkgname"
src_root = ""
packages = ["pkgname"]
nơi phần [tool.enscons]
chứa nhiều điều quen thuộc với người setuptools/distutils setup
chức năng. Sao chép từ here, các setup.py
chức năng có thể chứa một cái gì đó như:
#!/usr/bin/env python
# Call enscons to emulate setup.py, installing if necessary.
import sys, subprocess, os.path
sys.path[0:0] = ['setup-requires']
try:
import enscons.setup
except ImportError:
requires = ["enscons"]
subprocess.check_call([sys.executable, "-m", "pip", "install",
"-t", "setup-requires"] + requires)
del sys.path_importer_cache['setup-requires'] # needed if setup-requires was absent
import enscons.setup
enscons.setup.setup()
Cuối cùng, các tập tin SConstruct
có thể giống như thế:
# Build pkgname
import sys, os
import pytoml as toml
import enscons, enscons.cpyext
metadata = dict(toml.load(open('pyproject.toml')))['tool']['enscons']
# most specific binary, non-manylinux1 tag should be at the top of this list
import wheel.pep425tags
full_tag = next(tag for tag in wheel.pep425tags.get_supported() if not 'manylinux' in tag)
env = Environment(tools=['default', 'packaging', enscons.generate, enscons.cpyext.generate],
PACKAGE_METADATA=metadata,
WHEEL_TAG=full_tag)
ext_filename = os.path.join('pkgname', 'libcfile')
extension = env.SharedLibrary(target=ext_filename,
source=['pkgname/cfile.c'])
py_source = Glob('pkgname/*.py')
platlib = env.Whl('platlib', py_source + extension, root='')
whl = env.WhlFile(source=platlib)
# Add automatic source files, plus any other needed files.
sdist_source=list(set(FindSourceFiles() +
['PKG-INFO', 'setup.py'] +
Glob('pkgname/*', exclude=['pkgname/*.os'])))
sdist = env.SDist(source=sdist_source)
env.Alias('sdist', sdist)
install = env.Command("#DUMMY", whl,
' '.join([sys.executable, '-m', 'pip', 'install', '--no-deps', '$SOURCE']))
env.Alias('install', install)
env.AlwaysBuild(install)
env.Default(whl, sdist)
Sau này, bạn sẽ có thể chạy
sudo python setup.py install
để biên dịch phần mở rộng C và tạo bánh xe và cài đặt gói python hoặc
python setup.py sdist
để tạo phân phối nguồn.
Tôi nghĩ bạn về cơ bản có thể làm bất cứ điều gì bạn có thể với SCons trong tệp SConstruct
.
Thay vì đăng các liên kết dưới dạng câu trả lời, hãy thêm một số văn bản để giải thích cách câu trả lời này giúp OP trong việc khắc phục vấn đề hiện tại.Thanks –
@ ρяσѕρєяK Tôi đã thêm một ví dụ cụ thể hơn từ các liên kết. –
Tôi nghĩ @joeforker là tác giả của enscons, vì vậy họ có thể thêm vào câu trả lời này. –