question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Poetry can't handle private default source and additional secondary sources

See original GitHub issue
  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

Issue

I’m currently working to develop a Jinja template to facilitate Machine Learning workflows in my company. I’ve developed a library which serves as an interface to many GCP systems and this is in the package gcp_tools, which sits in our private Gitlab package registry. I need this dependent library to be installed into my Jinja template repo.

In addition to this, I’ve got the constraint of my environment being in a VPC without any internet access, rather there is a proxy that connects us to PyPi.

Therefore, I’ve set up my pyproject.toml to have the following source configuration:

[[tool.poetry.source]]
name = "gcp_tools"
url = "https://<private_gitlab_repo>/api/v4/projects/<project_id>/packages/pypi/simple"
# Have tried with secondary = true here also

[[tool.poetry.source]]
name = "nexus"
url = "https://<private_pypi_proxy>/nexus/repository/pypi-proxy/simple"
default = true

And I’ve got both of my sources listed in the config for poetry too (I’ve set poetry config http-basic.gcp_tools with my credentials to access the private Gitlab package registry, but there shouldn’t be any authentication for the nexus proxy):

root@1f0dab1f1134:/home/theia/project/machine-learning-deployment-template# poetry config --list
cache-dir = "/root/.cache/pypoetry"
experimental.new-installer = true
installer.parallel = true
repositories.gcp_tools.url = "https://<private_gitlab_repo>/api/v4/projects/<project_id>/packages/pypi/simple"
repositories.nexus.url = "https://<private_pypi_proxy>/nexus/repository/pypi-proxy/simple"
virtualenvs.create = true
virtualenvs.in-project = false
virtualenvs.path = "{cache-dir}/virtualenvs"  # /root/.cache/pypoetry/virtualenvs

However, as you can see from my full stacktrace below, the versioning is failing as it’s trying to access pypi.org for the dependent packages for gcp_tools.

I’ve tried to switch around the different sources, and add secondary = true to the gcp_tools source, but to no avail.

Full Stacktrace

root@1f0dab1f1134:/home/theia/project/machine-learning-deployment-template# poetry add 'gcp_tools>=1.1.0' -vvv
Using virtualenv: /root/.cache/pypoetry/virtualenvs/machine-learning-deployment-template-1tOBkp6x-py3.7
gcp_tools: 1 packages found for gcp-tools >=1.1.0

Updating dependencies
Resolving dependencies...
   1: fact: machine-learning-deployment-template is 2.1.0
   1: derived: machine-learning-deployment-template
   1: fact: machine-learning-deployment-template depends on sklearn (^0.0)
   1: fact: machine-learning-deployment-template depends on xgboost (>=0.9.0,<1.0.0;)
   1: fact: machine-learning-deployment-template depends on seaborn (^0.11.2)
   1: fact: machine-learning-deployment-template depends on matplotlib (^3.4.3)
   1: fact: machine-learning-deployment-template depends on tqdm (>=4.61.0,<4.62.0)
   1: fact: machine-learning-deployment-template depends on pycodestyle (>=2.7.0,<2.8.0)
   1: fact: machine-learning-deployment-template depends on flake8 (>=3.9.2,<3.10.0)
   1: fact: machine-learning-deployment-template depends on pycodestyle_magic (>=0.5.0,<0.6.0)
   1: fact: machine-learning-deployment-template depends on copier (^5.1.0)
   1: fact: machine-learning-deployment-template depends on absl-py (>0.9,<0.11;)
   1: fact: machine-learning-deployment-template depends on plumbum (^1.7.2)
   1: fact: machine-learning-deployment-template depends on gcp-tools (>=1.1.0)
   1: selecting machine-learning-deployment-template (2.1.0)
   1: derived: gcp-tools (>=1.1.0)
   1: derived: plumbum (>=1.7.2,<2.0.0)
   1: derived: absl-py (>0.9,<0.11)
   1: derived: copier (>=5.1.0,<6.0.0)
   1: derived: pycodestyle_magic (>=0.5.0,<0.6.0)
   1: derived: flake8 (>=3.9.2,<3.10.0)
   1: derived: pycodestyle (>=2.7.0,<2.8.0)
   1: derived: tqdm (>=4.61.0,<4.62.0)
   1: derived: matplotlib (>=3.4.3,<4.0.0)
   1: derived: seaborn (>=0.11.2,<0.12.0)
   1: derived: xgboost (>=0.9.0,<1.0.0)
   1: derived: sklearn (>=0.0,<0.1)
