在设置包括.gitignore吗?-错误:不存在或不存在常规文件。

时间:2022-08-29 22:57:57

setup.py

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')]}
    )

Tree

.
├── gen
│   ├── __init__.py
│   ├── templates
│   │   ├── __init__.py
│   │   ├── .gitignore
└── setup.py

Error

error: can't copy 'gen/ld/gen/templates/.gitignore': doesn't exist or not a regular file

错误:无法复制的创/ ld /创/模板/。gitignore:不存在或不存在一个常规文件。

2 个解决方案

#1


0  

Try use abspath(split(__file__)[0]) instead.

尝试使用abspath(分裂(__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')]}
    )

Let me know if it's work.

如果是工作,请告诉我。

#2


0  

Confirmed that using data_files works inside/outside a virtualenv on Linux and Windows:

确认使用data_files在Linux和Windows的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')])]
    )

#1


0  

Try use abspath(split(__file__)[0]) instead.

尝试使用abspath(分裂(__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')]}
    )

Let me know if it's work.

如果是工作,请告诉我。

#2


0  

Confirmed that using data_files works inside/outside a virtualenv on Linux and Windows:

确认使用data_files在Linux和Windows的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')])]
    )