Warning: If your project has optional C extensions, it is recommended not to publish a universal wheel, because pip will prefer the wheel over a source installation.
Last active
June 22, 2022 23:35
-
-
Save rochacbruno/90efe90e6549721e4189 to your computer and use it in GitHub Desktop.
Python Setup Tips and Tricks http://j.mp/setup_py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: test install pep8 release clean | |
test: pep8 | |
py.test --cov -l --tb=short --maxfail=1 program/ | |
install: | |
python setup.py develop | |
pep8: | |
@flake8 program --ignore=F403 --exclude=junk | |
release: test | |
@python setup.py sdist bdist_wheel upload | |
clean: | |
@find ./ -name '*.pyc' -exec rm -f {} \; | |
@find ./ -name 'Thumbs.db' -exec rm -f {} \; | |
@find ./ -name '*~' -exec rm -f {} \; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[bdist_wheel] | |
universal = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pip | |
try: | |
from setuptools import setup, find_packages | |
except ImportError: | |
from distutils.core import setup, find_packages | |
try: | |
import pypandoc | |
long_description = pypandoc.convert('README.md', 'rst') | |
except (IOError, ImportError): | |
long_description = "Python rulez" | |
links = [] # for repo urls (dependency_links) | |
requires = [] # for package names | |
try: | |
requirements = pip.req.parse_requirements('requirements.txt') | |
except: | |
# new versions of pip requires a session | |
requirements = pip.req.parse_requirements( | |
'requirements.txt', session=pip.download.PipSession() | |
) | |
for item in requirements: | |
if getattr(item, 'url', None): # older pip has url | |
links.append(str(item.url)) | |
if getattr(item, 'link', None): # newer pip has link | |
links.append(str(item.link)) | |
if item.req: | |
requires.append(str(item.req)) # always the package name | |
setup( | |
name='My Program', | |
version="0.0.1", | |
url='https://github.com/myname/myprogram', | |
license='MIT', | |
author="Super Man", | |
author_email="me@world.com", | |
description='Awesome project', | |
long_description=long_description, | |
packages=find_packages(), | |
include_package_data=True, | |
zip_safe=False, | |
platforms='any', | |
install_requires=requires, | |
dependency_links=links, | |
entry_points={ | |
"console_scripts": [ | |
"program = program.module:main" | |
] | |
}, | |
classifiers=[ | |
'Development Status :: 4 - Beta', | |
'Intended Audience :: Developers', | |
'Operating System :: POSIX', | |
'Operating System :: POSIX :: Linux', | |
'License :: OSI Approved :: MIT License', | |
'Programming Language :: Python :: 2', | |
'Programming Language :: Python :: 2.7', | |
'Programming Language :: Python :: 3', | |
'Programming Language :: Python :: 3.3', | |
'Programming Language :: Python :: 3.4', | |
] | |
) |
o setuptools (distutils aparentemente não implementa isso) possui a opção extras_require
a qual suporta "dependências condicionais" (eu não achei uma descrição melhor)
https://github.com/audreyr/cookiecutter/blob/master/setup.py#L65-L72
Ótimo gist! Usando em um projeto uma versão similar (tive que inverter o requirements loading; parece que requirements sem session funciona, mas quando você tenta iterar pelos elementos, ele lança uma exceção TypeError)
Po, na verdade acabei de reverter e usar o exemplo do JupyterHub. Parece que pip
em Python 3.8 não tem mais o pip.req
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Imprima estrelinhas enquanto instala - aqui sorteie uns 2000 caracteres desta lista: [".", "\u22c5", "\u00b7", "\u2022", "\u2219", "\u2024", "\u2027", "\u205b", ":", "\u2056", "\u205a", "\u205d", "\u2058", "\u2059", "\u2025", "\u2026", "*", "\u2042", "\u204e", "\u2051", "\u205e", "\u1fed", "\u1fee", "\u1fcd", "\u1fce", "\u2218", "\u2217", "\u2234", "\u2235", "\u2236", "\u2237", "\u22c6", "\u22c7", "\u22c4", "\u22ee", "\u22ef", "\u22f0", "\u22f1", "\u2316"]