Skip to content

Commit

Permalink
[autofix.ci] apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored Sep 5, 2024
1 parent 5d03c88 commit 7a5b818
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 59 deletions.
1 change: 1 addition & 0 deletions scripts/ci/update_lf_base_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ def main() -> None:
verify_pep440(base_version)
update_base_dep("pyproject.toml", base_version)


if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions scripts/update_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def get_version_from_pypi(package_name):
return json.loads(response.read())["info"]["version"]
return None


def is_development_release(version):
"""
Determines if the version is a development version based on PEP 440.
Expand All @@ -38,6 +39,7 @@ def is_development_release(version):
"""
return "dev" in version


def update_pyproject_dependency(pyproject_path, version, is_nightly):
pattern = re.compile(r'langflow-base = \{ path = "\./src/backend/base", develop = true \}')
if is_nightly:
Expand Down
72 changes: 18 additions & 54 deletions src/backend/base/langflow/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,31 +80,19 @@ def set_var_for_macos_issue():

@app.command()
def run(
host: str = typer.Option(
"127.0.0.1", help="Host to bind the server to.", envvar="LANGFLOW_HOST"
),
workers: int = typer.Option(
1, help="Number of worker processes.", envvar="LANGFLOW_WORKERS"
),
timeout: int = typer.Option(
300, help="Worker timeout in seconds.", envvar="LANGFLOW_WORKER_TIMEOUT"
),
host: str = typer.Option("127.0.0.1", help="Host to bind the server to.", envvar="LANGFLOW_HOST"),
workers: int = typer.Option(1, help="Number of worker processes.", envvar="LANGFLOW_WORKERS"),
timeout: int = typer.Option(300, help="Worker timeout in seconds.", envvar="LANGFLOW_WORKER_TIMEOUT"),
port: int = typer.Option(7860, help="Port to listen on.", envvar="LANGFLOW_PORT"),
components_path: Optional[Path] = typer.Option(
Path(__file__).parent / "components",
help="Path to the directory containing custom components.",
envvar="LANGFLOW_COMPONENTS_PATH",
),
# .env file param
env_file: Path = typer.Option(
None, help="Path to the .env file containing environment variables."
),
log_level: str = typer.Option(
"critical", help="Logging level.", envvar="LANGFLOW_LOG_LEVEL"
),
log_file: Path = typer.Option(
"logs/langflow.log", help="Path to the log file.", envvar="LANGFLOW_LOG_FILE"
),
env_file: Path = typer.Option(None, help="Path to the .env file containing environment variables."),
log_level: str = typer.Option("critical", help="Logging level.", envvar="LANGFLOW_LOG_LEVEL"),
log_file: Path = typer.Option("logs/langflow.log", help="Path to the log file.", envvar="LANGFLOW_LOG_FILE"),
cache: Optional[str] = typer.Option(
envvar="LANGFLOW_LANGCHAIN_CACHE",
help="Type of cache to use. (InMemoryCache, SQLiteCache)",
Expand Down Expand Up @@ -228,9 +216,7 @@ def wait_for_server_ready(host, port):


def run_on_mac_or_linux(host, port, log_level, options, app):
webapp_process = Process(
target=run_langflow, args=(host, port, log_level, options, app)
)
webapp_process = Process(target=run_langflow, args=(host, port, log_level, options, app))
webapp_process.start()
wait_for_server_ready(host, port)

Expand Down Expand Up @@ -292,9 +278,7 @@ def get_letter_from_version(version: str):

def build_version_notice(current_version: str, package_name: str) -> str:
latest_version = fetch_latest_version(package_name, langflow_is_pre_release(current_version))
if latest_version and pkg_version.parse(current_version) < pkg_version.parse(
latest_version
):
if latest_version and pkg_version.parse(current_version) < pkg_version.parse(latest_version):
release_type = "pre-release" if langflow_is_pre_release(latest_version) else "version"
return f"A new {release_type} of {package_name} is available: {latest_version}"
return ""
Expand Down Expand Up @@ -344,18 +328,14 @@ def print_banner(host: str, port: int):
notices.append(f"Run '{pip_command}' to update.")

styled_notices = [f"[bold]{notice}[/bold]" for notice in notices if notice]
styled_package_name = stylize_text(
package_name, package_name, any("pre-release" in notice for notice in notices)
)
styled_package_name = stylize_text(package_name, package_name, any("pre-release" in notice for notice in notices))

title = f"[bold]Welcome to :chains: {styled_package_name}[/bold]\n"
info_text = "Collaborate, and contribute at our [bold][link=https://github.com/langflow-ai/langflow]GitHub Repo[/link][/bold] :star2:"
telemetry_text = "We collect anonymous usage data to improve Langflow.\nYou can opt-out by setting [bold]DO_NOT_TRACK=true[/bold] in your environment."
access_link = f"Access [link=http://{host}:{port}]http://{host}:{port}[/link]"

panel_content = "\n\n".join(
[title, *styled_notices, info_text, telemetry_text, access_link]
)
panel_content = "\n\n".join([title, *styled_notices, info_text, telemetry_text, access_link])
panel = Panel(panel_content, box=box.ROUNDED, border_style="blue", expand=False)
rprint(panel)

Expand Down Expand Up @@ -387,12 +367,8 @@ def run_langflow(host, port, log_level, options, app):
@app.command()
def superuser(
username: str = typer.Option(..., prompt=True, help="Username for the superuser."),
password: str = typer.Option(
..., prompt=True, hide_input=True, help="Password for the superuser."
),
log_level: str = typer.Option(
"error", help="Logging level.", envvar="LANGFLOW_LOG_LEVEL"
),
password: str = typer.Option(..., prompt=True, hide_input=True, help="Password for the superuser."),
log_level: str = typer.Option("error", help="Logging level.", envvar="LANGFLOW_LOG_LEVEL"),
):
"""
Create a superuser.
Expand All @@ -407,9 +383,7 @@ def superuser(
# Verify that the superuser was created
from langflow.services.database.models.user.model import User

user: User = session.exec(
select(User).where(User.username == username)
).first()
user: User = session.exec(select(User).where(User.username == username)).first()
if user is None or not user.is_superuser:
typer.echo("Superuser creation failed.")
return
Expand Down Expand Up @@ -487,9 +461,7 @@ def migration(

@app.command()
def api_key(
log_level: str = typer.Option(
"error", help="Logging level.", envvar="LANGFLOW_LOG_LEVEL"
),
log_level: str = typer.Option("error", help="Logging level.", envvar="LANGFLOW_LOG_LEVEL"),
):
"""
Creates an API key for the default superuser if AUTO_LOGIN is enabled.
Expand All @@ -505,30 +477,22 @@ def api_key(
settings_service = get_settings_service()
auth_settings = settings_service.auth_settings
if not auth_settings.AUTO_LOGIN:
typer.echo(
"Auto login is disabled. API keys cannot be created through the CLI."
)
typer.echo("Auto login is disabled. API keys cannot be created through the CLI.")
return
with session_scope() as session:
from langflow.services.database.models.user.model import User

superuser = session.exec(
select(User).where(User.username == DEFAULT_SUPERUSER)
).first()
superuser = session.exec(select(User).where(User.username == DEFAULT_SUPERUSER)).first()
if not superuser:
typer.echo(
"Default superuser not found. This command requires a superuser and AUTO_LOGIN to be enabled."
)
typer.echo("Default superuser not found. This command requires a superuser and AUTO_LOGIN to be enabled.")
return
from langflow.services.database.models.api_key import ApiKey, ApiKeyCreate
from langflow.services.database.models.api_key.crud import (
create_api_key,
delete_api_key,
)

api_key = session.exec(
select(ApiKey).where(ApiKey.user_id == superuser.id)
).first()
api_key = session.exec(select(ApiKey).where(ApiKey.user_id == superuser.id)).first()
if api_key:
delete_api_key(session, api_key.id)

Expand Down
1 change: 1 addition & 0 deletions src/backend/base/langflow/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def get_is_component_from_data(data: dict):

async def check_langflow_version(component: StoreComponentCreate):
from langflow.version import get_version

__version__ = get_version()

if not component.last_tested_version:
Expand Down
1 change: 0 additions & 1 deletion src/backend/base/langflow/services/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ def set_database_url(cls, value, info):
if not info.data["config_dir"]:
raise ValueError("config_dir not set, please set it or provide a database_url")


from langflow.utils.version import get_version_info
from langflow.utils.version import is_pre_release as langflow_is_pre_release

Expand Down
6 changes: 2 additions & 4 deletions src/backend/base/langflow/utils/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def _get_version_info():

VERSION_INFO = _get_version_info()


def is_pre_release(v: str) -> bool:
"""
Returns a boolean indicating whether the version is a pre-release version,
Expand All @@ -76,9 +77,7 @@ def fetch_latest_version(package_name: str, include_prerelease: bool) -> Optiona
try:
response = httpx.get(f"https://pypi.org/pypi/{package_name}/json")
versions = response.json()["releases"].keys()
valid_versions = [
v for v in versions if include_prerelease or not is_pre_release(v)
]
valid_versions = [v for v in versions if include_prerelease or not is_pre_release(v)]

except Exception as e:
logger.exception(e)
Expand All @@ -89,6 +88,5 @@ def fetch_latest_version(package_name: str, include_prerelease: bool) -> Optiona
return max(valid_versions, key=lambda v: pkg_version.parse(v))



def get_version_info():
return VERSION_INFO

0 comments on commit 7a5b818

Please sign in to comment.