Skip to main content

External plugin for PyBuilder to generate a base project structure

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybuilder-archetype-base-0.1.1.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

pybuilder_archetype_base-0.1.1-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file pybuilder-archetype-base-0.1.1.tar.gz.

File metadata

  • Download URL: pybuilder-archetype-base-0.1.1.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for pybuilder-archetype-base-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e6be40eb54190b7653f9b4e18fc47ea6aceb714f65fecc982bc0baf5a06b29ad
MD5 02171a590920d2e037cd2f29f27a7db3
BLAKE2b-256 88159aef5475d98270b3c38d4354b54908d8b8d5f619a60b5cc0edb1a4600852

See more details on using hashes here.

File details

Details for the file pybuilder_archetype_base-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pybuilder_archetype_base-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for pybuilder_archetype_base-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 22595323db95309fce733c5adb0ee0e052a1fe621e73101da6c9c499357225a3
MD5 46bce6e0e0f1ae1b72a530f8b2a3abc8
BLAKE2b-256 980cc0eb3957a3e56f20ac6347932c94b6f6784a44216789ff55bdb24360ef9c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page