Git Product home page Git Product logo

rpds's Introduction

rpds.py

PyPI version Supported Python versions Build status

Python bindings to the Rust rpds crate for persistent data structures.

What's here is quite minimal (in transparency, it was written initially to support replacing pyrsistent in the referencing library). If you see something missing (which is very likely), a PR is definitely welcome to add it.

Installation

The distribution on PyPI is named rpds.py (equivalently rpds-py), and thus can be installed via e.g.:

$ pip install rpds-py

Note that if you install rpds-py from source, you will need a Rust toolchain installed, as it is a build-time dependency. An example of how to do so in a Dockerfile can be found here.

If you believe you are on a common platform which should have wheels built (i.e. and not need to compile from source), feel free to file an issue or pull request modifying the GitHub action used here to build wheels via maturin.

Usage

Methods in general are named similarly to their rpds counterparts (rather than pyrsistent's conventions, though probably a full drop-in pyrsistent-compatible wrapper module is a good addition at some point).

>>> from rpds import HashTrieMap, HashTrieSet, List

>>> m = HashTrieMap({"foo": "bar", "baz": "quux"})
>>> m.insert("spam", 37) == HashTrieMap({"foo": "bar", "baz": "quux", "spam": 37})
True
>>> m.remove("foo") == HashTrieMap({"baz": "quux"})
True

>>> s = HashTrieSet({"foo", "bar", "baz", "quux"})
>>> s.insert("spam") == HashTrieSet({"foo", "bar", "baz", "quux", "spam"})
True
>>> s.remove("foo") == HashTrieSet({"bar", "baz", "quux"})
True

>>> L = List([1, 3, 5])
>>> L.push_front(-1) == List([-1, 1, 3, 5])
True
>>> L.rest == List([3, 5])
True

rpds's People

Contributors

andersk avatar byron-lambda avatar dependabot[bot] avatar here-abarany avatar hroncok avatar julian avatar pre-commit-ci[bot] avatar xiangzhai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rpds's Issues

rpds objects cannot be copied with deepcopy

I stumbled upon this issue due to jsonschema using this lib. I am not sure whether this issue belongs here.

When I execute this sample snippet:

from copy import deepcopy
from rpds import HashTrieMap

m = HashTrieMap({"foo": "bar", "baz": "quux"})

c = deepcopy(m)

print(c)

I get the following stacktrace:

python test.py
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    L2 = deepcopy(L)
  File "/Users/kevin.stillhammer/.rye/py/[email protected]/install/lib/python3.8/copy.py", line 161, in deepcopy
    rv = reductor(4)
TypeError: cannot pickle 'rpds.List' object

It would be great if this lib supports deepcopy.

RFE: please provide suppot for latest 1.x maturin

rpds/pyproject.toml

Lines 1 to 2 in 373e9d7

[build-system]
requires = ["maturin>=0.14,<0.15"]

Just tested with maturin 1.1.0 and on first look module builds correctly

+ /usr/bin/python3 -sBm build -w --no-isolation
* Getting build dependencies for wheel...
* Building wheel...
Running `maturin pep517 build-wheel -i /usr/bin/python3 --compatibility off`
    Updating crates.io index
  Downloaded target-lexicon v0.12.6
  Downloaded pyo3-macros v0.18.1
  Downloaded quote v1.0.23
  Downloaded once_cell v1.17.1
  Downloaded proc-macro2 v1.0.51
  Downloaded pyo3-macros-backend v0.18.1
  Downloaded pyo3-build-config v0.18.1
  Downloaded unicode-ident v1.0.6
  Downloaded windows_x86_64_gnullvm v0.42.1
  Downloaded libc v0.2.139
  Downloaded windows_i686_msvc v0.42.1
  Downloaded pyo3-ffi v0.18.1
  Downloaded windows-targets v0.42.1
  Downloaded windows_x86_64_gnu v0.42.1
  Downloaded windows_aarch64_gnullvm v0.42.1
  Downloaded pyo3 v0.18.1
  Downloaded windows_aarch64_msvc v0.42.1
  Downloaded windows_x86_64_msvc v0.42.1
  Downloaded windows_i686_gnu v0.42.1
  Downloaded windows-sys v0.45.0
  Downloaded archery v0.5.0
  Downloaded rpds v0.13.0
  Downloaded 22 crates (8.2 MB) in 1.34s (largest was `windows-sys` at 2.6 MB)
๐Ÿ“ฆ Including license file "/home/tkloczko/rpmbuild/BUILD/rpds-0.7.1/LICENSE"
๐Ÿ”— Found pyo3 bindings with abi3 support for Python โ‰ฅ 3.8
๐Ÿ Not using a specific python interpreter
๐Ÿ“ก Using build options features from pyproject.toml
   Compiling target-lexicon v0.12.6
   Compiling autocfg v1.1.0
   Compiling once_cell v1.17.1
   Compiling proc-macro2 v1.0.51
   Compiling unicode-ident v1.0.6
   Compiling quote v1.0.23
   Compiling libc v0.2.139
   Compiling syn v1.0.109
   Compiling parking_lot_core v0.9.7
   Compiling smallvec v1.10.0
   Compiling cfg-if v1.0.0
   Compiling scopeguard v1.1.0
   Compiling static_assertions v1.1.0
   Compiling unindent v0.1.11
   Compiling indoc v1.0.9
   Compiling archery v0.5.0
   Compiling rpds v0.13.0
   Compiling lock_api v0.4.9
   Compiling memoffset v0.8.0
   Compiling pyo3-build-config v0.18.1
   Compiling parking_lot v0.12.1
   Compiling pyo3-macros-backend v0.18.1
   Compiling pyo3-ffi v0.18.1
   Compiling pyo3 v0.18.1
   Compiling pyo3-macros v0.18.1
   Compiling rpds-py v0.7.1 (/home/tkloczko/rpmbuild/BUILD/rpds-0.7.1)
    Finished release [optimized] target(s) in 58.61s
๐Ÿ“– Found type stub file at rpds.pyi
๐Ÿ“ฆ Built wheel for abi3 Python โ‰ฅ 3.8 to /home/tkloczko/rpmbuild/BUILD/rpds-0.7.1/target/wheels/rpds_py-0.7.1-cp38-abi3-linux_x86_64.whl
/home/tkloczko/rpmbuild/BUILD/rpds-0.7.1/target/wheels/rpds_py-0.7.1-cp38-abi3-linux_x86_64.whl
Successfully built rpds_py-0.7.1-cp38-abi3-linux_x86_64.whl

v0.8.8: Bitdefender quarantines "infected" rpds.cp311-win_amd64.pyd

I've no idea whether this is real or not, but Bitdefender (an anti-virus app) immediately flags and quarantines one of the files created upon install:

The file C:\Users\estau.virtualenvs\process_wavelength\Lib\site-packages\rpds\rpds.cp311-win_amd64.pyd is infected with Gen:Suspicious.Cloud.4.Bu4@a4QxQep and was moved to quarantine. It is recommended that you run a System Scan to make sure your system is clean.

I'd guess this only shows up on systems with AMD processors.

HashTrieMap should return a KeysView not a list

We anyways had something to fix here (duplicating the Vec), but more concretely, we return the wrong type for HashTrieMap.keys, specifically, compare:

โŠ™  ~[python] -c 'from rpds import HashTrieMap; d = {1: 2}; print(d.keys(), HashTrieMap(d).keys())'                                                                                                                                                                                                                 julian@Airm
dict_keys([1]) [1]

(where obviously KeysView objects are set-like).

Wheels for Python 3.12

Hi,

There is no wheels built and distributed for Python 3.12.
This package is now a dependency of jsonschema v4.18.0.

To allow software testing against Python 3.12 which is in beta state, that would be great if you could provide Py3.12 wheels.

Thanks.

Mis-named method in `rpds.pyi` causes type checking to fail

rpds/rpds.pyi

Line 52 in b1ed53f

def drop_front(self) -> "List[T]": ...

This method name should be drop_first to match lib.rs method name.

To reproduce:

$ cat test.py 
from rpds import List
L = List([1, 3, 5])
print(L.drop_first())
$ python3 test.py 
List([3, 5])
$ mypy test.py 
test.py:3: error: "rpds.List[int]" has no attribute "drop_first"; maybe "drop_front"?  [attr-defined]
Found 1 error in 1 file (checked 1 source file)

DLL load failed (python=3.10.8)


ImportError Traceback (most recent call last)
Cell In[1], line 1
----> 1 import gradio as gr
2 import os
3 from langchain.chat_models import ChatOpenAI

File c:\ProgramData\anaconda3\envs\wenan3\lib\site-packages\gradio_init_.py:3
1 import json
----> 3 import gradio._simple_templates
4 import gradio.image_utils
5 import gradio.processing_utils

File c:\ProgramData\anaconda3\envs\wenan3\lib\site-packages\gradio_simple_templates_init_.py:1
----> 1 from .simpledropdown import SimpleDropdown
2 from .simpleimage import SimpleImage
3 from .simpletextbox import SimpleTextbox

File c:\ProgramData\anaconda3\envs\wenan3\lib\site-packages\gradio_simple_templates\simpledropdown.py:6
3 import warnings
4 from typing import Any, Callable
----> 6 from gradio.components.base import FormComponent
7 from gradio.events import Events
10 class SimpleDropdown(FormComponent):
...
----> 1 from .rpds import *
3 doc = rpds.doc
4 if hasattr(rpds, "all"):

ImportError: DLL load failed while importing rpds: ๆ‹’็ป่ฎฟ้—ฎใ€‚

Document the rust toolchain requirement for source installs and build MUSL wheels

Would be nice to have an instruction with pre-requisites and what is the recommended way of installation.

I tried to install it inside docker with image python:3.11-alpine

#6 4.061   Downloading rpds_py-0.7.1.tar.gz (15 kB)
#6 4.071   Installing build dependencies: started
#6 5.599   Installing build dependencies: finished with status 'done'
#6 5.601   Getting requirements to build wheel: started
#6 5.684   Getting requirements to build wheel: finished with status 'done'
#6 5.686   Preparing metadata (pyproject.toml): started
#6 5.755   Preparing metadata (pyproject.toml): finished with status 'error'
#6 5.761   error: subprocess-exited-with-error
#6 5.761   
#6 5.761   ร— Preparing metadata (pyproject.toml) did not run successfully.
#6 5.761   โ”‚ exit code: 1
#6 5.761   โ•ฐโ”€> [6 lines of output]
#6 5.761       
#6 5.761       Cargo, the Rust package manager, is not installed or is not on PATH.
#6 5.761       This package requires Rust and Cargo to compile extensions. Install it through
#6 5.761       the system's package manager or via https://rustup.rs/
#6 5.761       
#6 5.761       Checking for Rust toolchain....
#6 5.761       [end of output]
#6 5.761   
#6 5.761   note: This error originates from a subprocess, and is likely not a problem with pip.
#6 5.764 error: metadata-generation-failed
#6 5.764 
#6 5.764 ร— Encountered error while generating package metadata.
#6 5.764 โ•ฐโ”€> See above for output.
#6 5.764 
#6 5.764 note: This is an issue with the package mentioned above, not pip.
#6 5.764 hint: See above for details.

Failing to install latest version with python 3.9.16 and pypi

pip install rpds-py
Looking in indexes: https://pypi.org/simple
Collecting rpds-py
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error

  ร— Preparing metadata (pyproject.toml) did not run successfully.
  โ”‚ exit code: 1
  โ•ฐโ”€> [14 lines of output]
      error: failed to parse manifest at `/private/var/folders/2x/lmlfhwrx449fvlxzyq5z8djr0000gn/T/pip-install-emrxykip/rpds-py_d9e40e1ca0f146599493c7411b8b98cf/Cargo.toml`

      Caused by:
        feature `edition2021` is required

        this Cargo does not support nightly features, but if you
        switch to nightly channel you can add
        `cargo-features = ["edition2021"]` to enable this feature
      ๐Ÿ’ฅ maturin failed
        Caused by: Cargo metadata failed. Does your crate compile with `cargo build`?
        Caused by: `cargo metadata` exited with an error:
      Error running maturin: Command '['maturin', 'pep517', 'write-dist-info', '--metadata-directory', '/private/var/folders/2x/lmlfhwrx449fvlxzyq5z8djr0000gn/T/pip-modern-metadata-k42g9uso', '--interpreter', '/Users/hugodupras/.pyenv/versions/3.9.16/bin/python3.9']' returned non-zero exit status 1.
      Checking for Rust toolchain....
      Running `maturin pep517 write-dist-info --metadata-directory /private/var/folders/2x/lmlfhwrx449fvlxzyq5z8djr0000gn/T/pip-modern-metadata-k42g9uso --interpreter /Users/hugodupras/.pyenv/versions/3.9.16/bin/python3.9`
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

ร— Encountered error while generating package metadata.
โ•ฐโ”€> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

No problem with python3.10 where it find the correct wheel on pypi

I'm on MacOS 13.4.1 x86

Couldn't find a setup script

Installed /home/circleci/my-project/.venv/lib/python3.10/site-packages/SecretStorage-3.3.3-py3.10.egg
Searching for rpds-py>=0.7.1
Reading https://pypi.org/simple/rpds-py/
Downloading https://files.pythonhosted.org/packages/48/0b/f42f99419c5150c2741fe28bf97674d928d46ee17f46f2bc5be031cce0bc/rpds_py-0.13.2.tar.gz#sha256=f8eae66a1304de7368932b42d801c67969fd090ddb1a7a24f27b435ed4bed68f
Best match: rpds-py 0.13.2
Processing rpds_py-0.13.2.tar.gz
error: Couldn't find a setup script in /tmp/easy_install-qrzhwtkm/rpds_py-0.13.2.tar.gz

Exited with code exit status 1

Error when installing latest version with Poetry

This error doesn't happen on version 0.7.1

Package operations: 1 install, 9 updates, 0 removals

  โ€ข Updating rpds-py (0.7.1 -> 0.8.7): Failed

  ChefBuildError

  Backend subprocess exited when trying to invoke build_wheel
  
  Running `maturin pep517 build-wheel -i /var/folders/p2/pwvr5hs54yx3drlwc9d4w3xh0000gn/T/tmpzac82swx/.venv/bin/python --compatibility off`
  ๐Ÿ’ฅ maturin failed
    Caused by: Cargo metadata failed. Do you have cargo in your PATH?
    Caused by: No such file or directory (os error 2)
  Error: command ['maturin', 'pep517', 'build-wheel', '-i', '/var/folders/p2/pwvr5hs54yx3drlwc9d4w3xh0000gn/T/tmpzac82swx/.venv/bin/python', '--compatibility', 'off'] returned non-zero exit status 1
  

  at ~/Library/Application Support/pypoetry/venv/lib/python3.9/site-packages/poetry/installation/chef.py:147 in _prepare
      143โ”‚ 
      144โ”‚                 error = ChefBuildError("\n\n".join(message_parts))
      145โ”‚ 
      146โ”‚             if error is not None:
    โ†’ 147โ”‚                 raise error from None
      148โ”‚ 
      149โ”‚             return path
      150โ”‚ 
      151โ”‚     def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path:

Note: This error originates from the build backend, and is likely not a problem with poetry but with rpds-py (0.8.7) not supporting PEP 517 builds. You can verify this by running 'pip wheel --use-pep517 "rpds-py (==0.8.7)"'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.