fonttools / fontbakery

🧁 A font quality assurance tool for everyone
https://fontbakery.readthedocs.io
Apache License 2.0
534 stars 99 forks source link

[check-profile] TypeError: the 'package' argument is required to perform a relative import for './scripts/fontbakery_checks.py' #4693

Closed arrowtype closed 2 months ago

arrowtype commented 2 months ago

Observed behaviour

I’m trying to run a custom check profile, and it works sometimes, but sometimes doesn’t. I get this error:

▶ fontbakery check-profile "scripts/fontbakery_profile.py" "fonts/otf/Familyname-*.otf" --html ttf-fb-tests.html
Traceback (most recent call last):
  File "/Users/stephennixon/type-repos/Familyname/venv/bin/fontbakery", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/stephennixon/type-repos/Familyname/venv/lib/python3.11/site-packages/fontbakery/cli.py", line 424, in main
    profile = profile_factory(get_module(args.profile))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/stephennixon/type-repos/Familyname/venv/lib/python3.11/site-packages/fontbakery/fonts_profile.py", line 134, in profile_factory
    module = get_module(check_definition)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/stephennixon/type-repos/Familyname/venv/lib/python3.11/site-packages/fontbakery/fonts_profile.py", line 86, in get_module
    imported = importlib.import_module(name, package=None)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/stephennixon/.pyenv/versions/3.11.3/lib/python3.11/importlib/__init__.py", line 121, in import_module
    raise TypeError(msg.format(name))
TypeError: the 'package' argument is required to perform a relative import for './scripts/fontbakery_checks.py'

Earlier, it seemed that running rehash fixed this, but now, it seems to be more stuck.

I’ve tried working within a venv within the same directory as the project, and moving the profile to different locations, and I’m copying the relative paths, so I’ve been very careful to check that I’m not making any typos.

I also restarted my computer, just in case. The issue remains.

Expected behaviour

This works sometimes, and runs checks as specified in the profile. But, now it’s not.

This feels like it might be some kind of issue with my Python setup, but it’s hard to say.

Am I doing something wrong, or how might I debug this? I’ll keep trying, and update this issue if I find a solution.

Resources and steps needed to reproduce

I’m using FontBakery 0.12.4, on Python 3.11. Please let me know if you need any further details.

In case it’s useful, it does seem that which gets the results I expect:

▶ which python
/Users/stephennixon/type-repos/Familyname/venv/bin/python

▶ which fontbakery
/Users/stephennixon/type-repos/Familyname/venv/bin/fontbakery
arrowtype commented 2 months ago

Oh, my mistake: there were a multiple python files as part of the profile in this particular project, and I was only using one of them. Copying in the full set made it work ask usual.