我想为我的python包实现以下两个功能,它包含setup.py并使用setuptools:
首先,我通常会这样做:
pip install -e . --user
它工作正常。
对于第二个,我在setup.py中执行:
from __future__ import print_function
from setuptools import setup
from setuptools.command.install import install
import os
class CustomInstallCommand(install):
def run(self):
print ("Custom code here")
install.run(self)
setup(...,
packages=['package_name'],
package_dir={'package_name':'package_name'},
cmdclass={'install': CustomInstallCommand},
zip_safe=False)
然而,我发现:
如果我这样做,自定义代码会运行:
python setup.py install --user
但我不确定如何将此命令与等效-e
选项一起使用,以便安装符号链接而不是文件副本。我怎样才能实现这两个目标?
答案 0 :(得分:1)
那是因为python setup.py install
不会被调用。有两种模式可供选择:
python setup.py develop
调用“真实”安装模式并复制源develop
调用,只会为来源创建符号链接。所以你必须覆盖install
命令,就像使用from setuptools.command.develop import develop
...
class CustomDevInstallCommand(develop):
def run(self):
print('running custom develop command')
super(CustomDevInstallCommand, self).run()
setup(
...,
cmdclass={
'install': CustomInstallCommand,
'develop': CustomDevInstallCommand,
},
)
一样:
pip install --editable .
通过$ pip install --editable . -v
Created temporary directory: /private/var/folders/_y/2qk6029j4c7bwv0ddk3p96r00000gn/T/pip-ephem-wheel-cache-1yw7baz2
...
Installing collected packages: spam
Running setup.py develop for spam
Running command python -c "import setuptools"
Running command /Users/hoefling/.virtualenvs/stackoverflow/bin/python -c "import setuptools, tokenize;__file__='/Users/hoefling/projects/private/stackoverflow/so-49326214/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" develop --no-deps
running develop
running custom develop command
running egg_info
...
Successfully installed spam
Cleaning up...
安装产生:
$ResourceGroupName = "group"
$ServerName = "serverName"
$DatabaseName = "databaseName"
$StorageKeyType = "StorageAccessKey"
$StorageKey = "storageKey"
$StorageUri = "storageUri"
$AdminLogin = "admin"
$AdminPassword = (ConvertTo-SecureString "12345" -AsPlainText -Force)
New-AzureRmSqlDatabaseExport `
-AdministratorLogin $AdminLogin `
-AdministratorLoginPassword $AdminPassword `
-DatabaseName $DatabaseName `
-ResourceGroupName $ResourceGroupName `
-ServerName $ServerName `
-StorageKey $StorageKey `
-StorageKeyType $StorageKeyType `
-StorageUri $StorageUri `