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

Pjob/poc/pyapp binary with plugins #2035

Draft
wants to merge 2 commits into
base: pjob/SNOW-1747473-enable-disable-plugin-commands
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions build_pyapp_binary.sh
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. This script is just PoC - probably not all commands are needed.
  2. I don't know how it works on different operating systems and CPUs.
  3. I don't how will work signing of the binaries.
  4. We should probably move the script to scripts directory.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pip install -U hatch
hatch clean
hatch build
pip install git+https://github.com/hobbsd/[email protected]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. It's external script. It should be reviewed.
  2. The script uses tomllib, so it requires python 3.11.

build-binary
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,6 @@ markers = [

[tool.codespell]
skip = 'tests/*,snow.spec'

[tool.hatch.build.targets.binary]
python-version = "3.11"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use python 3.11 but we had issues with pyinstaller binaries when using python 3.11 - we should check it.

2 changes: 1 addition & 1 deletion src/snowflake/cli/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

from __future__ import annotations

VERSION = "3.4.0.dev0"
VERSION = "3.4.0.dev8"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have issues with caching of my builds, that's why I bump version in my PoC. This should be resolved.

3 changes: 3 additions & 0 deletions src/snowflake/cli/_app/commands_registration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
from dataclasses import dataclass

from snowflake.cli.api.plugins.command import CommandSpec

sys.path.append("/tmp/cli_plugins/lib/python3.11/site-packages")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should consider if we can do it better. For sure we need to load plugins from configurable directory.



@dataclass
class LoadedCommandPlugin:
Expand Down
29 changes: 28 additions & 1 deletion src/snowflake/cli/_plugins/plugin/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from __future__ import annotations

import logging
import subprocess
import sys

import typer
from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
Expand All @@ -26,10 +28,35 @@
app = SnowTyperFactory(
name="plugin",
help="Plugin management commands.",
is_hidden=lambda: True,
)


@app.command(name="install", requires_connection=False)
def install(
package: str = typer.Argument(
None, help="Pip compatible package (PyPI name / URL / local path)"
),
**options,
) -> CommandResult:
"""Installs a plugin from a package"""
target_dir: str = (
"/tmp/cli_plugins" # TODO make it configurable in config.toml with some default
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be configurable.

)
subprocess.check_call(
[
sys.executable,
"-m",
"pip",
"install",
"--prefix",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

--prefix, not --target to install only the plugin and new dependencies, without installation of existing CLI's dependencies.

target_dir,
"--upgrade",
package,
]
)
return MessageResult(f"Plugin successfully installed.")


@app.command(name="enable", requires_connection=False)
def enable(
plugin_name: str = typer.Argument(None, help="Plugin name"),
Expand Down
Loading