by eesmith · 5y ago · 0 comments
Not if you have a Python/C extension.
Not if your build step includes code generation (other than Cython).
Not if you have special per-file compilation args.
Also, in the declarative configuration format, how do I enable/disable compile-time flags like "compile with OpenMP" ?
Yes, I have these, and it really irks me reading all of these "you don't need setup.py" when as far as I can tell, I can't.
That said, it would be really nice if at least the C-extension part of this worked with the declarative format. My OSS time has been severely curtailed lately and I'm spread way too thin, so I probably won't be able to execute on this, but my long term vision for setuptools has always been that most common build configurations should be achievable using declarative config only, and everything else has setup.py as an escape hatch. This is similar to the way almost all Rust projects are configured with Cargo.toml, but in rare cases you can use build.rs to execute some Rust code as part of the build.
> and as part of the deprecation of distutils, having setuptools installed at all even when you don't import it can change the behavior of import distutils.
How am I supposed to replace the following (a modified version of https://stackoverflow.com/questions/724664/python-distutils-... ):
from setuptools import Extension, setup
from distutils.command.build_ext import build_ext
copt = {'msvc': ['/openmp', '/Ox', '/fp:fast','/favor:INTEL64','/Og'] ,
'mingw32' : ['-fopenmp','-O3','-ffast-math','-march=native'] }
lopt = {'mingw32' : ['-fopenmp'] }
class build_ext_subclass( build_ext ):
def build_extensions(self):
c = self.compiler.compiler_type
if copt.has_key(c):
for e in self.extensions:
e.extra_compile_args = copt[ c ]
if lopt.has_key(c):
for e in self.extensions:
e.extra_link_args = lopt[ c ]
build_ext.build_extensions(self)
If distutils is deprecated, and setuptools causes problems ... what should I do?I know setuptools is a "hot mess". It took hours of puzzling to figure out how to compile things correctly, and includes input from other people who spent hours puzzling things out.
So I am ... sad isn't quite right. Depressed? Down? Feeling like and outsider? .. every time I am reminded that I am not one of the "most people" in "works for most people".
While I (and you) are here, is some way to distinguish between "developer" build environments and "deployment" build environments?
I was looking more at the general topic, trying to figure out how to migrate. I saw this example:
[build-system]
requires = ["setuptools >= 40.6.0", "wheel"]
build-backend = "setuptools.build_meta"
I have two build environments. A development build environment requires Cython (I have hand-written Python/C extensions and Cython extensions). On the other hand, source distributions include the "cythonized" C code from Cython, so people who install and deploy from source don't need Cython. [1]In my setup.py I say:
try:
from Cython.Build import cythonize
except ImportError:
def cythonize(x):
return x
def rename(filename):
return filename.replace(".pyx", ".c")
else:
def rename(filename):
return filename
...
= cythonize([Extension("spam", sources = [rename("foo.pyx"), "bar.c"])])
Is there a way to distinguish these two environments in pyproject.toml?[1] Other than 'setuptools' and the need for a C compiler, my package has no dependencies when building from a source distribution.
EDIT: P.S. A reason to stick with "python setup.py develop" instead of "pip install -e ." is to avoid that frequent nag to "consider upgrading" pip. ;)
Is it possible for Cython? Their guide shows using setup.py:
https://cython.readthedocs.io/en/latest/src/tutorial/cython_...
> setuptools will detect at build time whether Cython is installed or not. If Cython is not found setuptools will ignore pyx files.
> To ensure Cython is available, include Cython in the build-requires section of your pyproject.toml:
[build-system]
requires=[..., "cython"]
> Built with pip 10 or later, that declaration is sufficient to include Cython in the build. For broader compatibility, declare the dependency in your setup-requires of setup.cfg: