From 5bf9b4cfa6f2823ddbb8fa79d93a771544348a48 Mon Sep 17 00:00:00 2001 From: Thomas Rausch Date: Thu, 24 Oct 2024 18:58:55 +0200 Subject: [PATCH] fix issue with absolute paths landing in SOURCE.txt (#27) --- plux/__init__.py | 2 +- plux/build/setuptools.py | 8 ++++++-- tests/cli/test_entrypoints.py | 7 +++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/plux/__init__.py b/plux/__init__.py index 7b3328a..cbabbe7 100644 --- a/plux/__init__.py +++ b/plux/__init__.py @@ -17,7 +17,7 @@ name = "plux" -__version__ = "1.12.0" +__version__ = "1.12.1" __all__ = [ "FunctionPlugin", diff --git a/plux/build/setuptools.py b/plux/build/setuptools.py index 3d65919..bc8a87e 100644 --- a/plux/build/setuptools.py +++ b/plux/build/setuptools.py @@ -345,13 +345,17 @@ def get_distribution_from_workdir(workdir: str) -> setuptools.Distribution: dist = setuptools.Distribution() dist.parse_config_files(config_files) - if os.path.exists("setup.py"): + if os.path.exists(os.path.join(workdir, "setup.py")): # use setup.py script if available dist.script_name = os.path.join(workdir, "setup.py") else: - # else use a bogus file (seems to work regardless) + # else use a config file (seems to work regardless) dist.script_name = config_files[0] + # note: the property Distribution.script_name is added to `SOURCES.txt` during the `sdist` command. the path + # must be a relative path. see https://github.com/localstack/plux/issues/23 + dist.script_name = os.path.relpath(dist.script_name, workdir) + return dist diff --git a/tests/cli/test_entrypoints.py b/tests/cli/test_entrypoints.py index 3672bad..9849425 100644 --- a/tests/cli/test_entrypoints.py +++ b/tests/cli/test_entrypoints.py @@ -1,5 +1,6 @@ import os.path import sys +from pathlib import Path import pytest @@ -26,3 +27,9 @@ def test_entrypoints(project_name): with open(os.path.join(project, "test_project.egg-info", "entry_points.txt"), "r") as f: lines = [line.strip() for line in f.readlines() if line.strip()] assert lines == ["[plux.test.plugins]", "myplugin = mysrc.plugins:MyPlugin"] + + # make sure that SOURCES.txt contain no absolute paths + with open(os.path.join(project, "test_project.egg-info", "SOURCES.txt"), "r") as f: + lines = [line.strip() for line in f.readlines() if line.strip()] + for line in lines: + assert not line.startswith("/")