Is there a way to run 2to3 with pip installed?

I am trying to maintain dependencies with pip install -r requirements.txt

. However, some of the required packages do not support Python 3 directly, but can be manually converted using 2to3

.

Is there a way to force these packages to pip

run 2to3

automatically on execution pip install -r requirements.txt

?

+3


source to share


1 answer


No, it must be part of the package customization configuration. See Supporting both Python 2 and 3 using the mailing list .

You add metadata to your package installer:

setup(
    name='your.module',
    version = '1.0',
    description='This is your awesome module',
    author='You',
    author_email='your@email',
    package_dir = {'': 'src'},
    packages = ['your', 'your.module'],
    test_suite = 'your.module.tests',
    use_2to3 = True,
    convert_2to3_doctests = ['src/your/module/README.txt'],
    use_2to3_fixers = ['your.fixers'],
    use_2to3_exclude_fixers = ['lib2to3.fixes.fix_import'],
)

      

Such a package will automatically run 2to3

when installed on a Python 3 system.



2to3

is a tool, not a magic bullet, you cannot apply it to an arbitrary batch of pip

downloads from PyPI. The package must support it the way it is coded. Thus, launching automatically from pip

will not work; responsibility lies with the maintainer of the package.

Note that just because it 2to3

succeeds in a package does not necessarily mean that the package will work in Python 3. Bytes and unicode assumptions usually arise when the package is actually run.

Refer to the maintainers for the packages you are interested in and ask what the status for that package is for Python 3. Patching patches to them usually helps. If such requests and suggestions for help fall into deaf ears, for open source packages you can always fork them and make the necessary changes yourself.

+6


source







All Articles