aedev.project_vars
project development variables
this portion of the aedev namespace is providing constants and helper functions to keep your projects
DRY. this is done by bundling all development
environment properties and settings of your project without any redundancies. e.g. the short
description/title or the version number of a project is maintained and can be changed in one (!) single place.
the following Python project types are supported:
GUI applications
Django web applications
console app and library modules
console app and library packages
namespace library portions
namespace roots
source code parent folders
playgrounds
project development variables data includes:
project name, version, title and description
virtual environment (pyenv)
contributing author name and email
project documentation (README, manuals, contribution docs, license)
external dependencies/requirements
project file templates
repository status, branches and tags (git)
repository remote urls and CI (GitLab or GitHub)
deployment remotes (web servers, cloud storage, PyPi-release of project and its namespace children|portions)
setup (pip and setuptools)
determine project development variables
the ProjectDevVars class provided by this portion is a dictionary subclass that represents the project
development variables. On instantiation, it is analyzing the project folder, collecting defaults, merging environment
variables, and compiles values suitable for packaging and publishing.
to collect the data of a project, create a new instance of this class:
pdv = ProjectDevVars()
for existing projects no arguments are needed if the current working directory is the project root folder. in order
to analyze a project in any other directory specify the path via the
project_path keyword argument:
pdv = ProjectDevVars(project_path='path/to/project_or_parent')
the project property values can be retrieved from the returned dictionary-like instance,
either via the method pdv_val() (used mainly for non-string values),
or directly via getitem. the following example is retrieving a string reflecting the name of the project:
project_name = pdv['project_name']
the type of project gets mapped by the ‘project_type’ project development variable.
recognized project types are e.g. a module, a package,
a namespace root, or an gui application.
determining the project development variables of projects with the types PARENT_PRJ
or ROOT_PRJ will gather also the project dev vars of their containing children projects.
these children dev variables are stored as list in the parent project development
variable children_project_vars, where each item is an instance of the ProjectDevVars class,
representing a child project.
key methods of a ProjectDevVars instance
ProjectDevVars.as_dict()– export pdv values as a plain dict.ProjectDevVars.copy()– create a newProjectDevVarswith copied values.ProjectDevVars.errors()– validate pdv values and return a list of errors/warnings.ProjectDevVars.pdv_val()– fetch a variable’s value, falling back to defaults.
project introspection helpers and constants
these standalone functions provide utilities for inspecting Python source code files and project environments.
editable_project_root_path(): determines the project path of a package installed in an editable mode
(e.g., via pip install -e).
* find_extra_modules(): determines a list of additional module names within a local package,
excluding templates and __init__.py files.
* increment_version(): increments a semantic version string (e.g., major, minor, or patch part).
* latest_remote_version() – determine the latest or next available version tag from git remotes.
* main_file_path() – compute the expected main/version file path for a project type.
* pdv_default_values() – collect default pdv values from module globals.
* pdv_env_values() – load pdv values from environment variables.
* project_owner_name_version() – split a project string into owner, name, and version.
* root_packages_masks() – return package glob masks for root packages.
* skip_files_migrations() – filter callback to exclude django migrations.
* skip_files_lean_web() – filter callback to minimize files for web deployment.
* replace_file_version() – update a file’s version string in place.
project development variable value constants
PDV_APP_BUILD_CFG_FILENAME: the name of the application building configuration file (e.g. buildozer.spec).
PDV_COMMIT_MSG_FILE_NAME: the default file name for a git commit message.
PDV_DOCS_FOLDER: the default folder name for documentation (e.g., docs).
PDV_DOCS_HOST_PROTOCOL: the default protocol for the documentation host (e.g., https://).
PDV_docs_domain: the default dns domain for documentation (e.g., readthedocs.io).
PDV_KEYWORDS: a list of default keywords for :pypi:`pypi` release metadata.
PDV_LICENSE: the default license for the project (e.g., gpl-3.0-or-later, PEP 639).
PDV_MAIN_BRANCH: the default name for the main branch in a git repository.
PDV_MIN_PYTHON_VERSION: the minimum version of the python runtime required for the project (e.g., 3.9).
PDV_NULL_VERSION: the initial package version, chosen to meet :pypi:`pypi` classifier requirements.
PDV_PARENT_FOLDERS: a tuple of common names for parent folders that contain python project directories.
PDV_PYTHON_REQUIRES: the default required python version string for setup files (e.g., >=3.9).
PDV_RELEASE_REF_PREFIX: the prefix for project release branch names or references.
PDV_REMOTE_ORIGIN: the name of the git remote from which the local repository was cloned.
PDV_REMOTE_UPSTREAM: the name of the git remote for the fork’s source repository.
PDV_REPO_HOST_PROTOCOL: the default protocol for the code repository host (e.g., https://).
PDV_repo_domain: the default dns domain for the code repository (e.g., gitlab.com).
PDV_REPO_PAGES_DOMAIN: the internet/dns domain for repository pages (e.g., gitlab.io).
PDV_REPO_GROUP_SUFFIX: the suffix used for the default repository users group name.
PDV_REPO_ISSUES_SUFFIX: the url suffix for the repository’s issues page (e.g., /-/issues).
PDV_REQ_FILE_NAME: the default filename for the main project dependencies (e.g., requirements.txt).
PDV_REQ_DEV_FILE_NAME: the default filename for development or template-specific requirements.
PDV_TEMPLATES_FOLDER: the default folder name for file templates (e.g., templates).
PDV_TESTS_FOLDER: the default folder name for unit tests (e.g., tests).
PDV_VERSION_TAG_PREFIX: the prefix for git version tags.
configure individual project development variable values
this portion is providing default values for most of the project development variables. individual default values can be configured as OS/shell/console environment variables.
for projects released at PyPI at least the author name and a contact email address should be configured,
because their default values (in PDV_AUTHOR and PDV_AUTHOR_EMAIL) are empty strings.
the package data resources of a project gets determined by the method _find_package_data(). the return
value gets directly passed to the package_data development variable, which will be used to create
the setup.py file of your project (as kwarg passed to setuptools.setup()).
Module Attributes
used for env var names and the constant names declared in this module |
|
name of the git commit message file |
|
app building config file |
|
docs folder name |
|
documentation host connection protocol |
|
documentation dns domain |
|
PyPi release keywords |
|
project license default (PEP 639) |
|
default main branch name |
|
minimum version of the Python/CPython runtime |
|
initial package version (3==min classifier accepted by PyPI) |
|
names of parent folders containing Python project directories |
|
repo host connection protocol |
|
code repository dns domain (gitlab.com|github.com) |
|
repository pages internet/dns domain |
|
repo users group name suffix (used for 'repo_group' default) |
|
repo host URL suffix to the issues page (GitHub=="/issues") |
|
requirements default file name |
|
default file name for development/template requirements |
|
templates folder name |
|
unit tests folder name |
|
project release branch-name/ref prefix |
|
project version tag prefix |
|
name of git remote from where the local repo get cloned from |
|
name of git remote from where the fork repo get forked from |
|
children pdv of a project parent or a namespace root |
|
setup_kwargs['data_files'] |
|
setup_kwargs['package_data'] |
|
setuptools.setup()-kwargs |
|
project development variable value types, including also types of later/externally added vars by pjm, like e.g. 'TemplateProjectsType' for the 'project_templates' variable, or 'RemoteHost' for the 'host_api' variable, or dict[str, str] for the 'main_app_options' variable (already covered via SetupKwargsType/dict[str, Any]. |
Functions
|
determine additional modules of a local (namespace portion) package/project. |
|
check if a frozen requirements.txt file exists (with version numbers). |
|
increment version number. |
|
determine the latest or the next free origin remote repository version of the specified project. |
|
return the file path of the main/version type for the specified project type. |
collect the ProjectDevVars defaults from the globals of this module. |
|
read pdv default values from environment variables. |
|
|
guess name of project name from project root directory path (also for backups under old_src parent directory). |
|
split the specified project string into its owner user|group name, the project name, and the project version. |
|
replace version number in specified project main/version file, removing any pre/alpha version subpart/suffix. |
|
determine root sub packages from the passed project packages and add them glob path wildcards. |
|
file exclusion callback to reduce the deployed files on the web server to the minimum. |
|
file exclusion callback for the files under the django migrations folders. |
Classes
|
project development variables mapping. |
- ENV_VAR_NAME_PREFIX = 'PDV_'
used for env var names and the constant names declared in this module
- PDV_COMMIT_MSG_FILE_NAME = '.commit_msg.txt'
name of the git commit message file
- PDV_APP_BUILD_CFG_FILENAME = 'buildozer.spec'
app building config file
- PDV_DOCS_FOLDER = 'docs'
docs folder name
- PDV_DOCS_HOST_PROTOCOL = 'https://'
documentation host connection protocol
- PDV_docs_domain = 'readthedocs.io'
documentation dns domain
- PDV_KEYWORDS = ['configuration', 'development', 'environment', 'productivity']
PyPi release keywords
- PDV_MAIN_BRANCH = 'develop'
default main branch name
- PDV_MIN_PYTHON_VERSION = '3.12'
minimum version of the Python/CPython runtime
- PDV_NULL_VERSION = '0.3.0'
initial package version (3==min classifier accepted by PyPI)
- PDV_PARENT_FOLDERS = ('Projects', 'PycharmProjects', 'ae-group', 'aedev-group', 'code', 'dev', 'esc', 'old_src', 'projects', 'python', 'repos', 'source', 'src', 'TsT', 'docs')
names of parent folders containing Python project directories
- PDV_REPO_HOST_PROTOCOL = 'https://'
repo host connection protocol
- PDV_repo_domain = 'gitlab.com'
code repository dns domain (gitlab.com|github.com)
- PDV_REPO_PAGES_DOMAIN = 'gitlab.io'
repository pages internet/dns domain
- PDV_REPO_GROUP_SUFFIX = '-group'
repo users group name suffix (used for ‘repo_group’ default)
- PDV_REPO_ISSUES_SUFFIX = '/-/issues'
repo host URL suffix to the issues page (GitHub==”/issues”)
- PDV_REQ_FILE_NAME = 'requirements.txt'
requirements default file name
- PDV_REQ_DEV_FILE_NAME = 'dev_requirements.txt'
default file name for development/template requirements
- PDV_TEMPLATES_FOLDER = 'templates'
templates folder name
- PDV_TESTS_FOLDER = 'tests'
unit tests folder name
- PDV_RELEASE_REF_PREFIX = 'release'
project release branch-name/ref prefix
- PDV_VERSION_TAG_PREFIX = 'v'
project version tag prefix
- PDV_REMOTE_ORIGIN = 'origin'
name of git remote from where the local repo get cloned from
- PDV_REMOTE_UPSTREAM = 'upstream'
name of git remote from where the fork repo get forked from
- ChildrenType
children pdv of a project parent or a namespace root
alias of
OrderedDict[str,ProjectDevVars]
- PdvVarValType
project development variable value types, including also types of later/externally added vars by pjm, like e.g. ‘TemplateProjectsType’ for the ‘project_templates’ variable, or ‘RemoteHost’ for the ‘host_api’ variable, or dict[str, str] for the ‘main_app_options’ variable (already covered via SetupKwargsType/dict[str, Any].
alias of
str|Sequence[str] |list[tuple[str,tuple[str, …]]] |dict[str,str] |dict[str,Any] |list[dict[str,str]] |RemoteHost
- find_extra_modules(package_path, tpls_folder)[source]
determine additional modules of a local (namespace portion) package/project.
- Parameters:
- Return type:
- Returns:
list of module import name strings (without file extension and path separators as dots). modules in
PDV_TEMPLATES_FOLDERas well asPY_INITmodules are excluded.
- frozen_req_file_path(req_file_path='requirements.txt', strict=False)[source]
check if a frozen requirements.txt file exists (with version numbers).
- Parameters:
- Return type:
- Returns:
path of the frozen version of the specified *requirements.txt file (in the same folder) or if no frozen version exists: an empty string (if strict got specified as True), or (if strict is False) the specified path of the (normal|un-frozen) requirements-file.
- latest_remote_version(pdv, increment_part=3)[source]
determine the latest or the next free origin remote repository version of the specified project.
- Parameters:
pdv¶ (
ProjectDevVars) – project development variables (project_path, project_version, VERSION_TAG_PREFIX).increment_part¶ (
int) – part of the version number to be incremented (1=mayor, 2=minor/namespace, 3=patch). pass zero/0 to return the latest published package version.
- Return type:
- Returns:
the incremented latest published repository package version as a string or the first version accepted by PyPI (increment_version(PDV_NULL_VERSION, increment_part) | “0.3.1”) if the project never published a version tag to the git origin remote.
- main_file_path(project_path, project_type, namespace_name='')[source]
return the file path of the main/version type for the specified project type.
- Parameters:
- Return type:
- Returns:
main file path and name.
Note
in contrary to
project_main_file()this function will also work for new projects where neither exists the main file nor the project root folder.
- project_name_guess(project_path, stripped_name='')[source]
guess name of project name from project root directory path (also for backups under old_src parent directory).
- project_owner_name_version(project_string, owner_default='', namespace_default='', version_default='')[source]
split the specified project string into its owner user|group name, the project name, and the project version.
- Parameters:
- Return type:
- Returns:
tuple with owner name, project name and project version
- replace_file_version(file_name, version='', increment_part=3)[source]
replace version number in specified project main/version file, removing any pre/alpha version subpart/suffix.
- Parameters:
file_name¶ (
str) – version file name to be patched/version-bumped.version¶ (
str) – version number to increment/bump (if the argumentincrement_partis not 0) and to replace/put into the version file. defaults to the version number in the version file, if not specified.increment_part¶ (
int) – part of the version number to be incremented: 1=mayor, 2=minor, 3=build/revision. specify 0 to not increment the version number. defaults to 3 (build) if not specified.
- Return type:
- Returns:
empty string on success, else error string.
- root_packages_masks(project_packages)[source]
determine root sub packages from the passed project packages and add them glob path wildcards.
- skip_files_lean_web(file_path)[source]
file exclusion callback to reduce the deployed files on the web server to the minimum.
- skip_files_migrations(file_path)[source]
file exclusion callback for the files under the django migrations folders.
- class ProjectDevVars(**var_values)[source]
Bases:
dict[str,str|Sequence[str] |list[tuple[str,tuple[str, …]]] |dict[str,str] |dict[str,Any] |list[dict[str,str]] |RemoteHost]project development variables mapping.
- __init__(**var_values)[source]
analyze and map the environment and status of a code project into project development variables.
- Parameters:
var_values¶ – fixed dev var values, overwriting OS environment variables and defaults. to get the project dev variable values from an existing project pass the project_path kwarg with the path of the project root folder. the project root path defaults to the current working directory, if the kwargs project_path and project_name are not specified; if only project_name is specified then it defaults to the folder with the project name situated underneath the current working directory.
- Raises:
AssertionError if both kwargs project_path and project_name are specified.
- Returns:
special mapping with all the determinable project development variable values.
- disable_non_string_fetch_warning
set to True to disable warning on access to non-str-item-value
- __getitem__(var_name)[source]
get the string value of the project development variable with the specified var name.
- Parameters:
- Return type:
- Returns:
string value of the specified pdv (other types are returned too, but a warning will be displayed in this case). or if not exists in
pdvthen the global constant/default value of this module, or any empty string if no constant with this name exists.
- _find_package_data()[source]
find doc, template, kv, i18n translation text, image and sound files of an app/package.
- Return type:
- Returns:
setuptools package_data dict, where the key is an empty string (to be included for all sub-packages) and the dict item is a list of all found resource files with a relative path to the
package_pathdirectory. folder names with a leading underscore (like e.g. the docs _build, thePY_CACHE_FOLDER`|`__pycache__and the __enamlcache__ folders) get excluded. explicitly included will be anyPDV_APP_BUILD_CFG_FILENAMEfile, as well as any folder name starting withPACKAGE_INCLUDE_FILES_PREFIX(used e.g. byae.updater), situated directly in the directory specified bypackage_path.
- _init_project_type()[source]
determine project type from project_path, project_name, namespace_name, portion_name and version_file.
- Return type:
- _load_descriptions()[source]
load long description from the README file of the project.
- Parameters:
self¶ – dict of project development variables with a ‘project_path’ key.
- _load_requirements()[source]
load requirements from the available requirements.txt file(s) of this project.
- Parameters:
self¶ –
project development variables instance with the following required project dev vars: DOCS_FOLDER, REQ_FILE_NAME, REQ_DEV_FILE_NAME, TESTS_FOLDER, namespace_name, project_name, project_path.
the project env vars overwritten in this argument by this function are: dev_requires, docs_requires, install_requires, portions_packages, tests_requires.
- children_app_options()[source]
determine the main app options needed for to initialize its children w/o ‘project_name’ and ‘project_path’.
- __orig_bases__ = (dict[str, typing.Union[str, typing.Sequence[str], list[tuple[str, tuple[str, ...]]], dict[str, str], dict[str, typing.Any], list[dict[str, str]], ForwardRef('RemoteHost')]],)
- errors(warnings_as_error=False)[source]
checks the completeness and integrity of the project development variable values.