Skip to content

Instantly share code, notes, and snippets.

@rochacbruno
Last active June 22, 2022 23:35
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save rochacbruno/90efe90e6549721e4189 to your computer and use it in GitHub Desktop.
Save rochacbruno/90efe90e6549721e4189 to your computer and use it in GitHub Desktop.
Python Setup Tips and Tricks http://j.mp/setup_py

setup.cfg

Wheels

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.

.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 {} \;
[bdist_wheel]
universal = 1
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',
]
)
@jsbueno
Copy link

jsbueno commented Dec 1, 2015

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"]

@luzfcb
Copy link

luzfcb commented Dec 1, 2015

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

@kinow
Copy link

kinow commented Jul 15, 2020

Ó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)

@kinow
Copy link

kinow commented Jul 15, 2020

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