Support custom PyPI repositories
This commit is contained in:
parent
c5ce7fa86a
commit
4686cfeccc
2 changed files with 25 additions and 9 deletions
|
@ -246,6 +246,7 @@ Drone currently has these `deploy` and `publish` plugins implemented (more to co
|
||||||
**publish**
|
**publish**
|
||||||
- [Amazon s3](#docs)
|
- [Amazon s3](#docs)
|
||||||
- [OpenStack Swift](#docs)
|
- [OpenStack Swift](#docs)
|
||||||
|
- [PyPI](#docs)
|
||||||
|
|
||||||
### Notifications
|
### Notifications
|
||||||
|
|
||||||
|
|
|
@ -10,17 +10,18 @@ var pypirc = `
|
||||||
cat <<EOF > $HOME/.pypirc
|
cat <<EOF > $HOME/.pypirc
|
||||||
[distutils]
|
[distutils]
|
||||||
index-servers =
|
index-servers =
|
||||||
pypi
|
%s
|
||||||
|
|
||||||
[pypi]
|
[%s]
|
||||||
username:%s
|
username:%s
|
||||||
password:%s
|
password:%s
|
||||||
|
%s
|
||||||
EOF`
|
EOF`
|
||||||
|
|
||||||
var deployCmd = `
|
var deployCmd = `
|
||||||
if [ -z $_PYPI_SETUP_PY ]
|
if [ -n "$_PYPI_SETUP_PY" ]
|
||||||
then
|
then
|
||||||
python $_PYPI_SETUP_PY sdist %s upload
|
python $_PYPI_SETUP_PY sdist %s upload -r %s
|
||||||
if [ $? -ne 0 ]
|
if [ $? -ne 0 ]
|
||||||
then
|
then
|
||||||
echo "Deploy to PyPI failed - perhaps due to the version number not being incremented. Continuing..."
|
echo "Deploy to PyPI failed - perhaps due to the version number not being incremented. Continuing..."
|
||||||
|
@ -31,27 +32,41 @@ fi
|
||||||
`
|
`
|
||||||
|
|
||||||
type PyPI struct {
|
type PyPI struct {
|
||||||
Username string `yaml:"username,omitempty"`
|
Username string `yaml:"username,omitempty"`
|
||||||
Password string `yaml:"password,omitempty"`
|
Password string `yaml:"password,omitempty"`
|
||||||
Formats []string `yaml:"formats,omitempty"`
|
Formats []string `yaml:"formats,omitempty"`
|
||||||
|
Repository string `yaml:"repository,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PyPI) Write(f *buildfile.Buildfile) {
|
func (p *PyPI) Write(f *buildfile.Buildfile) {
|
||||||
|
var indexServer string
|
||||||
|
var repository string
|
||||||
|
|
||||||
if len(p.Username) == 0 || len(p.Password) == 0 {
|
if len(p.Username) == 0 || len(p.Password) == 0 {
|
||||||
// nothing to do if the config is fundamentally flawed
|
// nothing to do if the config is fundamentally flawed
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle the setting a custom pypi server/repository
|
||||||
|
if len(p.Repository) == 0 {
|
||||||
|
indexServer = "pypi"
|
||||||
|
repository = ""
|
||||||
|
} else {
|
||||||
|
indexServer = "custom"
|
||||||
|
repository = fmt.Sprintf("repository:%s", p.Repository)
|
||||||
|
}
|
||||||
|
|
||||||
f.WriteCmdSilent("echo 'publishing to PyPI...'")
|
f.WriteCmdSilent("echo 'publishing to PyPI...'")
|
||||||
|
|
||||||
// find the setup.py file
|
// find the setup.py file
|
||||||
f.WriteCmdSilent("_PYPI_SETUP_PY=$(find . -name 'setup.py')")
|
f.WriteCmdSilent("_PYPI_SETUP_PY=$(find . -name 'setup.py')")
|
||||||
|
|
||||||
// build the .pypirc file that pypi expects
|
// build the .pypirc file that pypi expects
|
||||||
f.WriteCmdSilent(fmt.Sprintf(pypirc, p.Username, p.Password))
|
f.WriteCmdSilent(fmt.Sprintf(pypirc, indexServer, indexServer, p.Username, p.Password, repository))
|
||||||
formatStr := p.BuildFormatStr()
|
formatStr := p.BuildFormatStr()
|
||||||
|
|
||||||
// if we found the setup.py file use it to deploy
|
// if we found the setup.py file use it to deploy
|
||||||
f.WriteCmdSilent(fmt.Sprintf(deployCmd, formatStr))
|
f.WriteCmdSilent(fmt.Sprintf(deployCmd, formatStr, indexServer))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PyPI) BuildFormatStr() string {
|
func (p *PyPI) BuildFormatStr() string {
|
||||||
|
|
Loading…
Reference in a new issue