8000 Drop Python 3.6, some Python 2 + Python <= 3.6 cleanup by wisp3rwind · Pull Request #4374 · beetbox/beets · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Drop Python 3.6, some Python 2 + Python <= 3.6 cleanup #4374

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

Merged
merged 17 commits into from
Feb 19, 2023

Conversation

wisp3rwind
Copy link
Member

Description

Fixes #4372; best reviewed commit-by-commit. Don't merge this just yet, I want to review the case_sensitive change again (please do so, too!).

@wisp3rwind wisp3rwind force-pushed the pr_drop_old_python branch 4 times, most recently from a4bd51b to acc2cf4 Compare June 15, 2022 10:35
@sampsyo sampsyo mentioned this pull request Jun 24, 2022
Copy link
Member
@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally had a chance to read though everything and think through it all! This is really helpful; it's wonderful to excise some of these old and sad workarounds. Here are a few scattered comments. I am pretty convinced of the case_sensitive changes in particular.

@wisp3rwind wisp3rwind force-pushed the pr_drop_old_python branch 7 times, most recently from 04760e4 to 1d06715 Compare September 25, 2022 15:49
@wisp3rwind wisp3rwind force-pushed the pr_drop_old_python branch 2 times, most recently from c9c4329 to f7871c6 Compare October 16, 2022 07:48
@wisp3rwind wisp3rwind force-pushed the pr_drop_old_python branch 6 times, most recently from 20f842c to 17f8479 Compare December 18, 2022 14:35
when symlinks aren't supported, recent python will only raise
NotImplementedError (or might even support symlinks), ending up in the
other except arm
These didn't match the code anymore (which had already been changes
manually or automatically as part of the 2->3 transition).
We still need these custom Logger modifications, but the precise
reasoning as given in the comments didn't quite apply anymore.
Also, `stack_info` and `stacklevel` arguments have been added in recent
Python, which we now support.
This was a helper for situations when Python 2 and 3 APIs returned bytes
and unicode, respectively. In these situation, we should nowadays know
which of the two we receive, so there's no need to wrap & hide the
`bytes.decode()` anymore (when it is still required).

Detailed justification:

beets/ui/__init__.py:
- command line options are always parsed to str

beets/ui/commands.py:
- confuse's config.dump always returns str
- open(...) defaults to text mode, read()ing str

beetsplug/keyfinder.py:
- ...

beetsplug/web/__init__.py:
- internally, paths are always bytestrings
- additionally, I took the liberty to slighlty re-arrange the code: it
  makes sense to split off the basename first, since we're only
  interested in the unicode conversion of that part.

test/helper.py:
- capture_stdout() gives a StringIO, which yields str

test/test_ui.py:
- self.io, from _common.TestCase, ultimately contains a
  _common.DummyOut, which appears to be dealing with str (cf.
  DummyOut.get)
@wisp3rwind wisp3rwind force-pushed the pr_drop_old_python branch 2 times, most recently from 6521789 to d24cf69 Compare December 24, 2022 12:23
- move tests for case_sensitive to test_util.py, since this is not
  really the concern of PathQueryTest
- removes part of the tests, since the tests that patch os.path.samefile
  and os.path.exists are super brittle since they test the
  implementation rather than the functionality of case_sensitive().
  This is a prepartory step for actually changing the implementation,
  which would otherwise break the tests in a confusing way...
@wisp3rwind wisp3rwind force-pushed the pr_drop_old_python branch 3 times, most recently from c2caa8e to 0a22e28 Compare December 24, 2022 15:13
- samefile exists on all platforms for recent python
- don't rely on monkey-patching os/os.path and on specifics on the
  implementation: as a result of doing so, the tests start failing in
  obscure ways as soon as the implementation (and its usage of
  os.path.exists and os.path.samefile) is changed
normpath already applies bytestring_path() to its output
- some cleanup for recent Python which has samefile() on Windows
- also, fix this function by only upper-/lower-casing one path component
  at a time. It is unclear to me how this could have ever worked.
@wisp3rwind
Copy link
Member Author

Ok, this should finally be ready to go: The case_sensitive refactor triggered test failures since 1) the tests were monkey-patching things in a very brittle way, 2) PathQuerys were actualyl incorrect due to inconsistent SQL and pure-Python matching. Those were a major hassle to debug; the fix is hopefully reasonably simple to understand. Would be happy about another pair of eyes on those changes.

(This PR is still best studied commit-by-commit, which are well-organized, whereas the scope of the entire PR has grown a lot...)

Copy link
Member
@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gone through this again commit by commit, and I've found nothing to be concerned about. I share your fears about some of the path-query stuff, which is really quite mind-bending at times (that case_sensitive function is an incredible pile of hacks unto itself).

This seems good to go! Care to hit the green button?

Comment on lines +99 to +100
if cls.force_implicit_query_detection:
return True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pretty good idea. It's a sort of ugly thing to need to do, but it's much less mysterious than the stdlib mocking we were resorting to before.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to d 8000 escribe this comment to others. Learn more.

Yeah, I don't really like this flag either, but at least it's obvious what's going on.

finally:
self.patcher_exists.start()
os.chdir(cur_dir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some very tricky stuff to get right! Very nice work here. It all looks right to me, though.

# lowercased.
# This also ensures that the `match()` method below and the SQL
# from `col_clause()` do the same thing.
path = path.lower()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, so we need to lower-case the entire normalized path: not just the part the user actually typed as the query pattern. This makes sense, and it is one of those situations where I now wonder how this ever worked before.

@wisp3rwind wisp3rwind merged commit 22ca6ef into beetbox:master Feb 19, 2023
@wisp3rwind wisp3rwind deleted the pr_drop_old_python branch February 19, 2023 09:19
@JOJ0
Copy link
Member
JOJ0 commented Feb 19, 2023

❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Drop Python 3.6
3 participants
0