3

In my Node.JS projects, I save my project metadata into package.json: dependencies, version number, author, description, and so on. This makes it so anyone can clone my project and run npm install to create a virtually identical local environment.

Is there a such thing for Python? Some sort of standard file where I can save project metadata, including a version number and PIP dependencies?

sffc
  • 133
  • 5
  • Possibly [Python eggs](http://peak.telecommunity.com/DevCenter/PythonEggs) is what you are looking for. This is the standard format for Python code distribution. – 9000 Jan 22 '15 at 05:20
  • 1
    There's a good guide to getting an open-source Python project set up here: http://www.jeffknupp.com/blog/2013/08/16/open-sourcing-a-python-project-the-right-way/ – jonrsharpe Jan 22 '15 at 10:26

1 Answers1

2

Python setuptools is a module that you use to write a script, called setup.py in the main directory of your Python project. For distribution purposes, you can use your setup.py to make a Python egg. 9000's link goes into more detail about how to make the egg.

The first link contains detailed documentation on how to write the perfect setup.py, but below is a complete example modified for a Python project I wrote some time ago.

from setuptools import setup

def readme():
    """
    This is a function I wrote to read my README file and return it.
    """
    with open('README.rst') as f:
        return f.read()

setup(name='stackexample',
      version='0.1',
      description='An answer to a question on StackOverflow',
      long_description=readme(), # Get that README.rst
      classifiers=[
          'Development Status :: 3 - Alpha',
          'License :: OSI Approved :: MIT License',
          'Programming Language :: Python :: 3.0'
      ],
      keywords='questions answers programming',
      url='http://stackexchange.com/',
      author_email='bob@example.com',
      license='MIT',
      entry_points = {
          'console_scripts' :
          ['stackex=stackexample.command_line:main']
      },
      packages=['stackexample'],
      install_requires=[
          "requests",
          "something_on_pip",
      ],
      test_suite='nose.collector',
      test_requires=['nose', 'nose-cover3'], # Requirements for the test suite
      include_package_data=True,
      zip_safe=False)

You can also use a requirements.txt file to list dependencies. This blog post goes into pretty good detail about the difference between requirements.txt and setup.py.

James Mishra
  • 1,499
  • 1
  • 12
  • 16