2

I tried making one to post on my GitHub and help users download dependencies for the program, but in the end, all it does is generate duplicate files. I was hoping to have (in the end) a package where the user could enter:

>>> import my_package
>>> my_package.main

but that isn't working. I've looked at several different websites and different templates, but seem to be getting nowhere with this.


Directory structure

Kodimer_Project
    ├── LICENSE
    ├── MANIFEST.in
    ├── Makefile
    ├── README.md
    ├── requirements.txt
    ├── setup.py
    └── wav2bin
        ├── __version__.py
        ├── imgs
        │   ├── App_Icon.gif
        │   ├── App_Icon.ico
        │   └── __init__.py
        └── src
            ├── DrawGraph.py
            ├── GraphicInterface.py
            ├── SplashScreen.py
            ├── __init__.py
            ├── __main__.py
            └── helper_functions.py

setup.py

From: https://github.com/kennethreitz/setup.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Note: To use the 'upload' functionality of this file, you must:
#   $ pip install twine

import io
import os
import sys
from shutil import rmtree

from setuptools import find_packages, setup, Command

# Package meta-data.
NAME = 'wav2bin'
DESCRIPTION = 'GUI graphing tool used concurrently with lab.'
URL = 'https://github.com/jvanderen1/Kodimer_Project'
EMAIL = 'jvanderen1@gmail.com'
AUTHOR = 'Joshua Van Deren'

# What packages are required for this module to be executed?
REQUIRED = [
    'matplotlib',
    'numpy',
    'scipy'
]

# The rest you shouldn't have to touch too much :)
# ------------------------------------------------
# Except, perhaps the License and Trove Classifiers!
# If you do change the License, remember to change the Trove Classifier for that!

here = os.path.abspath(os.path.dirname(__file__))

# Import the README and use it as the long-description.
# Note: this will only work if 'README.md' is present in your MANIFEST.in file!
with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f:
    LONG_DESCRIPTION = '\n' + f.read()

# Load the package's __version__.py module as a dictionary.
about = {}
with open(os.path.join(here, NAME, '__version__.py')) as f:
    exec(f.read(), about)


class UploadCommand(Command):
    """Support setup.py upload."""

    description = 'Build and publish the package.'
    user_options = []

    @staticmethod
    def status(s):
        """Prints things in bold."""
        print('\033[1m{0}\033[0m'.format(s))

    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

    def run(self):
        try:
            self.status('Removing previous builds…')
            rmtree(os.path.join(here, 'dist'))
        except OSError:
            pass

        self.status('Building Source and Wheel (universal) distribution…')
        os.system('{0} setup.py sdist bdist_wheel --universal'.format(sys.executable))

        self.status('Uploading the package to PyPi via Twine…')
        os.system('twine upload dist/*')

        sys.exit()


# Where the magic happens:
setup(
    name=NAME,
    version=about['__version__'],
    description=DESCRIPTION,
    long_description=LONG_DESCRIPTION,
    author=AUTHOR,
    author_email=EMAIL,
    url=URL,
    package_dir={'': 'wav2bin'},
    packages=find_packages(exclude=('tests', 'docs')),
    # If your package is a single module, use this instead of 'packages':
    # py_modules=['mypackage'],

     entry_points={
         'gui_scripts': ['wav2bin = wav2bin.__main__:main'],
     },
    install_requires=REQUIRED,
    python_requires='>=3',
    include_package_data=True,
    license='MIT',
    classifiers=[
        # Trove classifiers
        # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 3 :: Only',
        'Natural Language :: English',
        'Topic :: Scientific/Engineering :: Human Machine Interfaces',
        'Topic :: Software Development :: User Interfaces'
    ],
    # $ setup.py publish support.
    cmdclass={
        'upload': UploadCommand,
    },
)

wav2bin/src/__main__.py

Snippet of code:

if __name__ == '__main__':
    main()
Josh
  • 2,232
  • 3
  • 15
  • 33

1 Answers1

1

After you have some experience with various packaging modules what you would usually do is decide how professional you want your packaging to be? Do you want to host it on pypi? Distribute it from github? Pass it along to friends?

That's how you pick your packaging method, but first you should probably get some experience with the existing packaging modules, the two most popular ones are:

  1. setuptools which is what I usually go with and to which I linked a good tutorial
  2. distutils an older api to distribute packages but it's still around and is also very good to know

If then you decide this is an overkill and you want a less professional approach you can always do it manually.

Either installation to the python package folder, which for pip usually means something like entering the packages root folder and entering either

pip install .

If you are certain of your package, or

pip install -e .

For installing in edit mode if you still wish to keep the package malleable

or having the package in your python path in some other manner before import is mandatory.

Veltzer Doron
  • 934
  • 2
  • 10
  • 31
  • I would like to distribute this from my GIthub, to showcase some of the projects I've worked on to potential companies. It should be 1) Easy to install 2) Easy to run – Josh Feb 11 '18 at 18:42
  • Unless you have good reason, if I were you I'd try setuptools – Veltzer Doron Feb 12 '18 at 09:12
  • Yes, that's what I was trying. However, it isn't quite working for me. When I type in "python3 -m wav2bin", it doesn't seem to recognize that command. – Josh Feb 12 '18 at 16:22
  • install pip and use it as your installer (and learn the virutalenv issue, its very well established) you're probably looking at some tutorial that is assuming anaconda3 is installed – Veltzer Doron Feb 14 '18 at 09:42