Skip to main content

Generate python package

Project description

Package Generate

一个简单的 Python 包框架生成器,目的是为了方便快速构建一个全局命令行参数。而不必每次都构建类似的结构和去敲那些类似的代码。

安装

通过 pypi 安装

pip install package-gen

或者通过本地安装。进入 pyproject.toml 路径,运行

pip install .

使用方式

在安装完成后,获得一个全局命令:pk-gen

$pk-gen -h
usage: pk-gen [-h] [-l | --name NAME | --template-dir TEMPLATE_DIR]
             [packagename]

generate python package

positional arguments:
 packagename           the package name

optional arguments:
 -h, --help            show this help message and exit
 -l, --list            list the default template names and exit
 --name NAME           use the default template from name
 --template-dir TEMPLATE_DIR
                       custom template directory path

举例说明

最小使用

$pk-gen mytest

将会在当前路径下生成一个标准 python package

└─mytest
    │  pyproject.toml
    │
    └─mytest
            main.py
            __init__.py
            __main__.py

可以在 pyproject.toml 中自定义自己需要的全局命令,将 your_custom_command 换成自己需要的命令即可。所生成的模块即可直接通过 pip install . 安装,或者 pip install -e . 进行实时调试。

# pyproject.toml
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "$packagename"
version = ""
authors = [
    { name = "", email = "" }
]
description = ""
readme = "README.md"
requires-python = ">=3.8"

[project.urls]
Homepage = ""

[project.scripts]
your_custom_command="$packagename_format:main"
# main.py
import argparse


def main():
    parser = argparse.ArgumentParser(description='')

    # add argparse parameters here

    args = parser.parse_args()

    # handle arguments

目前内置有多个模板,默认模板为 base。通过 pk-gen -l 可以查看当前内置的可使用的所有模板名。可以将模板拷贝出去自己订制,将 --template-dir 参数指向自己自定义的模板位置即可。

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

package_gen-1.0.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

package_gen-1.0.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file package_gen-1.0.0.tar.gz.

File metadata

  • Download URL: package_gen-1.0.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.6

File hashes

Hashes for package_gen-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7cddf0152d6392d716b7b6a8624b073fcad0061b428652175972dba5be32ce83
MD5 f5d52872d246873468c9dcdeb0f977fe
BLAKE2b-256 efe8372c2a6aa735492356c6a7c505c8f8a6386553db95805dc036a32659f46e

See more details on using hashes here.

File details

Details for the file package_gen-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: package_gen-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.6

File hashes

Hashes for package_gen-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9112a04cbb4f186d6e05fc8f3f7922ec5f975e2bbb0188c28cf2e17aa01d5cfd
MD5 81d44214930ec81b8dcc89a8a5d94e15
BLAKE2b-256 ad07cc65d2b3e3571893cad284c31f8317944ba9cddae5babd8f19081aaba005

See more details on using hashes here.

Supported by

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