Skip to content

Commit 2aac433

Browse files
authored
feat: add SUSE/openSUSE ecosystem (#2571)
add SUSE/openSUSE ecosystem.
1 parent 7b948b1 commit 2aac433

File tree

5 files changed

+162
-5
lines changed

5 files changed

+162
-5
lines changed

osv/ecosystems/_ecosystems.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
from .rubygems import RubyGems
3232
from .semver_ecosystem_helper import SemverEcosystem
3333
from .ubuntu import Ubuntu
34+
from .suse import SUSE
35+
from .opensuse import OpenSUSE
3436

3537
_ecosystems = {
3638
# SemVer-based ecosystems (remember keep synced with SEMVER_ECOSYSTEMS):
@@ -55,11 +57,6 @@
5557
'Wolfi': Wolfi(),
5658
# Ecosystems which require a release version for enumeration, which is
5759
# handled separately in get().
58-
'AlmaLinux': OrderingUnsupportedEcosystem(),
59-
'Alpine': OrderingUnsupportedEcosystem(),
60-
'Debian': OrderingUnsupportedEcosystem(),
61-
'Rocky Linux': OrderingUnsupportedEcosystem(),
62-
'Ubuntu': OrderingUnsupportedEcosystem(),
6360
# Ecosystems missing implementations:
6461
'Android': OrderingUnsupportedEcosystem(),
6562
'ConanCenter': OrderingUnsupportedEcosystem(),
@@ -130,6 +127,12 @@ def get(name: str) -> Ecosystem:
130127
if name.startswith('Ubuntu'):
131128
return Ubuntu()
132129

130+
if name.startswith('openSUSE'):
131+
return OpenSUSE()
132+
133+
if name.startswith('SUSE'):
134+
return SUSE()
135+
133136
return _ecosystems.get(name)
134137

135138

osv/ecosystems/opensuse.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""openSUSE ecosystem helper."""
15+
16+
from ..third_party.univers.rpm import RpmVersion
17+
18+
from .helper_base import Ecosystem
19+
20+
21+
class OpenSUSE(Ecosystem):
22+
""""openSUSE ecosystem"""
23+
24+
@property
25+
def name(self):
26+
return "openSUSE"
27+
28+
def sort_key(self, version):
29+
return RpmVersion.from_string(version)
30+
31+
def enumerate_versions(self,
32+
package,
33+
introduced,
34+
fixed=None,
35+
last_affected=None,
36+
limits=None):
37+
raise NotImplementedError('Ecosystem helper does not support enumeration')
38+
39+
@property
40+
def supports_comparing(self):
41+
return True

osv/ecosystems/opensuse_test.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""openSUSE ecosystem helper tests."""
15+
16+
import unittest
17+
from .. import ecosystems
18+
19+
20+
class OpenSUSEEcosystemTest(unittest.TestCase):
21+
"""openSUSE ecosystem helper tests."""
22+
23+
def test_suse(self):
24+
"""Test sort key"""
25+
ecosystem = ecosystems.get('openSUSE')
26+
self.assertGreater(
27+
ecosystem.sort_key("4.2-lp151.4.3.1"),
28+
ecosystem.sort_key("1.5.1-lp151.4.3.1"))
29+
self.assertGreater(
30+
ecosystem.sort_key("4.9.6-bp152.2.3.1"), ecosystem.sort_key("0"))
31+
self.assertGreater(
32+
ecosystem.sort_key("6.2.8-bp156.2.3.1"),
33+
ecosystem.sort_key("6.2.8-bp156"))
34+
self.assertLess(
35+
ecosystem.sort_key("0.4.6-15.8"), ecosystem.sort_key("1.4.6-15.8"))
36+
self.assertEqual(
37+
ecosystem.sort_key("6.2.8-bp156.2.3.1"),
38+
ecosystem.sort_key("6.2.8-bp156.2.3.1"))

osv/ecosystems/suse.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""SUSE ecosystem helper."""
15+
16+
from ..third_party.univers.rpm import RpmVersion
17+
18+
from .helper_base import Ecosystem
19+
20+
21+
class SUSE(Ecosystem):
22+
""""SUSE ecosystem"""
23+
24+
def sort_key(self, version):
25+
return RpmVersion.from_string(version)
26+
27+
def enumerate_versions(self,
28+
package,
29+
introduced,
30+
fixed=None,
31+
last_affected=None,
32+
limits=None):
33+
raise NotImplementedError('Ecosystem helper does not support enumeration')
34+
35+
@property
36+
def supports_comparing(self):
37+
return True

osv/ecosystems/suse_test.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""SUSE ecosystem helper tests."""
15+
16+
import unittest
17+
from .. import ecosystems
18+
19+
20+
class SUSEEcosystemTest(unittest.TestCase):
21+
"""SUSE ecosystem helper tests."""
22+
23+
def test_suse(self):
24+
"""Test sort key"""
25+
ecosystem = ecosystems.get('SUSE')
26+
self.assertGreater(
27+
ecosystem.sort_key("2.38.5-150400.4.34.2"),
28+
ecosystem.sort_key("2.37.5-150400.4.34.2"))
29+
self.assertGreater(
30+
ecosystem.sort_key("2.0.8-4.8.2"), ecosystem.sort_key("0"))
31+
self.assertGreater(
32+
ecosystem.sort_key("2.0.8_k4.12.14_10.118-4.8.2"),
33+
ecosystem.sort_key("2.0.8-4.8.2"))
34+
self.assertLess(
35+
ecosystem.sort_key("1.86-150100.7.23.11"),
36+
ecosystem.sort_key("2.86-150100.7.23.1"))
37+
self.assertEqual(
38+
ecosystem.sort_key("2.0.8-4.8.2"), ecosystem.sort_key("2.0.8-4.8.2"))

0 commit comments

Comments
 (0)