Skip to content

Commit

Permalink
feat: add SUSE/openSUSE ecosystem (#2571)
Browse files Browse the repository at this point in the history
add SUSE/openSUSE ecosystem.
  • Loading branch information
hogo6002 authored Sep 5, 2024
1 parent 7b948b1 commit 2aac433
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 5 deletions.
13 changes: 8 additions & 5 deletions osv/ecosystems/_ecosystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
from .rubygems import RubyGems
from .semver_ecosystem_helper import SemverEcosystem
from .ubuntu import Ubuntu
from .suse import SUSE
from .opensuse import OpenSUSE

_ecosystems = {
# SemVer-based ecosystems (remember keep synced with SEMVER_ECOSYSTEMS):
Expand All @@ -55,11 +57,6 @@
'Wolfi': Wolfi(),
# Ecosystems which require a release version for enumeration, which is
# handled separately in get().
'AlmaLinux': OrderingUnsupportedEcosystem(),
'Alpine': OrderingUnsupportedEcosystem(),
'Debian': OrderingUnsupportedEcosystem(),
'Rocky Linux': OrderingUnsupportedEcosystem(),
'Ubuntu': OrderingUnsupportedEcosystem(),
# Ecosystems missing implementations:
'Android': OrderingUnsupportedEcosystem(),
'ConanCenter': OrderingUnsupportedEcosystem(),
Expand Down Expand Up @@ -130,6 +127,12 @@ def get(name: str) -> Ecosystem:
if name.startswith('Ubuntu'):
return Ubuntu()

if name.startswith('openSUSE'):
return OpenSUSE()

if name.startswith('SUSE'):
return SUSE()

return _ecosystems.get(name)


Expand Down
41 changes: 41 additions & 0 deletions osv/ecosystems/opensuse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""openSUSE ecosystem helper."""

from ..third_party.univers.rpm import RpmVersion

from .helper_base import Ecosystem


class OpenSUSE(Ecosystem):
""""openSUSE ecosystem"""

@property
def name(self):
return "openSUSE"

def sort_key(self, version):
return RpmVersion.from_string(version)

def enumerate_versions(self,
package,
introduced,
fixed=None,
last_affected=None,
limits=None):
raise NotImplementedError('Ecosystem helper does not support enumeration')

@property
def supports_comparing(self):
return True
38 changes: 38 additions & 0 deletions osv/ecosystems/opensuse_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""openSUSE ecosystem helper tests."""

import unittest
from .. import ecosystems


class OpenSUSEEcosystemTest(unittest.TestCase):
"""openSUSE ecosystem helper tests."""

def test_suse(self):
"""Test sort key"""
ecosystem = ecosystems.get('openSUSE')
self.assertGreater(
ecosystem.sort_key("4.2-lp151.4.3.1"),
ecosystem.sort_key("1.5.1-lp151.4.3.1"))
self.assertGreater(
ecosystem.sort_key("4.9.6-bp152.2.3.1"), ecosystem.sort_key("0"))
self.assertGreater(
ecosystem.sort_key("6.2.8-bp156.2.3.1"),
ecosystem.sort_key("6.2.8-bp156"))
self.assertLess(
ecosystem.sort_key("0.4.6-15.8"), ecosystem.sort_key("1.4.6-15.8"))
self.assertEqual(
ecosystem.sort_key("6.2.8-bp156.2.3.1"),
ecosystem.sort_key("6.2.8-bp156.2.3.1"))
37 changes: 37 additions & 0 deletions osv/ecosystems/suse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""SUSE ecosystem helper."""

from ..third_party.univers.rpm import RpmVersion

from .helper_base import Ecosystem


class SUSE(Ecosystem):
""""SUSE ecosystem"""

def sort_key(self, version):
return RpmVersion.from_string(version)

def enumerate_versions(self,
package,
introduced,
fixed=None,
last_affected=None,
limits=None):
raise NotImplementedError('Ecosystem helper does not support enumeration')

@property
def supports_comparing(self):
return True
38 changes: 38 additions & 0 deletions osv/ecosystems/suse_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""SUSE ecosystem helper tests."""

import unittest
from .. import ecosystems


class SUSEEcosystemTest(unittest.TestCase):
"""SUSE ecosystem helper tests."""

def test_suse(self):
"""Test sort key"""
ecosystem = ecosystems.get('SUSE')
self.assertGreater(
ecosystem.sort_key("2.38.5-150400.4.34.2"),
ecosystem.sort_key("2.37.5-150400.4.34.2"))
self.assertGreater(
ecosystem.sort_key("2.0.8-4.8.2"), ecosystem.sort_key("0"))
self.assertGreater(
ecosystem.sort_key("2.0.8_k4.12.14_10.118-4.8.2"),
ecosystem.sort_key("2.0.8-4.8.2"))
self.assertLess(
ecosystem.sort_key("1.86-150100.7.23.11"),
ecosystem.sort_key("2.86-150100.7.23.1"))
self.assertEqual(
ecosystem.sort_key("2.0.8-4.8.2"), ecosystem.sort_key("2.0.8-4.8.2"))

0 comments on commit 2aac433

Please sign in to comment.