diazona / setuptools-pyproject-migration

Generate a pyproject.toml file from setuptools
https://setuptools-pyproject-migration.readthedocs.io/en/latest/
MIT License
16 stars 3 forks source link

AttributeError: 'str' object has no attribute 'items' when running. #152

Closed Lord-Kamina closed 5 months ago

Lord-Kamina commented 5 months ago

I wanted to try this app but I'm getting the above error. Tried it in a python3.11 environment, as well as a 3.9 one.

Following is the traceback, along with the python3 and pip versions, as well as the output of pip3 list:

setuptools-pyproject-migration 
running pyproject
Traceback (most recent call last):
  File "/Users/Koji/.local/bin/setuptools-pyproject-migration", line 8, in <module>
    sys.exit(main())
  File "/Users/Koji/.local/pipx/venvs/setuptools-pyproject-migration/lib/python3.9/site-packages/setuptools_pyproject_migration/cli.py", line 67, in main
    exec(setup_bytecode)
  File "setup.py", line 27, in <module>
    setup(
  File "/Users/Koji/.local/pipx/shared/lib/python3.11/site-packages/setuptools/__init__.py", line 87, in setup
    return distutils.core.setup(**attrs)
  File "/Users/Koji/.local/pipx/shared/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 185, in setup
    return run_commands(dist)
  File "/Users/Koji/.local/pipx/shared/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
    dist.run_commands()
  File "/Users/Koji/.local/pipx/shared/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 968, in run_commands
    self.run_command(cmd)
  File "/Users/Koji/.local/pipx/shared/lib/python3.11/site-packages/setuptools/dist.py", line 1217, in run_command
    super().run_command(command)
  File "/Users/Koji/.local/pipx/shared/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 987, in run_command
    cmd_obj.run()
  File "/Users/Koji/.local/pipx/venvs/setuptools-pyproject-migration/lib/python3.9/site-packages/setuptools_pyproject_migration/__init__.py", line 403, in run
    tomlkit.dump(self._generate(), sys.stdout)
  File "/Users/Koji/.local/pipx/venvs/setuptools-pyproject-migration/lib/python3.9/site-packages/setuptools_pyproject_migration/__init__.py", line 383, in _generate
    entry_points = _generate_entry_points(dist.entry_points)
  File "/Users/Koji/.local/pipx/venvs/setuptools-pyproject-migration/lib/python3.9/site-packages/setuptools_pyproject_migration/__init__.py", line 74, in _generate_entry_points
    for eptype, raweps in entry_points.items():
AttributeError: 'str' object has no attribute 'items'
$ python3 -V
Python 3.11.9
$ pip3 -V
pip 24.0 from /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip (python 3.11)
$ pip3 list
Package                   Version
------------------------- ---------
altgraph                  0.17.4
anytree                   2.12.1
argcomplete               3.3.0
attrs                     23.2.0
Automat                   20.2.0
bcrypt                    4.1.2
build                     1.0.3
calver                    2024.4.10
cffi                      1.16.0
click                     8.1.7
constantly                15.1.0
cryptography              42.0.5
Cython                    3.0.10
docutils                  0.20.1
editables                 0.5
fancycompleter            0.9.1
flit_core                 3.9.0
hatch-fancy-pypi-readme   24.1.0
hatch-vcs                 0.4.0
hatchling                 1.24.2
hyperlink                 21.0.0
idna                      3.6
incremental               22.10.0
installer                 0.7.0
Jinja2                    3.1.3
libtorrent                2.0.10
libxml2-python            2.12.6
lxml                      5.2.1
m2r                       0.2.1
macholib                  1.16.3
Mako                      1.3.2
Markdown                  3.6
markdown-it-py            3.0.0
MarkupSafe                2.1.5
mdurl                     0.1.2
meson                     1.4.0
meson-python              0.15.0
mistune                   3.0.2
modulegraph               0.19.6
modulegraph2              2.3
numpy                     1.26.4
objectgraph               1.0.3
oldest-supported-numpy    0.1
olefile                   0.47
packaging                 24.0
Parsley                   1.3
pathspec                  0.12.1
pdb-attach                3.0.1
pdbpp                     0.10.2
pep508-parser             2019.3
Pillow                    9.5.0
pip                       24.0
platformdirs              4.2.2
pluggy                    1.4.0
poetry-core               1.9.0
py2app                    2.0a0
pyasn1                    0.5.1
pyasn1_modules            0.3.0
pycairo                   1.26.0
pycparser                 2.22
pygame                    2.5.2
Pygments                  2.17.2
PyGObject                 3.46.0
PyHamcrest                2.0.2
pyOpenSSL                 24.1.0
pyproject_hooks           1.1.0
pyproject-metadata        0.7.1
pyrepl                    0.9.0
pyxdg                     0.28
PyYAML                    6.0.1
rencode                   1.0.6
rich                      13.7.1
roman                     4.1
semantic_version          2.10.0
service-identity          23.1.0
setproctitle              1.2.2
setupmeta                 3.6.0
setuptools                69.5.1
setuptools-git-versioning 2.0.0
setuptools-rust           1.8.1
setuptools-scm            8.0.4
six                       1.16.0
smartypants               2.0.1
toml                      0.10.2
tomlkit                   0.12.5
trove-classifiers         2024.4.10
Twisted                   24.3.0
typing_extensions         4.11.0
typogrify                 2.0.7
userpath                  1.9.2
wheel                     0.43.0
wmctrl                    0.3
zope.interface            6.1
diazona commented 5 months ago

Thanks for the report! I'll investigate this weekend.

Lord-Kamina commented 5 months ago

I accidentally mixed the traceback from the python3.9 run with the python3.11 environment, but the error was the same.

This was run a plug-in package for Deluge. I suspect the reason is that the entry-points are defined in a hacky way:

#
# Copyright (C) 2009 GazpachoKing <chase.sterling@gmail.com>
# Copyright (C) 2011 Pedro Algarvio <pedro@algarvio.me>
#
# Basic plugin template created by:
# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
# Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com>
# Copyright (C) 2009 Damien Churchill <damoxc@gmail.com>
#
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# the additional special exception to link portions of this program with the OpenSSL library.
# See LICENSE for more details.
#

from setuptools import find_packages, setup

__plugin_name__ = 'AutoAdd'
__author__ = 'Chase Sterling, Pedro Algarvio'
__author_email__ = 'chase.sterling@gmail.com, pedro@algarvio.me'
__version__ = '1.8'
__url__ = 'http://dev.deluge-torrent.org/wiki/Plugins/AutoAdd'
__license__ = 'GPLv3'
__description__ = 'Monitors folders for .torrent files.'
__long_description__ = """"""
__pkg_data__ = {'deluge_' + __plugin_name__.lower(): ['data/*', 'data/*/*']}

setup(
    name=__plugin_name__,
    version=__version__,
    description=__description__,
    author=__author__,
    author_email=__author_email__,
    url=__url__,
    license=__license__,
    long_description=__long_description__ if __long_description__ else __description__,
    packages=find_packages(),
    package_data=__pkg_data__,
    entry_points="""
    [deluge.plugin.core]
    %s = deluge_%s:CorePlugin
    [deluge.plugin.gtk3ui]
    %s = deluge_%s:Gtk3UIPlugin
    [deluge.plugin.web]
    %s = deluge_%s:WebUIPlugin
    """
    % ((__plugin_name__, __plugin_name__.lower()) * 3),
)

If a better solution cannot be realistically found, even just directly copy-pasting as a comment or a warning would be much preferable to crashing.

diazona commented 5 months ago

Well yes, of course emitting a warning would be better than crashing, but this is one of the cases we didn't anticipate at all (in fact I'm not sure we even knew it was possible to define entry points as a string) so we didn't even have an opportunity to catch the error. Anyway, now that we know, we should be able to do something about it.

sjlongland commented 5 months ago

Ouch… hacky indeed.

The question I suppose is how do we even interpret this stringy mess? Or do we just dump it in the output and hope for the best?

sjlongland commented 5 months ago

https://stackoverflow.com/questions/69111347/python-setup-py-entry-points-syntax-with-triple-single-quotes/69125407#69125407 ← looks like the official word is it's "INI-style" syntax.

diazona commented 5 months ago

Yeah, I'm hoping setuptools does the parsing and we can just access the parsed result if we find the right attribute or method.

sjlongland commented 5 months ago

It might do… but it wasn't difficult to do it manually anyway.

https://github.com/diazona/setuptools-pyproject-migration/pull/153/commits/e16f5f15db4e8c9a7f001cda993b5da4bea0e65f