frostming / pdm-packer

A PDM plugin that packs your packages into a zipapp
MIT License
48 stars 4 forks source link

Version 0.8.0 failing with FileNotFoundError #43

Open genericmoniker opened 2 months ago

genericmoniker commented 2 months ago

Describe the bug

With the release of 0.8.0 I discovered:

  1. I don't have the version of pdm-packer pinned in my project
  2. I get a FileNotFoundError when I try to pack

To Reproduce

$ pdm --version
PDM, version 2.18.1
$ mkdir test
$ cd test
$ pdm init
Creating a pyproject.toml for PDM...
Please enter the Python interpreter to use
 0. cpython@3.9 (/usr/bin/python3)
 1. cpython@3.12 (/usr/bin/python3.12)
 2. cpython@3.9 (/usr/bin/python3.9)
 3. cpython@3.12 (/bin/python3.12)
Please select (0): 1
Virtualenv is created successfully at /home/vagrant/test/.venv
Project name (test): 
Project version (0.1.0): 
Do you want to build this project for distribution(such as wheel)?
If yes, it will be installed by default when running `pdm install`. [y/n] (n): 
License(SPDX name) (MIT): 
Author name (Eric Smith): 
Author email (eric@esmithy.net): 
Python requires('*' to allow any) (==3.12.*): 
Project is initialized successfully
$ vi pyproject.toml    # Adding `plugins = ["pdm-packer"]`
$ pdm install --plugins
Plugins are installed successfully into .pdm-plugins.
$ pdm lock
Changes are written to pdm.lock.
  0:00:00 🔒 Lock successful.  
$ pdm pack
Packing packages...
/home/vagrant/test/.pdm-plugins/lib/python3.12/site-packages/pdm_packer/env.py:55: PDMDeprecationWarning: .values() is deprecated on the requirements collection, it's not a mapping but a list.
  requirements = project.get_dependencies().values()
All packages are synced to date, nothing to do.
  ✔ Install test 0.1.0 successful

  0:00:00 🎉 All complete! 0/0
[FileNotFoundError]: [Errno 2] No such file or directory: '/tmp/pdm-pack-c68x4fg7/lib64/python3.12/site-packages'
WARNING: Add '-v' to see the detailed traceback

Expected behavior

A zipapp to be created.

System (please complete the following information):

Additional context

In debugging, the first exists, but the second doesn't:

/tmp/pdm-pack-c68x4fg7/lib/python3.12/site-packages /tmp/pdm-pack-c68x4fg7/lib64/python3.12/site-packages

If I pin the version to 0.7.0, packing works (other than an expected "Archive has no entry point").

Also, BTW, 0.7.0 doesn't exist in CHANGELOG.md.

frostming commented 2 months ago

Can you show the output of the following command:

/usr/bin/python3.12 /path/to/pdm/lib/site-packages/pdm/models/in_process/sysconfig_get_paths.py prefix
genericmoniker commented 2 months ago

Sure:

$ /usr/bin/python3.12 /usr/local/lib/python3.12/site-packages/pdm/models/in_process/sysconfig_get_paths.py prefix
{"stdlib": "/usr/lib64/python3.12", "platstdlib": "/usr/local/lib64/python3.12", "purelib": "/usr/local/lib/python3.12/site-packages", "platlib": "/usr/local/lib64/python3.12/site-packages", "include": "/usr/include/python3.12", "platinclude": "/usr/include/python3.12", "scripts": "/usr/local/bin", "data": "/usr/local"}
frostming commented 2 months ago

That does not make sense, since we are using the purelib path: https://github.com/frostming/pdm-packer/blob/3ec0828a8f18711028bf73702b029de62295914d/src/pdm_packer/env.py#L74

Can you provide the full traceback by adding -v

genericmoniker commented 2 months ago
$ pdm pack -v
Packing packages...
STATUS: Resolving packages from lockfile...
All packages are synced to date, nothing to do.
  Installing the project as a package...
  ✔ Install test 0.1.0 successful
  🎉 All complete!
Traceback (most recent call last):
  File "/usr/local/bin/pdm", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pdm/core.py", line 351, in main
    return core.main(args or sys.argv[1:])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pdm/core.py", line 269, in main
    raise cast(Exception, err).with_traceback(traceback) from None
  File "/usr/local/lib/python3.12/site-packages/pdm/core.py", line 264, in main
    self.handle(project, options)
  File "/usr/local/lib/python3.12/site-packages/pdm/core.py", line 196, in handle
    command.handle(project, options)
  File "/home/vagrant/test/.pdm-plugins/lib/python3.12/site-packages/pdm_packer/command.py", line 114, in handle
    lib = pack_env.prepare_lib_for_pack(compile=options.compile)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vagrant/test/.pdm-plugins/lib/python3.12/site-packages/pdm_packer/env.py", line 73, in prepare_lib_for_pack
    synchronizer.synchronize()
  File "/usr/local/lib/python3.12/site-packages/pdm/installers/synchronizers.py", line 441, in synchronize
    self._fix_pth_files()
  File "/usr/local/lib/python3.12/site-packages/pdm/installers/synchronizers.py", line 333, in _fix_pth_files
    for path in list(Path(lib_paths[scheme]).iterdir()):
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/pathlib.py", line 1056, in iterdir
    for name in os.listdir(self):
                ^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pdm-pack-h9fyqbtr/lib64/python3.12/site-packages'

Just in case it is interesting...

$ uname -srm
Linux 6.8.0-40-generic x86_64
$ lsb_release -a
LSB Version:    n/a
Distributor ID: CentOS
Description:    CentOS Stream 9
Release:    9
Codename:   n/a

Running under Docker.