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: python dependency specification #2483

Merged
merged 14 commits into from
Mar 1, 2024
Merged

fix: python dependency specification #2483

merged 14 commits into from
Mar 1, 2024

Conversation

tychoish
Copy link
Collaborator

No description provided.

@tychoish
Copy link
Collaborator Author

tychoish commented Jan 24, 2024

I expect the environment/optional dependency thing something we should discuss (do we want to force pulling in pandas and polars? Probably dev dependencies are going to lead to some kind of issue...

@talagluck
Copy link
Contributor

I don't think we want to force pulling in polars and I'm not sure about pandas. The more dev dependencies we have the harder this will be to navigate (ran into this a lot at a previous place) and pip's dependency resolver can be kind of heavy, so unless something is strictly necessary for core functionality, it should be optional

Copy link
Contributor

@universalmind303 universalmind303 left a comment

Choose a reason for hiding this comment

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

in addition to making things optional dependencies, we should also properly handle when the deps are not installed.

It should error instead of panicking

this is what polars does if you try df.to_arrow() without pyarrow installed

Traceback (most recent call last):
  File "/Users/me/Development/glaredb/test_pl.py", line 3, in <module>
    pl.DataFrame({"foo": [1, 2, 3]}).to_arrow()
  File "/Users/me/Development/glaredb/.venv/lib/python3.11/site-packages/polars/dataframe/frame.py", line 1970, in to_arrow
    record_batches = self._df.to_arrow()
                     ^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'pyarrow'

we instead just panic.

@tychoish
Copy link
Collaborator Author

in addition to making things optional dependencies, we should also properly handle when the deps are not installed.

It should error instead of panicking

Totally agree. I think we should probably do that work as part of a seperate ticket just to fix the bug, incase we do a point release early next week.

Do you, @universalmind303 or @talagluck, want to take this over? g

@tychoish
Copy link
Collaborator Author

tychoish commented Feb 1, 2024

I spent a couple hours playing with this, and I have something that maybe works:

  • installs build time dependencies and test/runtime dependencies into different virtualvens that are scoped to the bindings.
  • installs the extra dependencies (I think we want to have this off by default?
  • the install succeeds but it has a patchelf error message. I was able to run something locally, but I didn't kick the tires very hard.

I'm not sure how to do the better error messages you're interested in Cory, but that'd definitely be a good thing to add.

@tychoish tychoish closed this Feb 28, 2024
@tychoish
Copy link
Collaborator Author

tychoish commented Feb 28, 2024

I did a different update to the pytests, and this should just hit the python deps. There was a merge issue for a while, but I've cherry-picked and force pushed this for the moment.

Remaining work should be buildsystem related, I believe.

@tychoish
Copy link
Collaborator Author

@universalmind303 could you take another look.

bindings/python/justfile Outdated Show resolved Hide resolved
bindings/python/requirements.txt Outdated Show resolved Hide resolved
bindings/python/justfile Outdated Show resolved Hide resolved
bindings/python/pyproject.toml Outdated Show resolved Hide resolved
tychoish and others added 3 commits February 29, 2024 12:05
Co-authored-by: universalmind303 <cory.grinstead@gmail.com>
Copy link
Contributor

@greyscaled greyscaled left a comment

Choose a reason for hiding this comment

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

I just ran this from the repository root dir - should we add a dependency on venv for pytest in the root Justfile?

greyb ~/Repos/glaredb [tycho/python-deps] $ just pytest
.venv/bin/poetry -C tests lock --no-update
sh: .venv/bin/poetry: No such file or directory
error: Recipe `pytest` failed on line 131 with exit code 127

Copy link
Contributor

@greyscaled greyscaled left a comment

Choose a reason for hiding this comment

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

After the previous comment, I ran just venv and got this:

greyb ~/Repos/glaredb [tycho/python-deps] $ just venv
python3 -c "import virtualenv" || python3 -m pip --quiet install virtualenv
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'virtualenv'
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try brew install
    xyz, where xyz is the package you are trying to
    install.
    
    If you wish to install a non-brew-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip.
    
    If you wish to install a non-brew packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
error: Recipe `venv` failed on line 124 with exit code 1

I recognize that it's prompting me to install virtualenv but I'm wondering if this is expected, and if so, can we document this somewhere (if it's not already)

I must admit the command itself: python3 -c "import virtualenv" || python3 -m pip --quiet install virtualenv makes this feel unexpected.

@tychoish
Copy link
Collaborator Author

tychoish commented Mar 1, 2024

@talagluck @universalmind303 can you take another look at this?

@tychoish tychoish requested a review from talagluck March 1, 2024 14:27
Copy link
Contributor

@talagluck talagluck left a comment

Choose a reason for hiding this comment

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

Overall the approach feels reasonable, and I was able to successfully run the code, but I'll defer to Cory for the final sign-off.

@tychoish tychoish merged commit aad410f into main Mar 1, 2024
25 checks passed
@tychoish tychoish deleted the tycho/python-deps branch March 1, 2024 16:46
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.

None yet

5 participants