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

chore: create alias to source sky env in dev mode #4553

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sachiniyer
Copy link

Added a small change to the template to create an alias for sourcing the python env. Addressing #4453 as a good first issue.

I ran the smoke tests, as well as verified that the alias existed when I created a job.

Tested (run the relevant ones):

  • [ x] Code formatting: bash format.sh
  • Any manual or new tests for this PR (please specify below) - None
  • All smoke tests: pytest tests/test_smoke.py
  • [ x] Relevant individual smoke tests: pytest tests/test_smoke.py::test_job_and_serve
  • Backward compatibility tests: conda deactivate; bash -i tests/backward_compatibility_tests.sh

Copy link
Collaborator

@romilbhardwaj romilbhardwaj left a comment

Choose a reason for hiding this comment

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

Welcome to the SkyPilot community @sachiniyer! Thanks for this PR - left a minor comment.

Comment on lines 26 to 31
echo 'export SKYPILOT_DEV=1' >> ~/.bashrc
{% endif %}

{% if controller_envs.get("SKYPILOT_DEV") %}
type sky-env > /dev/null 2>&1 || echo 'alias sky-env="{{ sky_activate_python_env }}"' >> ~/.bashrc
{% endif %}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we reuse the is_dev conditional check above and wrap it into the same block?

Suggested change
echo 'export SKYPILOT_DEV=1' >> ~/.bashrc
{% endif %}
{% if controller_envs.get("SKYPILOT_DEV") %}
type sky-env > /dev/null 2>&1 || echo 'alias sky-env="{{ sky_activate_python_env }}"' >> ~/.bashrc
{% endif %}
echo 'export SKYPILOT_DEV=1' >> ~/.bashrc
type sky-env > /dev/null 2>&1 || echo 'alias sky-env="{{ sky_activate_python_env }}"' >> ~/.bashrc
{% endif %}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, IIUC type checks symbols in the active shell. While it will work here, do you think something like this would be a more robust check:

  if ! grep -q "alias sky-env=" ~/.bashrc; then
    echo 'alias sky-env="{{ sky_activate_python_env }}"' >> ~/.bashrc
  fi

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1 to the grep solution, especially since I don't think it's guaranteed that the commands here are running in bash (could be some other sh like dash)

Copy link
Author

Choose a reason for hiding this comment

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

Both suggestions make sense. Let me try again!

Copy link
Author

@sachiniyer sachiniyer Jan 14, 2025

Choose a reason for hiding this comment

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

Okay, so I was able to get the grep statement to work.

However, I am not able to figure out how the other dev statement ({% if is_dev %}) works. I am also not seeing 'export SKYPILOT_DEV=1' in .bashrc when I run the smoke tests or when I create a job manually (with SKYPILOT_DEV=1 set in my local shell)

I am also not seeing is_dev in the vars_to_fill map here. Not sure if there is something I am missing.

I also know that the controller envs are being set into the environment through this statement

envs:
{%- for env_name, env_value in controller_envs.items() %}
  {{env_name}}: {{env_value}}
{%- endfor %}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Wow, yeah, that's apparently been broken for more than a year. #2458 removed is_dev but apparently didn't remove this use. Good catch!
Could you move the export SKYPILOT_DEV=1 into your new conditional, delete the old one, and add a similar grep check? e.g.

grep -q "export SKYPILOT_DEV=" ~/.bashrc || echo 'export SKYPILOT_DEV=1' >> ~/.bashrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants