From e1ea06ffd34c254745a0585e58ac47ce3c2447af Mon Sep 17 00:00:00 2001 From: purepani Date: Sun, 23 Jun 2024 15:20:11 -0500 Subject: [PATCH 1/2] python: Moves python-local-development example into src layout --- .../python-local-development/{ => src}/mytool/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/packages/languages/python-local-development/{ => src}/mytool/__init__.py (100%) diff --git a/examples/packages/languages/python-local-development/mytool/__init__.py b/examples/packages/languages/python-local-development/src/mytool/__init__.py similarity index 100% rename from examples/packages/languages/python-local-development/mytool/__init__.py rename to examples/packages/languages/python-local-development/src/mytool/__init__.py From cbe72c89ba649b6ba9aad7b123076f45e0efc3ce Mon Sep 17 00:00:00 2001 From: purepani Date: Sun, 23 Jun 2024 15:20:56 -0500 Subject: [PATCH 2/2] python-editables: Exports environment variables for python whether .dream2nix needs updating or not (editables.py) --- .../dream2nix/python-editables/editable.py | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/modules/dream2nix/python-editables/editable.py b/modules/dream2nix/python-editables/editable.py index efd8516b..d18c87c1 100644 --- a/modules/dream2nix/python-editables/editable.py +++ b/modules/dream2nix/python-editables/editable.py @@ -1,14 +1,14 @@ -import os -import sys -import json -import shutil -import subprocess import configparser import importlib +import json +import os +import shutil +import subprocess +import sys from contextlib import redirect_stdout -from textwrap import dedent from pathlib import Path from tempfile import TemporaryDirectory +from textwrap import dedent import tomli @@ -173,6 +173,15 @@ def needs_update(args, dream2nix_python_dir): return old_args != args +def export_environment_vars(python_environment, bin_dir, site_dir, site_packages): + print( + f""" + export PYTHONPATH="{site_dir}:{python_environment / site_packages}:$PYTHONPATH" + export PATH="{bin_dir}:${python_environment}/bin:$PATH" + """ + ) + + def pretty_print_editables(editables, root_dir, root_name): if os.environ.get("D2N_QUIET"): return @@ -218,6 +227,7 @@ if __name__ == "__main__": if dream2nix_python_dir.exists(): shutil.rmtree(dream2nix_python_dir) else: + export_environment_vars(python_environment, bin_dir, site_dir, site_packages) pretty_print_editables(editables, root_dir, root_name) exit(0) @@ -259,14 +269,8 @@ for index, path in enumerate(sys.path): """ ) - print( - f""" -export PYTHONPATH="{site_dir}:{python_environment / site_packages}:$PYTHONPATH" -export PATH="{bin_dir}:${python_environment}/bin:$PATH" - """ - ) - with open(dream2nix_python_dir / "editable-args.json", "w") as f: json.dump(args, f, indent=2) + export_environment_vars(python_environment, bin_dir, site_dir, site_packages) pretty_print_editables(editables, root_dir, root_name)