Skip to content

Commit

Permalink
Working package example for hello2
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Livingston committed Jan 30, 2018
1 parent ca86bf6 commit 46eab74
Show file tree
Hide file tree
Showing 18 changed files with 292 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# general things to ignore
build/
dist/
*.egg-info/
*.egg
*.py[cod]
__pycache__/
*.so
*~

# due to using tox and pytest
.tox
.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# this file is *not* meant to cover or endorse the use of travis, but rather to
# help confirm pull requests to this project.

language: python

env:
- TOXENV=py27
- TOXENV=py33
- TOXENV=py34

install: pip install tox

script: tox

notifications:
email: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

# Like Hello world, but built with Pants. This time, with both C++ and Py sources

python_distribution(
name='sample'
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2016 The Python Packaging Authority (PyPA)

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Include the license file
include LICENSE.txt

# Include the data files
recursive-include data *
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
A sample Python project
=======================

A sample project that exists as an aid to the `Python Packaging User Guide
<https://packaging.python.org>`_'s `Tutorial on Packaging and Distributing
Projects <https://packaging.python.org/en/latest/distributing.html>`_.

This projects does not aim to cover best practices for Python project
development as a whole. For example, it does not provide guidance or tool
recommendations for version control, documentation, or testing.

----

This is the README file for the project.

The file should use UTF-8 encoding and be written using `reStructuredText
<http://docutils.sourceforge.net/rst.html>`_. It
will be used to generate the project webpage on PyPI and will be displayed as
the project homepage on common code-hosting services, and should be written for
that purpose.

Typical contents for this file would include an overview of the project, basic
usage examples, etc. Generally, including the project changelog in here is not
a good idea, although a simple "What's New" section for the most recent version
may be appropriate.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

#include <Python.h>

static PyObject * super_greet(PyObject *self, PyObject *args) {
return Py_BuildValue("s", "Super hello");
}

static PyMethodDef Methods[] = {
{"super_greet", super_greet, METH_VARARGS, "A super greeting"},
{NULL, NULL, 0, NULL}
};

PyMODINIT_FUNC initsuper_greet(void) {
(void) Py_InitModule("super_greet", Methods);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
some data
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import super_greet
def main():
"""Entry point for the application script"""
print("Call your main application code here")

def ext():
print(super_greet.super_greet())
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import super_greet

def lol():
print(super_greet.super_greet())
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
some data
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[bdist_wheel]
# This flag says that the code is written to work on both Python 2 and Python
# 3. If at all possible, it is good practice to do this. If you cannot, you
# will need to generate wheels for each Python version that you support.
universal=1
115 changes: 115 additions & 0 deletions examples/src/python/example/python_distribution/hello/hello2/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
"""A setuptools based setup module.
See:
https://packaging.python.org/en/latest/distributing.html
https://github.com/pypa/sampleproject
"""

# Always prefer setuptools over distutils
from setuptools import setup, find_packages
# To use a consistent encoding
from codecs import open
from os import path
from distutils.core import Extension
here = path.abspath(path.dirname(__file__))

# Get the long description from the README file
with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
long_description = f.read()

c_module = Extension(str('super_greet'), sources=[str('c/super_greet.c')])

setup(
name='sample',

# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='1.2.0',
ext_modules=[c_module],
description='A sample Python project',
long_description=long_description,

# The project's main homepage.
url='https://github.com/pypa/sampleproject',

# Author details
author='The Python Packaging Authority',
author_email='pypa-dev@googlegroups.com',

# Choose your license
license='MIT',

# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
# How mature is this project? Common values are
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
'Development Status :: 3 - Alpha',

# Indicate who your project is intended for
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',

# Pick your license as you wish (should match "license" above)
'License :: OSI Approved :: MIT License',

# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
],

# What does your project relate to?
keywords='sample setuptools development',

# You can just specify the packages manually here if your project is
# simple. Or you can use find_packages().
packages=find_packages(exclude=['contrib', 'docs', 'tests']),

# Alternatively, if you want to distribute just a my_module.py, uncomment
# this:
# py_modules=["my_module"],

# List run-time dependencies here. These will be installed by pip when
# your project is installed. For an analysis of "install_requires" vs pip's
# requirements files see:
# https://packaging.python.org/en/latest/requirements.html
#install_requires=['peppercorn'],

# List additional groups of dependencies here (e.g. development
# dependencies). You can install these using the following syntax,
# for example:
# $ pip install -e .[dev,test]
extras_require={
'dev': ['check-manifest'],
'test': ['coverage'],
},

# If there are data files included in your packages that need to be
# installed, specify them here. If using Python 2.6 or less, then these
# have to be included in MANIFEST.in as well.
package_data={
'sample': ['package_data.dat'],
},

# Although 'package_data' is the preferred approach, in some case you may
# need to place data files outside of your packages. See:
# http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files # noqa
# In this case, 'data_file' will be installed into '<sys.prefix>/my_data'
data_files=[('my_data', ['data/data_file'])],

# To provide executable scripts, use entry points in preference to the
# "scripts" keyword. Entry points provide cross-platform support and allow
# pip to create the appropriate form of executable for the target platform.
entry_points={
'console_scripts': [
'sample=sample:main',
],
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# the inclusion of the tests module is not meant to offer best practices for
# testing in general, but rather to support the `find_packages` example in
# setup.py that excludes installing the "tests" package
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# the inclusion of the tests module is not meant to offer best practices for
# testing in general, but rather to support the `find_packages` example in
# setup.py that excludes installing the "tests" package


def test_success():
assert True
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# this file is *not* meant to cover or endorse the use of tox or pytest or
# testing in general,
#
# It's meant to show the use of:
#
# - check-manifest
# confirm items checked into vcs are in your sdist
# - python setup.py check (using the readme_renderer extension)
# confirms your long_description will render correctly on pypi
#
# and also to help confirm pull requests to this project.

[tox]
envlist = py{27,33,34}

[testenv]
basepython =
py27: python2.7
py33: python3.3
py34: python3.4
deps =
check-manifest
readme_renderer
flake8
pytest
commands =
check-manifest --ignore tox.ini,tests*
python setup.py check -m -r -s
flake8 .
py.test tests
[flake8]
exclude = .tox,*.egg,build,data
select = E,W,F
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

#include <Python.h>

static PyObject * super_greet(PyObject *self, PyObject *args) {
return Py_BuildValue("s", "Super hello");
}

static PyMethodDef Methods[] = {
{"super_greet", super_greet, METH_VARARGS, "A super greeting"},
{NULL, NULL, 0, NULL}
};

PyMODINIT_FUNC initsuper_greet(void) {
(void) Py_InitModule("super_greet", Methods);
}

This file was deleted.

0 comments on commit 46eab74

Please sign in to comment.