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.9.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

merge_functions-0.0.9-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: merge_functions-0.0.9.tar.gz
  • Upload date:
  • Size: 5.4 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.9.tar.gz
Algorithm Hash digest
SHA256 5d35f6bc70ae6c6ef01aefff0ed85847bd976f3bd0ffb4b07d933fb8a6e35a4d
MD5 98513a86f96e48d06c5e402b3e4c1c1a
BLAKE2b-256 30321ff5b752be2377aee2d6152c1952ad07c108f20b36fd82a8f89e3155441d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: merge_functions-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • 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.9-py3-none-any.whl
Algorithm Hash digest
SHA256 9870a09613bfe25f9a96e9c71da8b08acca3a0407d20497f79e51aaba2be80a5
MD5 6e6f244a24087a7a7d50f56dbec97b8a
BLAKE2b-256 f2d0f7ad37586853deb7234b72494f10c12298d646acaf431cfa0955a89f1ce4

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