Skip to content

Commit a554583

Browse files
author
Steven Silvester
authored
Merge pull request #122 from fcollonval/fix/extract-config
Fix Extract Release Config and Npm Config Handling
2 parents 511399d + 66c8104 commit a554583

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

jupyter_releaser/lib.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ def extract_release(auth, dist_dir, dry_run, release_url, npm_install_options):
281281
orig_dir = os.getcwd()
282282
os.chdir(util.CHECKOUT_NAME)
283283

284+
# Read in the config
285+
config = util.read_config()
286+
options = config.get("options", {})
287+
npm_install_options = npm_install_options or options.get("npm-install-options", "")
288+
284289
# Clean the dist folder
285290
dist = Path(dist_dir)
286291
if dist.exists():
@@ -306,7 +311,7 @@ def extract_release(auth, dist_dir, dry_run, release_url, npm_install_options):
306311
for asset in assets:
307312
suffix = Path(asset.name).suffix
308313
if suffix in [".gz", ".whl"]:
309-
python.check_dist(path)
314+
python.check_dist(dist / asset.name)
310315
elif suffix == ".tgz":
311316
pass # already handled
312317
else:
@@ -372,9 +377,9 @@ def publish_assets(dist_dir, npm_token, npm_cmd, twine_cmd, dry_run):
372377
os.environ.setdefault("TWINE_USERNAME", "__token__")
373378

374379
if len(glob(f"{dist_dir}/*.tgz")):
375-
npm.handle_npm_config(npm_token, os.getcwd())
380+
npm.handle_npm_config(npm_token)
376381
if npm_token:
377-
util.run("npm whoami", cwd=os.getcwd())
382+
util.run("npm whoami")
378383

379384
found = False
380385
for path in sorted(glob(f"{dist_dir}/*.*")):

jupyter_releaser/npm.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,27 @@ def extract_package(path):
123123
return data
124124

125125

126-
def handle_npm_config(npm_token, dist_dir):
126+
def handle_npm_config(npm_token):
127127
"""Handle npm_config"""
128-
npmrc = Path(dist_dir) / Path(".npmrc")
128+
npmrc = Path("~/.npmrc").expanduser()
129129
registry = os.environ.get("NPM_REGISTRY", "https://registry.npmjs.org/")
130-
text = f"registry={registry}"
130+
reg_entry = text = f"registry={registry}"
131+
auth_entry = ""
131132
if npm_token:
132-
registry = registry.replace("https:", "")
133-
registry = registry.replace("http:", "")
134-
text += f"\n{registry}:_authToken={npm_token}"
133+
short_reg = registry.replace("https://", "//")
134+
short_reg = short_reg.replace("http://", "//")
135+
auth_entry = f"{short_reg}:_authToken={npm_token}"
136+
137+
# Handle existing config
135138
if npmrc.exists():
136-
text = npmrc.read_text(encoding="utf-8") + text
139+
text = npmrc.read_text(encoding="utf-8")
140+
if reg_entry in text:
141+
reg_entry = ""
142+
if auth_entry in text:
143+
auth_entry = ""
144+
145+
text += f"\n{reg_entry}\n{auth_entry}"
146+
text = text.strip() + "\n"
137147
util.log(f"writing npm config to {npmrc}:\n{text}")
138148
npmrc.write_text(text, encoding="utf-8")
139149

jupyter_releaser/tests/test_functions.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
33
import json
4-
import os
54
import shutil
65
from pathlib import Path
76

@@ -121,10 +120,17 @@ def test_create_release_commit_hybrid(py_package, build_mock):
121120

122121

123122
def test_handle_npm_config(npm_package):
124-
npm.handle_npm_config("abc", os.getcwd())
125-
text = Path(".npmrc").read_text(encoding="utf-8")
123+
npmrc = Path("~/.npmrc").expanduser()
124+
existed = npmrc.exists()
125+
if existed:
126+
npmrc_text = npmrc.read_text(encoding="utf-8")
127+
npm.handle_npm_config("abc")
128+
text = npmrc.read_text(encoding="utf-8")
126129
assert "_authToken=abc" in text
127130

131+
if existed:
132+
npmrc.write_text(npmrc_text, encoding="utf-8")
133+
128134

129135
def test_bump_version(py_package):
130136
for spec in ["1.0.1", "1.0.1.dev1", "1.0.3a4"]:

0 commit comments

Comments
 (0)