用于PyBuilder生成基本项目结构的外部插件
pybuilder-archetype-base的Python项目详细描述
PyBuilder原型基插件
这个插件生成一个没有主要依赖关系的基本公共结构。主要的想法是得到一个可以 用于任何类型的Python模块。它稍微修改了PyBuilder结构逻辑,删除了一些使 它更少Java like。在
在下图中,create_archetype_base
期间创建的每个目录和文件:
bin docs src └── package_name ├── config # For any kind of configuration files or constants | ├── logger | | └── logger.yml | ├── __init__.py | ├── constants.py | └── messages.py ├── core # Logic of the project itself | └── __init__.py ├── errors # For every custom exception made | ├── core # Make as many scripts as packages in core (i.e. processing.py for core.processing) | | └── __init__.py | └── __init__.py ├── utils # For any kind of util used in the project | ├── logging | | ├── __init__.py | | └── handlers.yml # For custom logging handles (i.e. database logging) | ├── __init__.py | └── helpers.py └── __init__.py tests ├── __init__.py └── example_test.py .gitignore LICENSE # Empty file README.md requirements.txt setup.py
其他PyBuilder插件依赖于PyBuilder_archetype_base,其中包括其他更具体的包。 这些插件包括:
- pybuilder_archetype_api:对于专注于web服务的项目
- (WIP)
pybuilder_archetype_db:对于使用数据库的项目
如何使用pybuilder_archetype_base
NOTICE: This plugin only works on Windows due to its dependency with pybuilder_pycharm_workspace PyBuilder plugin. Using this plugin in other OS shall not work properly. Multi-platform support soon.
将插件依赖项添加到build.py
(它需要pybuilder_pycharm_workspace
正常工作):
{cd3>在函数中配置插件:
@initdefinitialise(project):project.set_property('project_base_path',project_path)project.set_property('pycharm_workspace_project_path',project_path)
这将告诉插件哪个是文件系统中的项目位置。project_base_path
属性值应为
总是一样的。它也需要通知pycharm_workspace_project_path
,以便获得
pybuilder_pycharm_工作区正在工作。在
启动任务时使用:
(venv)C:\Users\foo\PycharmProjects\bar> pyb create_archetype_base
build.py
推荐的文件
此插件不包括build.py
文件,因为在执行pyb
时应该已经有一个文件了
命令。下面的模板可以和这个插件一起使用。根据需要进行修改。在
frompathlibimportPathfrompybuilder.coreimportuse_plugin,init,Author,beforeuse_plugin('python.core')use_plugin('python.distutils')use_plugin('python.flake8')use_plugin('python.unittest')use_plugin('pypi:pybuilder_pycharm_workspace')use_plugin('pypi:pybuilder_archetype_base')project_path=Path(__file__).resolve().parentname=project_path.nameauthors=[Author("foo",'bar')]license="Apache License, Version 2.0"version='1.0.0'@initdefinitialise(project):project.depends_on_requirements('requirements.txt')project.set_property('dir_source_main_python','src')project.set_property('dir_source_unittest_python','tests')project.set_property('unittest_module_glob','test_*')project.set_property('project_base_path',project_path)project.set_property('pycharm_workspace_project_path',project_path)@init(environments='develop')definitialise_dev(project):project.version=f'{project.version}.dev'project.set_property('flake8_verbose_output',True)@init(environments='production')definitialise_pro(project):project.set_property('flake8_break_build',True)project.set_property('flake8_include_test_sources',True)@before('prepare')defpack_files(project):""" Includes non-Python files in the build. :param pybuilder.core.Project project: PyBuilder project instance :return: None """package_path=list(Path(project.get_property('dir_source_main_python')).glob('*'))[0]resources_paths=sorted(package_path.glob('**'))[1:]project.package_data.update({package_path.name:[str((path.relative_to(package_path)/'*').as_posix())forpathinresources_paths]})
{{cda4}的例子 插件自述,以满足它的需要。在
属性
插件的下一个属性是提供的默认值
Name | Type | Default Value | Description |
---|---|---|---|
project_base_path | Path | None | Project's path in filesystem (same as ^{ |
- 项目
标签: