Is your feature request related to a problem? Please describe.
I am trying to build a pyarmor-protected file.
In my setup.py, I would like to pass the arguments -3 --lenient --keep-going to the cythonize() call.
So far my file looks like this:
# setup.py try: from setuptools import setup from setuptools.extension import Extension except ImportError: from distutils.core import setup from distutils.extension import Extension import os from Cython.Build import cythonize from os.path import abspath libImport = abspath("../some/libs") pyImport = abspath("../some/include") cflags = '-3 --lenient --keep-going' ext_modules = [ Extension( "pytransform", sources=[ "src/dist/obf/pytransform.py" ], extra_compile_args=cflags ), Extension( "Calculate", sources=[ "src/dist/obf/calculate.py" ], extra_compile_args=cflags ) ] setup( name="Calculate", description= 'Calculate', author= 'Test', author_email= 'admin@test-net, install_requires= ['cython'], packages= ['calculate'], ext_modules= cythonize(ext_modules), include_dirs= [libImport, pyImport], )
but the "cflags" arguments dont get recognized?
I end up with the error:
dist\calculate.py:4:0: undeclared name not builtin: __pyarmor__
Describe the solution you'd like
Add documentation on how to properly pass in arguments from code.
The existing page does not say anything about it: http://docs.cython.org/en/latest/src/quickstart/build.html
Describe alternatives you've considered
This works:
cythonize -3 -k --lenient .\dist\calculate.py
But manually building from the command-line is annoying if you have a lot of files.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
There's a bit more detail in the user-guide section of the docs, although admittedly I don't think it covers this very well. Improvements are welcome.
--linient enables Options.error_on_unknown_names = False and Options.error_on_uninitialized = False so you'd be best advised to set it that way.
-3 is equivalent to defaulting to the language_level compiler directive to 3. Personally I'd set it with #cython: language_level = 3 in the source file, since the correct setting is defined by the source file.
I'm not sure about -k - my personal view is that it's rarely useful but that shouldn't stop you from using it if you want
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
-k stems from the time when I tried to compile CPython's standard library with Cython, and it would fail to compile several of the modules (sometimes even because of bugs, funny enough). That has become less of an issue these days, so yes, -k probably isn't very useful any more.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Note that cflags are really C flags, i.e. options for the C compiler and not for Cython.
You can look at Cython's command line parser to see what each of the options does and how to mimic it programmatically.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Actually, linking to the command line parser from the docs is probably a fair way to document the programmatic options in relation to the command line arguments.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
--linientenablesOptions.error_on_unknown_names = FalseandOptions.error_on_uninitialized = Falseso you'd be best advised to set it that way.
Note that
cflags(i.e.extra_compile_args) are really C flags, i.e. options for the C compiler and not for Cython.You can look at Cython's command line parser to see what each of the Cython options does and how to mimic it programmatically.
Oh well, thank you two for the hints!
I probably scrolled by the "Options" section at some point, but just didn't realise, the error_on_ -options are related to the --lenient argument.
-3is equivalent to defaulting to thelanguage_levelcompiler directive to 3. Personally I'd set it with#cython: language_level = 3in the source file, since the correct setting is defined by the source file.
This usually seems like a good advice aswell, but since I obfuscate the scripts with pyarmor before compiling, I don't have much control over the source in this case :(.
I'm not sure about
-k- my personal view is that it's rarely useful but that shouldn't stop you from using it if you want
And you're right, the option was recommended by the "pyarmor" devs but it seems to work without it aswell.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
For anyone interested, now my setup.py looks like this:
try:
from setuptools import setup
from setuptools.extension import Extension
except ImportError:
from distutils.core import setup
from distutils.extension import Extension
from os.path import abspath
from Cython.Build import cythonize
from Cython.Compiler import Options
libImport = abspath("../some/libs")
pyImport = abspath("../some/include")
Options.error_on_unknown_names = False
Options.error_on_uninitialized = False
Options.language_level = 3
ex_mod = [
Extension(
"pytransform",
sources=[ "dist/pytransform.py" ],
),
Extension(
"calculate",
sources=[ "dist/calculate.py" ],
)
]
setup(
name="Calculate",
description= 'Calculate',
author= 'Test',
author_email= 'admin@test-net,
install_requires= ['cython'],
packages= ['calculate'],
ext_modules= cythonize(ext_mod),
include_dirs= [libImport, pyImport],
)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Closed #4797 as completed.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()