Skip to content

Commit

Permalink
Merge pull request #209 from snyk/fix/openapi-spec-validator
Browse files Browse the repository at this point in the history
fix: upgrade setuptools for python3
  • Loading branch information
admons authored May 16, 2023
2 parents 3266372 + a85607b commit 3d23738
Show file tree
Hide file tree
Showing 39 changed files with 12,822 additions and 50 deletions.
82 changes: 65 additions & 17 deletions lib/dependencies/inspect-implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,50 +70,98 @@ function createAssets() {
path.join(__dirname, '../../pysrc/pytoml/core.py'),
path.join(__dirname, '../../pysrc/pytoml/parser.py'),
path.join(__dirname, '../../pysrc/pytoml/writer.py'),

path.join(
__dirname,
'../../pysrc/pkg_resources/_vendor/packaging/version.py'
'../../pysrc/pkg_resources_py2/_vendor/packaging/version.py'
),
path.join(
__dirname,
'../../pysrc/pkg_resources_py2/_vendor/packaging/__init__.py'
),
path.join(
__dirname,
'../../pysrc/pkg_resources_py2/_vendor/packaging/utils.py'
),
path.join(
__dirname,
'../../pysrc/pkg_resources_py2/_vendor/packaging/requirements.py'
),
path.join(
__dirname,
'../../pysrc/pkg_resources_py2/_vendor/packaging/_structures.py'
),
path.join(
__dirname,
'../../pysrc/pkg_resources_py2/_vendor/packaging/markers.py'
),
path.join(
__dirname,
'../../pysrc/pkg_resources_py2/_vendor/packaging/__about__.py'
),
path.join(
__dirname,
'../../pysrc/pkg_resources_py2/_vendor/packaging/_compat.py'
),
path.join(
__dirname,
'../../pysrc/pkg_resources_py2/_vendor/packaging/specifiers.py'
),
path.join(__dirname, '../../pysrc/pkg_resources_py2/_vendor/__init__.py'),
path.join(__dirname, '../../pysrc/pkg_resources_py2/_vendor/appdirs.py'),
path.join(__dirname, '../../pysrc/pkg_resources_py2/_vendor/six.py'),
path.join(__dirname, '../../pysrc/pkg_resources_py2/_vendor/pyparsing.py'),
path.join(__dirname, '../../pysrc/pkg_resources_py2/extern/__init__.py'),
path.join(__dirname, '../../pysrc/pkg_resources_py2/py31compat.py'),
path.join(__dirname, '../../pysrc/pkg_resources_py2/__init__.py'),
path.join(
__dirname,
'../../pysrc/pkg_resources_py3/_vendor/packaging/tags.py'
),
path.join(
__dirname,
'../../pysrc/pkg_resources_py3/_vendor/packaging/_musllinux.py'
),
path.join(
__dirname,
'../../pysrc/pkg_resources_py3/_vendor/packaging/version.py'
),
path.join(
__dirname,
'../../pysrc/pkg_resources/_vendor/packaging/__init__.py'
'../../pysrc/pkg_resources_py3/_vendor/packaging/__init__.py'
),
path.join(
__dirname,
'../../pysrc/pkg_resources/_vendor/packaging/utils.py'
'../../pysrc/pkg_resources_py3/_vendor/packaging/utils.py'
),
path.join(
__dirname,
'../../pysrc/pkg_resources/_vendor/packaging/requirements.py'
'../../pysrc/pkg_resources_py3/_vendor/packaging/requirements.py'
),
path.join(
__dirname,
'../../pysrc/pkg_resources/_vendor/packaging/_structures.py'
'../../pysrc/pkg_resources_py3/_vendor/packaging/_structures.py'
),
path.join(
__dirname,
'../../pysrc/pkg_resources/_vendor/packaging/markers.py'
'../../pysrc/pkg_resources_py3/_vendor/packaging/markers.py'
),
path.join(
__dirname,
'../../pysrc/pkg_resources/_vendor/packaging/__about__.py'
'../../pysrc/pkg_resources_py3/_vendor/packaging/__about__.py'
),
path.join(
__dirname,
'../../pysrc/pkg_resources/_vendor/packaging/_compat.py'
'../../pysrc/pkg_resources_py3/_vendor/packaging/_manylinux.py'
),
path.join(
__dirname,
'../../pysrc/pkg_resources/_vendor/packaging/specifiers.py'
'../../pysrc/pkg_resources_py3/_vendor/packaging/specifiers.py'
),
path.join(__dirname, '../../pysrc/pkg_resources/_vendor/__init__.py'),
path.join(__dirname, '../../pysrc/pkg_resources/_vendor/appdirs.py'),
path.join(__dirname, '../../pysrc/pkg_resources/_vendor/six.py'),
path.join(__dirname, '../../pysrc/pkg_resources/_vendor/pyparsing.py'),
path.join(__dirname, '../../pysrc/pkg_resources/extern/__init__.py'),
path.join(__dirname, '../../pysrc/pkg_resources/py31compat.py'),
path.join(__dirname, '../../pysrc/pkg_resources/__init__.py'),
path.join(__dirname, '../../pysrc/pkg_resources_py3/_vendor/__init__.py'),
path.join(__dirname, '../../pysrc/pkg_resources_py3/_vendor/appdirs.py'),
path.join(__dirname, '../../pysrc/pkg_resources_py3/_vendor/pyparsing.py'),
path.join(__dirname, '../../pysrc/pkg_resources_py3/__init__.py'),
path.join(__dirname, '../../pysrc/pkg_resources_py3/extern/__init__.py'),
];
}

