-
Notifications
You must be signed in to change notification settings - Fork 9
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
Added linters and pre-commit hooks #36
base: master
Are you sure you want to change the base?
Conversation
Thanks for PR .. why flake8? .. Thought we will use pylint #27 (reply in thread) .. to run tests locally we need a solution like running-tests ? |
This is great, thank you! Also, have a look at https://github.com/da4089/vobject/tree/dev-flake8, where I've been working on similar area. Also, we need to ensure that the resulting code is compatible with Python 2.7 for the 0.9.x releases still. I think I've managed to retain that, but I notice your comment that this is Python3.7+ only? |
I've been experimenting in my branch with using both, TBH. pylint seems to warn about a lot more stuff than flake8, but maybe both is ok? I still haven't got to a point of producing useful reporting artifacts from any of these either. |
I think the best solution for local execution is to put the configuration into
and then try to make sure the config options in pyproject.toml are universally useful. See the branch above for my first draft attempt at this. |
@@ -689,13 +700,13 @@ def __str__(self): | |||
if self.name: | |||
return "<{0}| {1}>".format(self.name, self.getSortedChildren()) | |||
else: | |||
return u'<*unnamed*| {0}>'.format(self.getSortedChildren()) | |||
return "<*unnamed*| {0}>".format(self.getSortedChildren()) |
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.
Python 2.x issue
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.
black did this, will check
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 think we'll need to use a Black version that supports a target of py27. Which I think means 21.12b0 (I've tried pinning that and it seems to work).
I haven't yet compared the output side-by-side with this PR.
@@ -12,7 +12,7 @@ | |||
DTSTART:20051005 | |||
DTEND:20051008 | |||
SUMMARY:Web 2.0 Conference | |||
LOCATION:Argent Hotel\, San Francisco\, CA | |||
LOCATION:Argent Hotel, San Francisco, CA |
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 think the correct fix here is to use a raw string, and preserve the "\," which are correct iCalendar syntax?
|
||
# DTSTART | ||
dtstart = event.getChildValue("dtstart") | ||
if dtstart: | ||
if type(dtstart) == date: | ||
if type(dtstart) is date: |
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 replaced these with
isinstance(dtstart, date)
which I like better, because it allows the use of a derived type if you want/need to do that for some reason.
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.
Due to this reason, type
is a simpler way as it doesn't depend on the order of if/else
. Using isinstance
will require reordering the code in all conditions and make sure it stays likewise in future. (maintainability issue)
Ideally, there shouldn't be so many type/instance checks. So, I kept the logic as it is (to refactor later) and cleared linting error only.
LGTM at first sight .. give me some more time ..
Is it compatible with 2.7?
Doc should include instructions to build up a virtualenv / otherwise the local test runs and package versions are highly dependent on the individual Python setup of the developer.
Not sure I fully understand what you mean by / what you expect .. can you explain it to me in more detail? I hope I have time next weekend to implement a PR that demonstrates what I have in mind .. |
I've pushed a change to my https://github.com/da4089/vobject/tree/dev-flake8 branch that:
I think we should be able to safely use this on the 0.9.x code without it breaking stuff like u"foo" strings. |
|
|
Thinking ... maybe I should create a branch off master and we can merge this PR into that, and my branch over that, and then sort of any remaining issues before merging the whole lot into master. Does that sound ok to you? |
@da4089 I lost the overview about the python releases you want support .. In the commit 992b8b70@dev-lint you targeting Python2.7 .. .. but in github CI we test starting with py3.7: vobject/.github/workflows/test.yml Line 8 in 8f72c86
Do you plan to add new branch later (after we merged linted code)? A branch for the 0.9.x releases? |
@rsb-23 I'm new to pre-commit but it looks interesting .. one thing I miss: we can't combine the linting test/tools (from pre-commit) with other tests needed to be run locally before create a commit / e.g the unit tests (see python tests.py) .. or is there a chance to add unit and other tests from the project to the |
I would like 0.9.x to continue to support 2.7. I wanted to do some cleanup before splitting, so it's easier to to share patches across the two branches. master will become 1.0 and support Python 3 only. I'd like to make the split pretty soon. |
I'm new to pre-commit too. I don't have a full understanding of what's possible yet. |
OK now I got you :) .. but then I think we should first go a step back ... vobject/.github/workflows/test.yml Line 8 in 8f72c86
and add back the py2.7 to the github CI. Second we need a way to test code in py2.7 locally (I have https://asdf-vm.com/ in mind). Reasons why we need to test Py 2.7 (before branching):
The good news: we only need the code changes before we split a 0.9.x branch ... there is no need to run lint tools in the 0.9.x: if we only transfer patches to the 0.9.x branch from the master, then we don't necessarily need a lint tool in the 0.9.x branch (further I expect that a 0.9.x branch will die soon).
This is the second point that makes me ponder: in the dev-lint branch we now have 3 different test & lint approaches / tools
The decision for or against pre-commit hooks should not be made before the 0.9.3 branch point has been created. In py2.7 this tool will probably not work. Furthermore, the decision should be carefully considered. The method of hooking the tests into the (git) pre-commit hooks is discussed controversial: https://www.reddit.com/r/git/comments/16ke0xa/arguments_for_and_against_precommit_hooks/ |
The tools don't run in Python 2.7. I tried in a venv without success. |
@return42 Thanks for all the details, I would have shared the same.
My setup idea:
|
@da4089 About code-cleanup: the source files in this project are using CRLF ( Be warned: The switch to LF will touch ever single file / conflict with all forks and branches. |
We should switch the repo to LF, and those working on Windows should use the automagic LF/CRLF translation built into git.
Perhaps you could create a GitHub issue for this, and we'll pick a good moment to do it when all branches are merged? |
One other approach might be to create the 0.9.x branch soon (more or less now). The changes resulting from eg. black, and fixes to lint-identified issues should then be applied first to the 0.9.x branch, and then merged to master. We could leave 0.9.x branch using setup.py, without pre-commit, and maybe just running the unit tests. master could get the pyproject.toml migration, pre-commit, and all the automation. It's more work to merge all the formatting, etc, changes through both branches, but the tooling setup might be better this way? |
OK ..
give me a little more time / I'm currently working on a commit line (thats why I ask al thes questions :) .. hopefully tomorrow I can present you a way that fulfill all your request :)
I have to correct .. only some files have CRLF .. |
We can add this hook. And can also add this to CI for PR too.
|
it's more than I expected / I'm still working on it ... there's a preview available in a PR I created in my fork for testing purposes. |
- lint changes by tools
@rsb-23, can we revisit this now that we have separate 0.9 and 1.0 branches? I think we're good now to add to |
Checks :
Changes :
isort, black, flake8
linters.TODO
andnoqa
for other cases.xrange
withrange
function in win32tz.py🙏🏼 Changes are mostly double quotes, whitespace, indentation and sort order. Apologies, as its too many changes in single PR.