I have a Python project (let's call it Project A) which contains a setup.py file as following:
from setuptools import setup
from setuptools import find_namespace_packages
from setuptools.command.develop import develop
from setuptools.command.install import install
def post_installation():
import nltk
nltk.download('punkt')
nltk.download('wordnet')
nltk.download('averaged_perceptron_tagger')
class PostDevelopCommand(develop):
"""Post-installation for development mode."""
def run(self):
develop.run(self)
post_installation()
class PostInstallCommand(install):
"""Post-installation for installation mode."""
def run(self):
install.run(self)
post_installation()
# Setup script
setup(
name='my-project-a',
version='1.2.3',
description='My project A',
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
packages=find_namespace_packages(exclude=['tests', 'tests.*']),
install_requires=list(open('requirements.txt')),
test_suite='tests',
cmdclass={
'develop': PostDevelopCommand,
'install': PostInstallCommand
}
)
And then, I used twine to deploy it to AWS Code Artifact in a GitHub action:
- name: "Publish to AWS CodeArtifact"
if: env.BUMPED == 'TRUE'
run: |
python3 setup.py sdist bdist_wheel
twine upload --repository codeartifact dist/*
And then, I added this project as a dependency to another project (Let's call it ProjectB) in requirements.txt. The problem is that, when I install all dependencies in requirements.txt at ProjectB, the Post installation from ProjectA is not being executed in ProjectB, which leads the code to crash, because NLTK modules were not installed.