gcp_tools: 1 packages found for gcp-tools >=1.1.0
   1: fact: gcp-tools (1.1.0) depends on coverage (>=6.3.2,<7.0.0)
   1: fact: gcp-tools (1.1.0) depends on croniter (>=1.3.4,<2.0.0)
   1: fact: gcp-tools (1.1.0) depends on gcsfs (>=2022.2.0,<2023.0.0)
   1: fact: gcp-tools (1.1.0) depends on google-cloud-aiplatform (>=1.11.0,<2.0.0)
   1: fact: gcp-tools (1.1.0) depends on google-cloud-pipeline-components (>=1.0.0,<2.0.0)
   1: fact: gcp-tools (1.1.0) depends on kfp (>=1.8.11,<2.0.0)
   1: fact: gcp-tools (1.1.0) depends on pandas (>=1.1.5,<2.0.0)
   1: fact: gcp-tools (1.1.0) depends on pyarrow (>=7.0.0,<8.0.0)
   1: fact: gcp-tools (1.1.0) depends on pylint (>=2.12.2,<3.0.0)
   1: fact: gcp-tools (1.1.0) depends on pytest (>=7.0.1,<8.0.0)
   1: fact: gcp-tools (1.1.0) depends on pytest-timeout (>=2.1.0,<3.0.0)
   1: fact: gcp-tools (1.1.0) depends on python-gitlab (>=3.2.0,<4.0.0)
   1: fact: gcp-tools (1.1.0) depends on sklearn (>=0.0,<0.1)
   1: selecting gcp-tools (1.1.0)
   1: derived: python-gitlab (>=3.2.0,<4.0.0)
   1: derived: pytest-timeout (>=2.1.0,<3.0.0)
   1: derived: pytest (>=7.0.1,<8.0.0)
   1: derived: pylint (>=2.12.2,<3.0.0)
   1: derived: pyarrow (>=7.0.0,<8.0.0)
   1: derived: pandas (>=1.1.5,<2.0.0)
   1: derived: kfp (>=1.8.11,<2.0.0)
   1: derived: google-cloud-pipeline-components (>=1.0.0,<2.0.0)
   1: derived: google-cloud-aiplatform (>=1.11.0,<2.0.0)
   1: derived: gcsfs (>=2022.2.0,<2023.0.0)
   1: derived: croniter (>=1.3.4,<2.0.0)
   1: derived: coverage (>=6.3.2,<7.0.0)
