Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use new mapping #888

Merged
merged 20 commits into from
Apr 8, 2024
Merged

Conversation

nichmor
Copy link
Contributor

@nichmor nichmor commented Feb 29, 2024

No description provided.

@nichmor nichmor marked this pull request as ready for review March 7, 2024 21:24
@baszalmstra
Copy link
Contributor

Before we merge this we want to make sure we open source the repository that generates the mapping.

Copy link
Contributor

@ruben-arts ruben-arts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also use the mapping in lock_file::pypi::resolve_dependencies so we don't add the wrong packages to the resolve.

@wolfv wolfv force-pushed the feat/use-new-mapping branch from f051f66 to 5ba6042 Compare March 20, 2024 14:19
@wolfv
Copy link
Member

wolfv commented Mar 20, 2024

I just rebased this PR on main.

A few things I am wondering:

  • should we even retry fetching the mapping? I think in some corporate environments this will be blocked etc, so retrying will be futile :)
  • we just discussed via voice that we do not store a mapping if the conda package has no corresponding pypi package. In that case it seems like we'd be retrying 3 times now for a file that doesn't exist. That sounds slow.

I think we might be better off not retrying and it might also be good to have some graceful fallback - maybe with the current github file, or something hard-coded?

@nichmor
Copy link
Contributor Author

nichmor commented Mar 20, 2024

I just rebased this PR on main.

A few things I am wondering:

  • should we even retry fetching the mapping? I think in some corporate environments this will be blocked etc, so retrying will be futile :)
  • we just discussed via voice that we do not store a mapping if the conda package has no corresponding pypi package. In that case it seems like we'd be retrying 3 times now for a file that doesn't exist. That sounds slow.

I think we might be better off not retrying and it might also be good to have some graceful fallback - maybe with the current github file, or something hard-coded?

What do you mean by hard-coded/current github file?

@baszalmstra
Copy link
Contributor

Retry with the middleware only happens for 500 errors and same rare 42x cases. A missing entry will not be retried.

I assume corporate firewalls will also return a normal 40x status which will also not be retried.

The main usecase for retry is to retry server issues.

@baszalmstra
Copy link
Contributor

@wolfv
Copy link
Member

wolfv commented Mar 20, 2024

Ah great, good to know!

@ruben-arts
Copy link
Contributor

Could you also add documentation on the use and working of this mapping?

@@ -50,4 +50,7 @@ pub struct ProjectMetadata {

/// URL of the project documentation
pub documentation: Option<Url>,

/// URL of the pypi name mapping
pub pypi_name_mapping: Option<Url>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im thinking that maybe we should have a mapping per channel. So you can use the prefix one for conda-forge but use a custom mapping for your own private channel?

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea!
some small discovery questions about how do you see it:

  • do we want to also allow to override conda-forge with your own mapping?
  • do we want to expose configuration via pypi-name-mapping = {"conda-forge": ..my_path, "my-own-channel": ..my_another_path } , or to hide the channel in the mapping itself? ( I go with the first approach )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to also allow to override conda-forge with your own mapping?

When we have mirrors or you are behind a firewall, then yes.

do we want to expose configuration via pypi-name-mapping = {"conda-forge": ..my_path, "my-own-channel": ..my_another_path } , or to hide the channel in the mapping itself? ( I go with the first approach )

@ruben-arts @wolfv WDYT?

Copy link
Contributor

@ruben-arts ruben-arts Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this!

Edit: Scrap the seperate table idea, this is a standalone definition specific to the project. So this is good.

[project]
pypi-name-mapping = { conda-forge = "url", "https://prefix.dev/my_channel" = "url" }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having some doubts on the name. What about:

  • conda-pypi-map
  • channel-index-map
  • conda-pypi-package-map

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about starting a [pypi-options] table? I feel there could be a number of future options to handle (keyring, extra index, etc.)

Not sure re. the specific name of the map, but we could maybe take 'pypi' out of it if it sits under a [pypi-options] table

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about starting a [pypi-options] table? I feel there could be a number of future options to handle (keyring, extra index, etc.)

Not sure re. the specific name of the map, but we could maybe take 'pypi' out of it if it sits under a [pypi-options] table

Hey @olivier-lacroix ! Good question!

My rationale for using [project] is that mapping is used for both conda and pypi - so in my view because we map conda name to python name, the upstream for it is the [project] table.
I'm totally open for any other ideas - maybe we can also ask @ruben-arts and @baszalmstra

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @nichmor, not a bad idea but not required in this case.

Copy link
Contributor

@baszalmstra baszalmstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good to me except that if I read it correctly you are only using the prefix mapping by default for packages from conda-forge. However, you can use the prefix mapping for all packages!

@baszalmstra
Copy link
Contributor

I approve of this PR! @ruben-arts If you are happy with it, feel free to merge :)

Comment on lines 27 to 32
let response = client
.get(url.clone())
.send()
.await
.into_diagnostic()
.context("failed to download pypi mapping from custom location")?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested what happens if you give a broken URL but then this doesn't get shown but then next one does. Could you make sure that it fails on downloading, and that it adds atleast also adds the url to the error so it helps the user find the cultprit? Now it gives this error:

  × failed to parse pypi name mapping
  ├─▶ error decoding response body: invalid type: integer `404`, expected a map at line 1 column 3
  ╰─▶ invalid type: integer `404`, expected a map at line 1 column 3

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-04-08 at 14 56 24 change the logic so know it will throw following error if requested mapping could not be located

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and following error if json is bad formatted ( for example, could not be able to serialized in our struct )
Screenshot 2024-04-08 at 14 58 36

})
.collect::<miette::Result<HashMap<ChannelName, MappingLocation>>>()?;

Ok(MappingSource::Custom { mapping })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to also warn the user if the have a mapping to conda-flibediefloep that it tells them that that channel doesn't exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-04-08 at 14 49 51 Changed the logic a little so know it will print a warning if defined channel is not present in project.channels

Copy link
Contributor

@ruben-arts ruben-arts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome

@ruben-arts ruben-arts merged commit a8b3fee into prefix-dev:main Apr 8, 2024
27 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants