| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
| date = line.removeprefix("Created:").strip() | ||
| try: | ||
| # Validate | ||
| dt.strptime(date, "%d-%b-%Y") |
There was a problem hiding this comment.
The "%d-%b-%Y" format depends on the current locale; it might be different across machines.
Sorry, something went wrong.
There was a problem hiding this comment.
Ah right, your suggestion at #1805 (comment) for something like %Y-%m-%d (2021-02-08) would help with this.
Sorry, something went wrong.
Great! That saves me a lot of work :) Rerunning on the top of that branch, everything validates except for: $ make lint
pre-commit --version > /dev/null || python3 -m pip install pre-commit
pre-commit run --all-files
rst ``code`` is two backticks............................................Passed
rst ``inline code`` next to normal text..................................Passed
Lint Created: dates......................................................Failed
- hook id: validate-created
- exit code: 1
pep-0102.txt:11:8: unconverted data remains: (edited down on 9-Jan-2002 to become PEP 102)
make: *** [lint] Error 1From: Line 11 in 604b513 Should this line be changed to pass the current validation, or the validation changed to accept this? |
Sorry, something went wrong.
There was a problem hiding this comment.
Hey, happened to see this PR and wanted to make sure it wasn't affected by pre-commit/pygrep-hooks#51 . Its not, but I did notice something else:
- uses: pre-commit/action@v2.0.0
with:
extra_args: --all-files --hook-stage manualAlso, as you might already be aware, language: script, entry: ./scripts/validate-created.py and a shebang and executable mode on the script is the nominal way to call scripts like this with pre-commit, but AFAIK there's isn't much of a practical difference doing it like this instead.
Sorry, something went wrong.
|
Thanks for checking! Python 3.9: I've pushed an update which allows #1809 (comment) to validate and also drops removeprefix so we have Python 3.6+ compatibility. Windows: good point, although we have a possibly related issue to decide on about locale: #1809 (comment). CI + local: my intention was to run both on CI and locally, and it currently does so. But if we decide only to run this check on Linux then your suggestions about running on only CI may help. (Possibly hoisting the check out of pre-commit.) |
Sorry, something went wrong.
|
Sure! I did notice that the older PEPs with the txt extension won't be linted by the rst checkers, but I assume that they are unlikely enough to be modified that adding a regex to files to match them wasn't seen as worthwhile (and neither this PR nor mine affects that). Python 3.9: Sounds good! Locale: IMO, I would strongly support a standard, locale-independent format that's unambiguous and easy to parse by both programs and programmers, i.e. ISO 8601/RFC 3339 (`%Y-%m-%d/YYYY-MM-DD). Particularly in this case, it seems a bit unnecessary to require anyone running the script to set their locale to English or get incorrect results. But that's just my personal opinion, its ultimately up to you all and I'm happy to help with whatever you decide. CI: Yeah, ideal to run them on both; I have some ideas to resolve the cross-platform compat issue without having to make it CI-only. If you do that, I'd suggest just confining it to the manual hook-stage; less work and less bespoke code, plus nicer UX. Windows: Yup, that comes back to the perennial issue that there's no reliable cross-platform way to invoke Python that works across Windows, *nix, venvs and conda; I recall reading yet another thread on that on Python-dev lately. In this case, we know a Python environment must be accessible (because Pre-Commit itself is running in it), but we don't know whether it is exposed at python, python3 or both, and a shell wrapper script with a fallback won't work since bash might not be available either (on Windows without Git bash, cygwin, etc). language: python takes care of everything but requires the target hook to be a Python package, which doesn't really make sense for a bespoke script (which is the purpose of local hooks). Maybe we can ask Anthony if he would accept a PR adding a python-script language that behaved like script, but executed the script using the same interpreter path as Pre-Commit itself, i,e, its own sys.executable? Or maybe there is some better way that projects shipping such scripts as local hooks handle this (I'm not immediately aware of any)? However, in this case you should be able to get away with a pygrep regex to do the validation almost as well as a bespoke script; that would run a lot faster and be a lot simpler, and would use pre-commit's own interpreter, avoiding the above issue. The following regex will match any Created: DD-mmm-YYYY that begins a line and is within the first 20 lines of the file, in the appropriate format, that is a valid date between 1990 and 2100; it will match either dates along or dates with an arbitrary parenthetical after them: ^(.*\n){1,20}Created: ([0-2][0-9]|(3[01]))-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(199[0-9]|20[0-9][0-9])( \(|\n)Here's the equivalent in YYYY-MM-DD: ^(.*\n){1,20}Created: ((199[0-9]|20[0-9][0-9])-(0[0-9]|1[0-2])-[0-2][0-9]|(3[01]))( \(|\n) |
Sorry, something went wrong.
|
I like the current format. I find it unambiguous and easier to read than
2021-03-12.--
--Guido (mobile)
|
Sorry, something went wrong.
|
Yeah, it is unambiguous and easy enough read since it includes %b, so no reason to change it on that grounds. The practical issue is that %b is locale-dependent, so any tools reading (or writing) it will break if they don't happen to be run in an English locale. Specifically, if this PR is commited as-is, make lint, pre-commit run --all-files and the pre-commit hook itself will all start failing locally for users unless they happen to have their locale set to English. However, either of my suggestions above (making it a pygrep hook or only running it on CI) will fix that issue for this PR without having to change the current format, as was previously proposed. |
Sorry, something went wrong.
|
Right, so we keep the existing format. @CAM-Gerlach I agree, makes sense to unhitch this at least the local pre-commit, maybe even move it outside pre-commit to run on CI. Sounds like you have some solid ideas and I'm a little swamped at the moment, would you like to come up with something? Feel free to take anything from this PR or start fresh, and either update my fork branch or just submit a new PR. Thank you! |
Sorry, something went wrong.
|
any tools reading (or writing) it will break if they don't happen to be
run in an English local
IMO the PEP format is pretty specialized and requires specialized tools, so
it behooves the authors of those tools not to depend on the user's locale.
|
Sorry, something went wrong.
|
Sorry for the delay; it was a busy week with other things. @hugovk Sure, I ended up just starting fresh with creating a simple pygrep hook as proposed above, as well as addressing a few related issues. I'll open a PR momentarily, thanks. @gvanrossum Right; as mentioned the solutions above and in the followup PR avoids locale dependence completely and doesn't require changing the existing format. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes #1803.
Also added to the make lint.
As we can see, 87 currently don't validate:
I'll fix them and update the PR.