Expand Down
10 changes: 1 addition & 9 deletions pysrc/pip_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@
import codecs
from operator import le, lt, gt, ge, eq, ne

try:
import pkg_resources
except ImportError:
# try using the version vendored by pip
try:
import pip._vendor.pkg_resources as pkg_resources
except ImportError:
raise ImportError(
"Could not import pkg_resources; please install setuptools or pip.")
import pkg_resources

PYTHON_MARKER_REGEX = re.compile(r'python_version\s*(?P<operator>==|<=|>=|>|<)\s*[\'"](?P<python_version>.+?)[\'"]')
SYSTEM_MARKER_REGEX = re.compile(r'sys_platform\s*==\s*[\'"](.+)[\'"]')
Expand Down
6 changes: 6 additions & 0 deletions pysrc/pkg_resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import sys

if sys.version_info >= (3, 0):
from pkg_resources_py3 import *
else:
from pkg_resources_py2 import *
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
except NameError:
FileExistsError = OSError

from pkg_resources.extern import six
from pkg_resources.extern.six.moves import urllib, map, filter
from pkg_resources_py2.extern import six
from pkg_resources_py2.extern.six.moves import urllib, map, filter

# capture these to bypass sandboxing
from os import utime
Expand All @@ -77,12 +77,12 @@
importlib_machinery = None

from . import py31compat
from pkg_resources.extern import appdirs
from pkg_resources.extern import packaging
__import__('pkg_resources.extern.packaging.version')
__import__('pkg_resources.extern.packaging.specifiers')
__import__('pkg_resources.extern.packaging.requirements')
__import__('pkg_resources.extern.packaging.markers')
from pkg_resources_py2.extern import appdirs
from pkg_resources_py2.extern import packaging
__import__('pkg_resources_py2.extern.packaging.version')
__import__('pkg_resources_py2.extern.packaging.specifiers')
__import__('pkg_resources_py2.extern.packaging.requirements')
__import__('pkg_resources_py2.extern.packaging.markers')


__metaclass__ = type
Expand Down Expand Up @@ -1493,7 +1493,7 @@ def _fn(self, base, resource_name):
def _validate_resource_path(path):
"""
Validate the resource paths according to the docs.
https://setuptools.readthedocs.io/en/latest/pkg_resources.html#basic-resource-access
https://setuptools.readthedocs.io/en/latest/pkg_resources_py2.html#basic-resource-access
>>> warned = getfixture('recwarn')
>>> warnings.simplefilter('always')
Expand Down Expand Up @@ -1960,7 +1960,7 @@ def register_finder(importer_type, distribution_finder):
`importer_type` is the type or class of a PEP 302 "Importer" (sys.path item
handler), and `distribution_finder` is a callable that, passed a path
item and the importer instance, yields ``Distribution`` instances found on
that path item. See ``pkg_resources.find_on_path`` for an example."""
that path item. See ``pkg_resources_py2.find_on_path`` for an example."""
_distribution_finders[importer_type] = distribution_finder


Expand Down Expand Up @@ -2183,7 +2183,7 @@ def namespace_handler(importer, path_entry, moduleName, module):
agreed that it can handle the relevant path item, and they should only
return a subpath if the module __path__ does not already contain an
equivalent subpath. For an example namespace handler, see
``pkg_resources.file_ns_handler``.
``pkg_resources_py2.file_ns_handler``.
"""
_namespace_handlers[importer_type] = namespace_handler

