Adding “–version” parameter to “python3 setup.py”

Adding “–version” parameter to “python3 setup.py”

When building Python packages using setuptools, you typically manually set the upcoming package version in setup.py. For my use case, I found it better to provide the version number on the command line such as this:

python3 setup.py sdist bdist_wheel --version=1.0.0

setuptools isn’t very fond of command line parameters, so I made a quick-n-dirty hack to work around this limitation:

#!/usr/bin/env python
import sys

from setuptools import setup, find_packages

# Quick 'n dirty workaround for being able to provide "--version=1" on the command line when building the app
number_of_arguments = len(sys.argv)
version_parameter = sys.argv[-1]
version = version_parameter.split("=")[1]
sys.argv = sys.argv[0:number_of_arguments-1]

with open('requirements.txt') as f:
    requirements = f.read().splitlines()

setup(name='my-app',
      version=version,
      description='Test',
      author='John Doe',
      author_email='john@doe',
      packages=find_packages(),
      install_requires=requirements,
      data_files=[('.',['requirements.txt'])]
      })

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this:
Secured By miniOrange