Skip to content

Give clear error messages for invalid types used for setup.py params (e.g. tuple for classifiers) #63809

Closed

Description

@berkerpeksag
BPO 19610
Nosy @nascheme, @ncoghlan, @pitrou, @tarekziade, @ned-deily, @merwok, @berkerpeksag, @serhiy-storchaka, @cryvate, @Marco-Sulla
PRs
  • bpo-19610: setup() now raises TypeError for invalid types #4519
  • bpo-19610: Warn if distutils is provided something other than a list to some fields #4685
  • Files
  • setup.py
  • fix-upload-cmd.diff
  • issue19610.diff
  • issue19610_catch_distribution.diff
  • issue19610_v2.diff
  • issue19610_v3.diff
  • issue19610_v4.diff
  • pip-errors.txt
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/berkerpeksag'
    closed_at = <Date 2017-12-05.17:27:01.310>
    created_at = <Date 2013-11-15.11:24:52.594>
    labels = ['3.7', 'type-feature', 'library']
    title = 'Give clear error messages for invalid types used for setup.py params (e.g. tuple for classifiers)'
    updated_at = <Date 2020-03-04.19:52:23.051>
    user = 'https://github.com/berkerpeksag'

    bugs.python.org fields:

    activity = <Date 2020-03-04.19:52:23.051>
    actor = 'Marco Sulla'
    assignee = 'berker.peksag'
    closed = True
    closed_date = <Date 2017-12-05.17:27:01.310>
    closer = 'nascheme'
    components = ['Distutils']
    creation = <Date 2013-11-15.11:24:52.594>
    creator = 'berker.peksag'
    dependencies = []
    files = ['32641', '32642', '32665', '35266', '37097', '38655', '38862', '47312']
    hgrepos = []
    issue_num = 19610
    keywords = ['needs review']
    message_count = 47.0
    messages = ['202938', '202941', '202943', '203130', '206821', '206828', '214799', '214810', '214915', '218673', '230443', '237395', '237425', '237447', '237590', '237596', '237597', '237648', '237789', '239014', '239915', '240250', '242974', '306750', '306753', '306755', '306818', '306853', '307450', '307455', '307457', '307458', '307463', '307464', '307465', '307468', '307475', '307483', '307486', '307488', '307495', '307514', '307521', '307588', '307622', '307645', '363385']
    nosy_count = 10.0
    nosy_names = ['nascheme', 'ncoghlan', 'pitrou', 'tarek', 'ned.deily', 'eric.araujo', 'berker.peksag', 'serhiy.storchaka', 'cryvate', 'Marco Sulla']
    pr_nums = ['4519', '4685']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue19610'
    versions = ['Python 3.7']

    Activity

    1. berkerpeksag commented on Nov 15, 2013

      @berkerpeksag
      MemberAuthor

      Python 3.4:

      $ ../cpython/./python setup.py sdist upload -r test --show-response
      ...
      ...
      Traceback (most recent call last):
        File "setup.py", line 24, in <module>
          'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
        File "/home/berker/projects/cpython/Lib/distutils/core.py", line 148, in setup
          dist.run_commands()
        File "/home/berker/projects/cpython/Lib/distutils/dist.py", line 930, in run_commands
          self.run_command(cmd)
        File "/home/berker/projects/cpython/Lib/distutils/dist.py", line 949, in run_command
          cmd_obj.run()
        File "/home/berker/projects/cpython/Lib/distutils/command/upload.py", line 65, in run
          self.upload_file(command, pyversion, filename)
        File "/home/berker/projects/cpython/Lib/distutils/command/upload.py", line 165, in upload_file
          body.write(value)
      TypeError: 'str' does not support the buffer interface

      Python 3.3:

      $ python3.3 setup.py sdist upload -r test --show-response
      ...
      ...
      Traceback (most recent call last):
        File "setup.py", line 24, in <module>
          'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
        File "/usr/local/lib/python3.3/distutils/core.py", line 148, in setup
          dist.run_commands()
        File "/usr/local/lib/python3.3/distutils/dist.py", line 917, in run_commands
          self.run_command(cmd)
        File "/usr/local/lib/python3.3/distutils/dist.py", line 936, in run_command
          cmd_obj.run()
        File "/usr/local/lib/python3.3/distutils/command/upload.py", line 66, in run
          self.upload_file(command, pyversion, filename)
        File "/usr/local/lib/python3.3/distutils/command/upload.py", line 155, in upload_file
          body.write(value)
      TypeError: 'str' does not support the buffer interface

      I also attached my setup.py.

    2. added
      type-bug
      stdlib
      on Nov 15, 2013
    3. vstinner commented on Nov 15, 2013

      @vstinner
      Member

      I never undersood why, but classifiers must be a list, not a tuple. This is a bug in my opinion.

      upload.upload_file() doesn't check if the tuple contains exactly 2 items. If the value is a tuple, it doesn't encode the value. This is another bug. I don't know in which cases a value should be a (key, value) tuple.

    4. vstinner commented on Nov 15, 2013

      @vstinner
      Member

      upload.upload_file() ... doesn't encode the value.

      fix-upload-cmd.diff should fix this specific bug, but the first bug (accept tuple for classifiers) should be fixed before or you will get an unexpected behaviour (only send 1 classifier?).

    5. berkerpeksag commented on Nov 17, 2013

      @berkerpeksag
      MemberAuthor

      [...] but the first bug (accept tuple for classifiers) should be fixed
      before or you will get an unexpected behaviour (only send 1
      classifier?).

      Here is a new patch that accepts tuple for classifiers.

      Thanks for the review, Victor.

    6. pitrou commented on Dec 22, 2013

      @pitrou
      Member

      I don't think accepting a tuple for classifiers is a bugfix. Furthermore, the latest patch is much too intrusive and may break legitimate uses.

    7. changed the title [-]TypeError in distutils.command.upload[/-] [+]setup.py should allow a tuple for classifiers[/+] on Dec 22, 2013
    8. added
      type-feature
      and removed
      type-bug
      on Dec 22, 2013
    9. merwok commented on Dec 22, 2013

      @merwok
      Member

      Classifiers have always been documented as a list; I don’t think a tuple makes more sense here (even if it does no harm), but more importantly I think it’s a bad idea to have a setup.py that would work in 3.5 and not in 3.2-3.4. I suggest rejecting this.

    10. merwok commented on Mar 25, 2014

      @merwok
      Member

      I’m open to a patch that would make it clear in the docs that classifiers must be a list.

      A patch to detect bad type for classifiers in the check command would also be acceptable for 3.5, or to catch it earlier, a check in the Distribution class.

    11. changed the title [-]setup.py should allow a tuple for classifiers[/-] [+]setup.py does not allow a tuple for classifiers[/+] on Mar 25, 2014
    12. vstinner commented on Mar 25, 2014

      @vstinner
      Member

      A patch to detect bad type for classifiers in the check command would also be acceptable for 3.5, or to catch it earlier, a check in the Distribution class.

      Why only in Python 3.5? Does it make sense to pass something different
      than a list in older Python versions?

      I would prefer to see a fix the bug fixed in Python 2.7, 3.4 and 3.5.

    13. merwok commented on Mar 26, 2014

      @merwok
      Member

      You seem to misunderstand me Victor: There is no bug here, classifiers should be a list and are documented as such. It is possible to make this clearer in the docs for all versions. In addition, we could make this easier for users who don’t see that part of the docs by warning them (in the check command, or from the Distribution class), but as a new feature this would go in 3.5 only.

    14. 34 remaining items

    15. berkerpeksag commented on Dec 2, 2017

      @berkerpeksag
      MemberAuthor

      Filed a bug simplejson/simplejson#198 for
      simplejson.

      I've opened simplejson/simplejson#197 to make CLASSIFIERS a list.

      I've also opened ianare/exif-py#80 to create a universal wheel for exifread.

      That's not how we develop Python.

      Thank you, but I don't need a lecture from you. Feel free to propose your solution in the form of pull request instead of acting like a project manager and telling people what to do.

    16. nascheme commented on Dec 2, 2017

      @nascheme
      Member

      Thank you, but I don't need a lecture from you. Feel free to propose our solution in the form of pull request instead of acting like a project manager and telling people what to do.

      I'm sorry you are offended. My pull request would consist of the patch being reverted. It is not ready to go in. If a change breaks a significant amount of previously working Python code, it needs very careful consideration and should be introduced in a way to minimize breakage and allow people time to fix their code.

      Repeatably pointing to the documentation and saying that existing code is broken because it doesn't respect documented requirements is not okay.

    17. ncoghlan commented on Dec 3, 2017

      @ncoghlan
      Contributor

      I'd prefer to see this change go in the other direction: instead of enforcing eager type checks, we should be unconditionally wrapping the given values in a "list(arg)" call, such that more typical iterable duck-typing behaviour applies.

      That will transparently fix any code that isn't already passing a list, will ensure that internal code can safely assume that the instance *attributes* are always lists (no matter what the caller passes in), and means that even when the caller is passing in a list, the instance will have its own copy (rather than retaining a reference to the caller's copy).

    18. nascheme commented on Dec 3, 2017

      @nascheme
      Member

      I like Nick's idea of calling list() to fix the argument. I've created a PR that implements it. I also generate a RuntimeWarning since if we document them as needing to be lists, we should at least warn for invalid types. The RuntimeWarning will be seen if you call setup.py directly which should have the effect of eventually pushing package authors to fix their code.

    19. serhiy-storchaka commented on Dec 3, 2017

      @serhiy-storchaka
      Member

      Perhaps it is worth to backport warnings to 2.7 in Py3k mode. This could help to detect some issues earlier.

      In 3.6 fields could be converted to lists silently, without warnings.

    20. pitrou commented on Dec 3, 2017

      @pitrou
      Member

      Le 03/12/2017 à 05:57, Neil Schemenauer a écrit :

      I like Nick's idea of calling list() to fix the argument.

      I don't think that's a good idea. Suppose someone is passing a string
      by mistake:

      setup(...,
            classifiers='Programming Language :: Python :: 3 :: Only',
            )
    21. ncoghlan commented on Dec 3, 2017

      @ncoghlan
      Contributor

      Prohibiting strings and bytes on the grounds of "Yes they're iterable, but are more likely intended as atomic here, so treat them as ambiguous and refuse to guess" would be fine. (Although I'll also note the classifier case will already fail on upload, since they won't be valid classifiers)

      The only part I'm not OK with is upgrading a historically unenforced type restriction that only sometimes causes problems into an eagerly enforced one that breaks currently working code.

    22. merwok commented on Dec 3, 2017

      @merwok
      Member

      I am sorry this snowballed. The intent in my messages here and in my PR review was to exchange a late, unfriendly traceback with a clear, early message, but only for package authors. I forgot that a Python 3.7 could execute an invalid setup.py from an existing tarball, as Neil pointed with the pip install exifread example. Even if these packages get PRs to build wheels, it’s still bad to break existing sdists. +1 to reverting the patch, +1 to reverting the breakage and also fixing the original problem with a warning and explicit conversion.

    23. nascheme commented on Dec 4, 2017

      @nascheme
      Member

      Don't be sorry. We are all passionate about making Python better. distutils will be better once we gets this sorted out. Berker deserves credit for seeing an issue and developing on a fix for it. The collaboration between all the core developers is making the final fix better than what any one of us could make.

      The process is working quite well IMHO. I had a small patch a few days ago that I was considering just committing without reviews. I went through the review process though and the patch was better as a result of the review feedback I got.

      The documentation says that the argument needs to be a list of strings or a string. So, unless we change the documentation, a string must be accepted without warnings or errors. The current PR works pretty well. Figuring out how to best warn is the trickiest bit. Sometimes it seems like DepreciationWarning doesn't work as we would like, since it often gets suppressed. It seems pip is especially "good" at hiding it.

    24. nascheme commented on Dec 5, 2017

      @nascheme
      Member

      New changeset 8837dd0 by Neil Schemenauer in branch 'master':
      bpo-19610: Warn if distutils is provided something other than a list to some fields (bpo-4685)
      8837dd0

    25. berkerpeksag commented on Dec 5, 2017

      @berkerpeksag
      MemberAuthor

      Thank you for fixing this, Neil. Can we close this issue now?

    26. Marco-Sulla commented on Mar 4, 2020

      Marco-Sullamannequin
      Mannequin

      This is IMHO broken.

      1. _ensure_list() allows strings, because, documentation says, they are split in finalize_options(). But finalize_options() does only split keywords and platforms. It does _not_ split classifiers.

      2. there's no need that keywords, platforms and classifiers must be a list. keywords and platforms can be any iterable, and classifiers can be any non text-like iterable.

      Indeed, keywords are written to file using ','.join(), and platforms and classifiers are written using DistributionMetadata._write_list(). They both accepts any iterable, so I do not understand why such a strict requirement.

    27. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    3.7 (EOL)stdlibtype-feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions