bloomberg / memray

Memray is a memory profiler for Python
https://bloomberg.github.io/memray/
Apache License 2.0
13.17k stars 392 forks source link

cppstring for python3 string objection #661

Closed sethtroisi closed 1 month ago

sethtroisi commented 1 month ago

Is there an existing issue for this?

Current Behavior

_memray.pyx line 391: is cdef cppstring command_line = " ".join(sys.argv)

non-pkg/tests/unit/test_reader.py:77: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
memray/_memray.pyx:391: in memray._memray.Tracker.__cinit__
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   TypeError: expected bytes, str found

Same issue happens for self._path at line 601 (and probably line603)

Expected Behavior

I hacked around this by using " ".join(sys.argv).encode(), I assume there may be a more elegant solution.

Steps To Reproduce

Run memray tests at google, I believe our environment is using cython 0.29 with language_level=2 and python3.11

Memray Version

1.7.0

Python Version

3.11

Operating System

Linux

Anything else?

No response

godlygeek commented 1 month ago

We support Cython 0.29 still, for now, but we do not and have never supported language_level=2. Are you patching the setup.py to override our choice of language level?

https://github.com/bloomberg/memray/blob/2062dd68427dc611699214ee1f5110646dae0ff2/setup.py#L141-L142

godlygeek commented 1 month ago

I'm not sure how you're managing to get Cython to use language level 2, but Memray doesn't support it. Our build script hardcodes language level 3. If you're somehow overriding that it's expected that the build will fail, just as it would if you overrode the C++ compiler invocation to build in C++03 mode instead of C++17.