2014-11-04 4 views
24

작동하지 않습니다PyPi 설명 인하가 내가 사용 PyPi에 패키지를 업로드

python setup.py register -r pypi 
python setup.py sdist upload -r pypi 

내가 decsription을 수정하기 위해 노력하고있어, 나는 다음과 같은 코드 조각의 서식을 편집하지 마십시오 (썼다 내가) 내 문제를 설명하는 목적에서 만들어 : 그대로

**nose-docstring-plugin** 

This plugin enables you to modify docstring of tests based on their attributes, for example: 
```python 
@attr(section='MySection', type='functional+', module='MyModule', id=1) 
def test_function(self): 
    """ 
    This is the original docstring 
    """ 
    pass 
``` 

그러나, 텍스트가 나타납니다 Markdown을 형식없이. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

답변

13

PyPI는 이 아니며은 Markdown을 지원하므로 README는 HTML로 렌더링되지 않습니다.

렌더링 된 README를 원하면 reStructuredText를 사용하십시오. Sphinx introduction to reStructuredText은 좋은 출발점입니다.

docutils package을 설치하여 문서를 로컬에서 테스트 할 수 있습니다. README에 포함 된 rst2html.py 스크립트를 실행하여 어떤 오류가 발생했는지 확인하십시오. 특정 샘플의 오류가 너무 많습니다.

$ bin/rst2html.py test.rst > /tmp/test.html 
test.rst:7: (ERROR/3) Unexpected indentation. 
test.rst:3: (WARNING/2) Inline literal start-string without end-string. 
test.rst:3: (WARNING/2) Inline interpreted text or phrase reference start-string without end-string. 
test.rst:11: (WARNING/2) Block quote ends without a blank line; unexpected unindent. 
test.rst:11: (WARNING/2) Inline literal start-string without end-string. 
test.rst:11: (WARNING/2) Inline interpreted text or phrase reference start-string without end-string. 

코드 블록이 Github의 Markdown 확장 프로그램을 사용하고 있는데, 이는 reStructuredText에서 완전히 잘못되었습니다. (docutils의 PyPI 버전은 충분히 새로운 경우 아마도) 당신은 나머지 코드 블록을 사용할 수

.. code-block:: python 

    @attr(section='MySection', type='functional+', module='MyModule', id=1) 
    def test_function(self): 
     """ 
     This is the original docstring 
     """ 
     pass 

당신이뿐만 아니라 Pygments을 설치해야합니다 로컬이를 테스트합니다.

관심이 있으시면 Markdown에 대한 지원을 추가 하시려면 feature request with pull request이 있습니다.

+0

