lovelytics-cli 0.4.8__tar.gz → 0.4.10__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lovelytics-cli
3
- Version: 0.4.8
3
+ Version: 0.4.10
4
4
  Summary: Development tools for Lovelytics Labs.
5
5
  License: LICENSE
6
6
  License-File: LICENSE
@@ -124,6 +124,20 @@ def python_package(package):
124
124
  install_commands.install_python_package(package)
125
125
 
126
126
 
127
+ @install.command(name="npm-package")
128
+ @click.argument("package")
129
+ def npm_package(package):
130
+ """Install a package from our private npm repository."""
131
+ install_commands.install_npm_package(package)
132
+
133
+
134
+ @install.command(name="pi-package")
135
+ @click.argument("package_name")
136
+ def pi_package(package_name):
137
+ """Install a @lovelytics package as a pi extension (e.g. 'pi-provider')."""
138
+ install_commands.install_pi_package(package_name)
139
+
140
+
127
141
  @install.command(name="cli-tool")
128
142
  @click.argument("name")
129
143
  @click.option(
@@ -1,4 +1,5 @@
1
1
  """Logic for downloading and installing CLI tools and packages."""
2
+ import base64
2
3
  import os
3
4
  import platform
4
5
  import shutil
@@ -140,3 +141,85 @@ def install_python_package(package):
140
141
  subprocess.run( # nosec
141
142
  ["pip", "install", "--extra-index-url", encoded_url, package]
142
143
  )
144
+
145
+
146
+ def configure_npm_registry_auth():
147
+ """Write @lovelytics scoped registry auth into ~/.npmrc.
148
+
149
+ Needed for tools like `pi install npm:...` that invoke npm internally and
150
+ won't pick up CLI-flag-based auth the way our own `npm install` calls do.
151
+ """
152
+ user = auth.AuthHandler.get_auth()
153
+ protocol = "https" if LANDO_URL.startswith("https") else "http"
154
+ base_url = LANDO_URL.strip("https://").strip("http://")
155
+ registry_url = f"{protocol}://{base_url}/npm/"
156
+ encoded_url = urllib3.util.parse_url(registry_url).url
157
+ token = base64.b64encode(user["token"].encode()).decode()
158
+
159
+ entries = {
160
+ "@lovelytics:registry": encoded_url,
161
+ f"//{base_url}/npm/:username": "lovelytics",
162
+ f"//{base_url}/npm/:_password": token,
163
+ f"//{base_url}/npm/:email": "lovelytics@lovelytics.com",
164
+ }
165
+
166
+ npmrc_path = os.path.expanduser("~/.npmrc")
167
+ lines = []
168
+ if os.path.exists(npmrc_path):
169
+ with open(npmrc_path) as f:
170
+ lines = f.readlines()
171
+
172
+ remaining = dict(entries)
173
+ new_lines = []
174
+ for line in lines:
175
+ key = line.split("=", 1)[0].strip() if "=" in line else None
176
+ if key in remaining:
177
+ new_lines.append(f"{key}={remaining.pop(key)}\n")
178
+ else:
179
+ new_lines.append(line)
180
+ for key, value in remaining.items():
181
+ new_lines.append(f"{key}={value}\n")
182
+
183
+ with open(npmrc_path, "w") as f:
184
+ f.writelines(new_lines)
185
+
186
+
187
+ def install_pi_package(package_name):
188
+ """Install a @lovelytics package as a pi extension."""
189
+ pi_binary = shutil.which("pi")
190
+ if not pi_binary:
191
+ raise click.ClickException(
192
+ "pi is not installed or not on PATH. Install it first, then re-run this command."
193
+ )
194
+ package = f"@lovelytics/{package_name}"
195
+ click.echo("Configuring npm authentication for @lovelytics packages...")
196
+ configure_npm_registry_auth()
197
+ click.echo(f"Installing {package} for pi...")
198
+ subprocess.run([pi_binary, "install", f"npm:{package}"]) # nosec
199
+
200
+
201
+ def install_npm_package(package):
202
+ """Download and install an npm package from the private repository."""
203
+ if not package.startswith("@lovelytics/"):
204
+ raise click.ClickException(
205
+ "Only packages in the @lovelytics namespace can be installed "
206
+ "from our private repository."
207
+ )
208
+ click.echo(f"Installing {package} from our private repository...")
209
+ user = auth.AuthHandler.get_auth()
210
+ protocol = "https" if LANDO_URL.startswith("https") else "http"
211
+ base_url = LANDO_URL.strip("https://").strip("http://")
212
+ registry_url = f"{protocol}://{base_url}/npm/"
213
+ encoded_url = urllib3.util.parse_url(registry_url).url
214
+ token = base64.b64encode(user["token"].encode()).decode()
215
+ subprocess.run( # nosec
216
+ [
217
+ "npm",
218
+ "install",
219
+ package,
220
+ f"--@lovelytics:registry={encoded_url}",
221
+ f"--//{base_url}/npm/:username=lovelytics",
222
+ f"--//{base_url}/npm/:_password={token}",
223
+ f"--//{base_url}/npm/:email=lovelytics@lovelytics.com",
224
+ ]
225
+ )
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "lovelytics-cli"
3
- version = "0.4.8"
3
+ version = "0.4.10"
4
4
  description = "Development tools for Lovelytics Labs."
5
5
  authors = ["Lovelytics Labs <labs@lovelytics.com>"]
6
6
  readme = "README.md"
@@ -21,7 +21,7 @@ docker = "^6.0.1"
21
21
  black = "^22.10.0"
22
22
  pre-commit = "^2.20.0"
23
23
  pytest = "^7.2.0"
24
- flake8 = "^5.0.4"
24
+ flake8 = "^6.1.0"
25
25
  twine = "^6.2.0"
26
26
  pydocstyle = "^6.3.0"
27
27
  bandit = "^1.9.4"