d0c-s4vage / lookatme

An interactive, terminal-based markdown presenter
https://lookatme.readthedocs.io/en/latest/
MIT License
2.09k stars 61 forks source link

Build for the M1 #114

Closed igbanam closed 3 years ago

igbanam commented 3 years ago

Describe the bug LookAtMe does not run on M1 Macs

To Reproduce

Install lookatme with pip

python3 -m pip install lookatme

Check the installed version

lookatme --version

Expected behavior …to see the version

Screenshots

Traceback (most recent call last):
  File "/opt/homebrew/bin/lookatme", line 33, in <module>
    sys.exit(load_entry_point('lookatme===-VERSION-', 'console_scripts', 'lookatme')())
  File "/opt/homebrew/bin/lookatme", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/opt/homebrew/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/metadata.py", line 77, in load
    module = import_module(match.group('module'))
  File "/opt/homebrew/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/opt/homebrew/lib/python3.9/site-packages/lookatme/__main__.py", line 17, in <module>
    import lookatme.tui
  File "/opt/homebrew/lib/python3.9/site-packages/lookatme/tui.py", line 16, in <module>
    from lookatme.contrib import shutdown_contribs, contrib_first
  File "/opt/homebrew/lib/python3.9/site-packages/lookatme/contrib/__init__.py", line 15, in <module>
    from . import file_loader
  File "/opt/homebrew/lib/python3.9/site-packages/lookatme/contrib/file_loader.py", line 42, in <module>
    class FileSchema(Schema):
  File "/opt/homebrew/lib/python3.9/site-packages/lookatme/contrib/file_loader.py", line 49, in FileSchema
    default=LineRange().dump(LineRange()),
  File "/opt/homebrew/lib/python3.9/site-packages/marshmallow/schema.py", line 547, in dump
    result = self._serialize(processed_obj, many=many)
  File "/opt/homebrew/lib/python3.9/site-packages/marshmallow/schema.py", line 515, in _serialize
    value = field_obj.serialize(attr_name, obj, accessor=self.get_attribute)
  File "/opt/homebrew/lib/python3.9/site-packages/marshmallow/fields.py", line 318, in serialize
    return self._serialize(value, attr, obj, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/marshmallow/fields.py", line 898, in _serialize
    ret = self._format_num(value)  # type: _T
  File "/opt/homebrew/lib/python3.9/site-packages/marshmallow/fields.py", line 873, in _format_num
    return self.num_type(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'Integer'

Environment (please complete the following information):

Additional context n/a

igbanam commented 3 years ago

I also tried getting the repository and running the tests, same issue.

I'm not well versed in Python to understand how Python reacts to the discrepancies between the normal Macs and the M1s. If anyone has a pointer, please share. We can get a fix up for this asap.

stweller commented 3 years ago

Hi @igbanam ,

I don't think this is related to M1 Macs. I'm getting the same error on Arch Linux. I'm getting this with the AUR package, but also if I install with pip directly. The only thing I can think of that our systems have in common is the relatively recent python version (3.9).

igbanam commented 3 years ago

Thanks for this, @stweller

I tried getting earlier versions of Python using pyenv — 3.8.x and 3.6.x — and I can't seem to build it on my mac either

╰─❯ pyenv install 3.8.5                                                                                                                                                        ─╯
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.8.5.tar.xz...
-> https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz
Installing Python-3.8.5...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk

BUILD FAILED (OS X 11.3.1 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/gp/y693kpms2dg_q_k5cf27bnf40000gn/T/python-build.20210514114502.9787
Results logged to /var/folders/gp/y693kpms2dg_q_k5cf27bnf40000gn/T/python-build.20210514114502.9787.log

Last 10 log lines:
checking size of _Bool... 1
checking size of off_t... 8
checking whether to enable large file support... no
checking size of time_t... 8
checking for pthread_t... yes
checking size of pthread_t... 8
checking size of pthread_key_t... 8
checking whether pthread_key_t is compatible with int... no
configure: error: Unexpected output of 'arch' on OSX
make: *** No targets specified and no makefile found.  Stop.

Could you get this working with other versions of Python at least?

stweller commented 3 years ago

Hi @igbanam ,

I was only suspecting that python 3.9 could be the culprit. To check this, I now installed python3.8, but unfortunately I run into the exact same error. So there must be some other reason for this. Let's wait whether the developer has something to say about this...

igbanam commented 3 years ago

Thanks for your time in helping triage this

SeniorMars commented 3 years ago

Hey aur maintainer here. I just did a chroot and updated all my depends packages. From what I've seen it does work. Any logs would be appreciated.

stweller commented 3 years ago

Sure, what logs do you need? My traceback from python looks very similar to the one posted above:

Traceback (most recent call last):
  File "/home/stweller/.virtualenvs/lookatme/bin/lookatme", line 5, in <module>
    from lookatme.__main__ import main
  File "/home/stweller/.virtualenvs/lookatme/lib/python3.9/site-packages/lookatme/__main__.py", line 17, in <module>
    import lookatme.tui
  File "/home/stweller/.virtualenvs/lookatme/lib/python3.9/site-packages/lookatme/tui.py", line 16, in <module>
    from lookatme.contrib import shutdown_contribs, contrib_first
  File "/home/stweller/.virtualenvs/lookatme/lib/python3.9/site-packages/lookatme/contrib/__init__.py", line 15, in <module>
    from . import file_loader
  File "/home/stweller/.virtualenvs/lookatme/lib/python3.9/site-packages/lookatme/contrib/file_loader.py", line 42, in <module>
    class FileSchema(Schema):
  File "/home/stweller/.virtualenvs/lookatme/lib/python3.9/site-packages/lookatme/contrib/file_loader.py", line 49, in FileSchema
    default=LineRange().dump(LineRange()),
  File "/home/stweller/.virtualenvs/lookatme/lib/python3.9/site-packages/marshmallow/schema.py", line 547, in dump
    result = self._serialize(processed_obj, many=many)
  File "/home/stweller/.virtualenvs/lookatme/lib/python3.9/site-packages/marshmallow/schema.py", line 515, in _serialize
    value = field_obj.serialize(attr_name, obj, accessor=self.get_attribute)
  File "/home/stweller/.virtualenvs/lookatme/lib/python3.9/site-packages/marshmallow/fields.py", line 318, in serialize
    return self._serialize(value, attr, obj, **kwargs)
  File "/home/stweller/.virtualenvs/lookatme/lib/python3.9/site-packages/marshmallow/fields.py", line 898, in _serialize
    ret = self._format_num(value)  # type: _T
  File "/home/stweller/.virtualenvs/lookatme/lib/python3.9/site-packages/marshmallow/fields.py", line 873, in _format_num
    return self.num_type(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'Integer'
stweller commented 3 years ago

Strangely, I tried this on another machine I have access to (Debian; python3.7) and get the exact same issue...

stweller commented 3 years ago

To be honest, when looking at the code, I don't understand how it could work. I'm not familiar with the marshmallow framework that is used here, but as far as I can understand,

class LineRange(Schema):
    start = fields.Integer(default=0, missing=0)
    end = fields.Integer(default=None, missing=None)

declares a new schema, which is supposed to support serialization/deserialization for objects with start and end, both of which are integers. Now, the following should serialize such an object:

LineRange().dump({'start':5,'end':10})

and indeed that works as expected when I try it. However, the lookatme source code contains the ine

LineRange().dump(LineRange())

which means that I try to serialize an object, but as object I pass a schema, not an object that follows this schema. Now why should this work? I understand the error message @igbanam and myself are getting, but I don't understand why it works in other cases.

Note that this is not the only lines where similar constructs are used. Just changing the default value to LineRange().dump({}) doesn't fix the issue.

stweller commented 3 years ago

Alright, guys, I think I narrowed this down a bit further. I installed an older version of the marshmallow package (3.0.0), which is apparently less strict, and with this lookatme seems to work as expected. However, to me that looks like I was right about the issue above, it just seems that older versions of the marshmallow framework don't care about these errors. This means that a lot more people will see this issue in the future unless it is fixed. @KarlWithK , what version of marshmallow did you use in your tests?

@igbanam : If you want a workaround, try installing marshmallow==3.0.0.

d0c-s4vage commented 3 years ago

Thank you all for your patience on this! I'm working on a fix to make lookatme compatible with the latest version of marshmallow.

d0c-s4vage commented 3 years ago

For context:

LineRange().dump(LineRange())

The method above used to be a way to get a fully instantiated dict with all defaults set. Marshmallow changed this behavior at some point. https://github.com/d0c-s4vage/lookatme/pull/116 fixes it though!

d0c-s4vage commented 3 years ago

Please comment if you're still running into any issues - from what I can tell (and from what I've read in this issue), everything should be good-to-go with the latest version of lookatme.

pip install --upgrade lookatme
stweller commented 3 years ago

Thanks a lot, @d0c-s4vage ! I can confirm the fix works.