summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernat Gabor <bgabor8@bloomberg.net>2018-10-25 15:51:38 +0100
committerBernat Gabor <bgabor8@bloomberg.net>2018-10-25 16:16:56 +0100
commit65c33caf12046592ca32a0e3fa92e07e5076948b (patch)
treea0593f724b6d0ae102745471cf98abf332dbdd9b
parentc8bd006d3f2a03756357937712b26b4671dabd35 (diff)
downloadvirtualenv-65c33caf12046592ca32a0e3fa92e07e5076948b.tar.gz
fix flake8 errors
-rw-r--r--.pre-commit-config.yaml7
-rw-r--r--AUTHORS.txt1
-rwxr-xr-xsrc/virtualenv.py110
-rw-r--r--tests/test_virtualenv.py8
-rw-r--r--tox.ini5
-rw-r--r--virtualenv_embedded/deactivate.bat1
-rw-r--r--virtualenv_embedded/distutils-init.py14
7 files changed, 71 insertions, 75 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index ff6b256..ff8b951 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -15,7 +15,7 @@ repos:
rev: v1.2.0
hooks:
- id: seed-isort-config
- args: [--application-directories, "src:."]
+ args: [--application-directories, "src:tests:virtualenv_embedded"]
- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.4
hooks:
@@ -27,8 +27,11 @@ repos:
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
+ - id: check-merge-conflict
+ - id: trailing-whitespace
+ - id: check-docstring-first
- id: flake8
- additional_dependencies: ["flake8-bugbear == 18.2.0"]
+ additional_dependencies: ["flake8-bugbear == 18.8.0"]
language_version: python3.7
- repo: https://github.com/asottile/pyupgrade
rev: v1.9.1
diff --git a/AUTHORS.txt b/AUTHORS.txt
index aa077b2..ea68f33 100644
--- a/AUTHORS.txt
+++ b/AUTHORS.txt
@@ -7,6 +7,7 @@ Maintainers
-----------
Brian Rosner
+Bernat Gabor
Carl Meyer
Jannis Leidel
Paul Moore
diff --git a/src/virtualenv.py b/src/virtualenv.py
index 3215427..e814484 100755
--- a/src/virtualenv.py
+++ b/src/virtualenv.py
@@ -24,13 +24,11 @@ import glob
import logging
import optparse
import os
-import pkgutil
import re
import shutil
import struct
import subprocess
import sys
-import tempfile
import textwrap
import zlib
from distutils.util import strtobool
@@ -696,14 +694,14 @@ def main():
)
if "extend_parser" in globals():
- extend_parser(parser)
+ extend_parser(parser) # noqa: F821
options, args = parser.parse_args()
global logger
if "adjust_options" in globals():
- adjust_options(options, args)
+ adjust_options(options, args) # noqa: F821
verbosity = options.verbose - options.quiet
logger = Logger([(Logger.level_for_integer(2 - verbosity), sys.stdout)])
@@ -764,7 +762,7 @@ def main():
symlink=options.symlink,
)
if "after_install" in globals():
- after_install(options, home_dir)
+ after_install(options, home_dir) # noqa: F821
def call_subprocess(
@@ -1175,8 +1173,8 @@ def install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages, clear, sy
if clear:
rmtree(lib_dir)
- ## FIXME: why not delete it?
- ## Maybe it should delete everything with #!/path/to/venv/python in it
+ # FIXME: why not delete it?
+ # Maybe it should delete everything with #!/path/to/venv/python in it
logger.notify("Not deleting %s", bin_dir)
if hasattr(sys, "real_prefix"):
@@ -1304,7 +1302,7 @@ def install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages, clear, sy
os.unlink(pyd_pth)
if sys.executable != py_executable:
- ## FIXME: could I just hard link?
+ # FIXME: could I just hard link?
executable = sys.executable
shutil.copyfile(executable, py_executable)
make_exe(py_executable)
@@ -1413,7 +1411,7 @@ def install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages, clear, sy
# And then change the install_name of the copied python executable
try:
mach_o_change(py_executable, os.path.join(prefix, "Python"), "@executable_path/../.Python")
- except:
+ except Exception:
e = sys.exc_info()[1]
logger.warn("Could not call mach_o_change: %s. " "Trying to call install_name_tool instead." % e)
try:
@@ -1426,7 +1424,7 @@ def install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages, clear, sy
py_executable,
]
)
- except:
+ except Exception:
logger.fatal("Could not call install_name_tool -- you must " "have Apple's development tools installed")
raise
@@ -1493,7 +1491,7 @@ def install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages, clear, sy
pydistutils = os.path.expanduser("~/.pydistutils.cfg")
if os.path.exists(pydistutils):
logger.notify("Please make sure you remove any previous custom paths from " "your %s file." % pydistutils)
- ## FIXME: really this should be calculated earlier
+ # FIXME: really this should be calculated earlier
fix_local_scheme(home_dir, symlink)
@@ -1553,17 +1551,17 @@ def install_python_config(home_dir, bin_dir, prompt=None):
else:
files = {"python-config": PYTHON_CONFIG}
install_files(home_dir, bin_dir, prompt, files)
- for name, content in files.items():
+ for name, _ in files.items():
make_exe(os.path.join(bin_dir, name))
def install_distutils(home_dir):
distutils_path = change_prefix(distutils.__path__[0], home_dir)
mkdir(distutils_path)
- ## FIXME: maybe this prefix setting should only be put in place if
- ## there's a local distutils.cfg with a prefix setting?
+ # FIXME: maybe this prefix setting should only be put in place if
+ # there's a local distutils.cfg with a prefix setting?
home_dir = os.path.abspath(home_dir)
- ## FIXME: this is breaking things, removing for now:
+ # FIXME: this is breaking things, removing for now:
# distutils_cfg = DISTUTILS_CFG + "\n[install]\nprefix=%s\n" % home_dir
writefile(os.path.join(distutils_path, "__init__.py"), DISTUTILS_INIT)
writefile(os.path.join(distutils_path, "distutils.cfg"), DISTUTILS_CFG, overwrite=False)
@@ -1651,10 +1649,7 @@ def is_executable(exe):
return os.path.isfile(exe) and os.access(exe, os.X_OK)
-############################################################
-## Relocating the environment:
-
-
+# Relocating the environment:
def make_environment_relocatable(home_dir):
"""
Makes the already-existing environment use relative paths, and takes out
@@ -1669,7 +1664,7 @@ def make_environment_relocatable(home_dir):
)
fixup_scripts(home_dir, bin_dir)
fixup_pth_and_egg_link(home_dir)
- ## FIXME: need to fix up distutils.cfg
+ # FIXME: need to fix up distutils.cfg
OK_ABS_SCRIPTS = [
@@ -1733,7 +1728,12 @@ def fixup_scripts(home_dir, bin_dir):
def relative_script(lines):
"Return a script that'll work in a relocatable environment."
- activate = "import os; activate_this=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'activate_this.py'); exec(compile(open(activate_this).read(), activate_this, 'exec'), dict(__file__=activate_this)); del os, activate_this"
+ activate = (
+ "import os; "
+ "activate_this=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'activate_this.py'); "
+ "exec(compile(open(activate_this).read(), activate_this, 'exec'), dict(__file__=activate_this)); "
+ "del os, activate_this"
+ )
# Find the last future statement in the script. If we insert the activation
# line before a future statement, Python will raise a SyntaxError.
activate_at = None
@@ -1843,10 +1843,7 @@ def make_relative_path(source, dest, dest_is_directory=True):
return os.path.sep.join(full_parts)
-############################################################
-## Bootstrap script creation:
-
-
+# Bootstrap script creation:
def create_bootstrap_script(extra_text, python_version=""):
"""
Creates a bootstrap script, which is like this script but with
@@ -1893,13 +1890,11 @@ def create_bootstrap_script(extra_text, python_version=""):
with codecs.open(filename, "r", encoding="utf-8") as f:
content = f.read()
py_exe = "python%s" % python_version
- content = ("#!/usr/bin/env %s\n" % py_exe) + "## WARNING: This file is generated\n" + content
+ content = ("#!/usr/bin/env %s\n" % py_exe) + "# WARNING: This file is generated\n" + content
return content.replace("##EXT" "END##", extra_text)
-##EXTEND##
-
-
+# EXTEND
def convert(s):
b = base64.b64decode(s.encode("ascii"))
return zlib.decompress(b).decode("utf-8")
@@ -2122,10 +2117,10 @@ MCqnOxv7/x7Np6yv9P2Ker5dmX8yNyCkkWnbZy3N5LarczlqL8htx2EM9rQ/2H5BvIsIEi8OEG8U
# file deactivate.bat
DEACTIVATE_BAT = convert(
"""
-eJyFkN0KgkAUhO8XfIdBkOoVAqFAQyF/EBO6ksrdXCg3cqvXbxdJTRTP3ZwzZ/iYDb2UAoIxgxik
-phKZn6SH7T53w8zWu8QN4IhqIfGqKZYrSIHTW/ACj6c43+i9xofLErKkd/AKVrxNPcsgnKESEgVl
-vKIF8mjv5L/sOImCOMVVqCw3dPxd1mwMAjWawmwWtjXyZ5mdb+SsqNf/oTMwx9SLQi8K3D6Q1n2c
-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PKXkjzanKHH10fCQbmuxFDthBx4SryQquOlfaGMYqWhlYR
+Cs93YEKR1PI30oa6x8jzhRbDMRKIM92PmVP7QtjCqpsOi45ZCHWYVlgMrbbyORnzjQPW+DPdPEvy
+9hwBV++S0K2G5r16aPXMXGuR8T7ZE8U4aq8uLYnSqdIYC5Y5NgscNjiPGgwi9cAsy4t0cqEq+yRx
+IC4iXikBbwhpedAnkdLxjE1FNA9Vla6Eb4Q7GhXUWHgTfCbliM8KDWJ6jS18yjFsqkV4vhRSlVSm
+vWI+FXWsGsSzkyk1zcK2osQnULnFEg352VIP6uBBHMPmsjd1+959XMsxHstwp057l1jF7FKYOPMq
+XfphuDTXC9klDGJ4ijk8M3vYuC6hSQ/QF9BE8RJNasQVjjSSXkQ3VgJqWf8j3IuopjF9FnzUuQx+
+JFwHf4ZmMUezt9eJTzyMnImpSLYKfyRPv+ZmZztgPT6dxRU/ne6Qg5ceEPRhvDTN1lradIg1fogN
+56YTeQiK3qaly3y6k/fvfsGHaOL/N8KONihN29OwfdcfuMdo+rjwicftIz6NqDfyphmOzh8FUQjU
+OmchoHvC5YLn/jHq19/AXef8fuqdzMaUHI4sSBblY4VlK1J2kRsLnsW8+Rc/zwIT
"""
)
@@ -2390,7 +2384,7 @@ def mach_o_change(path, what, value):
if bits == 64:
read_data(file, endian)
# The header is followed by ncmds commands
- for n in range(ncmds):
+ for _ in range(ncmds):
where = file.tell()
# Read command header
cmd, cmdsize = read_data(file, endian, 2)
@@ -2417,7 +2411,7 @@ def mach_o_change(path, what, value):
if magic == FAT_MAGIC:
# Fat binaries contain nfat_arch Mach-O binaries
nfat_arch = read_data(file, BIG_ENDIAN)
- for n in range(nfat_arch):
+ for _ in range(nfat_arch):
# Read arch header
cputype, cpusubtype, offset, size, align = read_data(file, BIG_ENDIAN, 5)
do_file(file, offset, size)
diff --git a/tests/test_virtualenv.py b/tests/test_virtualenv.py
index bf42a88..27f3d10 100644
--- a/tests/test_virtualenv.py
+++ b/tests/test_virtualenv.py
@@ -1,12 +1,11 @@
import optparse
import os
-import platform # noqa
import shutil
import sys
import tempfile
import pytest
-from mock import Mock, NonCallableMock, call, patch
+from mock import NonCallableMock, call, patch
import virtualenv
@@ -229,7 +228,10 @@ def test_activate_after_future_statements():
"from __future__ import with_statement",
"from __future__ import print_function",
"",
- "import os; activate_this=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'activate_this.py'); exec(compile(open(activate_this).read(), activate_this, 'exec'), dict(__file__=activate_this)); del os, activate_this",
+ "import os; "
+ "activate_this=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'activate_this.py'); "
+ "exec(compile(open(activate_this).read(), activate_this, 'exec'), dict(__file__=activate_this)); "
+ "del os, activate_this",
"",
'print("Hello, world!")',
]
diff --git a/tox.ini b/tox.ini
index e01a404..57b9f6b 100644
--- a/tox.ini
+++ b/tox.ini
@@ -94,8 +94,7 @@ commands = python {toxinidir}/bin/rebuild-script.py
[testenv:fix_lint]
description = format the code base to adhere to our styles, and complain about what we cannot do automatically
basepython = python3.7
-passenv = HOMEPATH
- PROGRAMDATA
+passenv = HOMEPATH PROGRAMDATA http_proxy https_proxy no_proxy
deps = pre-commit == 1.12.0
skip_install = True
commands = pre-commit run --all-files --show-diff-on-failure
@@ -106,7 +105,7 @@ multi_line_output = 3
include_trailing_comma = True
force_grid_wrap = 0
line_length = 120
-known_first_party = tox,tests
+known_first_party = virtualenv
known_third_party = __builtin__,_winreg,mock,pytest,sets,setuptools,sitecustomize,sphinx_rtd_theme,urlparse,usercustomize,winreg
[flake8]
diff --git a/virtualenv_embedded/deactivate.bat b/virtualenv_embedded/deactivate.bat
index 7bbc568..5ad81d4 100644
--- a/virtualenv_embedded/deactivate.bat
+++ b/virtualenv_embedded/deactivate.bat
@@ -17,3 +17,4 @@ if not defined _OLD_VIRTUAL_PATH goto ENDIFVPATH
set "PATH=%_OLD_VIRTUAL_PATH%"
set _OLD_VIRTUAL_PATH=
:ENDIFVPATH
+
diff --git a/virtualenv_embedded/distutils-init.py b/virtualenv_embedded/distutils-init.py
index 2cba3b1..59f55f1 100644
--- a/virtualenv_embedded/distutils-init.py
+++ b/virtualenv_embedded/distutils-init.py
@@ -14,7 +14,7 @@ distutils_path = os.path.join(os.path.dirname(opcode.__file__), "distutils")
if os.path.normpath(distutils_path) == os.path.dirname(os.path.normpath(__file__)):
warnings.warn("The virtualenv distutils package at %s appears to be in the same location as the system distutils?")
else:
- __path__.insert(0, distutils_path)
+ __path__.insert(0, distutils_path) # noqa: F821
real_distutils = imp.load_module("_virtualenv_distutils", None, distutils_path, ("", "", imp.PKG_DIRECTORY))
# Copy the relevant attributes
try:
@@ -30,8 +30,8 @@ try:
except NameError:
basestring = str
-## patch build_ext (distutils doesn't know how to get the libs directory
-## path on windows - it hardcodes the paths around the patched sys.prefix)
+# patch build_ext (distutils doesn't know how to get the libs directory
+# path on windows - it hardcodes the paths around the patched sys.prefix)
if sys.platform == "win32":
from distutils.command.build_ext import build_ext as old_build_ext
@@ -50,17 +50,13 @@ if sys.platform == "win32":
build_ext_module.build_ext = build_ext
-## distutils.dist patches:
+# distutils.dist patches:
old_find_config_files = dist.Distribution.find_config_files
def find_config_files(self):
found = old_find_config_files(self)
- system_distutils = os.path.join(distutils_path, "distutils.cfg")
- # if os.path.exists(system_distutils):
- # found.insert(0, system_distutils)
- # What to call the per-user config file
if os.name == "posix":
user_filename = ".pydistutils.cfg"
else:
@@ -76,7 +72,7 @@ def find_config_files(self):
dist.Distribution.find_config_files = find_config_files
-## distutils.sysconfig patches:
+# distutils.sysconfig patches:
old_get_python_inc = sysconfig.get_python_inc