-
Notifications
You must be signed in to change notification settings - Fork 506
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
ConfigParser code should be separated #1636
Comments
FYI, in addition here are a couple of buildozer.spec parser issues that result in non-deterministic behavior, and trip up users:
|
Thanks, @RobertFlatt. Knowing about existing minefields helps me not repeat mistakes.
I agree that could be confusing. It is a general rule in ConfigParser's "ini" files. I don't propose to change it.
That's not always true. Is there some special case where it is true?
Ahhh. I see. If someone starts a second option indented deeper than the first option, it will be treated as a multiline option. I agree that could be confusing. Again, this is part of the standard ConfigParser formatting, and I don't propose to change it. I added a test case to my prototype code in an effort to make sure I have understood your concerns, and show how I expect the result to work. I hope it is clarifying:
I haven't shown here the special case, only used in Android's log filtering option, in which the lists are not trimmed of whitespace. [No idea why.] Given you have identified two confusing cases which are general .ini file issues, not Buildozer-specific, I propose we modify the default.spec to warn people about them. (I'd suggest some short comment at the top saying there are some hints at the bottom, and a longer comment at the bottom warning users about these pitfalls.) |
Thanks @Julian-O The original choice of a config parser for a user's first encounter with Buildozer was a poor one, nothing practical to be done about that. Config parser does indeed not have good error checking, but in any viable software a human's input must be error checked. Specially in the case where parse errors do not necessarily mean build errors, and usually mean strange run time errors. I understand you view additional functionality as mission creep, but the technical term for tidying stuff up without fixing the issues is I believe turd polishing. |
Just to the last point, this is getting off-topic (we can take it to Discord if you like), but here are my motivations: I want to make some significant changes to the Buildozer class, but it currently is way too large and has too many responsibilities. It is hard to understand, hard to unit test and thus hard to safely change. I just had a PR merged which takes the responsibility for logging out of the Buildozer class and puts it in a separate file. I wish the logging was done using the standard Python logging module rather than from scratch. I spent a lot of effort on Kivy a year ago making it work better with the standard Python logging module, but I had a stronger motivation because it was wreaking havoc with my libraries that were being included. I don't plan a similar effort on Buildozer, but if someone wants to do it, it is all in one place now. I plan to do another PR for this issue which takes the responsibility for parsing out of the Buildozer class and puts it in a separate file. If someone wants to tackle the issues you describe, they will be easier and self-contained. I plan to do another PR which takes the responsibility for the low-level operations (file renames, directory deletions, running commands, etc.) out of the Buildozer class and put them in a separate file. This is where I want to spend my effort, because then I can make them platform independent. That will bring us one small step closer to making Buildozer be able to build Android binaries on native Windows. (Yes, much more effort will be required to enable pythonforandroid to work, but baby steps...) So, yes, I am tidying stuff up without fixing the issues, but that is because (a) my eyes are on a different prize, and I need it out of my way, and (b) I think my efforts to focus on Windows (with a cost in reviewer time and risk of bugs) will be more palatable to the non-Windows developers if I tidy up the common code as I go. I genuinely think that, if someone does want to replace the parser, then my work to get rid of the existing monkeypatching, move the code to a separate file, remove the duplicate implementations and provide some unit-testing for reassurance that the refactoring doesn't break things is a useful first step. |
Separate ConfigParser code from Buildozer. - Use subclass, rather than monkey-patching. - Single implementation of list-handling code. - Convenience functions to minimise impact of existing code (but instantly deprecated). - Treat defaults consistently - Apply the env overrides automatically (client doesn't need to trigger). - Apply the env overrides once (read-time) rather than on every get. - Avoid re-using term "raw" which has pre-existing definition in ConfigSpec. - Update android.py client to match, - Unit tests. Add comments to start and end of default.spec to explain the syntax (as discussed in kivy#1636)
Separate ConfigParser code from Buildozer. - Use subclass, rather than monkey-patching. - Single implementation of list-handling code. - Convenience functions to minimise impact of existing code (but instantly deprecated). - Treat defaults consistently - Apply the env overrides automatically (client doesn't need to trigger). - Apply the env overrides once (read-time) rather than on every get. - Avoid re-using term "raw" which has pre-existing definition in ConfigSpec. - Update android.py client to match, - Unit tests. Add comments to start and end of default.spec to explain the syntax (as discussed in kivy#1636)
* Separate ConfigSpec parser (Address #1636) Separate ConfigParser code from Buildozer. - Use subclass, rather than monkey-patching. - Single implementation of list-handling code. - Convenience functions to minimise impact of existing code (but instantly deprecated). - Treat defaults consistently - Apply the env overrides automatically (client doesn't need to trigger). - Apply the env overrides once (read-time) rather than on every get. - Avoid re-using term "raw" which has pre-existing definition in ConfigSpec. - Update android.py client to match, - Unit tests. Add comments to start and end of default.spec to explain the syntax (as discussed in #1636) * Add profile handling to configparser Move it from Buildozer. Rename it to be more meaningful. Add support for whitespace trimming. Update documentation in default.spec. Update tests.
Fixed via #1639 |
Versions
Description
[I am preparing a PR for this, but it is blocked by other higher-priority ones, so I am documenting the plan as a placeholder.]
The Buildozer class has a
config
object that is used by itself and the targets. It is a variant of the Python-standardConfigParser
, that supports case-sensitivity, lists and env variable overrides.It has a number of minor issues:
Buildozer
class too complex; should be split. #1629)Proposal
In a separate file (
specparser.py
), define SpecParser, a subclass of ConfigParser.Implement a single
getlist
method with parameters to support defaults (returned as is), fetching "values", stripping, section separators and split characters.Add convenience functions that map existing calls to getlist/get/getboolean with appropriate parameters. Deprecate them, because they are unnecessary.
Apply the env var overrides automatically, after the text is read and parsed, before it is accessed. (Note: This means changes to the environment variables while Buildozer is running won't take effect on the config - but I haven't found any examples of that. One could just set the config option directly in these cases.)
Remove the term "raw".
Retain case-sensitivity until it can be shown to be unnecessary.
Write unit-tests.
Update Buildozer class to instantiate the new class rather than ConfigParser. Remove all the monkey patching and the now unnecessary call to set env var overrides.
Update android.py to use getlist with appropriate params rather than the "raw" function.
The text was updated successfully, but these errors were encountered: