Modern Command Line interface for Cython #53

Open
wants to merge 55 commits into
from

Projects

None yet

4 participants

@esseks

NOTE: this replicates a previous pull request from a deleted repo.

Here is my modern command line interface, which performs a little slower if compared to old custom code, but is clear and easily extensible. It supports both argparse and optparse, though the "legacy" version has some 10 HACKs . Additionally, argparse performs better with complicated command lines (like those generated by autotools &co.) - especially if source files are not at the end of the argument list - and allows "read arguments from file" syntax.

This pull includes some changes to surrounding code (specifically, Cython.Compiler.Main), either for integration or performance issues.

The only potential issue is with --embed argument, since it allows its value to be implied:

cython --embed myfile

is ok, but:

cython --embed=mymain myfile

is correctly understood only by argparse. Secondly,

cython --embed mymain myfile

is ambigous. Since the parser is greedy for source files, mymain will be considered a source file, actually breaking the case above with a "more than one file" error. If anyone liked that syntax, it may use:

cython --embed mymain -- myfile

This syntax also allows for explicit main() name specification in optparse version.

This is hard to be fixed. At least, I could have optparse to ignore it and parse --embed form manually, but that would be a huge HACK.


NOTE: my branch has passed all tests from testsuite, including a purposedly written one (see Cython.Compiler.Tests.TestCommandLine) but, please, double check this ;)

vitek and others added some commits Jul 31, 2011
@vitek vitek Add Entry.cf_used attribute 231aabf
@vitek vitek Set entry.cf_used to False when argument is unused 5db9f26
@vitek vitek Mark unused cdef-function args with CYTHON_UNUSED 594e3ba
@vitek vitek Don't initialize unused cdef-function optional args f871cad
@vitek vitek Add generic python args test 480798a
@vitek vitek Code cleanup 8d4c8f4
@vitek vitek Add runtime test with unused arguments 6cf7ea9
@vitek vitek Don't remove optional args when function is overridable 8a3aa54
@vitek vitek Only mark skip_dispatch arg as unused if function has OverrideCheckNode a084a7b
@vitek vitek Mark unused vars with CYTHON_UNUSED qualifier cecd09c
@vitek vitek Mark unused METH_O arguments 7306e1e
@scoder scoder Merge pull request #50 from vitek/_unused_args
Silence warning about unused args
5ace507
@robertwb robertwb Some Python 2.3 cleanup. a0fff9f
@robertwb robertwb Refuse to compile for Python < 2.4 517c36d
@robertwb robertwb More Py2.3 cleanup. 6ff3b8e
Stefan Behnel AttributeNode.as_cython_attribute(): make method return value explicit 3769067
Stefan Behnel test case for ticket #653 bb90984
Stefan Behnel fix type inheritance check for builtin types ddba4f1
Stefan Behnel fix support for redeclaring builtin types as external extension types…
…, add a big FIXME to mark for eventual removal
ec2a95d
Stefan Behnel implement may_be_none() for CloneNode 7faf9c6
Stefan Behnel fix ticket #653
- generate correct code for optimised override calls to methods of builtin types in subtypes
- optimise calls for 'final' subtypes
- disable optimised C-API calls for non-final subtypes
9ff18ae
Stefan Behnel drop unused import e739f25
Stefano Sanfilippo Command line parsing now uses argparse module. Still a work in progre…
…ss, though.
5d55f8c
Stefano Sanfilippo Turned flags structure into a readable dictionary. c3f7f82
Stefano Sanfilippo Completed transition to argparse module. Start adding optparse compat…
…ibilty.
5508b3d
Stefano Sanfilippo Added optparse fallback. 3872ecb
Stefano Sanfilippo Added complete test case for Cython.Compiler.CmdLine module. 72b09e1
Stefano Sanfilippo Completed test case for debug options & directives. 2a81407
Stefano Sanfilippo Completed -X and --debug parsing options. Partial regression for optp…
…arse

compatibility.
e4303dc
Stefano Sanfilippo Small functional adds (to reflect changes in the CmdLine module) 0ef7868
Stefano Sanfilippo Fixed small error in alternate Parser() implementation b2113c1
Stefano Sanfilippo Now default options are no more overridden in Option a0b637c
Stefano Sanfilippo Removed deprecated internal functions. 3bff312
Stefano Sanfilippo Corrected other lack in alternate implementation (optparse) ef7bbc5
Stefano Sanfilippo Turned c-style booleans (0 as False, 1 as True) into real python bools. bdd47a7
Stefano Sanfilippo Fixed bug in optparse's --embed recognition 27b72e4
Stefano Sanfilippo Replaced conditional import of argparse with a try: catch: block 10e0231
Stefano Sanfilippo Replaced failUnlessEqual with assertEqual wherever possible. 68a0277
Stefano Sanfilippo Adequated some tests to new CmdLine.py internals. 4a20f39
Stefano Sanfilippo Now dictionaries and lists belonging to Options are no more overridden. 411838a
Stefano Sanfilippo Added a HACK to prevent unwanted behaviour of --embed in some test ca…
…ses.
404451e
Stefano Sanfilippo Updated tests for Cython.Compiler.CmdLine 6f0f931
Stefano Sanfilippo Added secure list for options to insert into Options module (so that …
…no unwanted

change is applied if a duplicate - but indipendent - variable will be added)
60aec93
Stefano Sanfilippo Added cleanup code to avoid a long series of nasty errors. BIG TODO: …
…restructure

Options module.
990487f
Stefano Sanfilippo Modified optparse code to support variable length --embed flag 2f30832
Stefano Sanfilippo Removed a test case, added a remark in error messages. 6f121c9
Stefano Sanfilippo Added one more hack for optparse, now both versions passed all the te…
…sts.
e8be8a5
Stefano Sanfilippo Removed fake import to force optparse version 80564a3
Stefano Sanfilippo Modified debug flags syntax. b5d44cd
Stefano Sanfilippo Removed obsoleted code. 291df3b
Stefano Sanfilippo Updated copyright line. 6bfa85a
@esseks esseks commented on the diff Aug 11, 2011
Cython/Compiler/CmdLine.py
@@ -1,181 +1,293 @@
#
-# Cython - Command Line Parsing
+# Copyright 2005-2006 The Pyrex team
+# Copyright 2006-2011 The Cython team
+# Copyright 2011 Stefano Sanfilippo <satufk on GitHub>
@esseks
esseks Aug 11, 2011

Actually, I rewrote this file from scratches, but I've updated the copyright line to Pyrex&Cython team. This is because there is no Cython Foundation to enforce our rights.

Stefano Sanfilippo Fixing small typo. 0b9da27
@esseks

Ok, I figured out a small HACK for --embed... I'll sketch it as soon as I'm back, and I'll commit :)

@robertwb robertwb commented on the diff Aug 15, 2011
Cython/Compiler/CmdLine.py
@@ -1,181 +1,292 @@
#
-# Cython - Command Line Parsing
+# Copyright 2005-2006 The Pyrex team
@robertwb
robertwb Aug 15, 2011

Any change to the licensing wording should be discussed on the list, not slipped into an unrelated pull request such as this. The top-level license and copying files have been sufficient without the need for per-file boilerplate.

@robertwb

This seems to add a lot of complexity, e.g. spanning optparse/argparse, without any clear benefit (and perhaps a regression, or a lot of hackery, regarding --embed). Also, the current omission of certain flags in usage was intentional. The current setup works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment