Skip to content

Commit

Permalink
Removed pycache and .pyc and pyo files
Browse files Browse the repository at this point in the history
  • Loading branch information
rembik committed Mar 8, 2024
1 parent bf2e0aa commit e58fd32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 0 additions & 2 deletions examples/function/function_app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import datetime
import sys
import os
from typing import List
import azure.functions as func
Expand All @@ -9,7 +8,6 @@
CertbotResult,
)
from acme_dns_azure.client import AcmeDnsAzureClient
import time

app = func.FunctionApp()

Expand Down
17 changes: 12 additions & 5 deletions examples/function/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def start_function():
def build():
add_plugins()
cmds = []
packages_path = "./.python_packages/lib/site-packages"
cmds.append(["pip", "install", "-q", "--upgrade", "pip"])
cmds.append(
[
Expand All @@ -105,19 +106,25 @@ def build():
"pip",
"install",
"-q",
"--target=./.python_packages/lib/site-packages",
"--target=" + packages_path,
"-r",
"requirements.txt",
]
)
for cmd in cmds:
subprocess.run(cmd, text=True, check=True, stderr=subprocess.STDOUT)

# Use more generic python interpreter for packaged modules
search = "#!{0}".format(os.path.abspath(str(sys.executable)))
for root, _, files in os.walk("./.python_packages/lib/site-packages"):
if root.endswith("bin"):
for file in files:
for root, dirs, files in os.walk(packages_path):
# Remove __pycache__ folders
if "__pycache__" in dirs:
shutil.rmtree(os.path.join(root, "__pycache__"))
for file in files:
# Remove .pyc, .pyo files
if file.endswith(".pyc") or file.endswith(".pyo"):
shutil.rmtree(os.path.join(root, file))
# Use generic python interpreter for packaged executable modules
if root.endswith("bin"):
with open(os.path.join(root, file), "r") as f:
data = f.read()
if search in data:
Expand Down

0 comments on commit e58fd32

Please sign in to comment.