Пример #1
0
 internal PipPackageView(PipPackageCache provider, string name, string version, string description) {
     _provider = provider;
     _name = name ?? "";
     if (!string.IsNullOrEmpty(version)) {
         Pep440Version.TryParse(version, out _version);
     }
     _description = description ?? "";
 }
Пример #2
0
 internal PipPackageView(PipPackageCache provider, string name, string version, string description)
 {
     _provider = provider;
     _name     = name ?? "";
     if (!string.IsNullOrEmpty(version))
     {
         Pep440Version.TryParse(version, out _version);
     }
     _description = description ?? "";
 }
Пример #3
0
 /// <summary>
 /// Creates a provider for managing packages through pip.
 /// </summary>
 /// <param name="factory">The associated interpreter.</param>
 /// <param name="index">
 /// The index URL. Defaults to https://pypi.python.org/pypi/
 /// </param>
 /// <param name="indexName">
 /// Display name of the index. Defaults to PyPI.
 /// </param>
 public PipExtensionProvider(
     IPythonInterpreterFactory factory,
     string index     = null,
     string indexName = null
     )
 {
     _factory = factory;
     _output  = new PipRedirector(this);
     if (!string.IsNullOrEmpty(index) && Uri.TryCreate(index, UriKind.Absolute, out _index))
     {
         _indexName = string.IsNullOrEmpty(indexName) ? _index.Host : indexName;
     }
     _cache = PipPackageCache.GetCache(_index, _indexName);
 }
Пример #4
0
        internal PipPackageView(PipPackageCache provider, string packageSpec, bool versionIsInstalled = true) {
            _provider = provider;
            Match m;
            try {
                m = PipListOutputRegex.Match(packageSpec);
            } catch (RegexMatchTimeoutException) {
                Debug.Fail("Regex timeout");
                m = null;
            }
            if (m == null || !m.Success) {
                try {
                    m = PipFreezeOutputRegex.Match(packageSpec);
                } catch (RegexMatchTimeoutException) {
                    Debug.Fail("Regex timeout");
                    m = null;
                }
                if (m == null || !m.Success) {
                    try {
                        m = NameAndDescriptionRegex.Match(packageSpec);
                    } catch (RegexMatchTimeoutException) {
                        Debug.Fail("Regex timeout");
                        m = null;
                    }
                }
            }

            Pep440Version version;
            if (m.Success) {
                _name = m.Groups["name"].Value;
                Pep440Version.TryParse(m.Groups["version"].Value, out version);
            } else {
                _name = packageSpec;
                version = Pep440Version.Empty;
            }

            var description = m.Groups["description"].Value;
            if (!string.IsNullOrEmpty(description)) {
                _description = Uri.UnescapeDataString(description);
            }

            if (versionIsInstalled) {
                _version = version;
                _upgradeVersion = null;
            } else {
                _version = Pep440Version.Empty;
                _upgradeVersion = version;
            }
        }
Пример #5
0
        public static PipPackageCache GetCache(Uri index = null, string indexName = null) {
            PipPackageCache cache;
            var key = (index ?? DefaultIndex).AbsoluteUri;
            lock (_knownCachesLock) {
                if (!_knownCaches.TryGetValue(key, out cache)) {
                    _knownCaches[key] = cache = new PipPackageCache(
                        index,
                        indexName,
                        GetCachePath(index ?? DefaultIndex, indexName ?? DefaultIndexName)
                    );
                }
                cache._userCount += 1;
            }

            return cache;
        }
Пример #6
0
        /// <summary>
        /// Creates a provider for managing packages through pip.
        /// </summary>
        /// <param name="factory">The associated interpreter.</param>
        /// <param name="index">
        /// The index URL. Defaults to https://pypi.python.org/pypi/
        /// </param>
        /// <param name="indexName">
        /// Display name of the index. Defaults to PyPI.
        /// </param>
        public PipExtensionProvider(
            IPythonInterpreterFactory factory,
            string index     = null,
            string indexName = null
            )
        {
            _factory        = factory;
            _packageManager = _factory.PackageManager;
            if (_packageManager == null)
            {
                throw new NotSupportedException();
            }

            if (!string.IsNullOrEmpty(index) && Uri.TryCreate(index, UriKind.Absolute, out _index))
            {
                _indexName = string.IsNullOrEmpty(indexName) ? _index.Host : indexName;
            }
            _cache = PipPackageCache.GetCache(_index, _indexName);
        }
Пример #7
0
        public static PipPackageCache GetCache(Uri index = null, string indexName = null)
        {
            PipPackageCache cache;
            var             key = (index ?? DefaultIndex).AbsoluteUri;

            lock (_knownCachesLock) {
                if (!_knownCaches.TryGetValue(key, out cache))
                {
                    _knownCaches[key] = cache = new PipPackageCache(
                        index,
                        indexName,
                        GetCachePath(index ?? DefaultIndex, indexName ?? DefaultIndexName)
                        );
                }
                cache._userCount += 1;
            }

            return(cache);
        }
Пример #8
0
        internal PipPackageView(PipPackageCache provider, string packageSpec, bool versionIsInstalled = true)
        {
            _provider = provider;
            Match m;

            try {
                m = PipListOutputRegex.Match(packageSpec);
            } catch (RegexMatchTimeoutException) {
                Debug.Fail("Regex timeout");
                m = null;
            }
            if (m == null || !m.Success)
            {
                try {
                    m = PipFreezeOutputRegex.Match(packageSpec);
                } catch (RegexMatchTimeoutException) {
                    Debug.Fail("Regex timeout");
                    m = null;
                }
                if (m == null || !m.Success)
                {
                    try {
                        m = NameAndDescriptionRegex.Match(packageSpec);
                    } catch (RegexMatchTimeoutException) {
                        Debug.Fail("Regex timeout");
                        m = null;
                    }
                }
            }

            Pep440Version version;

            if (m.Success)
            {
                _name = m.Groups["name"].Value;
                Pep440Version.TryParse(m.Groups["version"].Value, out version);
            }
            else
            {
                _name   = packageSpec;
                version = Pep440Version.Empty;
            }

            var description = m.Groups["description"].Value;

            if (!string.IsNullOrEmpty(description))
            {
                _description = Uri.UnescapeDataString(description);
            }

            if (versionIsInstalled)
            {
                _version        = version;
                _upgradeVersion = null;
            }
            else
            {
                _version        = Pep440Version.Empty;
                _upgradeVersion = version;
            }
        }