Repository: pypa/setuptools

Issue:
[BUG] autodiscovery for single-module layout causes `build_wheel(".")` to produce an empty wheel
### setuptools version

65.5.1

### Python version

3.11.0

### OS

Gentoo Linux

### Additional environment information

_No response_

### Description

When the package is using a flat distribution layout for a single Python module with autodiscovery, the build-backend produces an empty wheel if wheel_dir is `.`. It seems to work correctly if a subdirectory is used as wheel_dir.

I've noticed this with [bitstring](https://github.com/scott-griffiths/bitstring) package.

### Expected behavior

Correct package or an explicit error.

### How to Reproduce

```
cat > pyproject.toml <<EOF
[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"

[project]
name = "test"
version = "1"
EOF

> foo.py
python -c 'import setuptools.build_meta; setuptools.build_meta.build_wheel(".")'
```

### Output

```console
running bdist_wheel
running build
running build_py
running egg_info
creating test.egg-info
writing test.egg-info/PKG-INFO
writing dependency_links to test.egg-info/dependency_links.txt
writing top-level names to test.egg-info/top_level.txt
writing manifest file 'test.egg-info/SOURCES.txt'
listing git files failed - pretending there aren't any
reading manifest file 'test.egg-info/SOURCES.txt'
writing manifest file 'test.egg-info/SOURCES.txt'
installing to build/bdist.linux-x86_64/wheel
running install
running install_lib
warning: install_lib: 'build/lib' does not exist -- no Python modules to install

running install_egg_info
Copying test.egg-info to build/bdist.linux-x86_64/wheel/test-1-py3.11.egg-info
running install_scripts
creating build/bdist.linux-x86_64/wheel/test-1.dist-info/WHEEL
creating '/tmp/test/tmpygf6hdpg/test-1-py3-none-any.whl' and adding 'build/bdist.linux-x86_64/wheel' to it
adding 'test-1.dist-info/METADATA'
adding 'test-1.dist-info/WHEEL'
adding 'test-1.dist-info/top_level.txt'
adding 'test-1.dist-info/RECORD'
removing build/bdist.linux-x86_64/wheel

$ unzip -l test-1-py3-none-any.whl 
Archive:  test-1-py3-none-any.whl
  Length      Date    Time    Name
---------  ---------- -----   ----
       45  11-18-2022 17:32   test-1.dist-info/METADATA
       92  11-18-2022 17:32   test-1.dist-info/WHEEL
       12  11-18-2022 17:32   test-1.dist-info/top_level.txt
      268  11-18-2022 17:32   test-1.dist-info/RECORD
---------                     -------
      417                     4 files
```



Discussion:

Resolving patch:
diff --git a/setuptools/build_meta.py b/setuptools/build_meta.py
--- a/setuptools/build_meta.py
+++ b/setuptools/build_meta.py
@@ -385,7 +385,8 @@ def _build_with_temp_dir(self, setup_command, result_extension,
 
         # Build in a temporary directory, then copy to the target.
         os.makedirs(result_directory, exist_ok=True)
-        with tempfile.TemporaryDirectory(dir=result_directory) as tmp_dist_dir:
+        temp_opts = {"prefix": ".tmp-", "dir": result_directory}
+        with tempfile.TemporaryDirectory(**temp_opts) as tmp_dist_dir:
             sys.argv = [
                 *sys.argv[:1],
                 *self._global_args(config_settings),


Test patch:
diff --git a/setuptools/tests/test_config_discovery.py b/setuptools/tests/test_config_discovery.py
--- a/setuptools/tests/test_config_discovery.py
+++ b/setuptools/tests/test_config_discovery.py
@@ -248,6 +248,19 @@ def test_flat_layout_with_multiple_modules(self, tmp_path):
         with pytest.raises(PackageDiscoveryError, match="multiple (packages|modules)"):
             _get_dist(tmp_path, {})
 
+    def test_py_modules_when_wheel_dir_is_cwd(self, tmp_path):
+        """Regression for issue 3692"""
+        from setuptools import build_meta
+
+        pyproject = '[project]\nname = "test"\nversion = "1"'
+        (tmp_path / "pyproject.toml").write_text(DALS(pyproject), encoding="utf-8")
+        (tmp_path / "foo.py").touch()
+        with jaraco.path.DirectoryStack().context(tmp_path):
+            build_meta.build_wheel(".")
+        # Ensure py_modules are found
+        wheel_files = get_wheel_members(next(tmp_path.glob("*.whl")))
+        assert "foo.py" in wheel_files
+
 
 class TestNoConfig:
     DEFAULT_VERSION = "0.0.0"  # Default version given by setuptools