Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Register
  • Sign in
  • pygolang pygolang
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 1
    • Merge requests 1
  • Deployments
    • Deployments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • nexedinexedi
  • pygolangpygolang
  • Merge requests
  • !36

gpython: Fix `gpython dir` and `gpython any.zip` to behave like std python

  • Review changes

  • Download
  • Patches
  • Plain diff
Merged Kirill Smelkov requested to merge kirr/pygolang:y/gpy-run-dir into master May 06, 2025
  • Overview 7
  • Commits 2
  • Changes 9

@vnmabus reports that gpython does not support running directories with main.py inside:

With normal python:

    >>> mkdir kk
    >>> echo "print('Hello')" > kk/__main__.py
    >>> python kk
    Hello

With gpython:

    >>> mkdir kk
    >>> echo "print('Hello')" > kk/__main__.py
    >>> python kk
    Traceback (most recent call last):
      File "./software_release/bin/python", line 313, in <module>
        pymain(sys.argv)
      File ".../parts/pygolang/gpython/__init__.py", line 284, in pymain
        run(mmain)
      File ".../parts/pygolang/gpython/__init__.py", line 188, in run 
        _execfile(filepath, mmain.__dict__)
      File ".../parts/pygolang/gpython/__init__.py", line 328, in _execfile
        with open(path, "rb") as f:
    IOError: [Errno 21] Is a directory: 'kk'

-> Fix that by teaching gpython to effectively use runpy.run_path instead of unconditionally assuming that first non-optional argument is path of a file. This adds support, similarly to how std python behaves, for running directories with main.py and zip archives with main.py inside.

We do not use runpy.run_path directly because that function stashes installed main module and uses fresh stub while running anything with removing the stub after the run. For our situation, however, that is incorrect, for example because with -i we need to inspect the state left after running the workload. Implement our own runpy.run_path custom analog ourselves to handle that correctly.

/cc @jerome
/fixes https://lab.nexedi.com/nexedi/pygolang/-/issues/2

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: y/gpy-run-dir
GitLab Nexedi Edition | About GitLab | About Nexedi | 沪ICP备2021021310号-2 | 沪ICP备2021021310号-7