Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def generate(polyaxonfile, build_context, destination, params):
"""Generate a dockerfile given the polyaxonfile."""
if all([polyaxonfile, build_context]):
Printer.print_error(
"Only a polyaxonfile or a build context option is required."
)
sys.exit(1)
if build_context:
try:
build_context = BuildContextConfig.from_dict(reader.read(build_context))
except (PolyaxonSchemaError, ValidationError) as e:
Printer.print_error("received a non valid build context.")
Printer.print_error("Error message: {}.".format(e))
sys.exit(1)
else:
specification = check_polyaxonfile(polyaxonfile, params=params, log=False)
try:
run_spec = get_specification(specification.generate_run_data())
run_spec.apply_params(params=specification.config.params)
run_spec.apply_context()
except PolyaxonSchemaError:
Printer.print_error(
"Could not run this polyaxonfile locally, "
"a context is required to resolve it dependencies."
)
sys.exit(1)
build_context = run_spec.build_context
def create_polyaxonfile():
if os.path.isfile(constants.INIT_FILE_PATH):
try:
_ = PolyaxonFile(constants.INIT_FILE_PATH).specification # noqa
Printer.print_success("A valid polyaxonfile.yaml was found in the project.")
except Exception as e:
handle_cli_error(e, message="A Polyaxonfile was found but it is not valid.")
sys.exit(1)
else:
create_init_file(constants.INIT_FILE)
# if we are here the file was not created
if not os.path.isfile(constants.INIT_FILE_PATH):
Printer.print_error(
"Something went wrong, init command did not create a file.\n"
"Possible reasons: you don't have enough rights to create the file."
)
sys.exit(1)
Printer.print_success(
"{} was created successfully.".format(constants.INIT_FILE_PATH)
)
def read_deployment_config(filepaths):
if not filepaths:
return None
filepaths = to_list(filepaths)
for filepath in filepaths:
if not os.path.isfile(filepath):
Printer.print_error("`{}` must be a valid file".format(filepath))
sys.exit(1)
try:
deployment_config = reader.read(filepaths)
except Exception as e:
handle_cli_error(e, message="Polyaxon deployment file is not valid.")
sys.exit(1)
return deployment_config
)
sys.exit(1)
try:
body = polyaxon_sdk.models.V1CredsBodyRequest(
username=username, password=password
)
access_auth = polyaxon_client.auth_v1.login(body=body)
except (ApiException, HTTPError) as e:
AuthConfigManager.purge()
CliConfigManager.purge()
handle_cli_error(e, message="Could not login.")
sys.exit(1)
if not access_auth.token:
Printer.print_error("Failed to login")
return
else:
if not token:
token_url = "{}/app/token".format(polyaxon_client.config.host)
click.confirm(
"Authentication token page will now open in your browser. Continue?",
abort=True,
default=True,
)
click.launch(token_url)
logger.info("Please copy and paste the authentication token.")
token = click.prompt(
"This is an invisible field. Paste token and press ENTER",
type=str,
hide_input=True,
def create(ctx, name, owner, description, private, init):
"""Create a new project.
Uses [Caching](/references/polyaxon-cli/#caching)
Example:
\b
```bash
$ polyaxon project create --name=cats-vs-dogs --description="Image Classification with DL"
```
"""
owner = owner or AuthConfigManager.get_value("username")
if not owner:
Printer.print_error(
"Please login first or provide a valid owner --owner. "
"`polyaxon login --help`"
)
sys.exit(1)
try:
polyaxon_client = PolyaxonClient()
project_config = V1Project(
name=name, description=description, is_public=not private
)
_project = polyaxon_client.projects_v1.create_project(owner, project_config)
except (ApiException, HTTPError) as e:
handle_cli_error(e, message="Could not create project `{}`.".format(name))
sys.exit(1)
Printer.print_success(
try:
PolyaxonClient().project.upload_repo(
project.user, project.name, files, files_size, sync=sync
)
except (
PolyaxonHTTPError,
PolyaxonShouldExitError,
PolyaxonClientException,
) as e:
handle_cli_error(
e,
message="Could not upload code for project `{}`.".format(
project.name
),
)
Printer.print_error(
"Check the project exists, "
"and that you have access rights, "
"this could happen as well when uploading large files. "
"Please also make sure that you have enough space to upload the data."
)
sys.exit(1)
Printer.print_success("Files uploaded.")
except Exception as e:
handle_cli_error(e, message="Could not upload the file.")
sys.exit(1)
def get_config_or_raise(cls):
run = cls.get_config()
if not run:
Printer.print_error("No run was provided.")
sys.exit(1)
return run
def get_log_handler(polyaxon_client=None):
polyaxon_client = polyaxon_client or PolyaxonClient()
try:
return polyaxon_client.versions_v1.get_log_handler()
except ApiException as e:
if e.status == 403:
session_expired()
sys.exit(1)
handle_cli_error(e, message="Could not get cli version.")
sys.exit(1)
except HTTPError:
Printer.print_error("Could not connect to remote server.")
sys.exit(1)
def handle_cli_error(e, message=None):
if message:
Printer.print_error(message)
Printer.print_error("Error message: {}.".format(e))
if hasattr(e, "status"):
Printer.print_error(HTTP_ERROR_MESSAGES_MAPPING.get(e.status))