Skip to content

Commit 136275c

Browse files
pushpit kambojpushpit kamboj
authored andcommitted
[feature] Add support for npm, Docker, Ansible, and OpenWRT packages #123
- Added package type detection for npm, docker, ansible, and openwrt-agents - Enhanced version parsing for all package types - Updated bump_version() to handle all package type version formats - Added 25 new tests for non-Python packages Fixes #522
1 parent f5ba89d commit 136275c

File tree

6 files changed

+117
-76
lines changed

6 files changed

+117
-76
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@ Attribution
8181
- `Roboto webfont <https://www.google.com/fonts/specimen/Roboto>`_ is
8282
licensed under the `Apache License, Version 2.0
8383
<https://www.apache.org/licenses/LICENSE-2.0>`_. WOFF files extracted
84-
using https://github.com/majodev/google-webfonts-helper.
84+
using https://github.com/majodev/google-webfonts-helper.

openwisp_utils/releaser/config.py

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import ast
2+
import json
23
import os
34
import re
45
import subprocess
5-
import json
66

77

88
def get_package_name_from_setup():
@@ -22,19 +22,19 @@ def get_package_type_from_setup():
2222
"""Detects package type based on config files present in the project."""
2323
if os.path.exists("setup.py"):
2424
return "python"
25-
25+
2626
if os.path.exists("package.json"):
2727
return "npm"
28-
28+
2929
if os.path.exists("docker-compose.yml"):
3030
return "docker"
31-
31+
3232
if os.path.exists(".ansible-lint"):
3333
return "ansible"
34-
34+
3535
if os.path.exists(".luacheckrc"):
3636
return "openwrt-agents"
37-
37+
3838
return None
3939

4040

@@ -91,7 +91,9 @@ def load_config():
9191
if version_match:
9292
config["version_path"] = init_py_path
9393
try:
94-
version_tuple = ast.literal_eval(f"({version_match.group(1)})")
94+
version_tuple = ast.literal_eval(
95+
f"({version_match.group(1)})"
96+
)
9597
config["CURRENT_VERSION"] = list(version_tuple)
9698
except (ValueError, SyntaxError):
9799
config["CURRENT_VERSION"] = None
@@ -109,45 +111,67 @@ def load_config():
109111
version_tuple, version_type = version_str.split("_", 1)
110112
else:
111113
version_tuple, version_type = version_str, "final"
112-
114+
113115
parts = version_tuple.split(".")
114116
if len(parts) < 3:
115-
raise ValueError(f"Version '{version_str}' does not have expected 3 parts (X.Y.Z)")
116-
117+
raise ValueError(
118+
f"Version '{version_str}' does not have expected 3 parts (X.Y.Z)"
119+
)
120+
117121
config["CURRENT_VERSION"] = [
118122
int(parts[0]),
119123
int(parts[1]),
120124
int(parts[2]),
121-
version_type
125+
version_type,
122126
]
123-
except(ValueError, SyntaxError):
127+
except (ValueError, SyntaxError):
124128
config["CURRENT_VERSION"] = None
125129
elif config["package_type"] == "docker":
126130
if os.path.exists("Makefile"):
127131
with open("Makefile", "r") as f:
128132
content = f.read()
129-
version_match = re.search(r"^OPENWISP_VERSION\s*=\s*([^\s]+)", content, re.MULTILINE)
133+
version_match = re.search(
134+
r"^OPENWISP_VERSION\s*=\s*([^\s]+)", content, re.MULTILINE
135+
)
130136
if version_match:
131137
config["version_path"] = "Makefile"
132138
version_str = version_match.group(1)
133139
parts = version_str.split(".")
134140
if len(parts) < 3:
135-
raise ValueError(f"Version '{version_str}' does not have expected 3 parts (X.Y.Z)")
136-
config["CURRENT_VERSION"] = [int(parts[0]), int(parts[1]), int(parts[2]), "final"]
141+
raise ValueError(
142+
f"Version '{version_str}' does not have expected 3 parts (X.Y.Z)"
143+
)
144+
config["CURRENT_VERSION"] = [
145+
int(parts[0]),
146+
int(parts[1]),
147+
int(parts[2]),
148+
"final",
149+
]
137150
elif config["package_type"] == "ansible":
138151
version_py_path = os.path.join("templates", "openwisp2", "version.py")
139152
if os.path.exists(version_py_path):
140153
with open(version_py_path, "r") as f:
141154
content = f.read()
142-
version_match = re.search(r"^__openwisp_version__\s*=\s*['\"]([^'\"]+)['\"]", content, re.MULTILINE)
155+
version_match = re.search(
156+
r"^__openwisp_version__\s*=\s*['\"]([^'\"]+)['\"]",
157+
content,
158+
re.MULTILINE,
159+
)
143160
if version_match:
144161
config["version_path"] = version_py_path
145162
try:
146163
version_str = version_match.group(1)
147164
parts = version_str.split(".")
148165
if len(parts) < 3:
149-
raise ValueError(f"Version '{version_str}' does not have expected 3 parts (X.Y.Z)")
150-
config["CURRENT_VERSION"] = [int(parts[0]), int(parts[1]), int(parts[2]), "final"]
166+
raise ValueError(
167+
f"Version '{version_str}' does not have expected 3 parts (X.Y.Z)"
168+
)
169+
config["CURRENT_VERSION"] = [
170+
int(parts[0]),
171+
int(parts[1]),
172+
int(parts[2]),
173+
"final",
174+
]
151175
except (ValueError, SyntaxError):
152176
config["CURRENT_VERSION"] = None
153177
elif config["package_type"] == "openwrt-agents":
@@ -158,8 +182,15 @@ def load_config():
158182
config["version_path"] = "VERSION"
159183
parts = version_str.split(".")
160184
if len(parts) < 3:
161-
raise ValueError(f"Version '{version_str}' does not have expected 3 parts (X.Y.Z)")
162-
config["CURRENT_VERSION"] = [int(parts[0]), int(parts[1]), int(parts[2]), "final"]
185+
raise ValueError(
186+
f"Version '{version_str}' does not have expected 3 parts (X.Y.Z)"
187+
)
188+
config["CURRENT_VERSION"] = [
189+
int(parts[0]),
190+
int(parts[1]),
191+
int(parts[2]),
192+
"final",
193+
]
163194

