Skip to content

Commit

Permalink
Remove support for Python 2
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Jan 12, 2021
1 parent cc1cbce commit 8d60afa
Show file tree
Hide file tree
Showing 37 changed files with 210 additions and 243 deletions.
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,22 @@ Depending on your operating system, you will need to install:

### On Unix

* Python v2.7, v3.5, v3.6, v3.7, or v3.8
* Python v3.5, v3.6, v3.7, v3.8, or v3.9
* `make`
* A proper C/C++ compiler toolchain, like [GCC](https://gcc.gnu.org)

### On macOS

**ATTENTION**: If your Mac has been _upgraded_ to macOS Catalina (10.15), please read [macOS_Catalina.md](macOS_Catalina.md).

* Python v2.7, v3.5, v3.6, v3.7, or v3.8
* Python v3.5, v3.6, v3.7, v3.8, or v3.9
* [Xcode](https://developer.apple.com/xcode/download/)
* You also need to install the `XCode Command Line Tools` by running `xcode-select --install`. Alternatively, if you already have the full Xcode installed, you can find them under the menu `Xcode -> Open Developer Tool -> More Developer Tools...`. This step will install `clang`, `clang++`, and `make`.

### On Windows

Install the current version of Python from the [Microsoft Store package](https://docs.python.org/3/using/windows.html#the-microsoft-store-package).

#### Option 1

Install all the required tools and configurations using Microsoft's [windows-build-tools](https://github.com/felixrieseberg/windows-build-tools) using `npm install --global windows-build-tools` from an elevated PowerShell or CMD.exe (run as Administrator).

#### Option 2

Install tools and configuration manually:
* Install Visual C++ Build Environment: [Visual Studio Build Tools](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools)
(using "Visual C++ build tools" workload) or [Visual Studio 2017 Community](https://visualstudio.microsoft.com/pl/thank-you-downloading-visual-studio/?sku=Community)
Expand All @@ -64,8 +58,8 @@ Install tools and configuration manually:

### Configuring Python Dependency

`node-gyp` requires that you have installed a compatible version of Python, one of: v2.7, v3.5, v3.6,
v3.7, or v3.8. If you have multiple Python versions installed, you can identify which Python
`node-gyp` requires that you have installed a compatible version of Python, one of: v3.5, v3.6,
v3.7, v3.8, or v3.9. If you have multiple Python versions installed, you can identify which Python
version `node-gyp` should use in one of the following ways:

1. by setting the `--python` command-line option, e.g.:
Expand Down
12 changes: 6 additions & 6 deletions gyp/pylib/gyp/MSVSNew.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def MakeGuid(name, seed="msvs_new"):
# ------------------------------------------------------------------------------


class MSVSSolutionEntry(object):
class MSVSSolutionEntry:
def __cmp__(self, other):
# Sort by name then guid (so things are in order on vs2008).
return cmp((self.name, self.get_guid()), (other.name, other.get_guid()))
Expand Down Expand Up @@ -190,7 +190,7 @@ def set_msbuild_toolset(self, msbuild_toolset):
# ------------------------------------------------------------------------------


class MSVSSolution(object):
class MSVSSolution:
"""Visual Studio solution."""

def __init__(
Expand Down Expand Up @@ -292,14 +292,14 @@ def Write(self, writer=gyp.common.WriteOnDiff):
if e.items:
f.write("\tProjectSection(SolutionItems) = preProject\r\n")
for i in e.items:
f.write("\t\t%s = %s\r\n" % (i, i))
f.write(f"\t\t{i} = {i}\r\n")
f.write("\tEndProjectSection\r\n")

if isinstance(e, MSVSProject):
if e.dependencies:
f.write("\tProjectSection(ProjectDependencies) = postProject\r\n")
for d in e.dependencies:
f.write("\t\t%s = %s\r\n" % (d.get_guid(), d.get_guid()))
f.write(f"\t\t{d.get_guid()} = {d.get_guid()}\r\n")
f.write("\tEndProjectSection\r\n")

f.write("EndProject\r\n")
Expand All @@ -310,7 +310,7 @@ def Write(self, writer=gyp.common.WriteOnDiff):
# Configurations (variants)
f.write("\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\r\n")
for v in self.variants:
f.write("\t\t%s = %s\r\n" % (v, v))
f.write(f"\t\t{v} = {v}\r\n")
f.write("\tEndGlobalSection\r\n")

# Sort config guids for easier diffing of solution changes.
Expand Down Expand Up @@ -362,7 +362,7 @@ def Write(self, writer=gyp.common.WriteOnDiff):
if not isinstance(e, MSVSFolder):
continue # Does not apply to projects, only folders
for subentry in e.entries:
f.write("\t\t%s = %s\r\n" % (subentry.get_guid(), e.get_guid()))
f.write(f"\t\t{subentry.get_guid()} = {e.get_guid()}\r\n")
f.write("\tEndGlobalSection\r\n")

f.write("EndGlobal\r\n")
Expand Down
6 changes: 3 additions & 3 deletions gyp/pylib/gyp/MSVSProject.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# ------------------------------------------------------------------------------


class Tool(object):
class Tool:
"""Visual Studio tool."""

def __init__(self, name, attrs=None):
Expand All @@ -31,7 +31,7 @@ def _GetSpecification(self):
return ["Tool", self._attrs]


class Filter(object):
class Filter:
"""Visual Studio filter - that is, a virtual folder."""

def __init__(self, name, contents=None):
Expand All @@ -48,7 +48,7 @@ def __init__(self, name, contents=None):
# ------------------------------------------------------------------------------


class Writer(object):
class Writer:
"""Visual Studio XML project writer."""

def __init__(self, project_path, version, name, guid=None, platforms=None):
Expand Down
13 changes: 6 additions & 7 deletions gyp/pylib/gyp/MSVSSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
MSBuild install directory, e.g. c:\Program Files (x86)\MSBuild
"""

from __future__ import print_function

from gyp import string_types

Expand All @@ -36,7 +35,7 @@
_msbuild_name_of_tool = {}


class _Tool(object):
class _Tool:
"""Represents a tool used by MSVS or MSBuild.
Attributes:
Expand Down Expand Up @@ -68,7 +67,7 @@ def _GetMSBuildToolSettings(msbuild_settings, tool):
return msbuild_settings.setdefault(tool.msbuild_name, {})


class _Type(object):
class _Type:
"""Type of settings (Base class)."""

def ValidateMSVS(self, value):
Expand Down Expand Up @@ -195,7 +194,7 @@ class _Enumeration(_Type):
def __init__(self, label_list, new=None):
_Type.__init__(self)
self._label_list = label_list
self._msbuild_values = set(value for value in label_list if value is not None)
self._msbuild_values = {value for value in label_list if value is not None}
if new is not None:
self._msbuild_values.update(new)

Expand Down Expand Up @@ -342,7 +341,7 @@ def _Translate(value, msbuild_settings):
if value == "true":
tool_settings = _GetMSBuildToolSettings(msbuild_settings, tool)
if "AdditionalOptions" in tool_settings:
new_flags = "%s %s" % (tool_settings["AdditionalOptions"], flag)
new_flags = "{} {}".format(tool_settings["AdditionalOptions"], flag)
else:
new_flags = flag
tool_settings["AdditionalOptions"] = new_flags
Expand Down Expand Up @@ -536,14 +535,14 @@ def _ValidateSettings(validators, settings, stderr):
tool_validators[setting](value)
except ValueError as e:
print(
"Warning: for %s/%s, %s" % (tool_name, setting, e),
f"Warning: for {tool_name}/{setting}, {e}",
file=stderr,
)
else:
_ValidateExclusionSetting(
setting,
tool_validators,
("Warning: unrecognized setting %s/%s" % (tool_name, setting)),
(f"Warning: unrecognized setting {tool_name}/{setting}"),
stderr,
)

Expand Down
2 changes: 1 addition & 1 deletion gyp/pylib/gyp/MSVSToolFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import gyp.easy_xml as easy_xml


class Writer(object):
class Writer:
"""Visual Studio XML tool file writer."""

def __init__(self, tool_file_path, name):
Expand Down
4 changes: 2 additions & 2 deletions gyp/pylib/gyp/MSVSUserFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _QuoteWin32CommandLineArgs(args):
return new_args


class Writer(object):
class Writer:
"""Visual Studio XML user user file writer."""

def __init__(self, user_file_path, version, name):
Expand Down Expand Up @@ -93,7 +93,7 @@ def AddDebugSettings(
abs_command = _FindCommandInPath(command[0])

if environment and isinstance(environment, dict):
env_list = ['%s="%s"' % (key, val) for (key, val) in environment.items()]
env_list = [f'{key}="{val}"' for (key, val) in environment.items()]
environment = " ".join(env_list)
else:
environment = ""
Expand Down
4 changes: 2 additions & 2 deletions gyp/pylib/gyp/MSVSUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _SuffixName(name, suffix):
Target name with suffix added (foo_suffix#target)
"""
parts = name.rsplit("#", 1)
parts[0] = "%s_%s" % (parts[0], suffix)
parts[0] = "{}_{}".format(parts[0], suffix)
return "#".join(parts)


Expand Down Expand Up @@ -160,7 +160,7 @@ def _GetPdbPath(target_dict, config_name, vars):
return pdb_path

pdb_base = target_dict.get("product_name", target_dict["target_name"])
pdb_base = "%s.%s.pdb" % (pdb_base, TARGET_TYPE_EXT[target_dict["type"]])
pdb_base = "{}.{}.pdb".format(pdb_base, TARGET_TYPE_EXT[target_dict["type"]])
pdb_path = vars["PRODUCT_DIR"] + "/" + pdb_base

return pdb_path
Expand Down
4 changes: 2 additions & 2 deletions gyp/pylib/gyp/MSVSVersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def JoinPath(*args):
return os.path.normpath(os.path.join(*args))


class VisualStudioVersion(object):
class VisualStudioVersion:
"""Information regarding a version of Visual Studio."""

def __init__(
Expand Down Expand Up @@ -235,7 +235,7 @@ def _RegistryGetValueUsingWinReg(key, value):
assert root == "HKLM" # Only need HKLM for now.
with OpenKey(HKEY_LOCAL_MACHINE, subkey) as hkey:
return QueryValueEx(hkey, value)[0]
except WindowsError:
except OSError:
return None


Expand Down
3 changes: 1 addition & 2 deletions gyp/pylib/gyp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from __future__ import print_function

import copy
import gyp.input
Expand Down Expand Up @@ -193,7 +192,7 @@ def ShlexEnv(env_name):

def FormatOpt(opt, value):
if opt.startswith("--"):
return "%s=%s" % (opt, value)
return f"{opt}={value}"
return opt + value


Expand Down
8 changes: 4 additions & 4 deletions gyp/pylib/gyp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

# A minimal memoizing decorator. It'll blow up if the args aren't immutable,
# among other "problems".
class memoize(object):
class memoize:
def __init__(self, func):
self.func = func
self.cache = {}
Expand Down Expand Up @@ -348,7 +348,7 @@ def WriteOnDiff(filename):
the target if it differs (on close).
"""

class Writer(object):
class Writer:
"""Wrapper around file which only covers the target if it differs."""

def __init__(self):
Expand Down Expand Up @@ -566,8 +566,8 @@ def pop(self, last=True): # pylint: disable=W0221

def __repr__(self):
if not self:
return "%s()" % (self.__class__.__name__,)
return "%s(%r)" % (self.__class__.__name__, list(self))
return f"{self.__class__.__name__}()"
return "{}({!r})".format(self.__class__.__name__, list(self))

def __eq__(self, other):
if isinstance(other, OrderedSet):
Expand Down
8 changes: 4 additions & 4 deletions gyp/pylib/gyp/easy_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _ConstructContentList(xml_parts, specification, pretty, level=0):
rest = specification[1:]
if rest and isinstance(rest[0], dict):
for at, val in sorted(rest[0].items()):
xml_parts.append(' %s="%s"' % (at, _XmlEscape(val, attr=True)))
xml_parts.append(' {}="{}"'.format(at, _XmlEscape(val, attr=True)))
rest = rest[1:]
if rest:
xml_parts.append(">")
Expand All @@ -101,7 +101,7 @@ def _ConstructContentList(xml_parts, specification, pretty, level=0):
_ConstructContentList(xml_parts, child_spec, pretty, level + 1)
if multi_line and indentation:
xml_parts.append(indentation)
xml_parts.append("</%s>%s" % (name, new_line))
xml_parts.append(f"</{name}>{new_line}")
else:
xml_parts.append("/>%s" % new_line)

Expand All @@ -125,9 +125,9 @@ def WriteXmlIfChanged(content, path, encoding="utf-8", pretty=False, win32=False

# Get the old content
try:
with open(path, "r") as file:
with open(path) as file:
existing = file.read()
except IOError:
except OSError:
existing = None

# It has changed, write it
Expand Down
2 changes: 1 addition & 1 deletion gyp/pylib/gyp/flock_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def main(args):
executor.Dispatch(args)


class FlockTool(object):
class FlockTool:
"""This class emulates the 'flock' command."""

def Dispatch(self, args):
Expand Down
13 changes: 6 additions & 7 deletions gyp/pylib/gyp/generator/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
then the "all" target includes "b1" and "b2".
"""

from __future__ import print_function

import gyp.common
import json
Expand Down Expand Up @@ -216,7 +215,7 @@ def _ExtractSources(target, target_dict, toplevel_dir):
return results


class Target(object):
class Target:
"""Holds information about a particular target:
deps: set of Targets this Target depends upon. This is not recursive, only the
direct dependent Targets.
Expand Down Expand Up @@ -252,7 +251,7 @@ def __init__(self, name):
self.is_or_has_linked_ancestor = False


class Config(object):
class Config:
"""Details what we're looking for
files: set of files to search for
targets: see file description for details."""
Expand All @@ -271,10 +270,10 @@ def Init(self, params):
if not config_path:
return
try:
f = open(config_path, "r")
f = open(config_path)
config = json.load(f)
f.close()
except IOError:
except OSError:
raise Exception("Unable to open file " + config_path)
except ValueError as e:
raise Exception("Unable to parse config file " + config_path + str(e))
Expand Down Expand Up @@ -586,7 +585,7 @@ def _WriteOutput(params, **values):
f = open(output_path, "w")
f.write(json.dumps(values) + "\n")
f.close()
except IOError as e:
except OSError as e:
print("Error writing to output file", output_path, str(e))


Expand Down Expand Up @@ -627,7 +626,7 @@ def CalculateVariables(default_variables, params):
default_variables.setdefault("OS", operating_system)


class TargetCalculator(object):
class TargetCalculator:
"""Calculates the matching test_targets and matching compile_targets."""

def __init__(
Expand Down
Loading

0 comments on commit 8d60afa

Please sign in to comment.