Skip to content

Use posix_prefix scheme to avoid 'local' in path#386

Closed
sloretz wants to merge 2 commits intorollingfrom
sloretz__sysconfig__scheme
Closed

Use posix_prefix scheme to avoid 'local' in path#386
sloretz wants to merge 2 commits intorollingfrom
sloretz__sysconfig__scheme

Conversation

@sloretz
Copy link
Copy Markdown
Contributor

@sloretz sloretz commented Apr 20, 2022

Follow up from #378
Matches colcon/colcon-core#504
Related to colcon/colcon-core#503

This uses the posix_prefix scheme to avoid a local/ in the python path.

This should be backported to Humble

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
@sloretz sloretz requested a review from cottsay April 20, 2022 17:25
@sloretz sloretz self-assigned this Apr 20, 2022
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
"import os"
"import sysconfig"
"print(os.path.relpath(sysconfig.get_path('purelib', vars={'base': '${CMAKE_INSTALL_PREFIX}'}), start='${CMAKE_INSTALL_PREFIX}').replace(os.sep, '/'))"
"print(os.path.relpath(sysconfig.get_path('purelib', vars={'base': '${CMAKE_INSTALL_PREFIX}'}, scheme='posix_prefix'), start='${CMAKE_INSTALL_PREFIX}').replace(os.sep, '/'))"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question; is "posix_prefix" the correct thing to do on Windows?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not. It does change the paths away from what distutils used to report.

>>> import sysconfig
>>> sysconfig.get_path('purelib', vars={'base': '.'})
'Lib\\site-packages'
>>> sysconfig.get_path('purelib', vars={'base': '.'}, scheme='posix_prefix')
'lib\\python3.10\\site-packages'
>>> from distutils.sysconfig import get_python_lib
>>> get_python_lib(prefix='.')
'.\\Lib\\site-packages'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could mirror the same logic as cpython to conditionally enforce the scheme using os.name:
https://github.com/python/cpython/blob/7cdaf87ec50f76c934ba651256484c4624b84ef2/Lib/sysconfig.py#L278-L295

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh - even better. scheme='posix_prefix' if sysconfig.get_default_scheme() == 'posix_local' else None.

That should only enforce the scheme if the debian hack is present.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drat - None doesn't work for scheme.
Maybe something like:
get_path_kwargs = {'scheme': 'posix_prefix'} if sysconfig.get_default_scheme() == 'posix_local' else {}
and then pass **get_path_kwargs to get_path?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe:
scheme={'posix_local': 'posix_prefix'}.get(sysconfig.get_default_scheme(), sysconfig.get_default_scheme())
or
scheme='posix_prefix' if sysconfig.get_default_scheme() == 'posix_local' else sysconfig.get_default_scheme()

@clalancette
Copy link
Copy Markdown
Contributor

clalancette commented Apr 20, 2022

For what it is worth, this (combined with colcon/colcon-core#504) does not seem to fix the problem for me reported in colcon/colcon-core#503 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants