This article will show you how to use Include and Exclude patterns on a PyPi repository.
Since using the regular Include and Exclude patterns of names of artifacts will not work on PyPi repositories, in order to configure Include and Exclude patterns that will work on PyPi repositories you will need to use the Include and Exclude patterns to Include/Exclude the packages metadata (not its name).
As an example we uploaded a package to our local PyPi repository named 'hello1234' version 0.0.1. In the remote PyPi repository there is a version 0.0.2 of this package.
We performed the commend 'pip install hello1234' and at first Artifactory did go to the remote and fetched the version 0.0.2:
Then, we looked in the cache and saw that the metadata file is located in a folder named '.pypi' and is called 'hello1234.html'.
We then put the following Exclude pattern in the remote repository – .pypi/hello1234.* in order to block this metadata file from being downloaded and cleared the cache, and when performing the commend 'pip install hello1234' again we saw that we got the version 0.0.1 from the local and not version 0.0.2 from the remote:
In conclusion – in order to use Include and Exclude patterns for PyPi repositories you will need to Include/Exclude the metadata file of the artifact.
Note – the metadata files are all saved with lower case letters no matter the file name. This mean that the Include/Exclude pattern always needs to be in lower case. For example, in order to exclude the package named 'HAL' (all upper case letters in the remote repository), you will need to set the exclude pattern – .pypi/hal.*.