Skip to content

Commit

Permalink
Clean ad/ stub files and SOURCES for non-rss builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Daraan committed Sep 6, 2024
1 parent 9e8821d commit 39e17e9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
44 changes: 40 additions & 4 deletions PythonAPI/carla/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
# This work is licensed under the terms of the MIT license.
# For a copy, see <https://opensource.org/licenses/MIT>.

import shutil
from setuptools import setup, Extension

import fnmatch
import os
import sys

from distutils.command.install_lib import install_lib

def is_rss_variant_enabled():
if 'BUILD_RSS_VARIANT' in os.environ and os.environ['BUILD_RSS_VARIANT'] == 'true':
return True
Expand Down Expand Up @@ -135,8 +138,8 @@ def walk(folder, file_filter='*'):
else:
raise NotImplementedError

depends = [x for x in walk('source/libcarla')]
depends += [x for x in walk('dependencies')]
depends = list(walk('source/libcarla'))
depends += list(walk('dependencies'))

def make_extension(name, sources):

Expand All @@ -163,11 +166,42 @@ def get_license():
with open("README.md") as f:
long_description = f.read()

class CleanADStubFiles(install_lib):
"""
Removes the ad/ files from the build directory in a normal built
that else would be copies over.
"""

CARLA_RSS_STUB_FILE = "__carla_rss.pyi"
_CARLA_RSS_STUB_FILE_PATH = os.path.join("carla", CARLA_RSS_STUB_FILE)
CARLA_AD_STUB_DIR = os.path.join("carla", "ad")

def run(self):
if not is_rss_variant_enabled():
self.prune_rss()
super().run()

def prune_rss(self):
"""Removes files from an rss build that we do not want to be copied over to a non-rss build."""
if not self.build_dir:
return
print("Cleaning possible RSS files from previous build.")
shutil.rmtree(os.path.join(self.build_dir, self.CARLA_AD_STUB_DIR), ignore_errors=True)
try:
os.remove(os.path.join(self.build_dir, self._CARLA_RSS_STUB_FILE_PATH))
except FileNotFoundError:
pass
return

setup(
name='carla',
version='0.9.15',
package_dir={'': 'source'},
packages=['carla'] if not is_rss_variant_enabled() else ['carla', 'carla.ad', 'carla.ad.map', 'carla.ad.rss'],
# Avoid "Package would be ignored" warning for non-rss build if using ['carla'] here
packages=['carla', 'carla.ad', 'carla.ad.rss', 'carla.ad.map'] if is_rss_variant_enabled() else ['carla'],
# For non-rss build do a fine grained include/exclude on the package data.
package_data={'carla' : [""]},
exclude_package_data={} if is_rss_variant_enabled() else {'carla':[CleanADStubFiles.CARLA_RSS_STUB_FILE]},
ext_modules=get_libcarla_extensions(),
license=get_license(),
description='Python API for communicating with the CARLA server.',
Expand All @@ -176,4 +210,6 @@ def get_license():
url='https://github.com/carla-simulator/carla',
author='The CARLA team',
author_email='[email protected]',
include_package_data=True)
include_package_data=True,
cmdclass={'install_lib': CleanADStubFiles},
)
2 changes: 2 additions & 0 deletions Util/BuildTools/BuildPythonAPI.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ if ${BUILD_PYTHONAPI} ; then

for PY_VERSION in ${PY_VERSION_LIST[@]} ; do
log "Building Python API for Python ${PY_VERSION}."
# Building the RSS variant adds files to SOURCES.txt we do not want included in a normal build
rm -Rf source/carla.egg-info

if [[ -z ${TARGET_WHEEL_PLATFORM} ]] ; then
/usr/bin/env python${PY_VERSION} setup.py bdist_egg bdist_wheel --dist-dir dist/.tmp
Expand Down

0 comments on commit 39e17e9

Please sign in to comment.