Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
pygolang pygolang
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • Operations
    • Operations
    • Incidents
  • Analytics
    • Analytics
    • Repository
    • Value Stream
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • nexedi
  • pygolangpygolang
  • Merge requests
  • !32

Merged
Created Feb 24, 2025 by Kirill Smelkov@kirrOwner

gpython: Fix how --long-option=value=something is processed

  • Overview 2
  • Commits 1
  • Changes 2

Carlos reports that when pymain is invoked as

> python --login='uid=username,ou=people,dc=something,dc=de' my_script.py

it crashes as

Traceback (most recent call last):
  File "/srv/slapgrid/slappart5/software_release/bin/python", line 312, in <module>
    pymain(sys.argv)
  File "/opt/slapgrid/133edb8b6bfc135bce30900e2b50555e/parts/pygolang/gpython/__init__.py", line 113, in pymain
    for (opt, arg) in igetopt:
  File "/opt/slapgrid/133edb8b6bfc135bce30900e2b50555e/parts/pygolang/gpython/__init__.py", line 552, in __next__
    opt, arg = opt.split('=')

While @jerome correctly notices that the problem here is due to --login is passed to python instead of my_script.py it still highlights a problem on gpython side in its _IGetOpt parser for which I made a thinko in 26058b5b (gpython: Factor-out options parsing into getopt-style _IGetOpt helper) without considering that a value for --long-option=value could itself contain another '=' symbols.

-> Fix this thinko.

Without the fix gpython --unknown=x=y crashes as

Traceback (most recent call last):
  File "/home/kirr/src/wendelin/venv/py39.venv/bin/gpython", line 8, in <module>
    sys.exit(main())
  File "/home/kirr/src/tools/go/pygolang-master/gpython/__init__.py", line 402, in main
    for (opt, arg) in igetopt:
  File "/home/kirr/src/tools/go/pygolang-master/gpython/__init__.py", line 562, in __next__
    opt, arg = opt.split('=')
ValueError: too many values to unpack (expected 2)

but after the fix it reports more user-friendly

RuntimeError: unexpected option --unknown

/reported-by @vnmabus
/reported-on https://lab.nexedi.com/nexedi/pygolang/-/issues/1

Assignee
Assign to
Reviewer
Request review from
None
Milestone
None
Assign milestone
Time tracking
Source branch: y/gpy-longopt-fix
GitLab Nexedi Edition | About GitLab | About Nexedi | 沪ICP备2021021310号-2 | 沪ICP备2021021310号-7