Skip to content

Commit 1298c00

Browse files
author
Steven Silvester
committed
fix handling of workspace paths
1 parent 38f772b commit 1298c00

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

jupyter_releaser/npm.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def build_dist(package, dist_dir):
3232
data = extract_package(tarball)
3333

3434
# Move the tarball into the dist folder if public
35-
if not data.get("private", False) == True:
35+
if not data.get("private", False):
3636
shutil.move(str(tarball), str(dest))
3737
elif osp.isdir(package):
3838
os.remove(tarball)
@@ -42,17 +42,13 @@ def build_dist(package, dist_dir):
4242

4343
if "workspaces" in data:
4444
all_data = dict()
45-
for pattern in _get_workspace_packages(data):
46-
for path in glob(osp.join(basedir, pattern), recursive=True):
47-
path = Path(path)
48-
package_json = path / "package.json"
49-
if not osp.exists(package_json):
50-
continue
51-
data = json.loads(package_json.read_text(encoding="utf-8"))
52-
if data.get("private", False) == True:
53-
continue
54-
data["__path__"] = path
55-
all_data[data["name"]] = data
45+
for path in _get_workspace_packages(data):
46+
package_json = path / "package.json"
47+
data = json.loads(package_json.read_text(encoding="utf-8"))
48+
if data.get("private", False):
49+
continue
50+
data["__path__"] = path
51+
all_data[data["name"]] = data
5652

5753
i = 0
5854
for (name, data) in sorted(all_data.items()):
@@ -151,11 +147,10 @@ def get_package_versions(version):
151147
message += f'\nnpm version: {data["name"]}: {npm_version}'
152148
if "workspaces" in data:
153149
message += "\nnpm workspace versions:"
154-
for pattern in _get_workspace_packages(data):
155-
for path in glob(pattern, recursive=True):
156-
text = Path(path).joinpath("package.json").read_text()
157-
data = json.loads(text)
158-
message += f'\n{data["name"]}: {data.get("version", "")}'
150+
for path in _get_workspace_packages(data):
151+
text = path.joinpath("package.json").read_text(encoding="utf-8")
152+
data = json.loads(text)
153+
message += f'\n{data["name"]}: {data.get("version", "")}'
159154
return message
160155

161156

@@ -169,28 +164,34 @@ def tag_workspace_packages():
169164
if "workspaces" not in data:
170165
return
171166

172-
for pattern in _get_workspace_packages(data):
167+
for path in _get_workspace_packages(data):
168+
sub_package_json = path / "package.json"
169+
sub_data = json.loads(sub_package_json.read_text(encoding="utf-8"))
170+
tag_name = f"{sub_data['name']}@{sub_data['version']}"
171+
if tag_name in tags:
172+
util.log(f"Skipping existing tag {tag_name}")
173+
else:
174+
util.run(f"git tag {tag_name}")
175+
176+
177+
def _get_workspace_packages(data):
178+
"""Get the workspace package paths for a package given package data"""
179+
if isinstance(data["workspaces"], dict):
180+
patterns = []
181+
for value in data["workspaces"].values():
182+
patterns.extend(value)
183+
else:
184+
patterns = data["workspaces"]
185+
186+
paths = []
187+
for pattern in patterns:
173188
for path in glob(pattern, recursive=True):
174189
sub_package = Path(path)
175190
if not sub_package.is_dir():
176191
continue
177192
sub_package_json = sub_package / "package.json"
178193
if not sub_package_json.exists():
179194
continue
180-
sub_data = json.loads(sub_package_json.read_text(encoding="utf-8"))
181-
tag_name = f"{sub_data['name']}@{sub_data['version']}"
182-
if tag_name in tags:
183-
util.log(f"Skipping existing tag {tag_name}")
184-
else:
185-
util.run(f"git tag {tag_name}")
186-
195+
paths.append(sub_package)
187196

188-
def _get_workspace_packages(data):
189-
"""Get the workspace packages for a package given package data"""
190-
if isinstance(data["workspaces"], dict):
191-
packages = []
192-
for value in data["workspaces"].values():
193-
packages.extend(value)
194-
else:
195-
packages = data["workspaces"]
196-
return packages
197+
return paths

0 commit comments

Comments
 (0)