question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

--preamble runpy path error

See original GitHub issue

I believe this may be an issue on linux machines… but when trying to copy the cleanup example posted in PR #156 exactly, and running with the require flags:

... --preamble shiv_cleanup.py ...

I get the error:

Traceback (most recent call last):
  File "envs/python38/lib/python3.8/runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "envs/python38/lib/python3.8/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "./mpro/__main__.py", line 3, in <module>
  File "./mpro/_bootstrap/__init__.py", line 219, in bootstrap
  File "envs/python38/lib/python3.8/runpy.py", line 262, in run_path
    code, fname = _get_code_from_file(run_name, path_name)
  File "envs/python38/lib/python3.8/runpy.py", line 232, in _get_code_from_file
    with io.open_code(fname) as f:
TypeError: open_code() argument 'path' must be str, not PosixPath

Looks like this is because runpy doesn’t support Path objects? Its failing on 232:

  230 def _get_code_from_file(run_name, fname):
  231     # Check for a compiled file first
  232     with io.open_code(fname) as f:
  233         code = read_code(f)
  234     if code is None:
  235         # That didn't work, so try it as normal source code
  236         with io.open_code(fname) as f:
  237             code = compile(f.read(), fname, 'exec')
  238     return code, fname

As a near term fix, should this pathobj be converted to a string?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lorencarvalhocommented, Oct 13, 2020

hey @Alex-Mann,

I’ve actually observed this too, on Python 3.8.2 on macOS:

>       assert proc.returncode == 0
E       AssertionError: assert 1 == 0
E        +  where 1 = CompletedProcess(args=['/private/var/folders/rk/3q7k_qzs7mz4w2j44331qyv40005tq/T/pytest-of-lcarvalh/pytest-40/test_pre..._from_file\n    with io.open_code(fname) as f:\nTypeError: open_code() argument \'path\' must be str, not PosixPath\n').returncode

I’d happily ship an RB string-ifying those inputs 😃

0reactions
mhuckacommented, Oct 24, 2021

After studying the problem, I found a very simple, one-line fix. PR #196 implements the changes. This makes shiv-produced zipapps work on my version of the Apple-provided Python 3.8 on macOS 10.14 and macOS 11.1 (where I’ve tested so far).

Would the maintainers of shiv please consider incorporating this change?

Read more comments on GitHub >

github_iconTop Results From Across the Web

runpy — Locating and executing Python modules — Python ...
The runpy module is used to locate and run Python modules without importing them first. Its main use is to implement the -m...
Read more >
Could not import runpy module - python - Stack Overflow
So, I append my python's library path to the configuration(don't ... Had the same "Could not import runpy module" error, but in Windows....
Read more >
Changelog - ActivePython 3.6.6 Documentation
Exit with error in case that invalid parameters are specified to ... to “python -m” or runpy.run_module() is found in sys.modules after parent...
Read more >
Misc/HISTORY - external/github.com/python/cpython
Issue #19456: ntpath.join() now joins relative paths correctly when a drive ... Issue #14439: Python now prints the traceback on runpy failure at...
Read more >
History - setuptools 65.6.3.post20221216 documentation
unescape is deprecated and will be removed in Python 3.9. #1790: Added the file path to the error message when a UnicodeDecodeError occurs...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found