Skip to content
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

Update deprecated 'fn' to 'path' (evdev 1.9.0 removed 'fn') #169

Open
RedBearAK opened this issue Feb 8, 2025 · 3 comments · May be fixed by #170
Open

Update deprecated 'fn' to 'path' (evdev 1.9.0 removed 'fn') #169

RedBearAK opened this issue Feb 8, 2025 · 3 comments · May be fixed by #170
Labels
bug Something isn't working help welcome Help/contrib is esp welcome

Comments

@RedBearAK
Copy link
Contributor

@joshgoebel

FYI, I just had to do a quick update in xwaykeyz, my fork of xkeysnail/keyszer, due to the apparent removal of a deprecated InputDevice attribute name in an update to evdev that just happened this morning. (Saturday, Feb. 8, 2025)

This will most likely need to be dealt with in all forks of this keymapper. Anyone newly installing them along with evdev 1.9.0 or later will probably run into an AttributeError when attempting to run the keymapper.

There was a deprecation warning in the evdev code (in evdev/device.py), probably for quite some time now.

    @property
    def fn(self):
        msg = "Please use {0}.path instead of {0}.fn".format(self.__class__.__name__)
        warnings.warn(msg, DeprecationWarning, stacklevel=2)
        return self.path

And there's the note about the removal of the deprecated attribute in the evdev change log:

https://python-evdev.readthedocs.io/en/latest/changelog.html#feb-08-2025

Drop deprecated InputDevice.fn (use InputDevice.path instead).

I found that everywhere that device.fn was used needed to be updated to device.path in the keymapper's devices.py module. Including a couple of references that were in a formatting syntax in this, so it was a bit more abstract and needed more than a single simple find/replace operation:

    @staticmethod
    def print_list():
        devices = Devices.all()
        device_format = "{1.fn:<20} {1.name:<35} {1.phys}"
        device_lines = [
            device_format.format(n, d) for n, d in enumerate(devices)
        ]
        header_len = max([20 + 35 + 3 + len(x.phys) for x in devices])
        print("-" * header_len)
        print("{:<20} {:<35} {}".format("Device", "Name", "Phys"))
        print("-" * header_len)
        for i, line in enumerate(device_lines):
            dev = devices[i]
            if len(dev.name) > 35:
                fmt = "{1.fn:<20} {1.name:<35}"
                print(fmt.format(None, dev))
                print(" " * 57 + dev.phys)
            else:
                print(line)
        print("")

That needed to be updated like this, with {1.path:<20} replacing the two {1.fn:<20} instances:

    @staticmethod
    def print_list():
        devices = Devices.all()
        device_format = "{1.path:<20} {1.name:<35} {1.phys}"
        device_lines = [
            device_format.format(n, d) for n, d in enumerate(devices)
        ]
        header_len = max([20 + 35 + 3 + len(x.phys) for x in devices])
        print("-" * header_len)
        print("{:<20} {:<35} {}".format("Device", "Name", "Phys"))
        print("-" * header_len)
        for i, line in enumerate(device_lines):
            dev = devices[i]
            if len(dev.name) > 35:
                fmt = "{1.path:<20} {1.name:<35}"
                print(fmt.format(None, dev))
                print(" " * 57 + dev.phys)
            else:
                print(line)
        print("")

And that is all I know about that.

The fix worked for me after experiencing the AttributeError on a fresh install of Toshy this morning, and a Toshy user quickly confirmed that the updated xwaykeyz 1.4.0 release no longer had the AttributeError when the Toshy installer was run again and cloned the new version of the keymapper.

I'll be cross-posting this to the kinto and xkeysnail GitHub issues.

@RedBearAK RedBearAK added bug Something isn't working help welcome Help/contrib is esp welcome labels Feb 8, 2025
@joshgoebel
Copy link
Owner

I'd take a PR for this if you already identified the work needed. Thanks.

@RedBearAK
Copy link
Contributor Author

I don't have a working keyszer repo workspace hanging around anymore, so I would need to do the edit in the web UI. It's probably much easier for you to handle this. It's as simple as doing a find/replace in devices.py swapping device.path for the deprecated device.fn, and fixing the two {1.fn:<20} instances.

In my fork I also just replaced this whole static method, to update the older abstract output formatting syntax to the newer more readable f-strings syntax. That's optional, but means everywhere device.path is referenced it comes in that exact form, instead of {1.path:<20} in the older style formatting strings.

    @staticmethod
    def print_list():
        # Get all devices
        devices = Devices.all()
        
        # Define column widths
        DEVICE_WIDTH = 20
        NAME_WIDTH = 35
        
        # Calculate the total width needed for the table
        max_phys_length = max(len(device.phys) for device in devices)
        total_width = DEVICE_WIDTH + NAME_WIDTH + max_phys_length + 3  # +3 for spaces between columns
        
        # Print header
        print("-" * total_width)
        print(f"{'Device':<{DEVICE_WIDTH}} {'Name':<{NAME_WIDTH}} {'Phys'}")
        print("-" * total_width)
        
        # Print each device
        for device in devices:
            if len(device.name) > NAME_WIDTH:
                # Handle long names by printing on two lines
                print(f"{device.path:<{DEVICE_WIDTH}} {device.name[:NAME_WIDTH]:<{NAME_WIDTH}}")
                print(f"{'':<{DEVICE_WIDTH + NAME_WIDTH}} {device.phys}")
            else:
                # Print everything on one line
                print(f"{device.path:<{DEVICE_WIDTH}} {device.name:<{NAME_WIDTH}} {device.phys}")
        
        print()

This tested good in my fork, producing the same results. Compatible with Python 3.6 and later, so still maintains the 3.8 minimum requirement.

Up to you how much of this you want to do in keyszer.

@RedBearAK RedBearAK linked a pull request Feb 11, 2025 that will close this issue
@RedBearAK
Copy link
Contributor Author

RedBearAK commented Feb 11, 2025

@joshgoebel

PR submitted, with only the most basic changes required.

This issue has already been reported by a Kinto user, or attempted Kinto user. So it also affects xkeysnail, as expected.

rbreaves/kinto#892

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help welcome Help/contrib is esp welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants