Skip to main content

PyBuilder Archetype Base Plugin

This plugin generates a base common structure with no major dependecies. The main idea is to get an skeleton that can be used for any kind of Python module. It modifies PyBuilder structure logic lightly, removing some packages making it less Java-like.

In the following diagram there is every directory and file created during 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

There are other PyBuilder plugins that depend on pybuilder_archetype_base that include other more specific packages. These plugins are:

How to use 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.

Add plugin dependencies to your build.py (it requires pybuilder_pycharm_workspace to work properly):

use_plugin('pypi:pybuilder_archetype_base')
use_plugin('pypi:pybuilder_pycharm_workspace')

Configure the plugin within your init function:

@init
def initialise(project):
    project.set_property('project_base_path', project_path)
    project.set_property('pycharm_workspace_project_path', project_path)

This will tell the plugin which is the project location in the filesystem. project_base_path property value should be always the same. It is needed to inform pycharm_workspace_project_path too in order to get pybuilder_pycharm_workspace working.

Launch the task with:

(venv) C:\Users\foo\PycharmProjects\bar> pyb create_archetype_base

build.py file recommended

This plugin doesn't include a build.py file due to there should be already one at the moment of the execution of pyb command. The following template can be used along this plugin. Modify as desired.

from pathlib import Path

from pybuilder.core import use_plugin, init, Author, before


use_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().parent

name = project_path.name
authors = [Author("foo", 'bar')]
license = "Apache License, Version 2.0"
version = '1.0.0'


@init
def initialise(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')
def initialise_dev(project):
    project.version = f'{project.version}.dev'
    project.set_property('flake8_verbose_output', True)


@init(environments='production')
def initialise_pro(project):
    project.set_property('flake8_break_build', True)
    project.set_property('flake8_include_test_sources', True)


@before('prepare')
def pack_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()) for path in resources_paths] })

Take note of build.py example on pybuilder_pycharm_workspace plugin README to cover its needs too.

Properties

Plugin has next properties with provided defaults

Name Type Default Value Description
project_base_path Path None Project's path in filesystem (same as build.py file). Mandatory

Release files for pybuilder-archetype-base 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pybuilder-archetype-base 0.1.1
File Size Uploaded
pybuilder-archetype-base-0.1.1.tar.gz 13.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pybuilder-archetype-base 0.1.1
File Interpreter ABI Platform
pybuilder_archetype_base-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 30.7 kB

Release files / pybuilder-archetype-base-0.1.1.tar.gz

Download URL pybuilder-archetype-base-0.1.1.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e6be40eb54190b7653f9b4e18fc47ea6aceb714f65fecc982bc0baf5a06b29ad
BLAKE2b-256 checksum
How to use checksums
88159aef5475d98270b3c38d4354b54908d8b8d5f619a60b5cc0edb1a4600852
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3

Release files / pybuilder_archetype_base-0.1.1-py3-none-any.whl

Download URL pybuilder_archetype_base-0.1.1-py3-none-any.whl
Size 17.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
22595323db95309fce733c5adb0ee0e052a1fe621e73101da6c9c499357225a3
BLAKE2b-256 checksum
How to use checksums
980cc0eb3957a3e56f20ac6347932c94b6f6784a44216789ff55bdb24360ef9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page