Skip to main content

merge functions from other python files

Project description

Merge functions from other python files

this is a dirty way to merge functions from other python files into one python file in order to deploy fast.

install merge_functions

using python 3.9

pip install merge_functions
pip install astunparse=1.6.3

how to use

if you want to import from current directory python file, you need set environment:

if you current path is: ~/code or D:\code

mac or linux:

export PYTHONPATH=~/code

windows

set PYTHONPATH=D:\code

help info

mf -h

simple example:

mf -i main.py -m demo

this will import need functions and classes

mf -i main.py -m demo -a
  • -i: input file
  • -m: modules or keywords in modules
  • -a: get all code from source file

then, demo's functions will merge into one.py

PS: the code you need merge from extra module must in from ... import ... statements

main.py below

from demo import add, subtract, multiply, divide
import json


def run():
    a, b = 3, 4
    result1 = add(a, b)
    result2 = subtract(a, b)
    result3 = multiply(a, b)
    result4 = divide(a, b)
    result_dict = {
        "result1": result1,
        "result2": result2,
        "result3": result3,
        "result4": result4,
    }
    print(json.dumps(result_dict))


if __name__ == "__main__":
    run()

demo.py below

def add(a, b):
    return a + b


def subtract(a, b):
    return a - b


def multiply(a, b):
    return a * b


def divide(a, b):
    return a / b if b else 0

Pycharm settings

External tools settings

Program

$PyInterpreterDirectory$/mf.exe

Arguments

-i $FilePath$ -m utils -a

Working directory

$ProjectFileDir$

Advanced Options

Synchronize files after exection
Open console for tool output

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

merge_functions-0.0.10.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

merge_functions-0.0.10-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file merge_functions-0.0.10.tar.gz.

File metadata

  • Download URL: merge_functions-0.0.10.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.9.7 Darwin/23.6.0

File hashes

Hashes for merge_functions-0.0.10.tar.gz
Algorithm Hash digest
SHA256 22882643bd7977b0690006b93f6eccf202113d6d234a9af0e55e83acbbcd8a0d
MD5 6d4314c89c9b1fe213c023dcad162535
BLAKE2b-256 77dda819e88d74b956df0d8a2286dab103a9f6b28a72a2dd630df0bf9be893ca

See more details on using hashes here.

File details

Details for the file merge_functions-0.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for merge_functions-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 75b9f6fb9fb497d7588bc0b2ba1da166f622648a4de606d286194e3cd81eebcf
MD5 15dc98a489d341b744187a9637a5fee8
BLAKE2b-256 fc70ea4e0858c4be00ebc17cd0e380015e437e3e892a9b21174b626ced2317dd

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