pypa / pypa/setuptools

sys.meta_path is not cleaned up after install and before test

Open
#363 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug major
Dominant language
Python
Stars
2.9k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
1

Description

Originally reported by: icordasc (Bitbucket: icordasc, GitHub: Unknown)


Recently, requests added some logic to it's vendored module which adds a class to sys.meta_path.

Current versions of requests distribute a setup.py file which imports requests to retrieve the version. As such, sys.meta_path will have the instance of VendorAlias still when the tests are run. When requests is next imported, it will fail (because sys is None and the code in load_module (from the old instance of VendorAlias) is expecting it to not be None. If we re-import sys other module globals no longer exist).

In short, after the initial step (where dependencies are downloaded and placed in .eggs) sys.meta_path should be cleaned up by setuptools to prevent issues like this.

Discussion of the above bug is mostly on this pull request but also on this issue.

/cc @dstufft


Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the dependency-install step that places packages in .eggs and the point before tests run, then inspect how sys.meta_path is handled. Use requests/setup.py and requests/packages/init.py as the reproduction context. Done means the added VendorAlias state is cleaned up before tests so a later requests import does not fail.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.