source.py 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. import os
  2. import subprocess
  3. from importlib.metadata import version
  4. import opendevin
  5. from opendevin.core.logger import opendevin_logger as logger
  6. def create_project_source_dist():
  7. """Create a source distribution of the project. Return the path to the tarball."""
  8. # Copy the project directory to the container
  9. # get the location of "opendevin" package
  10. project_root = os.path.dirname(os.path.dirname(os.path.abspath(opendevin.__file__)))
  11. logger.info(f'Using project root: {project_root}')
  12. # run "python -m build -s" on project_root
  13. result = subprocess.run(['python', '-m', 'build', '-s', project_root])
  14. if result.returncode != 0:
  15. logger.error(f'Build failed: {result}')
  16. raise Exception(f'Build failed: {result}')
  17. logger.info(f'Source distribution create result: {result}')
  18. tarball_path = os.path.join(
  19. project_root, 'dist', f'opendevin-{version("opendevin")}.tar.gz'
  20. )
  21. if not os.path.exists(tarball_path):
  22. logger.error(f'Source distribution not found at {tarball_path}')
  23. raise Exception(f'Source distribution not found at {tarball_path}')
  24. logger.info(f'Source distribution created at {tarball_path}')
  25. return tarball_path