{"id":336904,"date":"2022-08-11T15:00:24","date_gmt":"2022-08-11T15:00:24","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=336904"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=336904","title":{"rendered":"<span>\u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043c\u043f\u043e\u0440\u0442 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0432 Python<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/b94\/634\/18d\/b9463418d50daab4567f20f007398605.jpg\" width=\"1540\" height=\"540\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b94\/634\/18d\/b9463418d50daab4567f20f007398605.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043d\u0430 \u0432\u0441\u0435 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u0430\u0448\u0438\u043d\u044b (\u0430\u0433\u0435\u043d\u0442\u044b \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0441\u0431\u043e\u0440\u043a\u0438) \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0430\u043a\u0435\u0442 Python. \u041d\u043e \u0432\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0437 \u0430\u0433\u0435\u043d\u0442\u0430, \u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0438\u0437 pypi.org \u0438\u043b\u0438 github.com \u043d\u0435\u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u0445 \u043f\u0430\u043a\u0435\u0442\u043e\u0432, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0430. \u041a\u0430\u043a \u0442\u0443\u0442 \u043d\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u043f\u0440\u043e <a href=\"https:\/\/www.opennet.ru\/opennews\/art.shtml?num=56870\">\u0432\u0440\u0435\u0434\u043e\u043d\u043e\u0441\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f<\/a> \u0432 \u043f\u0430\u043a\u0435\u0442\u0435 nmp \u0438\u043b\u0438 <a href=\"https:\/\/xakep.ru\/2022\/08\/05\/pypi-ransomware\">\u0431\u043e\u043b\u0435\u0435 \u0441\u0432\u0435\u0436\u0443\u044e<\/a> \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u0440\u043e PyPi.<\/p>\n<figure class=\"bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/c4c\/857\/fbf\/c4c857fbf05f555e042801b9428cc565.jpg\" alt=\"\" title=\"\" width=\"533\" height=\"372\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c4c\/857\/fbf\/c4c857fbf05f555e042801b9428cc565.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>Python \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c EAFP \u2014 Easier to ask for forgiveness, than permission (\u043b\u0435\u0433\u0447\u0435 \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f, \u0447\u0435\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f). \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043f\u0440\u043e\u0449\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c, \u0447\u0442\u043e \u0447\u0442\u043e-\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 (\u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435, \u0438\u043b\u0438 \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0434\u0443\u043b\u044c \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435) \u0438\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435.<\/p>\n<p>\u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434, <a href=\"https:\/\/peps.python.org\/pep-0302\">\u0440\u0430\u0437\u0432\u0438\u0442\u044b\u0439 \u0432 PEP-0302<\/a>, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u0445\u0443\u043a \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u043c\u043e\u0434\u0443\u043b\u0435\u0439, \u0447\u0442\u043e \u0432 \u0438\u0442\u043e\u0433\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043d\u0430\u0441 \u043a \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"python\">\u00a0\u00a0\u00a0\u00a0\u00a0 from &lt;\u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435> import &lt;\u043c\u043e\u0434\u0443\u043b\u044c><\/code><\/pre>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044f \u0447\u0430\u0441\u0442\u043e \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044e\u0441\u044c \u0441 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f CI\/CD \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Bamboo, \u0442\u043e \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0431\u044b\u043b\u043e \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u0434 \u0432\u044b\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u0432 \u0430\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u0430\u0445 JFrog \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c (\u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e PEP-0302) \u043a\u043b\u0430\u0441\u0441\u044b finder \u0438 loader \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043c\u043e\u0434\u0443\u043b\u0435\u0439. \u0412 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u0434 \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"python\">\u00a0\u00a0\u00a0\u00a0\u00a0 from &lt;artifactory_local.path_to_ artifactory> import &lt;module_tar_gz><\/code><\/pre>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e PEP-0302 \u0432 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0442 \u0434\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430: <code>finder<\/code> \u0438 <code>loader<\/code>.<\/p>\n<p>\u041f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e \u043c\u043e\u0434\u0443\u043b\u044c amtImport.py, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u0440\u0430\u0431\u043e\u0442\u0443 \u044d\u0442\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432:<\/p>\n<pre><code class=\"python\">import sys import pip import os import requests import shutil  class IntermediateModule:     \"\"\"     Module for paths like `artifactory_local.path`     \"\"\"      def __init__(self, fullname):         self.__package__ = fullname         self.__path__ = fullname.split('.')         self.__name__ = fullname  class ArtifactoryFinder:     \"\"\"     Handles `artifactory_local....` modules     \"\"\"     def find_module(self, module_name, package_path):         if module_name.startswith('artifactory_local'):             return ArtifactoryLoader()  class ArtifactoryLoader:     \"\"\"     Installs and imports modules from artifactory     \"\"\"     artifactory_modules: list = []      def _is_installed(self, fullname):         try:             self._import_module(fullname)             ArtifactoryLoader.artifactory_modules.append(fullname)             return True         except ImportError:             return False          def _import_module(self, fullname):         actual_name = '.'.join(fullname.split('.')[2:])         actual_name = actual_name.replace('_', '.').split('.')[0]         return __import__(actual_name)      def _install_module(self, fullname):         if not self._is_installed(fullname):             actual_name = '.'.join(fullname.split('.')[2:])             url = fullname.replace('artifactory_local', '').replace(actual_name, '').replace('_', '\/')             actual_name = actual_name.replace('_', '.')             url = 'https:\/\/artifactory.app.local' + url.replace('.', '\/') + actual_name             auth = (os.getenv(\"bamboo_artifactory_user_name\"), os.getenv(\"bamboo_artifactory_access_token_secret\"))             file_name = f\"{os.getenv('bamboo_build_working_directory')}\/{actual_name}\"             with requests.get(url=url, auth=auth, stream=True) as r:                 if r.status_code != 200:                     raise Exception(f\"Status code {r.status_code}: {r.reason}\")                               with open(file_name, 'wb') as f:                     shutil.copyfileobj(r.raw, f)             pip.main(['install', file_name])             ArtifactoryLoader.artifactory_modules.append(fullname)      def _is_repository_path(self, fullname):         return fullname.count('.') == 2      def _is_intermediate_path(self, fullname):         return fullname.count('.') &lt; 2      def load_module(self, fullname):         if self._is_repository_path(fullname):             self._install_module(fullname)          if self._is_intermediate_path(fullname):             module = IntermediateModule(fullname)         else:             module = self._import_module(fullname)          sys.modules[fullname] = module  sys.meta_path.append(ArtifactoryFinder())<\/code><\/pre>\n<p><em>(\u041a\u043e\u0434 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f \u0434\u043b\u044f Python 3.6)<\/em><\/p>\n<p>\u0418\u0442\u043e\u0433: \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043c\u043f\u043e\u0440\u0442 \u0438\u0437 \u0430\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e \u043e\u0444\u043e\u0440\u043c\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/cd1\/f07\/2b2\/cd1f072b2bac3a1782a2f3e8ffb38c8e.jpg\" width=\"1192\" height=\"671\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cd1\/f07\/2b2\/cd1f072b2bac3a1782a2f3e8ffb38c8e.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">from amtImport import ArtifactoryLoader # pyright: reportMissingImports=false, reportUnusedImport=false from artifactory_local.artifactory_amt_Sealed import smbprotocol_1_9_0_tar_gz  if \"artifactory_local.artifactory_amt_Sealed.smbprotocol_1_9_0_tar_gz\" in ArtifactoryLoader.artifactory_modules:     print(\"Package successfully loaded\")<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434, \u043c\u043e\u0436\u043d\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043c\u043f\u043e\u0440\u0442 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0438\u0437 \u043b\u044e\u0431\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430.<\/p>\n<p>P.S. \u041e\u0441\u043d\u043e\u0432\u043e\u0439 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u043b \u043f\u0430\u043a\u0435\u0442 <a href=\"https:\/\/github.com\/nvbn\/import_from_github_com\">import_from_github_com<\/a>.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/sportmaster_lab\/blog\/681680\/\"> https:\/\/habr.com\/ru\/company\/sportmaster_lab\/blog\/681680\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043d\u0430 \u0432\u0441\u0435 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u0430\u0448\u0438\u043d\u044b (\u0430\u0433\u0435\u043d\u0442\u044b \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0441\u0431\u043e\u0440\u043a\u0438) \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0430\u043a\u0435\u0442 Python. \u041d\u043e \u0432\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0437 \u0430\u0433\u0435\u043d\u0442\u0430, \u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0438\u0437 pypi.org \u0438\u043b\u0438 github.com \u043d\u0435\u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u0445 \u043f\u0430\u043a\u0435\u0442\u043e\u0432, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0430. \u041a\u0430\u043a \u0442\u0443\u0442 \u043d\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u043f\u0440\u043e <a href=\"https:\/\/www.opennet.ru\/opennews\/art.shtml?num=56870\">\u0432\u0440\u0435\u0434\u043e\u043d\u043e\u0441\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f<\/a> \u0432 \u043f\u0430\u043a\u0435\u0442\u0435 nmp \u0438\u043b\u0438 <a href=\"https:\/\/xakep.ru\/2022\/08\/05\/pypi-ransomware\">\u0431\u043e\u043b\u0435\u0435 \u0441\u0432\u0435\u0436\u0443\u044e<\/a> \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u0440\u043e PyPi.<\/p>\n<figure class=\"bordered full-width\"><figcaption><\/figcaption><\/figure>\n<p>Python \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c EAFP \u2014 Easier to ask for forgiveness, than permission (\u043b\u0435\u0433\u0447\u0435 \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f, \u0447\u0435\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f). \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043f\u0440\u043e\u0449\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c, \u0447\u0442\u043e \u0447\u0442\u043e-\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 (\u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435, \u0438\u043b\u0438 \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0434\u0443\u043b\u044c \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435) \u0438\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435.<\/p>\n<p>\u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434, <a href=\"https:\/\/peps.python.org\/pep-0302\">\u0440\u0430\u0437\u0432\u0438\u0442\u044b\u0439 \u0432 PEP-0302<\/a>, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u0445\u0443\u043a \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u043c\u043e\u0434\u0443\u043b\u0435\u0439, \u0447\u0442\u043e \u0432 \u0438\u0442\u043e\u0433\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043d\u0430\u0441 \u043a \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"python\">\u00a0\u00a0\u00a0\u00a0\u00a0 from &lt;\u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435> import &lt;\u043c\u043e\u0434\u0443\u043b\u044c><\/code><\/pre>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044f \u0447\u0430\u0441\u0442\u043e \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044e\u0441\u044c \u0441 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f CI\/CD \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Bamboo, \u0442\u043e \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0431\u044b\u043b\u043e \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u0434 \u0432\u044b\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u0432 \u0430\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u0430\u0445 JFrog \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c (\u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e PEP-0302) \u043a\u043b\u0430\u0441\u0441\u044b finder \u0438 loader \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043c\u043e\u0434\u0443\u043b\u0435\u0439. \u0412 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u0434 \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"python\">\u00a0\u00a0\u00a0\u00a0\u00a0 from &lt;artifactory_local.path_to_ artifactory> import &lt;module_tar_gz><\/code><\/pre>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e PEP-0302 \u0432 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0442 \u0434\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430: <code>finder<\/code> \u0438 <code>loader<\/code>.<\/p>\n<p>\u041f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e \u043c\u043e\u0434\u0443\u043b\u044c amtImport.py, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u0440\u0430\u0431\u043e\u0442\u0443 \u044d\u0442\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432:<\/p>\n<pre><code class=\"python\">import sys import pip import os import requests import shutil  class IntermediateModule:     \"\"\"     Module for paths like `artifactory_local.path`     \"\"\"      def __init__(self, fullname):         self.__package__ = fullname         self.__path__ = fullname.split('.')         self.__name__ = fullname  class ArtifactoryFinder:     \"\"\"     Handles `artifactory_local....` modules     \"\"\"     def find_module(self, module_name, package_path):         if module_name.startswith('artifactory_local'):             return ArtifactoryLoader()  class ArtifactoryLoader:     \"\"\"     Installs and imports modules from artifactory     \"\"\"     artifactory_modules: list = []      def _is_installed(self, fullname):         try:             self._import_module(fullname)             ArtifactoryLoader.artifactory_modules.append(fullname)             return True         except ImportError:             return False          def _import_module(self, fullname):         actual_name = '.'.join(fullname.split('.')[2:])         actual_name = actual_name.replace('_', '.').split('.')[0]         return __import__(actual_name)      def _install_module(self, fullname):         if not self._is_installed(fullname):             actual_name = '.'.join(fullname.split('.')[2:])             url = fullname.replace('artifactory_local', '').replace(actual_name, '').replace('_', '\/')             actual_name = actual_name.replace('_', '.')             url = 'https:\/\/artifactory.app.local' + url.replace('.', '\/') + actual_name             auth = (os.getenv(\"bamboo_artifactory_user_name\"), os.getenv(\"bamboo_artifactory_access_token_secret\"))             file_name = f\"{os.getenv('bamboo_build_working_directory')}\/{actual_name}\"             with requests.get(url=url, auth=auth, stream=True) as r:                 if r.status_code != 200:                     raise Exception(f\"Status code {r.status_code}: {r.reason}\")                               with open(file_name, 'wb') as f:                     shutil.copyfileobj(r.raw, f)             pip.main(['install', file_name])             ArtifactoryLoader.artifactory_modules.append(fullname)      def _is_repository_path(self, fullname):         return fullname.count('.') == 2      def _is_intermediate_path(self, fullname):         return fullname.count('.') &lt; 2      def load_module(self, fullname):         if self._is_repository_path(fullname):             self._install_module(fullname)          if self._is_intermediate_path(fullname):             module = IntermediateModule(fullname)         else:             module = self._import_module(fullname)          sys.modules[fullname] = module  sys.meta_path.append(ArtifactoryFinder())<\/code><\/pre>\n<p><em>(\u041a\u043e\u0434 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f \u0434\u043b\u044f Python 3.6)<\/em><\/p>\n<p>\u0418\u0442\u043e\u0433: \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043c\u043f\u043e\u0440\u0442 \u0438\u0437 \u0430\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e \u043e\u0444\u043e\u0440\u043c\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">from amtImport import ArtifactoryLoader # pyright: reportMissingImports=false, reportUnusedImport=false from artifactory_local.artifactory_amt_Sealed import smbprotocol_1_9_0_tar_gz  if \"artifactory_local.artifactory_amt_Sealed.smbprotocol_1_9_0_tar_gz\" in ArtifactoryLoader.artifactory_modules:     print(\"Package successfully loaded\")<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434, \u043c\u043e\u0436\u043d\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043c\u043f\u043e\u0440\u0442 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0438\u0437 \u043b\u044e\u0431\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430.<\/p>\n<p>P.S. \u041e\u0441\u043d\u043e\u0432\u043e\u0439 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u043b \u043f\u0430\u043a\u0435\u0442 <a href=\"https:\/\/github.com\/nvbn\/import_from_github_com\">import_from_github_com<\/a>.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/sportmaster_lab\/blog\/681680\/\"> https:\/\/habr.com\/ru\/company\/sportmaster_lab\/blog\/681680\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-336904","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/336904","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=336904"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/336904\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=336904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=336904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=336904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}