Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add CODE_SNIPPET_USE_AUTO_CONFIG environment variable #883

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/common/src/environment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export interface Env extends NodeJS.ProcessEnv {
* @example MAINTENANCE_MODE="We are currently down for maintenance.\n\nPlease try again later."
*/
MAINTENANCE_MODE?: string;

/**
* Controls whether the config object in the inputs/outputs Python code snippet is automatically constructed
* Leave unset to use the config object for endpoint window.location.host
*/
CODE_SNIPPET_USE_AUTO_CONFIG?: string;
}

/** Represents a plain object where string keys map to values of the same type */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { prism } from 'react-syntax-highlighter/dist/esm/styles/prism';
import FileCopyIcon from '@mui/icons-material/FileCopy';
import copyToClipboard from 'copy-to-clipboard';
import { env } from '@clients/common/environment';
import { errorBackgroundColor } from '@clients/theme/CommonStyles/constants';
import Button from '@mui/material/Button';
import Typography from '@mui/material/Typography';
Expand Down Expand Up @@ -31,19 +32,19 @@ export const ExecutionNodeURL: React.FC<{
const isHttps = /^https:/.test(window.location.href);
const ref = React.useRef<HTMLDivElement>(null);

const code = isHttps
? // https snippet
`from flytekit.remote.remote import FlyteRemote
const config =
// eslint-disable-next-line no-nested-ternary
env.CODE_SNIPPET_USE_AUTO_CONFIG === "true"
? 'Config.auto()'
: isHttps

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you just pass isHttps in as the 2nd parameter to Config.for_endpoint?

Copy link
Contributor Author

@ddl-rliu ddl-rliu Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context, this follows the nested ternary pattern that I've seen e.g. here

const typeOVerride =
// eslint-disable-next-line no-nested-ternary
isStaticGraph === true
? dTypes.staticNode
: isUnFetchedDynamicNode(node)
? dTypes.nestedMaxDepth
: undefined;

Since python booleans aren't one-to-one with JS booleans, to pass in isHttps as a param it would have to look like

const insecure = isHttps ? "False" : "True"
 ... `Config.for_endpoint("${window.location.host}",${insecure})`

which I wasn't sure would be much clearer.

Copy link

@ddl-ebrown ddl-ebrown Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the reason I asked was for exactly the reason the ignored eslinter calls out
https://eslint.org/docs/latest/rules/no-nested-ternary

It's fine to use the existing style / pattern they have here -- when in Rome :)

Copy link
Contributor Author

@ddl-rliu ddl-rliu Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha! Okay, updated it here: df63f99

? // https snippet
`Config.for_endpoint("${window.location.host}")`
: // http snippet
`Config.for_endpoint("${window.location.host}", True)`;
const code = `from flytekit.remote.remote import FlyteRemote
from flytekit.configuration import Config
remote = FlyteRemote(
Config.for_endpoint("${window.location.host}"),
)
remote.get("${dataSourceURI}")`
: // http snippet
`from flytekit.remote.remote import FlyteRemote
from flytekit.configuration import Config
remote = FlyteRemote(
Config.for_endpoint("${window.location.host}", True),
${config},
)
remote.get("${dataSourceURI}")`;

Expand Down
7 changes: 7 additions & 0 deletions website/console/env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ const ASSETS_PATH = `${BASE_URL}/assets/`;
*/
const MAINTENANCE_MODE = process.env.MAINTENANCE_MODE || '';

/**
* Controls whether the config object in the inputs/outputs Python code snippet is automatically constructed
*/
const CODE_SNIPPET_USE_AUTO_CONFIG = process.env.CODE_SNIPPET_USE_AUTO_CONFIG || '';

const processEnv = {
NODE_ENV,
PORT,
Expand All @@ -86,6 +91,7 @@ const processEnv = {
BASE_HREF,
DISABLE_CONSOLE_ROUTE_PREFIX,
MAINTENANCE_MODE,
CODE_SNIPPET_USE_AUTO_CONFIG,
};

export {
Expand All @@ -101,5 +107,6 @@ export {
ADMIN_API,
LOCAL_DEV_HOST,
MAINTENANCE_MODE,
CODE_SNIPPET_USE_AUTO_CONFIG,
processEnv,
};
Loading