3

I have developers that want to be able to publish a library as a "beta" or "release" version.

i.e.:

1.2.3-beta 1.2.3

On the consuming project, they couldn't give me any specific criteria of when they would want to use a beta or release package. We have CI in place, but without any definitive "when" I can't support two separate pip feeds, as they may flip flop. So I've suggested taking advantage of version range syntax in the requirements file, so they can just specify during checkin what they want. They've never had to do anything like this, and I'm basically a python rookie. Is it possible to filter on pre-release labels? I.e.

Will lib == 1.*.*-* pick up a beta package?

and

Will lib == 1.*.*, !=1.*.*-* pick up a release package and be sure to exclude any beta packages?

I would try out my theory myself, but I don't know python well enough to mock up some sort of sample libs locally, and they're too busy to research it.

sinoroc
  • 18,409
  • 2
  • 39
  • 70
user3066571
  • 1,381
  • 4
  • 14
  • 37

1 Answers1

5

By default pip will not install prereleases, like 1.0.0.b1

To enable installation of prereleases, you use the --pre flag with pip.

You can also use prerelease version specifiers to force pip to consider prereleases for individual packages without needing to use --pre. From https://pip.pypa.io/en/stable/reference/pip_install/#pre-release-versions:

If a Requirement specifier includes a pre-release or development version (e.g. >=0.0.dev0) then pip will allow pre-release and development versions for that requirement.

So in your requirements.txt file, you'd have something like:

package_a>=1.2.3       # will not install pre-releases
package_b>=1.2.3.dev0  # will install pre-releaes 
Dustin Ingram
  • 20,502
  • 7
  • 59
  • 82
  • That's good, but given that it's automation that does this, I feel like them adding or removing the --pre flag every time they wanted to consume a pre-release label package would...annoy them? If I did have --pre flag enabled just at all times, would there be a way to use requirements version syntax to exclude or include pre-release labels? I just want them to only have to interact with their requirements file, that way they're making conscious, deliberate decisions about what libs they're consuming all in one place. – user3066571 Jul 07 '20 at 17:58
  • I've run into a case where the only available version was a pre-release, in that case pip installs this version. From https://peps.python.org/pep-0440/#handling-of-pre-releases: "Pre-releases of any kind, including developmental releases, are implicitly excluded from all version specifiers, unless they are already present on the system, explicitly requested by the user, or if the only available version that satisfies the version specifier is a pre-release" – rite2hhh Aug 02 '22 at 19:04