def build(self): super().build() with simple_env_bzr(os.path.join(self.installdir, "bin")): # Install the packages that have already been downloaded installed_pipy_packages = self._install_project() requirements = self._get_list_of_packages_from_property( self.options.requirements) if requirements: self._manifest["requirements-contents"] = requirements constraints = self._get_list_of_packages_from_property( self.options.constraints) if constraints: self._manifest["constraints-contents"] = constraints self._manifest["python-packages"] = [ "{}={}".format(name, installed_pipy_packages[name]) for name in installed_pipy_packages ] _python.generate_sitecustomize( self._python_major_version, stage_dir=self.project.stage_dir, install_dir=self.installdir, )
def build(self): super().build() with simple_env_bzr(os.path.join(self.installdir, "bin")): # Install the packages that have already been downloaded installed_pipy_packages = self._install_project() # We record the requirements and constraints files only if they are # remote. If they are local, they are already tracked with the source. if self.options.requirements: self._manifest["requirements-contents"] = self._get_file_contents( self.options.requirements ) if self.options.constraints: self._manifest["constraints-contents"] = self._get_file_contents( self.options.constraints ) self._manifest["python-packages"] = [ "{}={}".format(name, installed_pipy_packages[name]) for name in installed_pipy_packages ] _python.generate_sitecustomize( self._python_major_version, stage_dir=self.project.stage_dir, install_dir=self.installdir, )
def _finish_build(self): self._use_in_snap_python() # We've finished the build, but we need to make sure we turn the cmake # files back into something that doesn't include our installdir. This # way it's usable from the staging area, and won't clash with the same # file coming from other parts. pattern = re.compile(r"^{}".format(self.installdir)) def _new_path(path): return pattern.sub("$ENV{SNAPCRAFT_STAGE}", path) self._rewrite_cmake_paths(_new_path) # Replace the CMAKE_PREFIX_PATH in _setup_util.sh setup_util_file = os.path.join(self.rosdir, "_setup_util.py") if os.path.isfile(setup_util_file): with open(setup_util_file, "r+") as f: pattern = re.compile(r"CMAKE_PREFIX_PATH = '.*/opt/ros.*") replaced = pattern.sub("CMAKE_PREFIX_PATH = []", f.read()) f.seek(0) f.truncate() f.write(replaced) # Set the _CATKIN_SETUP_DIR in setup.sh to a sensible default, removing # our installdir (this way it doesn't clash with a setup.sh coming # from another part). setup_sh_file = os.path.join(self.rosdir, "setup.sh") if os.path.isfile(setup_sh_file): with open(setup_sh_file, "r+") as f: pattern = re.compile(r"\${_CATKIN_SETUP_DIR:=.*}") replaced = pattern.sub( "${{_CATKIN_SETUP_DIR:=$SNAP/opt/ros/{}}}".format( self.options.rosdistro ), f.read(), ) f.seek(0) f.truncate() f.write(replaced) if self.options.underlay: underlay_run_path = self.options.underlay["run-path"] self._generate_snapcraft_setup_sh("$SNAP", underlay_run_path) # If pip dependencies were installed, generate a sitecustomize that # allows access to them. if self._pip.is_setup() and self._pip.list(user=True): _python.generate_sitecustomize( "2", stage_dir=self.project.stage_dir, install_dir=self.installdir )
def test_generate_sitecustomize_installed(self): stage_dir = "stage_dir" install_dir = "install_dir" # Create the python binary in the installed area self._create_python_binary(install_dir) # Create a site.py in both staging and install areas _create_site_py(stage_dir) _create_site_py(install_dir) # Create a user site dir in install area _create_user_site_packages(install_dir) _python.generate_sitecustomize( "test", stage_dir=stage_dir, install_dir=install_dir ) expected_sitecustomize = ( "import site\n" "import os\n" "\n" 'snap_dir = os.getenv("SNAP")\n' 'snapcraft_stage_dir = os.getenv("SNAPCRAFT_STAGE")\n' 'snapcraft_part_install = os.getenv("SNAPCRAFT_PART_INSTALL")\n' "\n" "for d in (snap_dir, snapcraft_stage_dir, " "snapcraft_part_install):\n" " if d:\n" " site_dir = os.path.join(d, " '"lib/pythontest/site-packages")\n' " site.addsitedir(site_dir)\n" "\n" "if snap_dir:\n" " site.ENABLE_USER_SITE = False" ) site_path = os.path.join( install_dir, "usr", "lib", "pythontest", "sitecustomize.py" ) self.assertThat(site_path, FileContains(expected_sitecustomize))
def test_generate_sitecustomize_installed(self): stage_dir = "stage_dir" install_dir = "install_dir" # Create the python binary in the installed area self._create_python_binary(install_dir) # Create a site.py in both staging and install areas _create_site_py(stage_dir) _create_site_py(install_dir) # Create a user site dir in install area _create_user_site_packages(install_dir) _python.generate_sitecustomize("test", stage_dir=stage_dir, install_dir=install_dir) expected_sitecustomize = ( "import site\n" "import os\n" "\n" 'snap_dir = os.getenv("SNAP")\n' 'snapcraft_stage_dir = os.getenv("SNAPCRAFT_STAGE")\n' 'snapcraft_part_install = os.getenv("SNAPCRAFT_PART_INSTALL")\n' "\n" "for d in (snap_dir, snapcraft_stage_dir, " "snapcraft_part_install):\n" " if d:\n" " site_dir = os.path.join(d, " '"lib/pythontest/site-packages")\n' " site.addsitedir(site_dir)\n" "\n" "if snap_dir:\n" " site.ENABLE_USER_SITE = False") site_path = os.path.join(install_dir, "usr", "lib", "pythontest", "sitecustomize.py") self.assertThat(site_path, FileContains(expected_sitecustomize))
def test_generate_sitecustomize_installed(self): stage_dir = 'stage_dir' install_dir = 'install_dir' # Create the python binary in the installed area self._create_python_binary(install_dir) # Create a site.py in both staging and install areas _create_site_py(stage_dir) _create_site_py(install_dir) # Create a user site dir in install area _create_user_site_packages(install_dir) _python.generate_sitecustomize( 'test', stage_dir=stage_dir, install_dir=install_dir) expected_sitecustomize = ( 'import site\n' 'import os\n' '\n' 'snap_dir = os.getenv("SNAP")\n' 'snapcraft_stage_dir = os.getenv("SNAPCRAFT_STAGE")\n' 'snapcraft_part_install = os.getenv("SNAPCRAFT_PART_INSTALL")\n' '\n' 'for d in (snap_dir, snapcraft_stage_dir, ' 'snapcraft_part_install):\n' ' if d:\n' ' site_dir = os.path.join(d, ' '"lib/pythontest/site-packages")\n' ' site.addsitedir(site_dir)\n' '\n' 'if snap_dir:\n' ' site.ENABLE_USER_SITE = False') site_path = os.path.join( install_dir, 'usr', 'lib', 'pythontest', 'sitecustomize.py') self.assertThat(site_path, FileContains(expected_sitecustomize))
def _finish_build(self): # Fix all shebangs to use the in-snap python. mangling.rewrite_python_shebangs(self.installdir) # We've finished the build, but we need to make sure we turn the cmake # files back into something that doesn't include our installdir. This # way it's usable from the staging area, and won't clash with the same # file coming from other parts. pattern = re.compile(r"^{}".format(self.installdir)) def _new_path(path): return pattern.sub("$ENV{SNAPCRAFT_STAGE}", path) self._rewrite_cmake_paths(_new_path) # Rewrite prefixes for both the underlay and overlay. self._fix_prefixes() # If pip dependencies were installed, generate a sitecustomize that # allows access to them. if self._pip.is_setup() and self._pip.list(user=True): _python.generate_sitecustomize("3", stage_dir=self.project.stage_dir, install_dir=self.installdir)