[this] (http://docutils.sourceforge.net/docs/user/rst/cheatsheet.txt)에 따르면,'** strong emphasis **'라고 써야하는데,'reStructuredText '? – Maroun

+2

Markdown 지원이 커밋 된 다음 보안 문제로 인해 롤백되었습니다. 이것은 두 번째 시도입니다. https://bitbucket.org/pypa/pypi/pull-request/59 – bukzor

+0

[restview] (https://pypi.python.org/pypi/restview)를보고 싶을 수도 있습니다.),'README.rst' 또는'long_description'을'setup.py' (거의)에서 미리 볼 수있게 해줍니다. –

52

@Martijn Pieters으로 명시된 바와 같이 PyPi은 Markdown을 지원하지 않습니다. 다음 트릭을 어디에서 배웠는지 모르겠지만, PyPi에 업로드하기 전에 PandocPyPandoc을 사용하여 Markdown 파일을 RestructuredText로 변환 할 수 있습니다. 이를 위해, 당신의 setup.py 파일에 다음을 추가

try: 
    import pypandoc 
    long_description = pypandoc.convert('README.md', 'rst') 
except(IOError, ImportError): 
    long_description = open('README.md').read() 

setup(
    name='blah', 
    version=find_version('blah.py'), 
    description='Short description', 
    long_description=long_description, 
) 

은 OS X에 Pandoc를 설치하려면, 내가 Homebrew을 사용 :

pip install pypandoc 
:

brew install pandoc 

PyPandoc를 설치하려면, 나는 pip 사용

+0

정말 고마워. – Maroun

+2

사이드 질문 : 왜 IOError를 잡을까요? 이 경우 ImportError만이 유일한 예외는 아닌가? –

+0

@NickChammas, 내가 틀릴 수도 있지만 ImportError는 pypandoc을 가져올 수 없거나 IOError가 'README.md'를 열 수 없거나 README.rst를 열 수없는 경우를 잡을 수 있습니다. 적어 라. – mre

4

\r 문자로 문제가 발생하여 구문 분석 문제가 발생합니다. e README가 pypi에 나타납니다. 아래의 코드는 그것이 pypandoc 모듈 저장소에서 오는 문제를 해결

try: 
    long_description = pypandoc.convert('README.md', 'rst') 
    long_description = long_description.replace("\r","") # Do not forget this line 
except OSError: 
    print("Pandoc not found. Long_description conversion failure.") 
    import io 
    # pandoc is not installed, fallback to using raw contents 
    with io.open('README.md', encoding="utf-8") as f: 
     long_description = f.read() 

이 방법 long_description은 추가 정보의 소각 버전을 포함 당신은 당신의 setup.py 스크립트에서 설정() 함수에 전달할 수 있습니다.

+0

잠시 후에 시도하지 않았습니다. 작동하지 않는다면보고 해주십시오. – Overdrivr

+0

감사합니다. 문제 해결에 몇 시간을 보냈습니다. ... 단지'open' 대신'io.open'을 쓰는 이유는 무엇입니까? –

+0

'convert_text'가'format = md' 인수를 필요로하고'convert_file'이 인수를 필요로하지 않기 때문에 Downvote가되었을 수 있습니다. 나는'convert'가 사용하는 메커니즘이 무엇인지 모르겠습니다. 어쩌면 특정한 상황에서도 논쟁이 필요할지도 모른다. c.f. https://github.com/bebraw/pypandoc/blob/master/README.md#usage –

14

다른 답변에서 언급 한 것처럼 PyPI는 첫 번째를 지원하며 마크 다운을 지원하지 않습니다. 하지만 pypandoc perse이 필요하지 않습니다. 단지 pandoc이 좋습니다. 먼저 로컬에서 첫 번째 파일을 생성 한 다음 설치 프로그램을 실행할 수 있습니다.py를 사용하여 패키지를 업로드하십시오.

upload.sh

: README라는 이름의 생성 된 파일을 자동으로 인식됩니다

#!/bin/bash 
pandoc --from=markdown --to=rst --output=README README.md 
python setup.py sdist upload 

. .gitignore에 반드시 추가하십시오! setup.py은 특별한 작업을 수행 할 필요가 없습니다.

setup.py

는 :
from distutils.core import setup 

setup(
    name='mypackage', 
    packages=['mypackage'], # this must be the same as the name above 
    version='0.2.8', 
    description='short', 
    author='Chiel ten Brinke', 
    author_email='<email>', 
    url='<github url>', # use the URL to the github repo 
    keywords=[], # arbitrary keywords 
    classifiers=[], 
) 

은 그럼 그냥 PyPI에 물건을 업로드 bash upload.sh를 실행합니다.

+2

제 경우에는 README 파일이 자동으로 long_description으로 인식되지 않았습니다. 하나는 setup.py에 long_description 필드를 추가해야합니다. 그렇지 않으면 README 파일이 pypi에 렌더링되지 않습니다. – asmaier

3

지금 내 설정에 그것을 사용하고

https://pypi.python.org/pypi/restructuredtext_lint/

나를 위해 일한 좋은 PIP 패키지가있다 : 나는을 만든

https://github.com/pablodav/burp_server_reports/blob/master/setup.py 또한

def check_readme(file='README.rst'): 
""" 
Checks readme rst file, to ensure it will upload to pypi and be formatted correctly. 
:param file: 
:return: 
""" 
errors = rst_lint.lint_file(file) 
if errors: 
    msg = 'There are errors in {}, errors \n {}'.format(file, errors[0].message) 
    raise SystemExit(msg) 
else: 
    msg = 'No errors in {}'.format(file) 
print(msg) 

은 나중에 py.test에서 사용할 수있는 lib

https://github.com/pablodav/burp_server_reports/blob/master/burp_reports/lib/check_readme.py 
+0

공유 덕분에 꽤 좋습니다. – Overdrivr