2014-04-19 12 views
5

मैंने पीई 2.7 में एक पैकेज बनाया है और मैं इसे पी 3 के साथ संगत बनाने की कोशिश कर रहा हूं। समस्या यह है कि अगर मैंsetup.py पैकेज और यूनिकोड_लिटर

__init__.py 

में unicode_literals शामिल निर्माण रिटर्न इस त्रुटि

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

मैं पीईपी पढ़ा है आयात करता है, लेकिन मैं नहीं समझ सकता है कि यह एक साथ क्या करना है क्या

__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'] 
) 

धन्यवाद,

जेएम

उत्तर

5

unicode_literals का उपयोग कर प्रत्येक स्ट्रिंग अपने इनपुट फ़ाइल, में शाब्दिक के लिए u'...' का उपयोग कर के रूप में ही है, जिसका अर्थ है अपने __init__.py में निर्दिष्ट है कि

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

है वास्तव में

के समान

python2 के लिए, setuptools unicode की अपेक्षा नहीं करता है लेकिन str, इसलिए यह विफल हो जाता है।

जैसा कि ऐसा लगता है कि आप अपने स्ट्रिंग अक्षर में __init__.py में किसी भी यूनिकोड वर्णों का उपयोग नहीं करते हैं, बस सादा एसीआईआई, तो आप बस unicode_literals आयात को हटा सकते हैं। यदि आप वास्तव में फ़ाइल में किसी भी स्थान पर यूनिकोड अक्षर का उपयोग करते हैं जो आपकी पोस्ट में नहीं दिखाया गया है, वहां स्पष्ट यूनिकोड अक्षर का उपयोग करें।

3

यह सेटअपtools में एक बग है। यह isinstance(k, str) के साथ मान मान्य कर रहा है जो स्ट्रिंग को 0xआयात द्वारा 2.x unicode कक्षा में परिवर्तित करने में विफल रहता है। इसे isinstance(k, basestring) का उपयोग करने के लिए पैच किया जाना चाहिए।

सबसे आसान समाधान कॉन्फ़िगरेशन सेटिंग्स को सीधे में __init__.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 के उपयोग 3 कोड अजगर को अजगर 2 अनुकूलता लाने के लिए जहां str अब बनाम अजगर 2 में बाइट-तार यूनिकोड-तार यह महान है है बाइट-स्ट्रिंग्स और यूनिकोड-स्ट्रिंग्स के मिश्रण को रोकें, पीई 2 पर लंबे समय की समस्या, हालांकि इस समस्या की तरह कुछ 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']} 
संबंधित मुद्दे