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

DRAFT: Feature/uv #112

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

DRAFT: Feature/uv #112

wants to merge 11 commits into from

Conversation

bearrito
Copy link

No description provided.

@bearrito bearrito requested a review from kronos30 July 15, 2024 14:47
@jprestwo jprestwo self-requested a review July 15, 2024 15:57
Copy link

@jprestwo jprestwo left a comment

Choose a reason for hiding this comment

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

Mostly just questions about UV, no obvious problems I can see.

INPUT_REQUIREMENTS requirements.in
USE_UV TRUE
UV_CACHE /tmp/testing/uv/cache
)

Choose a reason for hiding this comment

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

I know its just a draft, but I assume this will be the default? It would just be nice to enable this transparently without having to change any packages, if that is at all possible.

Also, as far as the cache location, what is the consequence if different packages set different cache locations? They just won't be able to share the venv I assume?

Copy link
Author

Choose a reason for hiding this comment

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

We wouldn't want this in /tmp because it would not survive a reboot. It should probably land in /var/lib/uv or whatever the current standard for persistent data is on Linux.

set(use_uv "--use-uv")

if( ARG_ISOLATE_REQUIREMENTS )
message( FATAL_ERROR "You can use ISOLATE_REQUIREMENTS in conjunction with USE_UV" )

Choose a reason for hiding this comment

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

Did you mean You can't use ISOLATE_REQUIREMENTS...

Copy link
Author

Choose a reason for hiding this comment

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

Depends on what that means. Do you not want to use uv at all, do you want your own cache (why?)
I'll have to look at what ISOLATE_REQUIREMENTS means a bit more, for some reason I thought it had to do with venv chaining and not necessarily using system-packages

Copy link
Contributor

@paulbovbel paulbovbel Jul 16, 2024

Choose a reason for hiding this comment

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

ISOLATE_REQUIREMENTS does indeed cause a package not to inherit its dependencies requirements.txt. Interestingly enough we don't seem to use it anywhere anymore, and I can't remember why we added it. However, does beg the questions why it's not supported with uv

USE_UV TRUE
UV_CACHE /tmp/testing/uv/cache
EXTRA_PIP_ARGS ....
)

Choose a reason for hiding this comment

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

My only concern here is if we have packages that use the extra pip args, and if they do for what reason and would this be supported with UV.

Copy link
Author

Choose a reason for hiding this comment

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

The issue with EXTRA_PIP_ARGS is they get passed in as string to uv some pip args aren't supported.
I thought it cleaner to say: use these args if using uv use these args if using pip.
Admittedly some of the args will overlap.

return logging.getLogger()


def run_command(cmd, *args, **kwargs):
def run_command(cmd: typing.List[str], *args, **kwargs) -> subprocess.CompletedProcess:

Choose a reason for hiding this comment

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

Not really your problem as this already existed, but we really need to move this into locus_common or somewhere. I keep seeing the same block of code copied into various packages 🤦

Copy link
Contributor

Choose a reason for hiding this comment

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

That is not a bad idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

catkin_virtualenv is a public package

"""Initialize a new uv virtualenv using the specified python version and extra arguments."""

"""
This differs vrom the VirtualEnv class mainly in that the VirtualEnv class has to determine,

Choose a reason for hiding this comment

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

"differs from"

Copy link
Author

Choose a reason for hiding this comment

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

noted.

@kronos30 kronos30 requested a review from paulbovbel July 16, 2024 13:39
return logging.getLogger()


def run_command(cmd, *args, **kwargs):
def run_command(cmd: typing.List[str], *args, **kwargs) -> subprocess.CompletedProcess:
Copy link
Contributor

Choose a reason for hiding this comment

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

That is not a bad idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the log file as part of the PR, or is this meant to act of what it should look like?

Copy link
Author

Choose a reason for hiding this comment

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

Should be removed. Mea culpa.

@paulbovbel
Copy link
Contributor

paulbovbel commented Jul 16, 2024

Will review in more detail, but my biggest upfront concern is that to leverage this, you have to figure out a way to distribute the uv cache as part of the bundle deb.

Replacing pip with another tool is frankly, scary. My philosophy with python packaging was historically 'avoid the newest sexy pip replacement because it will inevitably go out of style and be replaced with something else (pipenv, poetry, uv, what-have-you). Eventually the best stuff does get rolled into setuptools/pip.

My parallel effort to remove redundant files was https://github.com/locusrobotics/tailor-distro/pull/88/files, which I think conceptually (and in practice) is a lot simpler as a post-processing step. There's an extra hoop I didn't jump through to make deb packaging honor symlinks, but if you want to reap the benefits of this in the image builds without much added work, you can add:

rdfind -makesymlinks true /opt/locusrobotics

... below https://github.com/locusrobotics/locus_deployment/blob/adc994d09782b8c9d18d1e160b4e1bcab3299114/locus_ansible/roles/locus_bots/common/tasks/03-bare_metal.yaml#L130


catkin_run_tests_target("venv_check" "${PROJECT_NAME}-requirements" "venv_check-${PROJECT_NAME}-requirements.xml"
COMMAND "${CATKIN_ENV} rosrun catkin_virtualenv venv_check ${venv_dir} --requirements ${package_requirements} \
--use-uv \
Copy link
Contributor

@paulbovbel paulbovbel Jul 16, 2024

Choose a reason for hiding this comment

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

one easy pattern to reduce duplication here:

if(DEFINED ARG_USE_UV)
  set(extra_args "${extra_args} --use-uv")
endif()

catkin_run_tests_target(... COMMAND ... ${extra_args}

self.path: pathlib.Path = path

if self.path in protected_paths:
raise RuntimeError(f"Cannot install into {self.path}")
Copy link
Contributor

@paulbovbel paulbovbel Jul 16, 2024

Choose a reason for hiding this comment

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

I imagine these paths are protected by the nature of filesystem permissions? Do we really need to check this list at the application level?

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

Successfully merging this pull request may close these issues.

4 participants