Conversation
…nfig * 'master' of github.com:dbcli/cli_helpers: Pass CODECOV environment variable to tox. Do not trigger extra builds with codecov. Use CODECOV environment variable instead of TRAVIS. Fix markup format test. Fix kwargs in tabulate_adapter. Do coverage xml before uploading to codecov. Pass coverage file name to codecov. Coverage for tox tests Add coverage file to gitignore. Add -c argument to tox tests. Increase test coverage. Remove try/except that should never be hit. Test format_output() wrapper. Add coverage to changelog. Do not combine coverage. Add coverage badge. Do not count packages in coverage. Do not use parallel coverage. Fix codecov. Add codecov.
…nfig * 'master' of github.com:dbcli/cli_helpers: Test custom token names. Clarify skipif reason. Add test that tabulate handles ANSI escapes correctly. Remove missingval. Use override_missing_value for tabulate. Fix tox tests for noextras. Add styled output to changelog. Add style_output preprocessor. Add extra_requires for styles.
…nfig * 'master' of github.com:dbcli/cli_helpers: Update appveyor badge/link to be org project. Add appveyor to changelog. Add appveyor badge to readme. Upload appveyor coverage to codecov. Set PATH so it's easier to run things. Invoke pytest as a module. Use pytest, not py.test. Do not lint for windows tests. Add appveyor to check-manifest ignore. Add appveyor file.
…nfig * 'master' of github.com:dbcli/cli_helpers: (25 commits) Bump version for v0.2.0 release. Remove import decimal. Align floats as well. Test non-decimals in align_decimals function. Don't include number formatting by default. Reverse align_decimal changes. Add tests for is_number. Make align_decimals operate on strings. Use format_numbers for terminaltables and vertical table. Add format_numbers to changelog. Add format_numbers docstring. Use integer instead of decimal so it's not confusing. Remove unneeded "d". Add test for single format string. Add test for _get_type. Test full return values. Test that formatting doesn't happen without format strings/types. Remove u string prefix. Add docstrings. Move float and int types to compat.py. ...
This reverts commit 8f1b437.
…nfig * 'master' of github.com:dbcli/cli_helpers: Add unicode fix to change log. Test non-ascii on style output. Fix stringio and csv unicode problems. Add export to path variables. Set -ex together. Add mac tests to changelog. Remove extra install virtualenv. activate virtualenv before tox. Use virtualenv. Ignore .travis in manifest check. Add osx tests. Don't use venv. Use travis install script. Add install script for travis to use.
…nfig * 'master' of github.com:dbcli/cli_helpers: (21 commits) Bump version to 0.2.3. Do not add extra adapter in test. Pass column_types on unmodified. Unpack format_numbers result before testing assertion. fixup! fixes to accept iterator fixup! fixes to accept iterator fixup! fixes to accept iterator fixup! fixes to accept iterator fixup! fixes to accept iterator fixup! fixes to accept iterator fixup! fixes to accept iterator Add unicode error Python 2 fix to changelog. Add non-ascii text to newline test. Use compat module for StringIO. Add styling test with newlines in it. Bump version to v0.2.2. Add uneven row fix to changelog. Use itertools to get column types. fixup! fixes to accept iterator fixes to accept iterator ...
…nfig * 'master' of github.com:dbcli/cli_helpers: Do not test travis macos py27. Copy unit test from pgcli Releasing version v1.0.1. Update changelog for v1.0.1 release. Output all unicode for terminaltables, add unit test Release version 1.0.0 Bump changelog version to v1.0.0 Remove tasks entry points. fixup! Drop Python 3.3. Use backports.csv only for py2 Drop Python 3.3. Update changelog for tabulate. Remove vendored tabulate module. Use tabulate from PyPI. Output as generator
|
Hi Thomas, it looks all good, I'd like to know why you've chosen to split the code the way you did.
This would certainly improve readability, but if you already know all of these functions will directly used from mycli/pgcli/mssql-cli we should keep them (of course) seperate. |
|
@meeuw Thanks for the helpful feedback! I appreciate the good questions. I personally prefer a maximum of two-to-three levels deep of conditional/loop indentation in functions, with large blocks of code within loops being split into functions, which is why some of that is broken out the way it is. I feel like it's easier to read indented code blocks when they are put in named functions. I think some of the ones you mentioned make sense to merge. I'll try to rework these a bit so it's not as spread out:
The other short file-based ones ( Ultimately, my goal in this API was two-fold:
So, for number 1, we end up with one client-facing method that is the primary way to load the configuration -- For number 2, I tried to make it so client applications wouldn't have to replicate a whole lot of the logic if they want to override different portions of the config reading/writing:
|
|
Why not use https://github.com/ActiveState/appdirs to obtain the relevant directory paths when that is desired by the caller? As Windows has so many changes to their dirs, you are begging for support problems by reimplementing this. If |
|
@jayvdb I believe the original reason was, we wanted a standard place to put our config files so we can tell users to go to a specific location on their computer and edit the config file.
|
|
Ya, I guessed that, but you can use It leads to better behaviour on flavours of Unix which you dont want to even know about, but their users are rather finicky about how apps work ;-) |
|
The same reason applies to the Unix folks as well. We want our config files in a specific place so we can easily guide people there. We try to respect the standards wherever possible, for example, the config file used to go in the home folder ~/.pgclirc. We changed that to ~/.config/pgcli/config when we realized that it is disrespectful to litter the user's home folder. But we're trying to balance correctness and convenience. This is the best compromise we came up with, if you have examples of this being insufficient, I'm happy to consider it. |
|
Another specific use case is for macOS. In my experience, CLI apps users on Mac expect the config to behave like Linux (i.e. XDG). But, |
…nfig * 'master' of github.com:dbcli/cli_helpers: Releasing version 1.0.2. Move strip_ansi from tests.utils to cli_helpers.utils Fix pep8 issue in build. use safe float (2578310786669609 / pow(2, 50) == 2.29)
Codecov Report
@@ Coverage Diff @@
## master #39 +/- ##
======================================
Coverage 100% 100%
======================================
Files 10 11 +1
Lines 280 395 +115
======================================
+ Hits 280 395 +115
Continue to review full report at Codecov.
|
|
@meeuw Okay, I've combined some of the functions together to make the logic more readable. Thanks! I've kept some of them separate because I do think it will be helpful as a general-use API so that people can override the various behaviors as they need to. |
|
Can we merge this PR and release a new version? |
Description
Adds config file reading. Client applications do not need to worry about where the config files are stored (unless they want to). Client applications can trust that the config files will be read safely and validated for the correct types/options. Booleans are booleans, integers are integers, etc.
A few notes:
Current documentation for this: http://cli-helpers.readthedocs.io/en/feature-config/api.html#module-cli_helpers.config
NOTE: more documentation is being worked on for this.
The Simplest Use Case
Here is the simplest use case, with no default config and no custom file locations:
A Pretty Simple Use Case
Default config file:
Client code:
In that case, the log level is guaranteed to be a valid option and it defaults to
'INFO'.Default Config Values
Default values can be specified as a
dictor as a path to a config file.Checklist
CHANGELOG.AUTHORSfile (or it's already there).