Expand Down Expand Up @@ -2946,7 +2946,7 @@ def check_version_conflict(self):
if (modname not in sys.modules or modname in nsp
or modname in _namespace_packages):
continue
if modname in ('pkg_resources', 'setuptools', 'site'):
if modname in ('pkg_resources_py2', 'setuptools', 'site'):
continue
fn = getattr(sys.modules[modname], '__file__', None)
if fn and (normalize_path(fn).startswith(loc) or
Expand Down Expand Up @@ -3059,7 +3059,7 @@ def issue_warning(*args, **kw):
g = globals()
try:
# find the first stack frame that is *not* code in
# the pkg_resources module, to use for the warning
# the pkg_resources_py2 module, to use for the warning
while sys._getframe(level).f_globals is g:
level += 1
except ValueError:
Expand Down Expand Up @@ -3224,7 +3224,7 @@ def _mkstemp(*args, **kw):


# Silence the PEP440Warning by default, so that end users don't get hit by it
# randomly just because they use pkg_resources. We want to append the rule
# randomly just because they use pkg_resources_py2. We want to append the rule
# because we want earlier uses of filterwarnings to take precedence over this
# one.
warnings.filterwarnings("ignore", category=PEP440Warning, append=True)
Expand Down Expand Up @@ -3255,7 +3255,7 @@ def _initialize_master_working_set():
API available.
This function has explicit effects on the global state
of pkg_resources. It is intended to be invoked once at
of pkg_resources_py2. It is intended to be invoked once at
the initialization of this module.
Invocation by other packages is unsupported and done
Expand Down Expand Up @@ -3289,7 +3289,7 @@ def _initialize_master_working_set():

class PkgResourcesDeprecationWarning(Warning):
"""
Base class for warning about deprecations in ``pkg_resources``
Base class for warning about deprecations in ``pkg_resources_py2``
This class is not derived from ``DeprecationWarning``, and as such is
visible by default.
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import platform
import sys

from pkg_resources.extern.pyparsing import ParseException, ParseResults, stringStart, stringEnd
from pkg_resources.extern.pyparsing import ZeroOrMore, Group, Forward, QuotedString
from pkg_resources.extern.pyparsing import Literal as L # noqa
from pkg_resources_py2.extern.pyparsing import ParseException, ParseResults, stringStart, stringEnd
from pkg_resources_py2.extern.pyparsing import ZeroOrMore, Group, Forward, QuotedString
from pkg_resources_py2.extern.pyparsing import Literal as L # noqa

from ._compat import string_types
from .specifiers import Specifier, InvalidSpecifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import string
import re

from pkg_resources.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException
from pkg_resources.extern.pyparsing import ZeroOrMore, Word, Optional, Regex, Combine
from pkg_resources.extern.pyparsing import Literal as L # noqa
from pkg_resources.extern.six.moves.urllib import parse as urlparse
from pkg_resources_py2.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException
from pkg_resources_py2.extern.pyparsing import ZeroOrMore, Word, Optional, Regex, Combine
from pkg_resources_py2.extern.pyparsing import Literal as L # noqa
from pkg_resources_py2.extern.six.moves.urllib import parse as urlparse

from .markers import MARKER_EXPR, Marker
from .specifiers import LegacySpecifier, Specifier, SpecifierSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _legacy_cmpkey(version):
# as before all PEP 440 versions.
epoch = -1

# This scheme is taken from pkg_resources.parse_version setuptools prior to
# This scheme is taken from pkg_resources_py2.parse_version setuptools prior to
# it's adoption of the packaging library.
parts = []
for part in _parse_version_parts(version.lower()):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions pysrc/pkg_resources_py3/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright Jason R. Coombs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
Loading

0 comments on commit 3d23738

Please sign in to comment.