Skip to content

Commit

Permalink
chore/release-3.2.10 (#626)
Browse files Browse the repository at this point in the history
fix:jupyter notebook rich format removal
  • Loading branch information
dylanpulver authored and SafetyQuincyF committed Oct 31, 2024
1 parent d8095a7 commit a652bd2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 19 deletions.
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
],
"console": "integratedTerminal"
},
{
"name": "Safety Auth Login --headless",
"type": "debugpy",
"request": "launch",
"module": "safety",
"args": [
"auth","login","--headless"
],
"console": "integratedTerminal"
},
{
"name": "Safety Auth Logout",
"type": "debugpy",
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is partly based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [PEP 440](https://peps.python.org/pep-0440/)

## [3.2.10] - 2024-10-25
- Support for scanning pyproject.toml files (#625)
- Update safety-schemas version used (#624)
- Fix basic poloicy test (#622)

## [3.2.9] - 2024-10-23
- chore: deprection-message-for-license-command (4149b70)
- feat: add-pull-request-template (#604) (61b2fe2)
Expand Down
2 changes: 1 addition & 1 deletion safety/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.9
3.2.10
32 changes: 14 additions & 18 deletions safety/auth/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import click
from safety.auth.cli_utils import load_auth_session

from safety.auth.utils import is_jupyter_notebook
from safety.console import main_console as console

from safety.auth.constants import AUTH_SERVER_URL, CLI_AUTH_SUCCESS, CLI_LOGOUT_SUCCESS, HOST
Expand Down Expand Up @@ -191,7 +192,6 @@ class ThreadedHTTPServer(http.server.HTTPServer):
def __init__(self, server_address: Tuple, RequestHandlerClass: Any) -> None:
"""
Initialize the ThreadedHTTPServer.
Args:
server_address (Tuple): The server address as a tuple (host, port).
RequestHandlerClass (Any): The request handler class.
Expand Down Expand Up @@ -219,9 +219,7 @@ def handle_timeout(self) -> None:
headless = kwargs.get("headless", False)
initial_state = kwargs.get("initial_state", None)
ctx = kwargs.get("ctx", None)

message = "Copy and paste this url into your browser:"

message = "Copy and paste this URL into your browser:\n⚠️ Ensure there are no extra spaces, especially at line breaks, as they may break the link."

if not headless:
# Start a threaded HTTP server to handle the callback
Expand All @@ -231,13 +229,15 @@ def handle_timeout(self) -> None:
server.ctx = ctx
server_thread = threading.Thread(target=server.handle_request)
server_thread.start()
message = f"If the browser does not automatically open in 5 seconds, " \
"copy and paste this url into your browser:"
message = f"If the browser does not automatically open in 5 seconds, copy and paste this url into your browser:"

target = uri if headless else f"{uri}&port={PORT}"
console.print(f"{message} [link={target}]{target}[/link]")
console.print()

if is_jupyter_notebook():
console.print(f"{message} {target}")
else:
console.print(f"{message} [link={target}]{target}[/link]")

if headless:
# Handle the headless mode where user manually provides the response
exchange_data = None
Expand All @@ -247,29 +247,25 @@ def handle_timeout(self) -> None:
exchange_data = json.loads(auth_code_text)
state = exchange_data["state"]
code = exchange_data["code"]
except Exception as e:
except Exception:
code = state = None

return auth_process(code=code,
state=state,
initial_state=initial_state,
code_verifier=ctx.obj.auth.code_verifier,
client=ctx.obj.auth.client)
state=state,
initial_state=initial_state,
code_verifier=ctx.obj.auth.code_verifier,
client=ctx.obj.auth.client)
else:
# Wait for the browser authentication in non-headless mode
wait_msg = "waiting for browser authentication"

with console.status(wait_msg, spinner="bouncingBar"):
time.sleep(2)
click.launch(target)
server_thread.join()

except OSError as e:
if e.errno == socket.errno.EADDRINUSE:
reason = f"The port {HOST}:{PORT} is currently being used by another" \
"application or process. Please choose a different port or " \
"terminate the conflicting application/process to free up " \
"the port."
reason = f"The port {HOST}:{PORT} is currently being used by another application or process. Please choose a different port or terminate the conflicting application/process to free up the port."
else:
reason = "An error occurred while performing this operation."

Expand Down
11 changes: 11 additions & 0 deletions safety/auth/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,14 @@ def send(self, request: requests.PreparedRequest, **kwargs: Any) -> requests.Res
"""
request.headers.pop("Authorization", None)
return super().send(request, **kwargs)


def is_jupyter_notebook() -> bool:
"""Check if the code is being executed inside a Jupyter Notebook."""
try:
from IPython import get_ipython
if 'IPKernelApp' not in get_ipython().config:
return False
except Exception:
return False
return True

0 comments on commit a652bd2

Please sign in to comment.