nodeenv icon indicating copy to clipboard operation
nodeenv copied to clipboard

Installing environment for https://github.com/igorshubovych/markdownlint-cli fails with AttributeError: 'bytes' object has no attribute 'tell'

Open Casper321 opened this issue 2 years ago • 8 comments

Hi, I am using

- repo: https://github.com/igorshubovych/markdownlint-cli
    rev: v0.32.2
    hooks:
      - id: markdownlint

Sometimes, pre-commit fails with the following error.

[INFO] Installing environment for https://github.com/igorshubovych/markdownlint-cli.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/usr/local/bin/python', '-mnodeenv', '--prebuilt', '--clean-src', '/root/.cache/pre-commit/repoki3l4r17/node_env-default')
return code: 1
stdout: (none)
stderr:
     * Install prebuilt node (19.8.1) .Incomplete read while readingfrom https://nodejs.org/download/release/v19.8.1/node-v19.8.1-linux-x64.tar.gz
    .
    Traceback (most recent call last):
      File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code
        exec(code, run_globals)
      File "/usr/local/lib/python3.10/site-packages/nodeenv.py", line 1519, in <module>
        main()
      File "/usr/local/lib/python3.10/site-packages/nodeenv.py", line 1104, in main
        create_environment(env_dir, args)
      File "/usr/local/lib/python3.10/site-packages/nodeenv.py", line 980, in create_environment
        install_node(env_dir, src_dir, args)
      File "/usr/local/lib/python3.10/site-packages/nodeenv.py", line 739, in install_node
        install_node_wrapped(env_dir, src_dir, args)
      File "/usr/local/lib/python3.10/site-packages/nodeenv.py", line 762, in install_node_wrapped
        download_node_src(node_url, src_dir, args)
      File "/usr/local/lib/python3.10/site-packages/nodeenv.py", line 602, in download_node_src
        with ctx as archive:
      File "/usr/local/lib/python3.10/contextlib.py", line 135, in __enter__
        return next(self.gen)
      File "/usr/local/lib/python3.10/site-packages/nodeenv.py", line 573, in tarfile_open
        tf = tarfile.open(*args, **kwargs)
      File "/usr/local/lib/python3.10/tarfile.py", line 1630, in open
        saved_pos = fileobj.tell()
    AttributeError: 'bytes' object has no attribute 'tell'

It looks like nodeenv-1.7.0 is used.

Casper321 avatar Mar 20 '23 12:03 Casper321

Related with https://github.com/ekalinin/nodeenv/pull/329, in case of network glitch, nodeenv may receive a partial tar file when downloading node from official source. When it does so, it doesn't fail immediatly but propagate the partial archive (which turns out to be bytes instead of str) later on in the code, resulting in this error.

bagerard avatar Apr 21 '23 08:04 bagerard

Related using https://github.com/RobertCraigie/prisma-client-py

Installing Prisma CLI
/usr/local/lib/python3.11/site-packages/nodeenv.py:26: DeprecationWarning: 'pipes' is deprecated and slated for removal in Python 3.13
  import pipes
 * Install prebuilt node (20.0.0) .Incomplete read while readingfrom https://nodejs.org/download/release/v20.0.0/node-v20.0.0-linux-x64.tar.gz
.
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/local/lib/python3.11/site-packages/nodeenv.py", line 1519, in <module>
    main()
  File "/usr/local/lib/python3.11/site-packages/nodeenv.py", line 1104, in main
    create_environment(env_dir, args)
  File "/usr/local/lib/python3.11/site-packages/nodeenv.py", line 980, in create_environment
    install_node(env_dir, src_dir, args)
  File "/usr/local/lib/python3.11/site-packages/nodeenv.py", line 739, in install_node
    install_node_wrapped(env_dir, src_dir, args)
  File "/usr/local/lib/python3.11/site-packages/nodeenv.py", line 762, in install_node_wrapped
    download_node_src(node_url, src_dir, args)
  File "/usr/local/lib/python3.11/site-packages/nodeenv.py", line 602, in download_node_src
    with ctx as archive:
  File "/usr/local/lib/python3.11/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/nodeenv.py", line 573, in tarfile_open
    tf = tarfile.open(*args, **kwargs)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/tarfile.py", line 1630, in open
    saved_pos = fileobj.tell()
                ^^^^^^^^^^^^
AttributeError: 'bytes' object has no attribute 'tell'

nullswan avatar Apr 26 '23 13:04 nullswan

Did you came to a mitigation meanwhile @bagerard ?

nullswan avatar Apr 26 '23 13:04 nullswan

not really, we're using this library through pre-commit hooks so once it is installed, it gets cached and we are good for a while but I'm still hoping #329 will get merged soon

bagerard avatar Apr 27 '23 08:04 bagerard

Also getting the same error as @c3b5aw. Feels like a separate issue to the original one posted though.

strongishllama avatar May 02 '23 03:05 strongishllama

Same thing for us. Any hotfix available?

Alexander-Serov avatar May 05 '23 12:05 Alexander-Serov

I'm getting the same error for:

    - repo: https://github.com/pre-commit/mirrors-prettier
      rev: v2.7.1
      hooks:
          - id: prettier

I tried the latest code from master (https://github.com/ekalinin/nodeenv/commit/22d4cd9994e0a47b1f5d501cc674b5f48d7cc145) and the failure changed from AttributeError: 'bytes' object has no attribute 'tell' to http.client.IncompleteRead: IncompleteRead(42023557 bytes read, 4089771 more expected). This is consistent with what's described in https://github.com/ekalinin/nodeenv/pull/329.

The issue indeed seems to be network related. On my home network, it happens 100% of the times. On other I tried, it doesn't happen at all. Strangely, this issue appeared out of nowhere about at about the time of this GitHub issue being created. So I don't think this is an issue with my network in particular.

radeklat avatar May 10 '23 12:05 radeklat

~~I have a temporary workaround by setting the Python version in the GitHub workflow to 3.10 or lower. This may be useful to people who find this issue.~~

I was wrong.

carmenbianca avatar May 10 '23 13:05 carmenbianca