upciti / wheel2deb

Python Wheel to Debian package converter
MIT License
48 stars 22 forks source link

Argument --python-version is broken #20

Closed ericriff closed 2 years ago

ericriff commented 3 years ago

I came across this bug when trying to debianize a package using my py3 environment but trying to get a py2 package.

I was following the guide:

pip3 wheel somePackage
wheel2deb --map attrs=attr --python-version=2.7.14
wheel2deb build

But it fails right away on the second command, no matter what I pass to --python-version. This is the error message:

Traceback (most recent call last):
  File "/home/eric/.local/bin/wheel2deb", line 8, in <module>
    sys.exit(main())
  File "/home/eric/.local/lib/python3.6/site-packages/wheel2deb.py", line 224, in main
    debianize(args)
  File "/home/eric/.local/lib/python3.6/site-packages/wheel2deb.py", line 145, in debianize
    if not wheel.version_supported(ctx.python_version):
  File "/home/eric/.local/lib/python3.6/site-packages/_wheel2deb/pydist.py", line 145, in version_supported
    m = re.search(r"(?:py|cp)%s" % pyvers.major, self.python_tag)
AttributeError: 'str' object has no attribute 'major

So it looks like it is expecting something formatted as a Version but it is getting a string,

To debug this I added this print statements to wheel2deb.py, since I got the feeling the argument wasn't being parsed correctly:

    print("Settings:")
    print(settings)

    # config file takes precedence over command line arguments
    settings.default_ctx.update(vars(args))

    print("Settings after update:")
    print(settings)

Indeed the python_version key goes from a Version to a str after that update:

Settings:
Settings(config={}, default_ctx=Context(maintainer_name='wheel2deb', maintainer_email='wheel2deb@upciti.com', distribution='unstable', python_version=Version(major=3, minor=6, micro=1), platform_machine='x86_64', arch='', ignore_entry_points=False, ignore_upstream_versions=False, ignore_requirements=[], ignore_specifiers=[], extra='', map={}, depends=[], conflicts=[], provides=[], revision='1', epoch=0, version_template='{epoch}:{upstream_version}-{revision}~w2d{w2d_version[0]}'))
Settings after update:
Settings(config={}, default_ctx=Context(maintainer_name='wheel2deb', maintainer_email='wheel2deb@upciti.com', distribution='unstable', python_version='2.7.14', platform_machine='x86_64', arch='', ignore_entry_points=False, ignore_upstream_versions=False, ignore_requirements=[], ignore_specifiers=[], extra='', map={}, depends=[], conflicts=[], provides=[], revision='1', epoch=0, version_template='{epoch}:{upstream_version}-{revision}~w2d{w2d_version[0]}'))

I managed to work around this by changing the update function like this:

    def update(self, changes):
        for k, v in changes.items():
            if v and hasattr(self, k):
                if k == "python_version":
                    changes[k] = Version.from_str(v) if isinstance(v, str) else v
                setattr(self, k, changes[k])

Thanks for the amazing tool!

ericriff commented 3 years ago

To further clarify this, I only added these lines

if k == "python_version":
   changes[k] = Version.from_str(v) if isinstance(v, str) else v