nexus: 1 packages found for python-gitlab >=3.2.0,<4.0.0
   1: Version solving took 126.794 seconds.
   1: Tried 1 solutions.

  Stack trace:

  24  /opt/conda/lib/python3.7/site-packages/clikit/console_application.py:131 in run
       129β”‚             parsed_args = resolved_command.args
       130β”‚ 
     β†’ 131β”‚             status_code = command.handle(parsed_args, io)
       132β”‚         except KeyboardInterrupt:
       133β”‚             status_code = 1

  23  /opt/conda/lib/python3.7/site-packages/clikit/api/command/command.py:120 in handle
       118β”‚     def handle(self, args, io):  # type: (Args, IO) -> int
       119β”‚         try:
     β†’ 120β”‚             status_code = self._do_handle(args, io)
       121β”‚         except KeyboardInterrupt:
       122β”‚             if io.is_debug():

  22  /opt/conda/lib/python3.7/site-packages/clikit/api/command/command.py:171 in _do_handle
       169β”‚         handler_method = self._config.handler_method
       170β”‚ 
     β†’ 171β”‚         return getattr(handler, handler_method)(args, io, self)
       172β”‚ 
       173β”‚     def __repr__(self):  # type: () -> str

  21  /opt/conda/lib/python3.7/site-packages/cleo/commands/command.py:92 in wrap_handle
        90β”‚         self._command = command
        91β”‚ 
     β†’  92β”‚         return self.handle()
        93β”‚ 
        94β”‚     def handle(self):  # type: () -> Optional[int]

  20  /opt/conda/lib/python3.7/site-packages/poetry/console/commands/add.py:173 in handle
       171β”‚             self._installer.whitelist([r["name"] for r in requirements])
       172β”‚ 
     β†’ 173β”‚             status = self._installer.run()
       174β”‚         except BaseException:
       175β”‚             # Using BaseException here as some exceptions, eg: KeyboardInterrupt, do not inherit from Exception

  19  /opt/conda/lib/python3.7/site-packages/poetry/installation/installer.py:103 in run
       101β”‚         local_repo = Repository()
       102β”‚ 
     β†’ 103β”‚         return self._do_install(local_repo)
       104β”‚ 
       105β”‚     def dry_run(self, dry_run=True):  # type: (bool) -> Installer

  18  /opt/conda/lib/python3.7/site-packages/poetry/installation/installer.py:235 in _do_install
       233β”‚             )
       234β”‚ 
     β†’ 235β”‚             ops = solver.solve(use_latest=self._whitelist)
       236β”‚         else:
       237β”‚             self._io.write_line("Installing dependencies from lock file")

  17  /opt/conda/lib/python3.7/site-packages/poetry/puzzle/solver.py:65 in solve
        63β”‚         with self._provider.progress():
        64β”‚             start = time.time()
     β†’  65β”‚             packages, depths = self._solve(use_latest=use_latest)
        66β”‚             end = time.time()
        67β”‚ 

  16  /opt/conda/lib/python3.7/site-packages/poetry/puzzle/solver.py:234 in _solve
       232β”‚         try:
       233β”‚             result = resolve_version(
     β†’ 234β”‚                 self._package, self._provider, locked=locked, use_latest=use_latest
       235β”‚             )
       236β”‚ 

  15  /opt/conda/lib/python3.7/site-packages/poetry/mixology/__init__.py:7 in resolve_version
       5β”‚     solver = VersionSolver(root, provider, locked=locked, use_latest=use_latest)
       6β”‚ 
     β†’ 7β”‚     return solver.solve()
       8β”‚ 

  14  /opt/conda/lib/python3.7/site-packages/poetry/mixology/version_solver.py:84 in solve
        82β”‚             while next is not None:
        83β”‚                 self._propagate(next)
     β†’  84β”‚                 next = self._choose_package_version()
        85β”‚ 
        86β”‚             return self._result()

  13  /opt/conda/lib/python3.7/site-packages/poetry/mixology/version_solver.py:372 in _choose_package_version
       370β”‚             dependency = unsatisfied[0]
       371β”‚         else:
     β†’ 372β”‚             dependency = min(*unsatisfied, key=_get_min)
       373β”‚ 
       374β”‚         locked = self._get_locked(dependency)

  12  /opt/conda/lib/python3.7/site-packages/poetry/mixology/version_solver.py:364 in _get_min
       362β”‚                 return (
       363β”‚                     not dependency.marker.is_any(),
     β†’ 364β”‚                     len(self._provider.search_for(dependency)),
       365β”‚                 )
       366β”‚             except ValueError:

  11  /opt/conda/lib/python3.7/site-packages/poetry/puzzle/provider.py:139 in search_for
       137β”‚             packages = self.search_for_url(dependency)
       138β”‚         else:
     β†’ 139β”‚             packages = self._pool.find_packages(dependency)
       140β”‚ 
       141β”‚             packages.sort(

  10  /opt/conda/lib/python3.7/site-packages/poetry/repositories/pool.py:170 in find_packages
       168β”‚         packages = []
       169β”‚         for repo in self._repositories:
     β†’ 170β”‚             packages += repo.find_packages(dependency)
       171β”‚ 
       172β”‚         return packages

   9  /opt/conda/lib/python3.7/site-packages/poetry/repositories/legacy_repository.py:264 in find_packages
       262β”‚             versions = self._cache.store("matches").get(key)
       263β”‚         else:
     β†’ 264β”‚             page = self._get("/{}/".format(dependency.name.replace(".", "-")))
       265β”‚             if page is None:
       266β”‚                 return []

   8  /opt/conda/lib/python3.7/site-packages/poetry/repositories/legacy_repository.py:388 in _get
       386β”‚         url = self._url + endpoint
       387β”‚         try:
     β†’ 388β”‚             response = self.session.get(url)
       389β”‚             if response.status_code == 404:
       390β”‚                 return

   7  /opt/conda/lib/python3.7/site-packages/requests/sessions.py:555 in get
       553β”‚ 
       554β”‚         kwargs.setdefault('allow_redirects', True)
     β†’ 555β”‚         return self.request('GET', url, **kwargs)
       556β”‚ 
       557β”‚     def options(self, url, **kwargs):

   6  /opt/conda/lib/python3.7/site-packages/requests/sessions.py:542 in request
       540β”‚         }
       541β”‚         send_kwargs.update(settings)
     β†’ 542β”‚         resp = self.send(prep, **send_kwargs)
       543β”‚ 
       544β”‚         return resp

   5  /opt/conda/lib/python3.7/site-packages/requests/sessions.py:677 in send
       675β”‚             # Redirect resolving generator.
       676β”‚             gen = self.resolve_redirects(r, request, **kwargs)
     β†’ 677β”‚             history = [resp for resp in gen]
       678β”‚         else:
       679β”‚             history = []

   4  /opt/conda/lib/python3.7/site-packages/requests/sessions.py:677 in <listcomp>
       675β”‚             # Redirect resolving generator.
       676β”‚             gen = self.resolve_redirects(r, request, **kwargs)
     β†’ 677β”‚             history = [resp for resp in gen]
       678β”‚         else:
       679β”‚             history = []

   3  /opt/conda/lib/python3.7/site-packages/requests/sessions.py:245 in resolve_redirects
       243β”‚                     proxies=proxies,
       244β”‚                     allow_redirects=False,
     β†’ 245β”‚                     **adapter_kwargs
       246β”‚                 )
       247β”‚ 

   2  /opt/conda/lib/python3.7/site-packages/requests/sessions.py:655 in send
       653β”‚ 
       654β”‚         # Send the request
     β†’ 655β”‚         r = adapter.send(request, **kwargs)
       656β”‚ 
       657β”‚         # Total elapsed time of the request (approximately)

   1  /opt/conda/lib/python3.7/site-packages/cachecontrol/adapter.py:57 in send
        55β”‚             request.headers.update(self.controller.conditional_headers(request))
        56β”‚ 
     β†’  57β”‚         resp = super(CacheControlAdapter, self).send(request, **kw)
        58β”‚ 
        59β”‚         return resp

  ConnectionError

  HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/python-gitlab/ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f202de8e890>: Failed to establish a new connection: [Errno 110] Connection timed out'))

  at /opt/conda/lib/python3.7/site-packages/requests/adapters.py:516 in send
      512β”‚             if isinstance(e.reason, _SSLError):
      513β”‚                 # This branch is for urllib3 v1.22 and later.
      514β”‚                 raise SSLError(e, request=request)
      515β”‚ 
    β†’ 516β”‚             raise ConnectionError(e, request=request)
      517β”‚ 
      518β”‚         except ClosedPoolError as e:
      519β”‚             raise ConnectionError(e, request=request)
      520β”‚

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
goodmamicommented, Mar 16, 2022

(@Carl132 It looks like you might have unredacted tokens and URLs in the first code block of your second post.)

(P.S. too bad GitHub doesn’t have a PM feature)

0reactions
neersightedcommented, Dec 2, 2022

That is by-design, currently [[tool.poetry.source]] does not influence the build-system.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Poetry trying to install everything from private repository
Poetry trying to install everything from private repository Β· explicitly set the source for each dependency in the pyproject. Β· all possibleΒ ...
Read more >
Repositories | Documentation | Poetry - Python dependency ...
Repositories Poetry supports the use of PyPI and private repositories for discovery of packages as well as for publishing your projects. By default,...
Read more >
Private packages with CodeArtifact and Poetry, a ... - Jason Stitt
The option --source artifact is necessary here for two reasons. First, we specified CodeArtifact as a secondary, rather than default, source.
Read more >
Dependency Management With Python Poetry
Before diving into the nitty-gritty of Python Poetry, you'll take care of ... If you prefer to store your source code in an...
Read more >
Why you should use Poetry instead of Pip or Conda for Python ...
Ditch Conda totally if you plan to do Python programming for production Β· Pre-installed packages in Anaconda Β· Unnecessary packages added duringΒ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found