Skip to content

Commit

Permalink
feat: Define package main entry-point
Browse files Browse the repository at this point in the history
  • Loading branch information
artu-hnrq committed Aug 19, 2022
1 parent a743220 commit 13efb41
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Feat
- Structure package development start point
- Adopt a single-source package versioning strategy
- Define package main entry-point
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ build:: clean ## Process source code into package distributable artifacts
install:: uninstall ## Install on-developing package in current environment
$(PIP) install --editable .

run:: ## Execute package main entry-point
$(PYTHON) -m $(PACKAGE_MODULE)

TWINE_REPOSITORY=testpypi
publish:: build ## Upload distribution archives to python package index
$(PYTHON) -m twine upload \
Expand All @@ -74,4 +77,4 @@ veryclean:: uninstall clean ## Delete all generated files

.EXPORT_ALL_VARIABLES:
.ONESHELL:
.PHONY: help env init build install publish uninstall clean veryclean
.PHONY: help env init build install run publish uninstall clean veryclean
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ It also powers up python packing workflow by:
├── setup.cfg Package declarative configuration
└── src/
├── <package> Python package root folder
│ └── __init__.py Python package init script
│ ├── __init__.py Python package init script
│ └── __main__.py Package main entry-point
└── utils Auxiliary functions module
└── version.py PEP 440-compliant version management
```
Expand Down
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,6 @@ where = src
# A dictionary mapping entry point group names to strings or lists of strings defining the entry points
# Entry points are used to support dynamic discovery of services or plugins provided by a project
# See https://setuptools.pypa.io/en/latest/userguide/entry_point.html
;[options.entry_points]
;console_scripts =
[options.entry_points]
console_scripts =
run = python_package.__main__:main
20 changes: 20 additions & 0 deletions src/python_package/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Package main entry-point
#
# This file enables package to be executed as a python module
# See https://docs.python.org/3/library/__main__.html#main-py-in-python-packages.


import sys
from . import PACKAGE_NAME, __version__


def package_info():
return f'{PACKAGE_NAME} {__version__}'


def main():
print(package_info())


if __name__ == '__main__':
sys.exit(main())

0 comments on commit 13efb41

Please sign in to comment.