我正在pipenv使用a small project。代码看起来可能有用,我想通过pypi分发它。我在pipenv网页或其github repo上找不到任何有关如何实现此目的的指导。
我可以将Pipfile.lock
中的依赖项放入setup.py
的{{3}},但我找不到自动执行此操作的工具,并且手动执行此操作不会由DRY执行
有没有人有更好的建议?
答案 0 :(得分:0)
这似乎对我有用:
import os
from setuptools import setup, find_packages
import json
def get_requirements_from_pipfile_lock(pipfile_lock=None):
if pipfile_lock is None:
pipfile_lock = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Pipfile.lock')
lock_data = json.load(open(pipfile_lock))
return [package_name for package_name in lock_data.get('default', {}).keys()]
packages = find_packages('.', exclude=['*.test', '*.test.*'])
pipfile_lock_requirements = get_requirements_from_pipfile_lock()
setup(
name='my_package',
version='0.0.1',
packages=packages,
license='MIT',
long_description=open('README.md').read(),
install_requires=pipfile_lock_requirements,
python_requires=">=3.5",
)
答案 1 :(得分:0)
支持外部git依赖关系和版本。我已经更新了winni2kk代码。
import os
from setuptools import setup, find_packages
import json
def get_requirements_from_pipfile_lock(pipfile_lock=None):
if pipfile_lock is None:
pipfile_lock = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Pipfile.lock')
lock_data = json.load(open(pipfile_lock))
retval = []
for package_name, package_data in lock_data.get('default', {}).items():
if package_data.get('file'):
package_ref = f'{package_name} @ {package_data["file"]}'
else:
package_ref = f'{package_name}{package_data["version"]}'
retval.append(package_ref)
return retval
packages = find_packages('.', exclude=['*.test', '*.test.*'])
pipfile_lock_requirements = get_requirements_from_pipfile_lock()
setup(
name='my_package',
version='0.0.1',
packages=packages,
license='MIT',
long_description=open('README.md').read(),
install_requires=pipfile_lock_requirements,
python_requires=">=3.5",
)
重要说明:在MANIFEST.in中包含Pipfile.lock,例如:
包括Pipfile.lock