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
  • !36

Merged
Created May 06, 2025 by Kirill Smelkov@kirrOwner

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

  • 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 #2 (closed)

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