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

Compile time env available from cython command line options #2315

Merged
merged 10 commits into from Jun 11, 2018

Conversation

kif
Copy link
Contributor

@kif kif commented Jun 8, 2018

I used the "-E" short option but if you believe other letters are better suited, I can change.
close #2314

x_args = pop_value()
try:
options.compile_time_env = Options.parse_compile_time_env(
x_args, current_settings=options.compile_time_env)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason the current_settings are only passed here and not in Cythonize.py?

>>> parse_compile_time_env(' ')
{}
>>> (parse_compile_time_env('boundscheck=True') ==
... {'boundscheck': True})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good example, because it suggests directive names to be evaluated. The compile time env has nothing to do with directives.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I'll fix that with dummy variable names

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the doctest to be more realistic and less misleading for other developers.

continue
if '=' not in item:
raise ValueError('Expected "=" in option "%s"' % item)
name, value = [s.strip() for s in item.strip().split('=', 1)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for stripping the original string here, since we need to strip each part anyway.

@@ -423,7 +423,7 @@ def parse_directive_list(s, relaxed_bool=False, ignore_unknown=False,
item = item.strip()
if not item:
continue
if not '=' in item:
if '=' not in item:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit sad that these changes slipped in. Probably a commit hook on your side or so.
While I think that cleaning them up is a good thing, it should better not happen as part of an unrelated commit.

@@ -139,6 +139,9 @@ def parse_args(args):
parser.add_option('-X', '--directive', metavar='NAME=VALUE,...', dest='directives',
type=str, action='callback', callback=parse_directives, default={},
help='set a compiler directive')
parser.add_option('-E', '--compile-time-env', metavar='NAME=VALUE,...', dest='compile_time_env',
type=str, action='callback', callback=Options.parse_compile_time_env, default={},
help='set a compile time environment variables')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"a ... variable"

@@ -139,6 +139,9 @@ def parse_args(args):
parser.add_option('-X', '--directive', metavar='NAME=VALUE,...', dest='directives',
type=str, action='callback', callback=parse_directives, default={},
help='set a compiler directive')
parser.add_option('-E', '--compile-time-env', metavar='NAME=VALUE,...', dest='compile_time_env',
type=str, action='callback', callback=Options.parse_compile_time_env, default={},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see in the surrounding code where this is coming from, but it seems wrong to say type=str when the actual value is a dict. And I'm also not sure that this allows passing -E multiple times.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type is the input type, before the action of the callback.
Setting it to "dict" would require the definition of what is a dict in OptParser, how to parse it, ... and duplicate most of the code already present.
When not defining it, the callback gets None instead of "" and most of them fail in parsing the string.

I am not very familiar with cythonize in the command line but apparently it works now as well.

@scoder
Copy link
Contributor

scoder commented Jun 9, 2018

I'm a bit torn whether -E is better than -D, but I'm not entirely sure that we'll never want to use -D to pass macro definitions down to the C compiler in cythonize, so ...

@kif
Copy link
Contributor Author

kif commented Jun 9, 2018 via email

@scoder
Copy link
Contributor

scoder commented Jun 9, 2018

The spacing/PEP8 changes don't need to be a separate PR, really, but they should not be part of an unrelated commit. Having them as a separate commit would be ok. (I admit that I'm guilty of doing such cleanups myself from time to time, and not always taking the time to separate them out either. We're all human...)

@scoder
Copy link
Contributor

scoder commented Jun 9, 2018

What I'm saying is: my other comments are more important than the one about the style changes. :)

@scoder scoder added this to the 0.29 milestone Jun 11, 2018
@scoder scoder merged commit f25fb25 into cython:master Jun 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

compile_time_env on command line
2 participants