from setuptools import setup, find_packages
from os import path
from functools import partial
if __name__ == '__main__':
package_name = 'gen'
templates_join = partial(path.join, path.dirname(__file__), package_name,
'templates')
setup(
name=package_name,
test_suite=package_name + '.tests',
packages=find_packages(),
package_dir={package_name: package_name},
package_data={package_name: [templates_join('.gitignore')]}
)
.
├── gen
│ ├── __init__.py
│ ├── templates
│ │ ├── __init__.py
│ │ ├── .gitignore
└── setup.py
错误:无法复制&gen / ld / gen / templates / .gitignore':不存在或不存在常规文件
答案 0 :(得分:0)
请尝试使用abspath(split(__file__)[0])
。
from setuptools import setup, find_packages
from functools import partial
from os.path import join, abspath, split
if __name__ == '__main__':
package_name = 'gen'
templates_join = partial(join, abspath(split(__file__)[0]), 'gen', 'templates')
setup(
name=package_name,
test_suite=package_name + '.tests',
packages=find_packages(),
package_dir={package_name: package_name},
package_data={package_name: [templates_join('.gitignore')]}
)
让我知道它是否有效。
答案 1 :(得分:0)
确认在Linux和Windows上使用data_files
在virtualenv
内部/外部工作:
from setuptools import setup, find_packages
from os import path
from functools import partial
from pip import __file__ as pip_loc
if __name__ == '__main__':
package_name = 'gen'
templates_join = partial(path.join, path.dirname(__file__),
package_name, 'templates')
install_to = path.join(path.split(path.split(pip_loc)[0])[0],
package_name, 'templates')
setup(
name=package_name,
version='0.0.1',
test_suite=package_name + '.tests',
packages=find_packages(),
package_dir={package_name: package_name},
data_files=[(install_to, [templates_join('.gitignore'),
templates_join('logging.conf')])]
)