2014-04-19 2 views
5

Py2.7에서 패키지를 만들었으며 Py3과 호환되도록하려고합니다. 문제는 내가setup.py packages and unicode_literals

__init__.py 

에 unicode_literals을 포함 할 경우 빌드 반환을

error in daysgrounded setup command: package_data must be a dictionary mapping 
package names to lists of wildcard patterns 

내가 PEP를 읽은이 오류를 가져 오는 것입니다,하지만 난 그것과 관련이있다 이해할 수 없습니다 dict like

__pkgdata__ 

아무도 도와 줄 수 있습니까?

__init__.py 
#!/usr/bin/env python 
# -*- coding: latin-1 -*- 

"""Manage child(s) grounded days.""" 

from __future__ import (absolute_import, division, print_function, 
         unicode_literals) 
# ToDo: correct why the above unicode_literals import prevents setup.py from working 

import sys 
from os import path 
sys.path.insert(1, path.dirname(__file__)) 

__all__ = ['__title__', '__version__', 
      '__desc__', '__license__', '__url__', 
      '__author__', '__email__', 
      '__copyright__', 
      '__keywords__', '__classifiers__', 
      #'__packages__', 
      '__entrypoints__', '__pkgdata__'] 

__title__ = 'daysgrounded' 
__version__ = '0.0.9' 

__desc__ = __doc__.strip() 
__license__ = 'GNU General Public License v2 or later (GPLv2+)' 
__url__ = 'https://github.com/jcrmatos/DaysGrounded' 

__author__ = 'Joao Matos' 
__email__ = '[email protected]' 

__copyright__ = 'Copyright 2014 Joao Matos' 

__keywords__ = 'days grounded' 
__classifiers__ = [# Use below to prevent any unwanted publishing 
        #'Private :: Do Not Upload' 
        'Development Status :: 4 - Beta', 
        'Environment :: Console', 
        'Environment :: Win32 (MS Windows)', 
        'Intended Audience :: End Users/Desktop', 
        'Intended Audience :: Developers', 
        'Natural Language :: English', 
        'Natural Language :: Portuguese', 
        'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)', 
        'Operating System :: OS Independent', 
        'Programming Language :: Python', 
        'Programming Language :: Python :: 2.7', 
        'Programming Language :: Python :: 3.4', 
        'Topic :: Other/Nonlisted Topic'] 

#__packages__ = ['daysgrounded'] 

__entrypoints__ = { 
    'console_scripts': ['daysgrounded = daysgrounded.__main__:main'], 
    #'gui_scripts': ['app_gui = daysgrounded.daysgrounded:start'] 
    } 

__pkgdata__ = {'daysgrounded': ['*.txt']} 
#__pkgdata__= {'': ['*.txt'], 'daysgrounded': ['*.txt']} 


setup.py 
#!/usr/bin/env python 
# -*- coding: latin-1 -*- 

from __future__ import (absolute_import, division, print_function, 
         unicode_literals) 

from setuptools import setup, find_packages 
#import py2exe 

#from daysgrounded import * 
from daysgrounded import (__title__, __version__, 
          __desc__, __license__, __url__, 
          __author__, __email__, 
          __keywords__, __classifiers__, 
          #__packages__, 
          __entrypoints__, __pkgdata__) 

setup(
    name=__title__, 
    version=__version__, 

    description=__desc__, 
    long_description=open('README.txt').read(), 
    #long_description=(read('README.txt') + '\n\n' + 
    #     read('CHANGES.txt') + '\n\n' + 
    #     read('AUTHORS.txt')), 
    license=__license__, 
    url=__url__, 

    author=__author__, 
    author_email=__email__, 

    keywords=__keywords__, 
    classifiers=__classifiers__, 

    packages=find_packages(exclude=['tests*']), 
    #packages=__packages__, 

    entry_points=__entrypoints__, 
    install_requires=open('requirements.txt').read(), 
    #install_requires=open('requirements.txt').read().splitlines(), 

    include_package_data=True, 
    package_data=__pkgdata__, 

    #console=['daysgrounded\\__main__.py'] 
) 

감사합니다,

JM unicode_literals를 사용

답변

5

__init__.py

__pkgdata__ = {'daysgrounded': ['*.txt']} 

가 지정하는 것을 의미하여 입력 파일에서 문자 그대로 각각의 문자열을 u'...'을 사용하는 것과 같습니다 실제로는 동일

__pkgdata__ = {u'daysgrounded': [u'*.txt']} 

(python2)의 경우 setuptools는 unicode을 여기에 넣지 만 str을 기대하지 않으므로 실패합니다.

어쨌든 __init__.py의 문자열 리터럴에 유니 코드 문자를 사용하지 않는 것처럼 보입니다. 따라서 단순한 ASCII 문자이므로 unicode_literals 가져 오기를 제거하면됩니다. 게시물에 표시되지 않은 파일의 일부 위치에서 유니 코드 리터럴을 실제로 사용하는 경우 명시 적 유니 코드 리터럴을 사용하십시오.

3

이것은 setuptools의 버그입니다. 문자열이 unicode_literals 가져 오기로 2.x unicode 클래스로 변환 될 때 오류가 발생하는 isinstance(k, str) 값을 확인합니다. isinstance(k, basestring)을 사용하려면 패치해야합니다.

가장 쉬운 해결책은 구성 설정을 __init__.py에 저장하는 대신 setup.py에 직접 넣는 것입니다. __version__에 프로그래밍 방식으로 액세스해야하는 경우 setup.py__init__.py에 포함 된 별도의 패키지에 넣으십시오. setuptools에에서

는 dist.py :

def check_package_data(dist, attr, value): 
    """Verify that value is a dictionary of package names to glob lists""" 
    if isinstance(value,dict): 
     for k,v in value.items(): 
      if not isinstance(k,str): break 
      try: iter(v) 
      except TypeError: 
       break 
     else: 
     return 
    raise DistutilsSetupError(
     attr+" must be a dictionary mapping package names to lists of " 
     "wildcard patterns" 
    ) 
+0

"이것은 setuptools에 버그입니다" 버그보고가 있는지 여부를 알고 있습니까? –

0
unicode_literals의 사용은 str 지금 그것은에서 대단한 파이썬 2의 바이트 문자열 대 유니 코드 문자열입니다 파이썬 3 코드를 파이썬이 호환성을 가지고있다

바이트 문자열과 유니 코드 문자열의 혼합을 방지하고, Py2에서 오랜 시간 문제가 있지만,이 문제와 같은 몇 가지가 있습니다 (pitfalls).

Kevin

버그를 설명하고 나는 setup.py 것은 엄격하게 필요하지 않으며 당신이 package_data에 대한 항목의 수가 많은 경우 특히 조금 못생긴 해결하기 위해 말할 것입니다 것입니다.


unicode_literals을 설정하려는 경우.

if sys.version_info.major == 2: 
    __pkgdata__ = {b'daysgrounded': ['*.txt']} 
else: 
    __pkgdata__ = {'daysgrounded': ['*.txt']} 

: 그래서 두 버전을 모두 포함 할 필요가

__pkgdata__ = {b'daysgrounded': ['*.txt']} 

그러나 파이썬 3에서이 같은 메시지와 함께 실패합니다 : PY 만 바이트 문자열로 dict 키를 인코딩해야합니다 또한 future 모듈에서 bytes_to_native_str를 사용

from future.utils import bytes_to_native_str 

__pkgdata__ = {bytes_to_native_str(b'daysgrounded'): ['*.txt']}