wsba-hockey 1.0.3__py3-none-any.whl → 1.0.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. wsba_hockey/__init__.py +1 -1
  2. wsba_hockey/data_pipelines.py +183 -0
  3. wsba_hockey/evidence/weakside-breakout/node_modules/duckdb/vendor.py +146 -0
  4. wsba_hockey/evidence/weakside-breakout/node_modules/flatted/python/flatted.py +149 -0
  5. wsba_hockey/evidence/weakside-breakout/node_modules/flatted/python/test.py +63 -0
  6. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/gyp_main.py +45 -0
  7. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +367 -0
  8. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  9. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1270 -0
  10. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
  11. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  12. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +153 -0
  13. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +271 -0
  14. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
  15. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +690 -0
  16. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/common.py +661 -0
  17. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +78 -0
  18. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +165 -0
  19. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +109 -0
  20. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  21. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  22. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +808 -0
  23. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1173 -0
  24. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1321 -0
  25. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +120 -0
  26. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +103 -0
  27. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +464 -0
  28. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
  29. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +58 -0
  30. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2714 -0
  31. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3981 -0
  32. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  33. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2936 -0
  34. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +55 -0
  35. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1394 -0
  36. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +25 -0
  37. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/input.py +3130 -0
  38. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +98 -0
  39. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +771 -0
  40. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1271 -0
  41. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  42. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  43. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +374 -0
  44. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1939 -0
  45. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +302 -0
  46. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3197 -0
  47. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
  48. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/test_gyp.py +261 -0
  49. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/graphviz.py +102 -0
  50. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_gyp.py +156 -0
  51. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_sln.py +181 -0
  52. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_vcproj.py +339 -0
  53. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/test/fixtures/test-charmap.py +31 -0
  54. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/update-gyp.py +64 -0
  55. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/gyp_main.py +45 -0
  56. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +367 -0
  57. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  58. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1270 -0
  59. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
  60. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  61. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +153 -0
  62. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +271 -0
  63. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
  64. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +666 -0
  65. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/common.py +654 -0
  66. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +78 -0
  67. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +165 -0
  68. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +109 -0
  69. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  70. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  71. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +808 -0
  72. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1173 -0
  73. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1321 -0
  74. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +120 -0
  75. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +103 -0
  76. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +464 -0
  77. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
  78. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +58 -0
  79. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2518 -0
  80. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3978 -0
  81. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  82. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2936 -0
  83. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +55 -0
  84. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1394 -0
  85. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +25 -0
  86. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/input.py +3137 -0
  87. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +98 -0
  88. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +771 -0
  89. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1271 -0
  90. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  91. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  92. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +374 -0
  93. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1939 -0
  94. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +302 -0
  95. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3197 -0
  96. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
  97. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/setup.py +42 -0
  98. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/test_gyp.py +260 -0
  99. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/graphviz.py +102 -0
  100. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_gyp.py +156 -0
  101. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_sln.py +181 -0
  102. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_vcproj.py +339 -0
  103. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/test/fixtures/test-charmap.py +31 -0
  104. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/update-gyp.py +46 -0
  105. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/game_stats/app.py +400 -0
  106. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/game_stats/name_fix.py +47 -0
  107. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/app.py +108 -0
  108. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/plot.py +93 -0
  109. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/rink_plot.py +245 -0
  110. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/app.py +145 -0
  111. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/plot.py +77 -0
  112. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/rink_plot.py +245 -0
  113. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/app.py +389 -0
  114. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/plot.py +70 -0
  115. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/rink_plot.py +245 -0
  116. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/app.py +110 -0
  117. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/plot.py +58 -0
  118. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/rink_plot.py +245 -0
  119. wsba_hockey/tools/agg.py +243 -54
  120. wsba_hockey/tools/plotting.py +25 -25
  121. wsba_hockey/tools/scraping.py +154 -263
  122. wsba_hockey/tools/xg_model.py +369 -315
  123. wsba_hockey/workspace.py +22 -117
  124. wsba_hockey/wsba_main.py +499 -167
  125. {wsba_hockey-1.0.3.dist-info → wsba_hockey-1.0.5.dist-info}/METADATA +1 -1
  126. wsba_hockey-1.0.5.dist-info/RECORD +135 -0
  127. {wsba_hockey-1.0.3.dist-info → wsba_hockey-1.0.5.dist-info}/WHEEL +1 -1
  128. wsba_hockey/stats/calculate_viz/shot_impact.py +0 -2
  129. wsba_hockey-1.0.3.dist-info/RECORD +0 -19
  130. {wsba_hockey-1.0.3.dist-info → wsba_hockey-1.0.5.dist-info}/licenses/LICENSE +0 -0
  131. {wsba_hockey-1.0.3.dist-info → wsba_hockey-1.0.5.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,654 @@
1
+ # Copyright (c) 2012 Google Inc. All rights reserved.
2
+ # Use of this source code is governed by a BSD-style license that can be
3
+ # found in the LICENSE file.
4
+
5
+ import errno
6
+ import filecmp
7
+ import os.path
8
+ import re
9
+ import tempfile
10
+ import sys
11
+ import subprocess
12
+
13
+ from collections.abc import MutableSet
14
+
15
+
16
+ # A minimal memoizing decorator. It'll blow up if the args aren't immutable,
17
+ # among other "problems".
18
+ class memoize:
19
+ def __init__(self, func):
20
+ self.func = func
21
+ self.cache = {}
22
+
23
+ def __call__(self, *args):
24
+ try:
25
+ return self.cache[args]
26
+ except KeyError:
27
+ result = self.func(*args)
28
+ self.cache[args] = result
29
+ return result
30
+
31
+
32
+ class GypError(Exception):
33
+ """Error class representing an error, which is to be presented
34
+ to the user. The main entry point will catch and display this.
35
+ """
36
+
37
+ pass
38
+
39
+
40
+ def ExceptionAppend(e, msg):
41
+ """Append a message to the given exception's message."""
42
+ if not e.args:
43
+ e.args = (msg,)
44
+ elif len(e.args) == 1:
45
+ e.args = (str(e.args[0]) + " " + msg,)
46
+ else:
47
+ e.args = (str(e.args[0]) + " " + msg,) + e.args[1:]
48
+
49
+
50
+ def FindQualifiedTargets(target, qualified_list):
51
+ """
52
+ Given a list of qualified targets, return the qualified targets for the
53
+ specified |target|.
54
+ """
55
+ return [t for t in qualified_list if ParseQualifiedTarget(t)[1] == target]
56
+
57
+
58
+ def ParseQualifiedTarget(target):
59
+ # Splits a qualified target into a build file, target name and toolset.
60
+
61
+ # NOTE: rsplit is used to disambiguate the Windows drive letter separator.
62
+ target_split = target.rsplit(":", 1)
63
+ if len(target_split) == 2:
64
+ [build_file, target] = target_split
65
+ else:
66
+ build_file = None
67
+
68
+ target_split = target.rsplit("#", 1)
69
+ if len(target_split) == 2:
70
+ [target, toolset] = target_split
71
+ else:
72
+ toolset = None
73
+
74
+ return [build_file, target, toolset]
75
+
76
+
77
+ def ResolveTarget(build_file, target, toolset):
78
+ # This function resolves a target into a canonical form:
79
+ # - a fully defined build file, either absolute or relative to the current
80
+ # directory
81
+ # - a target name
82
+ # - a toolset
83
+ #
84
+ # build_file is the file relative to which 'target' is defined.
85
+ # target is the qualified target.
86
+ # toolset is the default toolset for that target.
87
+ [parsed_build_file, target, parsed_toolset] = ParseQualifiedTarget(target)
88
+
89
+ if parsed_build_file:
90
+ if build_file:
91
+ # If a relative path, parsed_build_file is relative to the directory
92
+ # containing build_file. If build_file is not in the current directory,
93
+ # parsed_build_file is not a usable path as-is. Resolve it by
94
+ # interpreting it as relative to build_file. If parsed_build_file is
95
+ # absolute, it is usable as a path regardless of the current directory,
96
+ # and os.path.join will return it as-is.
97
+ build_file = os.path.normpath(
98
+ os.path.join(os.path.dirname(build_file), parsed_build_file)
99
+ )
100
+ # Further (to handle cases like ../cwd), make it relative to cwd)
101
+ if not os.path.isabs(build_file):
102
+ build_file = RelativePath(build_file, ".")
103
+ else:
104
+ build_file = parsed_build_file
105
+
106
+ if parsed_toolset:
107
+ toolset = parsed_toolset
108
+
109
+ return [build_file, target, toolset]
110
+
111
+
112
+ def BuildFile(fully_qualified_target):
113
+ # Extracts the build file from the fully qualified target.
114
+ return ParseQualifiedTarget(fully_qualified_target)[0]
115
+
116
+
117
+ def GetEnvironFallback(var_list, default):
118
+ """Look up a key in the environment, with fallback to secondary keys
119
+ and finally falling back to a default value."""
120
+ for var in var_list:
121
+ if var in os.environ:
122
+ return os.environ[var]
123
+ return default
124
+
125
+
126
+ def QualifiedTarget(build_file, target, toolset):
127
+ # "Qualified" means the file that a target was defined in and the target
128
+ # name, separated by a colon, suffixed by a # and the toolset name:
129
+ # /path/to/file.gyp:target_name#toolset
130
+ fully_qualified = build_file + ":" + target
131
+ if toolset:
132
+ fully_qualified = fully_qualified + "#" + toolset
133
+ return fully_qualified
134
+
135
+
136
+ @memoize
137
+ def RelativePath(path, relative_to, follow_path_symlink=True):
138
+ # Assuming both |path| and |relative_to| are relative to the current
139
+ # directory, returns a relative path that identifies path relative to
140
+ # relative_to.
141
+ # If |follow_symlink_path| is true (default) and |path| is a symlink, then
142
+ # this method returns a path to the real file represented by |path|. If it is
143
+ # false, this method returns a path to the symlink. If |path| is not a
144
+ # symlink, this option has no effect.
145
+
146
+ # Convert to normalized (and therefore absolute paths).
147
+ if follow_path_symlink:
148
+ path = os.path.realpath(path)
149
+ else:
150
+ path = os.path.abspath(path)
151
+ relative_to = os.path.realpath(relative_to)
152
+
153
+ # On Windows, we can't create a relative path to a different drive, so just
154
+ # use the absolute path.
155
+ if sys.platform == "win32":
156
+ if (
157
+ os.path.splitdrive(path)[0].lower()
158
+ != os.path.splitdrive(relative_to)[0].lower()
159
+ ):
160
+ return path
161
+
162
+ # Split the paths into components.
163
+ path_split = path.split(os.path.sep)
164
+ relative_to_split = relative_to.split(os.path.sep)
165
+
166
+ # Determine how much of the prefix the two paths share.
167
+ prefix_len = len(os.path.commonprefix([path_split, relative_to_split]))
168
+
169
+ # Put enough ".." components to back up out of relative_to to the common
170
+ # prefix, and then append the part of path_split after the common prefix.
171
+ relative_split = [os.path.pardir] * (
172
+ len(relative_to_split) - prefix_len
173
+ ) + path_split[prefix_len:]
174
+
175
+ if len(relative_split) == 0:
176
+ # The paths were the same.
177
+ return ""
178
+
179
+ # Turn it back into a string and we're done.
180
+ return os.path.join(*relative_split)
181
+
182
+
183
+ @memoize
184
+ def InvertRelativePath(path, toplevel_dir=None):
185
+ """Given a path like foo/bar that is relative to toplevel_dir, return
186
+ the inverse relative path back to the toplevel_dir.
187
+
188
+ E.g. os.path.normpath(os.path.join(path, InvertRelativePath(path)))
189
+ should always produce the empty string, unless the path contains symlinks.
190
+ """
191
+ if not path:
192
+ return path
193
+ toplevel_dir = "." if toplevel_dir is None else toplevel_dir
194
+ return RelativePath(toplevel_dir, os.path.join(toplevel_dir, path))
195
+
196
+
197
+ def FixIfRelativePath(path, relative_to):
198
+ # Like RelativePath but returns |path| unchanged if it is absolute.
199
+ if os.path.isabs(path):
200
+ return path
201
+ return RelativePath(path, relative_to)
202
+
203
+
204
+ def UnrelativePath(path, relative_to):
205
+ # Assuming that |relative_to| is relative to the current directory, and |path|
206
+ # is a path relative to the dirname of |relative_to|, returns a path that
207
+ # identifies |path| relative to the current directory.
208
+ rel_dir = os.path.dirname(relative_to)
209
+ return os.path.normpath(os.path.join(rel_dir, path))
210
+
211
+
212
+ # re objects used by EncodePOSIXShellArgument. See IEEE 1003.1 XCU.2.2 at
213
+ # http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_02
214
+ # and the documentation for various shells.
215
+
216
+ # _quote is a pattern that should match any argument that needs to be quoted
217
+ # with double-quotes by EncodePOSIXShellArgument. It matches the following
218
+ # characters appearing anywhere in an argument:
219
+ # \t, \n, space parameter separators
220
+ # # comments
221
+ # $ expansions (quoted to always expand within one argument)
222
+ # % called out by IEEE 1003.1 XCU.2.2
223
+ # & job control
224
+ # ' quoting
225
+ # (, ) subshell execution
226
+ # *, ?, [ pathname expansion
227
+ # ; command delimiter
228
+ # <, >, | redirection
229
+ # = assignment
230
+ # {, } brace expansion (bash)
231
+ # ~ tilde expansion
232
+ # It also matches the empty string, because "" (or '') is the only way to
233
+ # represent an empty string literal argument to a POSIX shell.
234
+ #
235
+ # This does not match the characters in _escape, because those need to be
236
+ # backslash-escaped regardless of whether they appear in a double-quoted
237
+ # string.
238
+ _quote = re.compile("[\t\n #$%&'()*;<=>?[{|}~]|^$")
239
+
240
+ # _escape is a pattern that should match any character that needs to be
241
+ # escaped with a backslash, whether or not the argument matched the _quote
242
+ # pattern. _escape is used with re.sub to backslash anything in _escape's
243
+ # first match group, hence the (parentheses) in the regular expression.
244
+ #
245
+ # _escape matches the following characters appearing anywhere in an argument:
246
+ # " to prevent POSIX shells from interpreting this character for quoting
247
+ # \ to prevent POSIX shells from interpreting this character for escaping
248
+ # ` to prevent POSIX shells from interpreting this character for command
249
+ # substitution
250
+ # Missing from this list is $, because the desired behavior of
251
+ # EncodePOSIXShellArgument is to permit parameter (variable) expansion.
252
+ #
253
+ # Also missing from this list is !, which bash will interpret as the history
254
+ # expansion character when history is enabled. bash does not enable history
255
+ # by default in non-interactive shells, so this is not thought to be a problem.
256
+ # ! was omitted from this list because bash interprets "\!" as a literal string
257
+ # including the backslash character (avoiding history expansion but retaining
258
+ # the backslash), which would not be correct for argument encoding. Handling
259
+ # this case properly would also be problematic because bash allows the history
260
+ # character to be changed with the histchars shell variable. Fortunately,
261
+ # as history is not enabled in non-interactive shells and
262
+ # EncodePOSIXShellArgument is only expected to encode for non-interactive
263
+ # shells, there is no room for error here by ignoring !.
264
+ _escape = re.compile(r'(["\\`])')
265
+
266
+
267
+ def EncodePOSIXShellArgument(argument):
268
+ """Encodes |argument| suitably for consumption by POSIX shells.
269
+
270
+ argument may be quoted and escaped as necessary to ensure that POSIX shells
271
+ treat the returned value as a literal representing the argument passed to
272
+ this function. Parameter (variable) expansions beginning with $ are allowed
273
+ to remain intact without escaping the $, to allow the argument to contain
274
+ references to variables to be expanded by the shell.
275
+ """
276
+
277
+ if not isinstance(argument, str):
278
+ argument = str(argument)
279
+
280
+ if _quote.search(argument):
281
+ quote = '"'
282
+ else:
283
+ quote = ""
284
+
285
+ encoded = quote + re.sub(_escape, r"\\\1", argument) + quote
286
+
287
+ return encoded
288
+
289
+
290
+ def EncodePOSIXShellList(list):
291
+ """Encodes |list| suitably for consumption by POSIX shells.
292
+
293
+ Returns EncodePOSIXShellArgument for each item in list, and joins them
294
+ together using the space character as an argument separator.
295
+ """
296
+
297
+ encoded_arguments = []
298
+ for argument in list:
299
+ encoded_arguments.append(EncodePOSIXShellArgument(argument))
300
+ return " ".join(encoded_arguments)
301
+
302
+
303
+ def DeepDependencyTargets(target_dicts, roots):
304
+ """Returns the recursive list of target dependencies."""
305
+ dependencies = set()
306
+ pending = set(roots)
307
+ while pending:
308
+ # Pluck out one.
309
+ r = pending.pop()
310
+ # Skip if visited already.
311
+ if r in dependencies:
312
+ continue
313
+ # Add it.
314
+ dependencies.add(r)
315
+ # Add its children.
316
+ spec = target_dicts[r]
317
+ pending.update(set(spec.get("dependencies", [])))
318
+ pending.update(set(spec.get("dependencies_original", [])))
319
+ return list(dependencies - set(roots))
320
+
321
+
322
+ def BuildFileTargets(target_list, build_file):
323
+ """From a target_list, returns the subset from the specified build_file.
324
+ """
325
+ return [p for p in target_list if BuildFile(p) == build_file]
326
+
327
+
328
+ def AllTargets(target_list, target_dicts, build_file):
329
+ """Returns all targets (direct and dependencies) for the specified build_file.
330
+ """
331
+ bftargets = BuildFileTargets(target_list, build_file)
332
+ deptargets = DeepDependencyTargets(target_dicts, bftargets)
333
+ return bftargets + deptargets
334
+
335
+
336
+ def WriteOnDiff(filename):
337
+ """Write to a file only if the new contents differ.
338
+
339
+ Arguments:
340
+ filename: name of the file to potentially write to.
341
+ Returns:
342
+ A file like object which will write to temporary file and only overwrite
343
+ the target if it differs (on close).
344
+ """
345
+
346
+ class Writer:
347
+ """Wrapper around file which only covers the target if it differs."""
348
+
349
+ def __init__(self):
350
+ # On Cygwin remove the "dir" argument
351
+ # `C:` prefixed paths are treated as relative,
352
+ # consequently ending up with current dir "/cygdrive/c/..."
353
+ # being prefixed to those, which was
354
+ # obviously a non-existent path,
355
+ # for example: "/cygdrive/c/<some folder>/C:\<my win style abs path>".
356
+ # For more details see:
357
+ # https://docs.python.org/2/library/tempfile.html#tempfile.mkstemp
358
+ base_temp_dir = "" if IsCygwin() else os.path.dirname(filename)
359
+ # Pick temporary file.
360
+ tmp_fd, self.tmp_path = tempfile.mkstemp(
361
+ suffix=".tmp",
362
+ prefix=os.path.split(filename)[1] + ".gyp.",
363
+ dir=base_temp_dir,
364
+ )
365
+ try:
366
+ self.tmp_file = os.fdopen(tmp_fd, "wb")
367
+ except Exception:
368
+ # Don't leave turds behind.
369
+ os.unlink(self.tmp_path)
370
+ raise
371
+
372
+ def __getattr__(self, attrname):
373
+ # Delegate everything else to self.tmp_file
374
+ return getattr(self.tmp_file, attrname)
375
+
376
+ def close(self):
377
+ try:
378
+ # Close tmp file.
379
+ self.tmp_file.close()
380
+ # Determine if different.
381
+ same = False
382
+ try:
383
+ same = filecmp.cmp(self.tmp_path, filename, False)
384
+ except OSError as e:
385
+ if e.errno != errno.ENOENT:
386
+ raise
387
+
388
+ if same:
389
+ # The new file is identical to the old one, just get rid of the new
390
+ # one.
391
+ os.unlink(self.tmp_path)
392
+ else:
393
+ # The new file is different from the old one,
394
+ # or there is no old one.
395
+ # Rename the new file to the permanent name.
396
+ #
397
+ # tempfile.mkstemp uses an overly restrictive mode, resulting in a
398
+ # file that can only be read by the owner, regardless of the umask.
399
+ # There's no reason to not respect the umask here,
400
+ # which means that an extra hoop is required
401
+ # to fetch it and reset the new file's mode.
402
+ #
403
+ # No way to get the umask without setting a new one? Set a safe one
404
+ # and then set it back to the old value.
405
+ umask = os.umask(0o77)
406
+ os.umask(umask)
407
+ os.chmod(self.tmp_path, 0o666 & ~umask)
408
+ if sys.platform == "win32" and os.path.exists(filename):
409
+ # NOTE: on windows (but not cygwin) rename will not replace an
410
+ # existing file, so it must be preceded with a remove.
411
+ # Sadly there is no way to make the switch atomic.
412
+ os.remove(filename)
413
+ os.rename(self.tmp_path, filename)
414
+ except Exception:
415
+ # Don't leave turds behind.
416
+ os.unlink(self.tmp_path)
417
+ raise
418
+
419
+ def write(self, s):
420
+ self.tmp_file.write(s.encode("utf-8"))
421
+
422
+ return Writer()
423
+
424
+
425
+ def EnsureDirExists(path):
426
+ """Make sure the directory for |path| exists."""
427
+ try:
428
+ os.makedirs(os.path.dirname(path))
429
+ except OSError:
430
+ pass
431
+
432
+
433
+ def GetFlavor(params):
434
+ """Returns |params.flavor| if it's set, the system's default flavor else."""
435
+ flavors = {
436
+ "cygwin": "win",
437
+ "win32": "win",
438
+ "darwin": "mac",
439
+ }
440
+
441
+ if "flavor" in params:
442
+ return params["flavor"]
443
+ if sys.platform in flavors:
444
+ return flavors[sys.platform]
445
+ if sys.platform.startswith("sunos"):
446
+ return "solaris"
447
+ if sys.platform.startswith(("dragonfly", "freebsd")):
448
+ return "freebsd"
449
+ if sys.platform.startswith("openbsd"):
450
+ return "openbsd"
451
+ if sys.platform.startswith("netbsd"):
452
+ return "netbsd"
453
+ if sys.platform.startswith("aix"):
454
+ return "aix"
455
+ if sys.platform.startswith(("os390", "zos")):
456
+ return "zos"
457
+
458
+ return "linux"
459
+
460
+
461
+ def CopyTool(flavor, out_path, generator_flags={}):
462
+ """Finds (flock|mac|win)_tool.gyp in the gyp directory and copies it
463
+ to |out_path|."""
464
+ # aix and solaris just need flock emulation. mac and win use more complicated
465
+ # support scripts.
466
+ prefix = {"aix": "flock", "solaris": "flock", "mac": "mac", "win": "win"}.get(
467
+ flavor, None
468
+ )
469
+ if not prefix:
470
+ return
471
+
472
+ # Slurp input file.
473
+ source_path = os.path.join(
474
+ os.path.dirname(os.path.abspath(__file__)), "%s_tool.py" % prefix
475
+ )
476
+ with open(source_path) as source_file:
477
+ source = source_file.readlines()
478
+
479
+ # Set custom header flags.
480
+ header = "# Generated by gyp. Do not edit.\n"
481
+ mac_toolchain_dir = generator_flags.get("mac_toolchain_dir", None)
482
+ if flavor == "mac" and mac_toolchain_dir:
483
+ header += "import os;\nos.environ['DEVELOPER_DIR']='%s'\n" % mac_toolchain_dir
484
+
485
+ # Add header and write it out.
486
+ tool_path = os.path.join(out_path, "gyp-%s-tool" % prefix)
487
+ with open(tool_path, "w") as tool_file:
488
+ tool_file.write("".join([source[0], header] + source[1:]))
489
+
490
+ # Make file executable.
491
+ os.chmod(tool_path, 0o755)
492
+
493
+
494
+ # From Alex Martelli,
495
+ # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560
496
+ # ASPN: Python Cookbook: Remove duplicates from a sequence
497
+ # First comment, dated 2001/10/13.
498
+ # (Also in the printed Python Cookbook.)
499
+
500
+
501
+ def uniquer(seq, idfun=lambda x: x):
502
+ seen = {}
503
+ result = []
504
+ for item in seq:
505
+ marker = idfun(item)
506
+ if marker in seen:
507
+ continue
508
+ seen[marker] = 1
509
+ result.append(item)
510
+ return result
511
+
512
+
513
+ # Based on http://code.activestate.com/recipes/576694/.
514
+ class OrderedSet(MutableSet):
515
+ def __init__(self, iterable=None):
516
+ self.end = end = []
517
+ end += [None, end, end] # sentinel node for doubly linked list
518
+ self.map = {} # key --> [key, prev, next]
519
+ if iterable is not None:
520
+ self |= iterable
521
+
522
+ def __len__(self):
523
+ return len(self.map)
524
+
525
+ def __contains__(self, key):
526
+ return key in self.map
527
+
528
+ def add(self, key):
529
+ if key not in self.map:
530
+ end = self.end
531
+ curr = end[1]
532
+ curr[2] = end[1] = self.map[key] = [key, curr, end]
533
+
534
+ def discard(self, key):
535
+ if key in self.map:
536
+ key, prev_item, next_item = self.map.pop(key)
537
+ prev_item[2] = next_item
538
+ next_item[1] = prev_item
539
+
540
+ def __iter__(self):
541
+ end = self.end
542
+ curr = end[2]
543
+ while curr is not end:
544
+ yield curr[0]
545
+ curr = curr[2]
546
+
547
+ def __reversed__(self):
548
+ end = self.end
549
+ curr = end[1]
550
+ while curr is not end:
551
+ yield curr[0]
552
+ curr = curr[1]
553
+
554
+ # The second argument is an addition that causes a pylint warning.
555
+ def pop(self, last=True): # pylint: disable=W0221
556
+ if not self:
557
+ raise KeyError("set is empty")
558
+ key = self.end[1][0] if last else self.end[2][0]
559
+ self.discard(key)
560
+ return key
561
+
562
+ def __repr__(self):
563
+ if not self:
564
+ return f"{self.__class__.__name__}()"
565
+ return f"{self.__class__.__name__}({list(self)!r})"
566
+
567
+ def __eq__(self, other):
568
+ if isinstance(other, OrderedSet):
569
+ return len(self) == len(other) and list(self) == list(other)
570
+ return set(self) == set(other)
571
+
572
+ # Extensions to the recipe.
573
+ def update(self, iterable):
574
+ for i in iterable:
575
+ if i not in self:
576
+ self.add(i)
577
+
578
+
579
+ class CycleError(Exception):
580
+ """An exception raised when an unexpected cycle is detected."""
581
+
582
+ def __init__(self, nodes):
583
+ self.nodes = nodes
584
+
585
+ def __str__(self):
586
+ return "CycleError: cycle involving: " + str(self.nodes)
587
+
588
+
589
+ def TopologicallySorted(graph, get_edges):
590
+ r"""Topologically sort based on a user provided edge definition.
591
+
592
+ Args:
593
+ graph: A list of node names.
594
+ get_edges: A function mapping from node name to a hashable collection
595
+ of node names which this node has outgoing edges to.
596
+ Returns:
597
+ A list containing all of the node in graph in topological order.
598
+ It is assumed that calling get_edges once for each node and caching is
599
+ cheaper than repeatedly calling get_edges.
600
+ Raises:
601
+ CycleError in the event of a cycle.
602
+ Example:
603
+ graph = {'a': '$(b) $(c)', 'b': 'hi', 'c': '$(b)'}
604
+ def GetEdges(node):
605
+ return re.findall(r'\$\(([^))]\)', graph[node])
606
+ print TopologicallySorted(graph.keys(), GetEdges)
607
+ ==>
608
+ ['a', 'c', b']
609
+ """
610
+ get_edges = memoize(get_edges)
611
+ visited = set()
612
+ visiting = set()
613
+ ordered_nodes = []
614
+
615
+ def Visit(node):
616
+ if node in visiting:
617
+ raise CycleError(visiting)
618
+ if node in visited:
619
+ return
620
+ visited.add(node)
621
+ visiting.add(node)
622
+ for neighbor in get_edges(node):
623
+ Visit(neighbor)
624
+ visiting.remove(node)
625
+ ordered_nodes.insert(0, node)
626
+
627
+ for node in sorted(graph):
628
+ Visit(node)
629
+ return ordered_nodes
630
+
631
+
632
+ def CrossCompileRequested():
633
+ # TODO: figure out how to not build extra host objects in the
634
+ # non-cross-compile case when this is enabled, and enable unconditionally.
635
+ return (
636
+ os.environ.get("GYP_CROSSCOMPILE")
637
+ or os.environ.get("AR_host")
638
+ or os.environ.get("CC_host")
639
+ or os.environ.get("CXX_host")
640
+ or os.environ.get("AR_target")
641
+ or os.environ.get("CC_target")
642
+ or os.environ.get("CXX_target")
643
+ )
644
+
645
+
646
+ def IsCygwin():
647
+ try:
648
+ out = subprocess.Popen(
649
+ "uname", stdout=subprocess.PIPE, stderr=subprocess.STDOUT
650
+ )
651
+ stdout = out.communicate()[0].decode("utf-8")
652
+ return "CYGWIN" in str(stdout)
653
+ except Exception:
654
+ return False