コード例 #1
0
        /// <summary>
        /// Copies the dependencies to package directory.
        /// </summary>
        /// <param name="dependencyEntry">The dependency entry.</param>
        /// <param name="dependencyLocation">The dependency locations - one or more directories where dependencies may be found.</param>
        /// <exception cref="PackagerException">Module {library} not found in virtual env '{dependencyEntry.Location}'</exception>
        private void CopyDependenciesToPackageDirectory(
            LambdaDependency dependencyEntry,
            string dependencyLocation)
        {
            // Make this an array to use Linq to do path combine and existence check in one
            var dependencyLocationArray = new[] { dependencyLocation };

            foreach (var library in dependencyEntry.Libraries)
            {
                if (Path.IsPathRooted(library))
                {
                    if (File.Exists(library))
                    {
                        File.Copy(library, Path.Combine(this.packageDirectory.FullName, Path.GetFileName(library)));
                    }
                    else if (Directory.Exists(library))
                    {
                        var source = new DirectoryInfo(library);
                        var target = new DirectoryInfo(Path.Combine(this.packageDirectory.FullName, source.Name));
                        CopyAll(source, target);
                    }
                    else
                    {
                        throw new FileNotFoundException("Library module not found", library);
                    }
                }
                else
                {
                    var libDirectory = dependencyLocationArray.Select(d => Path.Combine(d, library))
                                       .FirstOrDefault(Directory.Exists);

                    if (libDirectory != null)
                    {
                        // Now copy to where we are building the package
                        var source = new DirectoryInfo(libDirectory);
                        var target = new DirectoryInfo(Path.Combine(this.packageDirectory.FullName, source.Name));
                        CopyAll(source, target);
                        continue;
                    }

                    // Perhaps the dependency is a single file
                    var libFile = dependencyLocationArray.Select(d => Path.Combine(d, $"{library}.py"))
                                  .FirstOrDefault(File.Exists);

                    if (libFile == null)
                    {
                        throw new PackagerException(
                                  $"Module {library} not found in virtual env '{dependencyEntry.Location}'");
                    }

                    // Copy the file to the packaging directory
                    File.Copy(libFile, Path.Combine(this.packageDirectory.FullName, Path.GetFileName(libFile)));
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Gets the virtual env site-packages for the current OS platform.
        /// </summary>
        /// <param name="dependencyEntry">The dependency entry.</param>
        /// <returns>virtual env site-packages</returns>
        protected override string GetSitePackagesDirectory(LambdaDependency dependencyEntry)
        {
            var sitePackages = Path.Combine(dependencyEntry.Location, this.LibDir, "site-packages");

            if (!Directory.Exists(sitePackages))
            {
                throw new PackagerException(
                          $"'{dependencyEntry.Location} looks like a virtual env, but no 'site-packages' found.");
            }

            return(sitePackages);
        }
コード例 #3
0
        /// <summary>
        /// Gets the virtual env site-packages for the current OS platform.
        /// </summary>
        /// <param name="dependencyEntry">The dependency entry.</param>
        /// <returns>virtual env site-packages</returns>
        protected override string GetSitePackagesDirectory(LambdaDependency dependencyEntry)
        {
            // Linux/Mac separate site-packages according to Python version
            var sitePackages = Path.Combine(dependencyEntry.Location, this.LibDir, this.LambdaArtifact.RuntimeInfo.Runtime, "site-packages");

            if (!Directory.Exists(sitePackages))
            {
                throw new PackagerException(
                          $"'{dependencyEntry.Location} looks like a virtual env, but no 'site-packages' found for {this.LambdaArtifact.RuntimeInfo.Runtime}");
            }

            return(sitePackages);
        }
コード例 #4
0
 /// <summary>
 /// Gets the virtual env site-packages for the current OS platform.
 /// </summary>
 /// <param name="dependencyEntry">The dependency entry.</param>
 /// <returns>virtual env site-packages</returns>
 protected abstract string GetSitePackagesDirectory(LambdaDependency dependencyEntry);