-
Notifications
You must be signed in to change notification settings - Fork 1
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
113 add markdown to descriptions #118
Conversation
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
"When 'action taken' equals 3 (denied), 4 (withdrawn by applicant), or 5 (incomplete), the following fields must all equal 999 (not applicable):\n" | ||
"* 'Interest rate type'\n" | ||
"* 'MCA/sales-based: additional cost for merchant cash advances or other sales-based financing: NA flag'\n" | ||
"* 'Prepayment penalty could be imposed'\n" | ||
"* 'Prepayment penalty exists'\n\n" | ||
"And the following fields must all be blank:\n\n" | ||
"* 'Total origination charges'\n" | ||
"* 'Amount of total broker fees'\n" | ||
"* 'Initial annual charges'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For these long ones, or maybe just any that aren't one-liners, it might be cleaner to use Python's multiline string, with textwrap.dedent
. You'd end up with something like:
from textwrap import dedent
...
description="""\
When 'action taken' equals 3 (denied), 4 (withdrawn by applicant), or 5 (incomplete), the following fields must all equal 999 (not applicable):
* 'Interest rate type'
* 'MCA/sales-based: additional cost for merchant cash advances or other sales-based financing: NA flag'
* 'Prepayment penalty could be imposed'
* 'Prepayment penalty exists'
And the following fields must all be blank:
* 'Total origination charges'
* 'Amount of total broker fees'
* 'Initial annual charges'
```.dedent()
With this model, you can pretty much copy/paste the markdown and not have to worry about all the quotes and \n
and that fun.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah cool was not familiar with dedent. Just read the api and yeah that would make this code prettier. I'll give that a go. Will possibly need to redo the csv depending on how it spits out stuff but it should match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jcadam14, how are you feeling about all this? Having the multiline strings seems like a bit of an improvement, but it does look a little odd still, and it seems like it's had implications for the CSV file (cfpb/sbl-content#22 (review)). Do you think we should keep it, or revert back to what you had before?
Looks like there are still quite a few descriptions in the old form. If we decide to keep the multiline, we should probably make 'em all like that.
description=dedent( | ||
"""\ | ||
* When 'credit product' does **not** equal 977 (other), 'free-form text field for other credit products' must be blank. | ||
* When 'credit product' equals 977, 'free-form text field for other credit products' must **not** be blank. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did black
format it this way, with the offset """
s?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup
"* 'Credit purpose' and 'free-form text field for other credit " | ||
"purpose' combined should **not** contain more than three values. " | ||
"Code 977 (other), within 'credit purpose', does **not** count " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is still the non-dedent
flavor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only used dedent on descriptions with actual multiple lines, the \n's. This is a single line description, but split into multiple strings for readability.
* When 'interest rate type' does **not** equal 3 (initial rate period > 12 months, adjustable interest), \ | ||
4 (initial rate period > 12 months, fixed interest), 5 (initial rate period <= 12 months, adjustable interest), \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be valid Markdown without the trailing \
. Is that needed to keep in sync with the CSV?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The \ are there to break the string up in the python file so you don't get a single line that looks like "* When 'interest rate type' does not equal 3 (initial rate period > 12 months, adjustable interest), 4 (initial rate period > 12 months, fixed interest), 5 (initial rate period <= 12 months, adjustable interest)..." and runs off the page in the IDE.
Which technically should break our linting but black has issues with long string reformatting.
Most descriptions are actually one single line/string, but they're broken up in the python file for readability. Need to make a distinction there. The ones that are actually multiline descriptions have been dedented. Honestly, the python looks cleaner, but the output to the csv and markdown (before being rendered) is uglier. Depends on if someone using the csv at some point wants a bunch of \n's. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. Found a little clump with leftover "
s. Founds similar artifacts over in PR cfpb/sbl-content#22 too. I think just the one little fixup and we're good. Thanks for slogging through all this.
@@ -36,7 +13,7 @@ def test_csv_differences(self): | |||
] | |||
|
|||
csv_df = pd.read_csv( | |||
"https://raw.githubusercontent.com/cfpb/sbl-content/main/fig-files/validation-spec/2024-validations.csv" | |||
"https://raw.githubusercontent.com/cfpb/sbl-content/21-update-descriptions-for-markdown/fig-files/validation-spec/2024-validations.csv" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming we'll merge PR cfpb/sbl-content#22 first.
"https://raw.githubusercontent.com/cfpb/sbl-content/21-update-descriptions-for-markdown/fig-files/validation-spec/2024-validations.csv" | |
"https://raw.githubusercontent.com/cfpb/sbl-content/main/fig-files/validation-spec/2024-validations.csv" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch thank you. After I updated I went through each to check for just this but your eyes start to cross after awhile!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. No doubt. 😄
Closes #113 - Updated phase_validations to include markdown based on wagtail descriptions https://www.consumerfinance.gov/data-research/small-business-lending/filing-instructions-guide/2024-guide/#4 - Updated pytest to be much simpler as it now just needs to do a direct description comparison instead of reformatting due to csv formatting.
Closes #113
Note, currently the pytest is pointing to the raw csv on the branch for cfpb/sbl-content#21. Once those changes are merged in, the pytest can be pointed back to main. So the approval of this PR can wait until that other issue is merged and then I'll reupdate the pytests for final approval.