Skip to content

Commit

Permalink
Removed usage of fs_str from vistir (#5062)
Browse files Browse the repository at this point in the history
* Removed usage of fs_str from vistir

  This function was all about compatability of py2-py3.3 versions.
  Later versions don't need it.

* Explicitly convert dict values to strings

* Add news fragment
  • Loading branch information
oz123 committed Apr 20, 2022
1 parent 891486e commit 2bf70b7
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 93 deletions.
1 change: 1 addition & 0 deletions news/5062.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed all usages of ``pipenv.vendor.vistir.compat.fs_str``, since this function was used for PY2-PY3 compatability and is no longer needed.
5 changes: 2 additions & 3 deletions pipenv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
sys.path.insert(0, PIPENV_PATCHED)

from pipenv.vendor.urllib3.exceptions import DependencyWarning
from pipenv.vendor.vistir.compat import fs_str

warnings.filterwarnings("ignore", category=DependencyWarning)
warnings.filterwarnings("ignore", category=ResourceWarning)
warnings.filterwarnings("ignore", category=UserWarning)

# Load patched pip instead of system pip
os.environ["PIP_SHIMS_BASE_MODULE"] = fs_str("pipenv.patched.notpip")
os.environ["PIP_DISABLE_PIP_VERSION_CHECK"] = fs_str("1")
os.environ["PIP_SHIMS_BASE_MODULE"] = "pipenv.patched.notpip"
os.environ["PIP_DISABLE_PIP_VERSION_CHECK"] = "1"

# Hack to make things work better.
try:
Expand Down
82 changes: 32 additions & 50 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ def batch_install(

with vistir.contextmanagers.temp_environ():
if not allow_global:
os.environ["PIP_USER"] = vistir.compat.fs_str("0")
os.environ["PIP_USER"] = "0"
if "PYTHONHOME" in os.environ:
del os.environ["PYTHONHOME"]
if "GIT_CONFIG" in os.environ and dep.is_vcs:
Expand Down Expand Up @@ -967,7 +967,7 @@ def do_create_virtualenv(project, python=None, site_packages=None, pypi_mirror=N
cmd.append("--system-site-packages")

if pypi_mirror:
pip_config = {"PIP_INDEX_URL": vistir.misc.fs_str(pypi_mirror)}
pip_config = {"PIP_INDEX_URL": pypi_mirror}
else:
pip_config = {}

Expand Down Expand Up @@ -998,7 +998,7 @@ def do_create_virtualenv(project, python=None, site_packages=None, pypi_mirror=N
# This mimics Pew's "setproject".
project_file_name = os.path.join(project.virtualenv_location, ".project")
with open(project_file_name, "w") as f:
f.write(vistir.misc.fs_str(project.project_directory))
f.write(project.project_directory)
from .environment import Environment

sources = project.pipfile_sources
Expand Down Expand Up @@ -1561,20 +1561,18 @@ def pip_install(
DEFAULT_EXISTS_ACTION = "w"
if selective_upgrade:
DEFAULT_EXISTS_ACTION = "i"
exists_action = vistir.misc.fs_str(
project.s.PIP_EXISTS_ACTION or DEFAULT_EXISTS_ACTION
)
exists_action = project.s.PIP_EXISTS_ACTION or DEFAULT_EXISTS_ACTION
pip_config = {
"PIP_CACHE_DIR": vistir.misc.fs_str(cache_dir.as_posix()),
"PIP_WHEEL_DIR": vistir.misc.fs_str(cache_dir.joinpath("wheels").as_posix()),
"PIP_DESTINATION_DIR": vistir.misc.fs_str(cache_dir.joinpath("pkgs").as_posix()),
"PIP_CACHE_DIR": cache_dir.as_posix(),
"PIP_WHEEL_DIR": cache_dir.joinpath("wheels").as_posix(),
"PIP_DESTINATION_DIR": cache_dir.joinpath("pkgs").as_posix(),
"PIP_EXISTS_ACTION": exists_action,
"PATH": vistir.misc.fs_str(os.environ.get("PATH")),
"PATH": os.environ.get("PATH"),
}
if src_dir:
if project.s.is_verbose():
click.echo(f"Using source directory: {src_dir!r}", err=True)
pip_config.update({"PIP_SRC": vistir.misc.fs_str(src_dir)})
pip_config.update({"PIP_SRC": src_dir})
c = subprocess_run(pip_command, block=block, env=pip_config)
c.env = pip_config
return c
Expand All @@ -1583,9 +1581,9 @@ def pip_install(
def pip_download(project, package_name):
cache_dir = Path(project.s.PIPENV_CACHE_DIR)
pip_config = {
"PIP_CACHE_DIR": vistir.misc.fs_str(cache_dir.as_posix()),
"PIP_WHEEL_DIR": vistir.misc.fs_str(cache_dir.joinpath("wheels").as_posix()),
"PIP_DESTINATION_DIR": vistir.misc.fs_str(cache_dir.joinpath("pkgs").as_posix()),
"PIP_CACHE_DIR": cache_dir.as_posix(),
"PIP_WHEEL_DIR": cache_dir.joinpath("wheels").as_posix(),
"PIP_DESTINATION_DIR": cache_dir.joinpath("pkgs").as_posix(),
}
for source in project.sources:
cmd = [
Expand Down Expand Up @@ -2130,16 +2128,14 @@ def do_install(
"Installing...", project.s
) as sp:
if not system:
os.environ["PIP_USER"] = vistir.compat.fs_str("0")
os.environ["PIP_USER"] = "0"
if "PYTHONHOME" in os.environ:
del os.environ["PYTHONHOME"]
sp.text = f"Resolving {pkg_line}..."
try:
pkg_requirement = Requirement.from_line(pkg_line)
except ValueError as e:
sp.write_err(
vistir.compat.fs_str("{}: {}".format(crayons.red("WARNING"), e))
)
sp.write_err("{}: {}".format(crayons.red("WARNING"), e))
sp.red.fail(
environments.PIPENV_SPINNER_FAIL_TEXT.format(
"Installation Failed"
Expand Down Expand Up @@ -2172,23 +2168,15 @@ def do_install(
crayons.red("Error: ", bold=True), crayons.green(pkg_line)
),
)
sp.write_err(vistir.compat.fs_str(f"Error text: {c.stdout}"))
sp.write_err(
crayons.cyan(vistir.compat.fs_str(format_pip_error(c.stderr)))
)
sp.write_err(f"Error text: {c.stdout}")
sp.write_err(crayons.cyan(format_pip_error(c.stderr)))
if project.s.is_verbose():
sp.write_err(
crayons.cyan(
vistir.compat.fs_str(format_pip_output(c.stdout))
)
)
sp.write_err(crayons.cyan(format_pip_output(c.stdout)))
if "setup.py egg_info" in c.stderr:
sp.write_err(
vistir.compat.fs_str(
"This is likely caused by a bug in {}. "
"Report this to its maintainers.".format(
crayons.green(pkg_requirement.name)
)
"This is likely caused by a bug in {}. "
"Report this to its maintainers.".format(
crayons.green(pkg_requirement.name)
)
)
sp.red.fail(
Expand All @@ -2198,11 +2186,7 @@ def do_install(
)
sys.exit(1)
except (ValueError, RuntimeError) as e:
sp.write_err(
vistir.compat.fs_str(
"{}: {}".format(crayons.red("WARNING"), e),
)
)
sp.write_err("{}: {}".format(crayons.red("WARNING"), e))
sp.red.fail(
environments.PIPENV_SPINNER_FAIL_TEXT.format(
"Installation Failed",
Expand All @@ -2225,16 +2209,14 @@ def do_install(
)
)
sp.write(
vistir.compat.fs_str(
"{} {} {} {}{}".format(
crayons.normal("Adding", bold=True),
crayons.green(f"{pkg_requirement.name}", bold=True),
crayons.normal("to Pipfile's", bold=True),
crayons.yellow(
"[dev-packages]" if dev else "[packages]", bold=True
),
crayons.normal(fix_utf8("..."), bold=True),
)
"{} {} {} {}{}".format(
crayons.normal("Adding", bold=True),
crayons.green(f"{pkg_requirement.name}", bold=True),
crayons.normal("to Pipfile's", bold=True),
crayons.yellow(
"[dev-packages]" if dev else "[packages]", bold=True
),
crayons.normal(fix_utf8("..."), bold=True),
)
)
# Add the package to the Pipfile.
Expand Down Expand Up @@ -2461,7 +2443,7 @@ def do_shell(
# Set an environment variable, so we know we're in the environment.
# Only set PIPENV_ACTIVE after finishing reading virtualenv_location
# otherwise its value will be changed
os.environ["PIPENV_ACTIVE"] = vistir.misc.fs_str("1")
os.environ["PIPENV_ACTIVE"] = "1"

os.environ.pop("PIP_SHIMS_BASE_MODULE", None)

Expand Down Expand Up @@ -2524,7 +2506,7 @@ def inline_activate_virtual_environment(project):
else:
_inline_activate_virtualenv(project)
if "VIRTUAL_ENV" not in os.environ:
os.environ["VIRTUAL_ENV"] = vistir.misc.fs_str(root)
os.environ["VIRTUAL_ENV"] = root


def _launch_windows_subprocess(script, env):
Expand Down Expand Up @@ -2630,7 +2612,7 @@ def do_run(
# Only set PIPENV_ACTIVE after finishing reading virtualenv_location
# such as in inline_activate_virtual_environment
# otherwise its value will be changed
env["PIPENV_ACTIVE"] = vistir.misc.fs_str("1")
env["PIPENV_ACTIVE"] = "1"
env.pop("PIP_SHIMS_BASE_MODULE", None)

try:
Expand Down
14 changes: 7 additions & 7 deletions pipenv/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@ def paths(self):
# type: () -> Dict[str, str]
paths = {}
with vistir.contextmanagers.temp_environ(), vistir.contextmanagers.temp_path():
os.environ["PYTHONIOENCODING"] = vistir.compat.fs_str("utf-8")
os.environ["PYTHONDONTWRITEBYTECODE"] = vistir.compat.fs_str("1")
os.environ["PYTHONIOENCODING"] = "utf-8"
os.environ["PYTHONDONTWRITEBYTECODE"] = "1"
paths = self.base_paths
os.environ["PATH"] = paths["PATH"]
os.environ["PYTHONPATH"] = paths["PYTHONPATH"]
Expand Down Expand Up @@ -954,16 +954,16 @@ def activated(self, include_extras=True, extra_dists=None):
with vistir.contextmanagers.temp_environ(), vistir.contextmanagers.temp_path():
os.environ["PATH"] = os.pathsep.join(
[
vistir.compat.fs_str(self.script_basedir),
vistir.compat.fs_str(self.prefix.as_posix()),
self.script_basedir,
self.prefix.as_posix(),
os.environ.get("PATH", ""),
]
)
os.environ["PYTHONIOENCODING"] = vistir.compat.fs_str("utf-8")
os.environ["PYTHONDONTWRITEBYTECODE"] = vistir.compat.fs_str("1")
os.environ["PYTHONIOENCODING"] = "utf-8"
os.environ["PYTHONDONTWRITEBYTECODE"] = "1"
if self.is_venv:
os.environ["PYTHONPATH"] = self.base_paths["PYTHONPATH"]
os.environ["VIRTUAL_ENV"] = vistir.compat.fs_str(prefix)
os.environ["VIRTUAL_ENV"] = prefix
else:
if not self.project.s.PIPENV_USE_SYSTEM and not os.environ.get(
"VIRTUAL_ENV"
Expand Down
5 changes: 3 additions & 2 deletions pipenv/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
from vistir.path import normalize_drive

from pipenv._compat import fix_utf8
from pipenv.vendor.vistir.misc import _isatty, fs_str
from pipenv.vendor.vistir.misc import _isatty

# HACK: avoid resolver.py uses the wrong byte code files.
# I hope I can remove this one day.
os.environ["PYTHONDONTWRITEBYTECODE"] = fs_str("1")

os.environ["PYTHONDONTWRITEBYTECODE"] = "1"
_false_values = ("0", "false", "no", "off")
_true_values = ("1", "true", "yes", "on")

Expand Down
4 changes: 1 addition & 3 deletions pipenv/utils/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

from packaging.markers import Marker

from pipenv import fs_str

from .constants import SCHEME_LIST, VCS_LIST
from .shell import temp_path

Expand Down Expand Up @@ -299,7 +297,7 @@ def locked_repository(requirement):
if not requirement.is_vcs:
return
original_base = os.environ.pop("PIP_SHIMS_BASE_MODULE", None)
os.environ["PIP_SHIMS_BASE_MODULE"] = fs_str("pipenv.patched.notpip")
os.environ["PIP_SHIMS_BASE_MODULE"] = "pipenv.patched.notpip"
src_dir = create_tracked_tempdir(prefix="pipenv-", suffix="-src")
try:
with requirement.req.locked_vcs_repo(src_dir=src_dir) as repo:
Expand Down
9 changes: 4 additions & 5 deletions pipenv/utils/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,6 @@ def venv_resolve_deps(
from pipenv import resolver
from pipenv._compat import decode_for_output
from pipenv.vendor.vistir.compat import JSONDecodeError, NamedTemporaryFile, Path
from pipenv.vendor.vistir.misc import fs_str

results = []
pipfile_section = "dev-packages" if dev else "packages"
Expand Down Expand Up @@ -980,19 +979,19 @@ def venv_resolve_deps(
target_file.close()
cmd.extend(["--write", make_posix(target_file.name)])
with temp_environ():
os.environ.update({fs_str(k): fs_str(val) for k, val in os.environ.items()})
os.environ.update({k: str(val) for k, val in os.environ.items()})
if pypi_mirror:
os.environ["PIPENV_PYPI_MIRROR"] = str(pypi_mirror)
os.environ["PIPENV_VERBOSITY"] = str(project.s.PIPENV_VERBOSITY)
os.environ["PIPENV_REQ_DIR"] = fs_str(req_dir)
os.environ["PIP_NO_INPUT"] = fs_str("1")
os.environ["PIPENV_REQ_DIR"] = req_dir
os.environ["PIP_NO_INPUT"] = "1"
pipenv_site_dir = get_pipenv_sitedir()
if pipenv_site_dir is not None:
os.environ["PIPENV_SITE_DIR"] = pipenv_site_dir
else:
os.environ.pop("PIPENV_SITE_DIR", None)
if keep_outdated:
os.environ["PIPENV_KEEP_OUTDATED"] = fs_str("1")
os.environ["PIPENV_KEEP_OUTDATED"] = "1"
with create_spinner(
text=decode_for_output("Locking..."), setting=project.s
) as sp:
Expand Down
3 changes: 1 addition & 2 deletions pipenv/utils/spinner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
@contextlib.contextmanager
def create_spinner(text, setting, nospin=None, spinner_name=None):
from pipenv.vendor.vistir import spin
from pipenv.vendor.vistir.misc import fs_str

if not spinner_name:
spinner_name = setting.PIPENV_SPINNER
if nospin is None:
nospin = setting.PIPENV_NOSPIN
with spin.create_spinner(
spinner_name=spinner_name,
start_text=fs_str(text),
start_text=text,
nospin=nospin,
write_to_stdout=False,
) as sp:
Expand Down
Loading

0 comments on commit 2bf70b7

Please sign in to comment.