Page MenuHomePhabricator

[lint] replace flynt linter with ruff
ClosedPublic

Authored by PiRK on Mon, Nov 10, 09:07.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABC3e7747330203: [lint] replace flynt linter with ruff
Summary

Another dependency dropped, another small gain in performance

For this diff we still don't apply these rules to the Electrum ABC codebase. But now we have the option to apply them incrementally, whereas flynt was a "all or nothing" tool.
Depends on D18907

Test Plan

ninja all check-all
arc lint --everything

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

contrib/buildbot/server.py
979–981 ↗(On Diff #56538)

I manually split this one into 3 lines because the linter wanter to remove the parentheses and make it a single line

contrib/devtools/chainparams/test_make_chainparams.py
204–206 ↗(On Diff #56538)

I manually edited the ones in this file to avoid a weird f-string with string literals.

Tail of the build log:

Build 'Bitcoin ABC Diffs / Diff Testing' #103266, branch 'refs/tags/phabricator/diff/56538'
Triggered 2025-11-10 09:07:18 by 'Phabricator Staging (phabricator-staging)'
Started 2025-11-10 09:28:36 on agent 'buildagent5'
Finished 2025-11-10 09:28:36 with status FAILURE 'Unable to collect changes'
VCS revisions: 'BitcoinABC_BitcoinAbcStaging' (Git, instance id 22): 'N/A' (checkout rules: '+:. => ./bitcoin-abc')
TeamCity URL https://build.bitcoinabc.org/buildConfiguration/BitcoinABC_BitcoinAbcStaging/1011574 
TeamCity server version is 2025.03.1 (build 186125), server timezone: GMT (UTC)

[09:07:18]E: bt15 (21m:17s)
[09:07:18]i: TeamCity server version is 2025.03.1 (build 186125)
[09:07:18] : Finalize build settings
[09:07:18] : Collecting changes in 2 VCS roots
[09:07:18] :	 [Collecting changes in 2 VCS roots] VCS Root details
[09:07:18] :		 [VCS Root details] "Bitcoin ABC Staging" {instance id=22, parent internal id=3, parent id=BitcoinABC_BitcoinAbcStaging, description: "ssh://vcs@reviews.bitcoinabc.org:2221/source/bitcoin-abc-staging.git#refs/heads/master"}
[09:07:18] :		 [VCS Root details] "abc-infrastructure" {instance id=24, parent internal id=7, parent id=AutomatedDeployments_BitcoinAbcDeveloperTools_AbcInfrastructure, description: "ssh://vcs@reviews.bitcoinabc.org:2221/source/infrastructure.git#refs/heads/master"}
[09:07:18]i: Loading current repository state for VCS root 'Bitcoin ABC Staging' (running for 21m:17s)
[09:07:18]i:	 [Loading current repository state for VCS root 'Bitcoin ABC Staging'] VCS root 'Bitcoin ABC Staging': git -c credential.helper= -c credential.helper=/opt/teamcity/temp/credHelper10825238893472853511.sh ls-remote origin
[09:07:18]i:	 [Loading current repository state for VCS root 'Bitcoin ABC Staging'] VCS root 'Bitcoin ABC Staging': Warning: Permanently added '[reviews.bitcoinabc.org]:2221' (ED25519) to the list of known hosts.
[09:07:18]i:	 [Loading current repository state for VCS root 'Bitcoin ABC Staging'] Loading current repository state for VCS root 'abc-infrastructure' (running for 21m:17s)
[09:07:18]i:		 [Loading current repository state for VCS root 'abc-infrastructure'] VCS root 'abc-infrastructure': git -c credential.helper= -c credential.helper=/opt/teamcity/temp/credHelper10897947908242667714.sh ls-remote origin
[09:07:18]i:		 [Loading current repository state for VCS root 'abc-infrastructure'] VCS root 'abc-infrastructure': Warning: Permanently added '[reviews.bitcoinabc.org]:2221' (ED25519) to the list of known hosts.
[09:07:19]i:		 [Loading current repository state for VCS root 'abc-infrastructure'] VCS root 'Bitcoin ABC Staging': phabricator-ssh-exec: Unable to establish a connection to any database host (while trying "reviews_bitcoinabc_user"). All masters and replicas are completely unreachable.
[09:07:19]i:		 [Loading current repository state for VCS root 'abc-infrastructure'] VCS root 'Bitcoin ABC Staging': 
[09:07:19]i:		 [Loading current repository state for VCS root 'abc-infrastructure'] VCS root 'Bitcoin ABC Staging': AphrontConnectionQueryException: Attempt to connect to phabricator@127.0.0.1 failed with error #1040: Too many connections.
[09:07:19]i:		 [Loading current repository state for VCS root 'abc-infrastructure'] VCS root 'Bitcoin ABC Staging': fatal: Could not read from remote repository.
[09:07:19]i:		 [Loading current repository state for VCS root 'abc-infrastructure'] VCS root 'Bitcoin ABC Staging': 
[09:07:19]i:		 [Loading current repository state for VCS root 'abc-infrastructure'] VCS root 'Bitcoin ABC Staging': Please make sure you have the correct access rights
[09:07:19]i:		 [Loading current repository state for VCS root 'abc-infrastructure'] VCS root 'Bitcoin ABC Staging': and the repository exists.
[09:07:19]i:		 [Loading current repository state for VCS root 'abc-infrastructure'] Detecting changes in VCS root 'abc-infrastructure' (used in 'Bitcoin-ABC Infra Checkout', 'Extract Electrum ABC from ABC' and 5 other configurations)
[09:07:19]i:		 [Loading current repository state for VCS root 'abc-infrastructure'] Will collect changes for 'abc-infrastructure' starting from revision 602c7e2af027bb16cc6a4fc5a25601e8c853be5e
[09:07:19] : Compute revision for 'abc-infrastructure' in Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout
[09:07:19] :	 [Compute revision for 'abc-infrastructure' in Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout] Upper limit revision: 602c7e2af027bb16cc6a4fc5a25601e8c853be5e
[09:07:19]i:	 [Compute revision for 'abc-infrastructure' in Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout] MaxModId = 83296
[09:07:19] :	 [Compute revision for 'abc-infrastructure' in Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout] Computed revision: 602c7e2af027bb16cc6a4fc5a25601e8c853be5e
[09:28:36] : The build is removed from the queue to be prepared for the start
[09:28:36]E: Failed to collect changes, error: git -c credential.helper= -c credential.helper=/opt/teamcity/temp/credHelper10825238893472853511.sh ls-remote origin command failed.
exit code: 128
stderr: Warning: Permanently added '[reviews.bitcoinabc.org]:2221' (ED25519) to the list of known hosts.
phabricator-ssh-exec: Unable to establish a connection to any database host (while trying "reviews_bitcoinabc_user"). All masters and replicas are completely unreachable.

AphrontConnectionQueryException: Attempt to connect to phabricator@127.0.0.1 failed with error #1040: Too many connections.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists., VCS root: "Bitcoin ABC Staging" {instance id=22, parent internal id=3, parent id=BitcoinABC_BitcoinAbcStaging, description: "ssh://vcs@reviews.bitcoinabc.org:2221/source/bitcoin-abc-staging.git#refs/heads/master"}
[09:28:36]E: Failed to collect changes, error: git -c credential.helper= -c credential.helper=/opt/teamcity/temp/credHelper10825238893472853511.sh ls-remote origin command failed.
exit code: 128
stderr: Warning: Permanently added '[reviews.bitcoinabc.org]:2221' (ED25519) to the list of known hosts.
phabricator-ssh-exec: Unable to establish a connection to any database host (while trying "reviews_bitcoinabc_user"). All masters and replicas are completely unreachable.

AphrontConnectionQueryException: Attempt to connect to phabricator@127.0.0.1 failed with error #1040: Too many connections.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists., VCS root: "Bitcoin ABC Staging" {instance id=22, parent internal id=3, parent id=BitcoinABC_BitcoinAbcStaging, description: "ssh://vcs@reviews.bitcoinabc.org:2221/source/bitcoin-abc-staging.git#refs/heads/master"}
[09:28:36] : Build finished

Failed tests logs:

====== test_endpoint_status.EndpointStatusTestCase.test_status_landbot ======
test_endpoint_status.py:1406 (EndpointStatusTestCase.test_status_landbot)
self = <test.test_endpoint_status.EndpointStatusTestCase testMethod=test_status_landbot>

    def test_status_landbot(self):
        data = statusRequestData()
        data.buildTypeId = "BitcoinAbcLandBot"
    
        # Side effects are only valid once per call, so we need to set side_effect
        # for every call to the endpoint.
        def setupTeamcity():
            self.configure_build_info(
                properties=test.mocks.teamcity.buildInfo_properties(
                    propsList=[
                        {
                            "name": "env.ABC_REVISION",
                            "value": "D1234",
                        }
                    ]
                )
            )
    
            self.teamcity.session.send.side_effect = [
                test.mocks.teamcity.Response(),
            ]
    
        def setupUserSearch(slackUsername):
            self.phab.user.search.return_value = test.mocks.phabricator.Result(
                [
                    {
                        "id": "5678",
                        "phid": revisionSearchResult.data[0]["fields"]["authorPHID"],
                        "fields": {
                            "username": "author-phab-username",
                            "custom.abc:slack-username": slackUsername,
                        },
                    }
                ]
            )
    
            slackUserProfile = test.mocks.slackbot.userProfile(
                {"real_name": "author-slack-username"}
            )
            slackUser = test.mocks.slackbot.user(
                userId="U8765", profile=slackUserProfile
            )
            self.slackbot.client.users_list.return_value = (
                test.mocks.slackbot.users_list(total=2, initialUsers=[slackUser])
            )
    
        revisionSearchResult = (
            test.mocks.phabricator.differential_revision_search_result()
        )
        self.phab.differential.revision.search.return_value = revisionSearchResult
    
        expectedBuildUrl = self.teamcity.build_url(
            "viewLog.html",
            {
                "buildTypeId": data.buildTypeId,
                "buildId": DEFAULT_BUILD_ID,
            },
        )
    
        # Test happy path
        setupTeamcity()
        setupUserSearch(slackUsername="author-slack-username")
        response = self.app.post("/status", headers=self.headers, json=data)
        self.assertEqual(response.status_code, 200)
    
        self.phab.differential.revision.search.assert_called_with(
            constraints={"ids": [1234]}
        )
        self.phab.user.search.assert_called_with(
            constraints={
                "phids": [revisionSearchResult.data[0]["fields"]["authorPHID"]]
            }
        )
>       self.slackbot.client.chat_postMessage.assert_called_with(
            channel="U8765",
            text=(
                "Successfully landed your change:\n"
                "Revision: https://reviews.bitcoinabc.org/D1234\n"
                f"Build: {expectedBuildUrl}"
            ),
        )

test_endpoint_status.py:1480: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

_mock_self = <Mock name='mock.chat_postMessage' id='140646821010640'>, args = ()
kwargs = {'channel': 'U8765', 'text': 'Successfully landed your change:\nRevision: https://reviews.bitcoinabc.org/D1234\nBuild: https://teamcity.test/viewLog.html?buildTypeId=BitcoinAbcLandBot&buildId=123456&guest=1'}
expected = call(channel='U8765', text='Successfully landed your change:\nRevision: https://reviews.bitcoinabc.org/D1234\nBuild: https://teamcity.test/viewLog.html?buildTypeId=BitcoinAbcLandBot&buildId=123456&guest=1')
actual = call(channel='U8765', text='Successfully landed your change:\nRevision: https://reviews.bitcoinabc.org/D1234\nBuild: {guest_url}')
_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x7feae3cd6340>
cause = None

    def assert_called_with(_mock_self, *args, **kwargs):
        """assert that the last call was made with the specified arguments.
    
        Raises an AssertionError if the args and keyword args passed in are
        different to the last call to the mock."""
        self = _mock_self
        if self.call_args is None:
            expected = self._format_mock_call_signature(args, kwargs)
            actual = 'not called.'
            error_message = ('expected call not found.\nExpected: %s\n  Actual: %s'
                    % (expected, actual))
            raise AssertionError(error_message)
    
        def _error_message():
            msg = self._format_mock_failure_message(args, kwargs)
            return msg
        expected = self._call_matcher(_Call((args, kwargs), two=True))
        actual = self._call_matcher(self.call_args)
        if actual != expected:
            cause = expected if isinstance(expected, Exception) else None
>           raise AssertionError(_error_message()) from cause
E           AssertionError: expected call not found.
E           Expected: chat_postMessage(channel='U8765', text='Successfully landed your change:\nRevision: https://reviews.bitcoinabc.org/D1234\nBuild: https://teamcity.test/viewLog.html?buildTypeId=BitcoinAbcLandBot&buildId=123456&guest=1')
E             Actual: chat_postMessage(channel='U8765', text='Successfully landed your change:\nRevision: https://reviews.bitcoinabc.org/D1234\nBuild: {guest_url}')

/usr/local/lib/python3.11/dist-packages/mock/mock.py:992: AssertionError

Each failure log is accessible here:
test_endpoint_status.EndpointStatusTestCase.test_status_landbot

fix server.py (manual edit introduced bug, the automated changes seem fine)

contrib/buildbot/server.py
991–1000 ↗(On Diff #56542)

apparently we still can't automatically convert some weird cases, probably because of python < 3.12 support and too many levels of nesting quotes.
We could simplify this to avoid the formatting-inside-a-formatting but let's not add too many manual edits in a scripted diff

PiRK published this revision for review.Mon, Nov 10, 11:26
This revision is now accepted and ready to land.Mon, Nov 10, 12:57
This revision was automatically updated to reflect the committed changes.