164195
possible_changelog_names = [
165196
"CHANGES.rst",

openwisp_utils/releaser/tests/conftest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ def init_git_repo():
6565
def _create_package_json(path: Path, version="1.2.3"):
6666
"""Helper to create a package.json file for npm projects."""
6767
import json
68+
6869
package_json_content = {
6970
"name": "my-npm-package",
7071
"version": version,
71-
"description": "Test npm package"
72+
"description": "Test npm package",
7273
}
7374
(path / "package.json").write_text(json.dumps(package_json_content, indent=2))
7475

@@ -96,7 +97,9 @@ def create_makefile():
9697

9798
def _create_docker_compose(path: Path):
9899
"""Helper to create a docker-compose.yml file."""
99-
(path / "docker-compose.yml").write_text("version: '3'\nservices:\n app:\n image: test")
100+
(path / "docker-compose.yml").write_text(
101+
"version: '3'\nservices:\n app:\n image: test"
102+
)
100103

101104

102105
@pytest.fixture

openwisp_utils/releaser/tests/test_config.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,11 @@ def test_npm_package_with_underscore_suffix(
221221
assert config["CURRENT_VERSION"] == [1, 2, 3, "rc1"]
222222

223223

224-
def test_npm_package_missing_version(
225-
project_dir, create_changelog, init_git_repo
226-
):
224+
def test_npm_package_missing_version(project_dir, create_changelog, init_git_repo):
227225
"""Tests that npm package handles missing version gracefully."""
228226
import json
229-
(project_dir / "package.json").write_text(
230-
json.dumps({"name": "test-package"})
231-
)
227+
228+
(project_dir / "package.json").write_text(json.dumps({"name": "test-package"}))
232229
create_changelog(project_dir)
233230
init_git_repo(project_dir)
234231

@@ -290,7 +287,9 @@ def test_docker_package_invalid_version(
290287
):
291288
"""Tests docker package with invalid version in Makefile."""
292289
create_docker_compose(project_dir)
293-
(project_dir / "Makefile").write_text("OPENWISP_VERSION = 1.2\n") # Invalid: only 2 parts
290+
(project_dir / "Makefile").write_text(
291+
"OPENWISP_VERSION = 1.2\n"
292+
) # Invalid: only 2 parts
294293
create_changelog(project_dir)
295294
init_git_repo(project_dir)
296295

@@ -300,7 +299,11 @@ def test_docker_package_invalid_version(
300299

301300
# Ansible Package Tests
302301
def test_ansible_package_detection(
303-
project_dir, create_ansible_lint, create_ansible_version_file, create_changelog, init_git_repo
302+
project_dir,
303+
create_ansible_lint,
304+
create_ansible_version_file,
305+
create_changelog,
306+
init_git_repo,
304307
):
305308
"""Tests that ansible package type is detected when .ansible-lint exists."""
306309
create_ansible_lint(project_dir)
@@ -394,8 +397,12 @@ def test_openwrt_agents_invalid_version(
394397

395398
# Package Type Priority Tests
396399
def test_package_type_priority_python_over_npm(
397-
project_dir, create_setup_py, create_package_dir_with_version,
398-
create_package_json, create_changelog, init_git_repo
400+
project_dir,
401+
create_setup_py,
402+
create_package_dir_with_version,
403+
create_package_json,
404+
create_changelog,
405+
init_git_repo,
399406
):
400407
"""Tests that Python is detected first when both setup.py and package.json exist."""
401408
create_setup_py(project_dir)

0 commit comments

Comments
 (0)