summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnderson Bravalheri <andersonbravalheri@gmail.com>2023-01-19 10:19:31 +0000
committerAnderson Bravalheri <andersonbravalheri@gmail.com>2023-01-19 11:19:13 +0000
commit4e766834d72623f3b938f1d4148547ea73af1bf5 (patch)
tree2e94b38c842274eb74b10afcc877313ad84c6946
parent596d9db7e89ddc6d16142344cc19e1ba7da5b090 (diff)
downloadpython-setuptools-git-4e766834d72623f3b938f1d4148547ea73af1bf5.tar.gz
Add files referenced by file: directive in setup.cfg to sdist
-rw-r--r--setuptools/command/egg_info.py7
-rw-r--r--setuptools/config/setupcfg.py15
-rw-r--r--setuptools/dist.py7
3 files changed, 24 insertions, 5 deletions
diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py
index 1885efb0..194230a9 100644
--- a/setuptools/command/egg_info.py
+++ b/setuptools/command/egg_info.py
@@ -565,6 +565,7 @@ class manifest_maker(sdist):
if os.path.exists(self.template):
self.read_template()
self.add_license_files()
+ self._add_referenced_files()
self.prune_file_list()
self.filelist.sort()
self.filelist.remove_duplicates()
@@ -622,6 +623,12 @@ class manifest_maker(sdist):
pass
self.filelist.extend(license_files)
+ def _add_referenced_files(self):
+ """Add files referenced by the config (e.g. `file:` directive) to filelist"""
+ referenced = getattr(self.distribution, '_referenced_files', [])
+ # ^-- fallback if dist comes from distutils or is a custom class
+ self.filelist.extend(referenced)
+
def prune_file_list(self):
build = self.get_finalized_command('build')
base_dir = self.distribution.get_fullname()
diff --git a/setuptools/config/setupcfg.py b/setuptools/config/setupcfg.py
index c2a974de..3df3b6e7 100644
--- a/setuptools/config/setupcfg.py
+++ b/setuptools/config/setupcfg.py
@@ -12,7 +12,7 @@ from collections import defaultdict
from functools import partial
from functools import wraps
from typing import (TYPE_CHECKING, Callable, Any, Dict, Generic, Iterable, List,
- Optional, Tuple, TypeVar, Union)
+ Optional, Set, Tuple, TypeVar, Union)
from distutils.errors import DistutilsOptionError, DistutilsFileError
from setuptools.extern.packaging.requirements import Requirement, InvalidRequirement
@@ -172,6 +172,9 @@ def parse_configuration(
distribution.src_root,
)
meta.parse()
+ distribution._referenced_files.update(
+ options._referenced_files, meta._referenced_files
+ )
return meta, options
@@ -247,6 +250,10 @@ class ConfigHandler(Generic[Target]):
self.sections = sections
self.set_options: List[str] = []
self.ensure_discovered = ensure_discovered
+ self._referenced_files: Set[str] = set()
+ """After parsing configurations, this property will enumerate
+ all files referenced by the "file:" directive. Private API for setuptools only.
+ """
@property
def parsers(self):
@@ -365,8 +372,7 @@ class ConfigHandler(Generic[Target]):
return parser
- @classmethod
- def _parse_file(cls, value, root_dir: _Path):
+ def _parse_file(self, value, root_dir: _Path):
"""Represents value as a string, allowing including text
from nearest files using `file:` directive.
@@ -388,7 +394,8 @@ class ConfigHandler(Generic[Target]):
return value
spec = value[len(include_directive) :]
- filepaths = (path.strip() for path in spec.split(','))
+ filepaths = [path.strip() for path in spec.split(',')]
+ self._referenced_files.update(filepaths)
return expand.read_files(filepaths, root_dir)
def _parse_attr(self, value, package_dir, root_dir: _Path):
diff --git a/setuptools/dist.py b/setuptools/dist.py
index 1c71e5ee..cd34d74a 100644
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -17,7 +17,7 @@ from distutils.fancy_getopt import translate_longopt
from glob import iglob
import itertools
import textwrap
-from typing import List, Optional, TYPE_CHECKING
+from typing import List, Optional, Set, TYPE_CHECKING
from pathlib import Path
from collections import defaultdict
@@ -481,6 +481,11 @@ class Distribution(_Distribution):
},
)
+ # Private API (setuptools-use only, not restricted to Distribution)
+ # Stores files that are referenced by the configuration and need to be in the
+ # sdist (e.g. `version = file: VERSION.txt`)
+ self._referenced_files: Set[str] = set()
+
# Save the original dependencies before they are processed into the egg format
self._orig_extras_require = {}
self._orig_install_requires = []