0

I want to include an MD5 hash of my source code whenever I install my module. To do this I put the hash at the end of the description field for setuptools.setup:

import subprocess
cmd="/sbin/md5 mymodule/*.py | md5 "
p=subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
hash=p.stdout.read().strip().decode()
print(hash)

from setuptools import setup

setup(name='mymodule',
      version='0.1',
      packages=['mymodule', ],
      description = "My awesome Module. \nsourcehash="+hash+"\n",

  )

Then in my __init__.py, I include:

import os.path
with open(os.path.split(__file__)[0]+'/../EGG-INFO/PKG-INFO', 'r') as f:
    pkg_info=f.read()
__sourcehash__ = pkg_info.split('sourcehash=')[1][:32]

This works, but it feels hacky. Is there a better way to do this? Thanks!

nick maxwell
  • 1,371
  • 2
  • 13
  • 22

0 Answers0