tangramdotdev / packages

A collection of community maintained Tangram packages.
https://www.tangram.dev
MIT License
8 stars 2 forks source link

Fix failing Python test #99

Closed deciduously closed 12 hours ago

deciduously commented 2 days ago

The python package defines a test:

export const test = tg.target(async () => {
    return await $`
                set -eux

                echo "Checking that we can run python scripts."
                python -I -c 'print("Hello, world!")'

                echo "Checking that we can run pip."
                pip3 --version

                echo "Checking that we can create virtual envs."
                python -m venv $OUTPUT || true
            `.env(toolchain());
});

This currently errors at the first test:

+ python -I -c 'print("Hello, world!")'
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Python path configuration:
  PYTHONHOME = (not set)
  PYTHONPATH = (not set)
  program name = 'python'
  isolated = 1
  environment = 0
  user site = 0
  safe_path = 1
  import site = 1
  is in build tree = 0
  stdlib dir = '/Users/benlovy/.tangram/tmp/069basw2y9ty51ern8vt6vqhh8/output/lib/python3.12'
  sys._base_executable = '/Users/benlovy/.tangram/artifacts/fil_01tjrev0fqs2gwq3e7cear274nz3hqem8snwwcradktkma65c15kpg'
  sys.base_prefix = '/Users/benlovy/.tangram/tmp/069basw2y9ty51ern8vt6vqhh8/output'
  sys.base_exec_prefix = '/Users/benlovy/.tangram/tmp/069basw2y9ty51ern8vt6vqhh8/output'
  sys.platlibdir = 'lib'
  sys.executable = '/Users/benlovy/.tangram/artifacts/fil_01tjrev0fqs2gwq3e7cear274nz3hqem8snwwcradktkma65c15kpg'
  sys.prefix = '/Users/benlovy/.tangram/tmp/069basw2y9ty51ern8vt6vqhh8/output'
  sys.exec_prefix = '/Users/benlovy/.tangram/tmp/069basw2y9ty51ern8vt6vqhh8/output'
  sys.path = [
    '/Users/benlovy/.tangram/tmp/069basw2y9ty51ern8vt6vqhh8/output/lib/python312.zip',
    '/Users/benlovy/.tangram/tmp/069basw2y9ty51ern8vt6vqhh8/output/lib/python3.12',
    '/Users/benlovy/.tangram/tmp/069basw2y9ty51ern8vt6vqhh8/output/lib/python3.12/lib-dynload',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00000001f3bb7240 (most recent call first):
  <no Python frame>
-> the process did not exit successfully
   internal:packages/server/src/runtime/darwin.rs:463:15 tangram_server::runtime::darwin::Runtime::build::{{closure}}

However, I can check out the artifact and use it on macOS:

$ tg build ./packages/python -c python-macos
$ ./python-macos/bin/python --version
Python 3.12.7
$ ./python-macos/bin/python -I -c 'print("Hello, world!")'
Hello, world!

Make the test pass.