Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Casper321 opened this issue Mar 20, 2023 · 8 comments

Comments

@Casper321
Copy link

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.

@bagerard
Copy link
Contributor

Related with #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.

@nullswan
Copy link

nullswan commented Apr 26, 2023

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
Copy link

Did you came to a mitigation meanwhile @bagerard ?

@bagerard
Copy link
Contributor

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

@strongishllama
Copy link

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

@Alexander-Serov
Copy link

Same thing for us. Any hotfix available?

@radeklat
Copy link

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 (22d4cd9) 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 #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.

carmenbianca added a commit to coopiteasy/oca-addons-repo-template that referenced this issue May 10, 2023
Recently (or recently enough that I've just begun noticing it), the
nodeenv dependency had troubles installing. Sometimes. It wasn't very
reliably failing.

This is related to <ekalinin/nodeenv#328>.

By explicitly setting the Python version to something <=3.10, we can
safely pretend the problem doesn't exist.

Ideally the Python versions match up to the ones used in test.yml, but
they don't, and I fear it might be too intrusive to fix that in this
commit.

Signed-off-by: Carmen Bianca BAKKER <carmen@coopiteasy.be>
@carmenbianca
Copy link

carmenbianca commented May 10, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants