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

Temporarily return to rapidjson #292

Closed
josejachuf opened this issue Oct 19, 2020 · 12 comments
Closed

Temporarily return to rapidjson #292

josejachuf opened this issue Oct 19, 2020 · 12 comments
Labels

Comments

@josejachuf
Copy link

I have a problem that is not directly from emmett but with the installation of orjson.

All the server infrastructure I use is freebsd (+ jails). The orjson installation with pip does not use binaries, it is compiled. To compile you need to install some dependencies, including maturin. In the maturin installation an error occurs (I reported it) and therefore I cannot install orjson.

I've been seeing this [1]

What I want to do is temporarily modify serializers.py [2] and go back to rapidjson. This is apparently the only place where orjson is referenced. The query is if this change is enough and nothing will break.

[1] 2878fbd
[2] 5bbbae3

@josejachuf josejachuf changed the title Install orjson in freebsd Temporarily return to rapidjson Oct 19, 2020
@josejachuf
Copy link
Author

I modified:
[1]
imports
and
json = partial(

and [2]
class JSONServicePipe(Pipe):

output = 'str' (with orjosn output = 'bytes')

and in a simple example it works

[1] emmett/serializers.py
[2] emmett/tools/service.py

@gi0baro
Copy link
Member

gi0baro commented Oct 19, 2020

@josejachuf yes it should be enough.

I'm thinking about a patch-release to make orjson an extra, will update you if I decide in that direction

@josejachuf
Copy link
Author

Hi @gi0baro. This how it would be, a parameter would be passed to App () when instantiating the application to tell it to use orjson?

@gi0baro
Copy link
Member

gi0baro commented Oct 19, 2020

@josejachuf I was thinking more to extra-packages, eg: pip install emmett[orjson]

@josejachuf
Copy link
Author

Ok. And then use try...except imports?

@gi0baro
Copy link
Member

gi0baro commented Oct 19, 2020

@josejachuf yep, I can't think about a better approach.

btw, I still need to think about this, AFAIK on the main platforms the only issue right now with orjson is the lack of wheels for windows and macos on Python 3.9 (that should be addressed within next 2 weeks I hope).

@josejachuf
Copy link
Author

Hi @gi0baro,
Here in service.py:

class JSONServicePipe(Pipe):
    __slots__ = ['decoder', 'encoder']
    # output = 'bytes'
    output = 'str'

is the library used (orjson / rapidjson) that defines the data type?

@gi0baro
Copy link
Member

gi0baro commented Oct 21, 2020

@josejachuf yes, orjson returns byte strings, while rapidjson returns unicode strings

@gi0baro
Copy link
Member

gi0baro commented Oct 28, 2020

@josejachuf with v2.1.1 orjson is optional. You can upgrade and just have the same behaviour of 2.0.x (ensure to cleanup your virtualenv eventually).

I'm closing this.

@gi0baro gi0baro closed this as completed Oct 28, 2020
@josejachuf
Copy link
Author

Thanks @gi0baro

@josejachuf
Copy link
Author

I received help to install maturin in freebsd and already with maturin installed orjson it installed without problems. in this link [1] is the solution in case someone needs it.
Basically in a new installation you should do the following

pkg install -y rust-nightly gcc9 python38

Here's the trick:

cd /usr/bin
mv ld ld.bak
ln -s /usr/local/bin/ld /usr/bin/ld

Then in your virtualenv simply:

pip install maturin

[1] PyO3/maturin#363

@rozhuk-im
Copy link

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

No branches or pull requests

3 participants