alexdlaird / pyngrok

A Python wrapper for ngrok
https://pyngrok.readthedocs.io
MIT License
421 stars 59 forks source link

7.1.5: create temporary directory in source tree breaks pep517 build #133

Closed kloczek closed 6 months ago

kloczek commented 6 months ago

Acknowledgements

Operating System

Linux x86/74

Python Version

3.9.18

pyngrok Version

7.1.5

Describe the Bug

Accidentally I sound that with some temporary created directory I was unable build module. Looks like there are some missing bits in pyproject.toml.

+ mkdir temp
+ /usr/bin/python3 -sBm build -w --no-isolation
* Getting build dependencies for wheel...
No `packages` or `py_modules` configuration, performing automatic discovery.
`flat-layout` detected -- analysing .
discovered packages -- ['pyngrok', 'SPECPARTS']
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
    main()
  File "/usr/lib/python3.9/site-packages/pyproject_hooks/_in_process/_in_process.py", line 335, in main
    json_out['return_val'] = hook(**hook_input['kwargs'])
  File "/usr/lib/python3.9/site-packages/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
    return hook(config_settings)
  File "/usr/lib/python3.9/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
    return self._get_build_requires(config_settings, requirements=['wheel'])
  File "/usr/lib/python3.9/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
    self.run_setup()
  File "/usr/lib/python3.9/site-packages/setuptools/build_meta.py", line 487, in run_setup
    super().run_setup(setup_script=setup_script)
  File "/usr/lib/python3.9/site-packages/setuptools/build_meta.py", line 311, in run_setup
    exec(code, locals())
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.9/site-packages/setuptools/__init__.py", line 103, in setup
    return distutils.core.setup(**attrs)
  File "/usr/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 159, in setup
    dist.parse_config_files()
  File "/usr/lib/python3.9/site-packages/setuptools/dist.py", line 627, in parse_config_files
    pyprojecttoml.apply_configuration(self, filename, ignore_option_errors)
  File "/usr/lib/python3.9/site-packages/setuptools/config/pyprojecttoml.py", line 67, in apply_configuration
    config = read_configuration(filepath, True, ignore_option_errors, dist)
  File "/usr/lib/python3.9/site-packages/setuptools/config/pyprojecttoml.py", line 132, in read_configuration
    return expand_configuration(asdict, root_dir, ignore_option_errors, dist)
  File "/usr/lib/python3.9/site-packages/setuptools/config/pyprojecttoml.py", line 157, in expand_configuration
    return _ConfigExpander(config, root_dir, ignore_option_errors, dist).expand()
  File "/usr/lib/python3.9/site-packages/setuptools/config/pyprojecttoml.py", line 205, in expand
    self._expand_all_dynamic(dist, package_dir)
  File "/usr/lib/python3.9/site-packages/setuptools/config/pyprojecttoml.py", line 250, in _expand_all_dynamic
    version=self._obtain_version(dist, package_dir),
  File "/usr/lib/python3.9/site-packages/setuptools/config/pyprojecttoml.py", line 299, in _obtain_version
    return _expand.version(self._obtain(dist, "version", package_dir))
  File "/usr/lib/python3.9/site-packages/setuptools/config/pyprojecttoml.py", line 288, in _obtain
    return self._expand_directive(
  File "/usr/lib/python3.9/site-packages/setuptools/config/pyprojecttoml.py", line 282, in _expand_directive
    return _expand.read_attr(directive["attr"], package_dir, root_dir)
  File "/usr/lib/python3.9/site-packages/setuptools/config/expand.py", line 189, in read_attr
    _parent_path, path, module_name = _find_module(module_name, package_dir, root_dir)
  File "/usr/lib/python3.9/site-packages/setuptools/config/expand.py", line 230, in _find_module
    if package_dir:
  File "/usr/lib/python3.9/site-packages/setuptools/config/expand.py", line 460, in __len__
    return len(self._target())
  File "/usr/lib/python3.9/site-packages/setuptools/config/expand.py", line 453, in _target
    self._value = self._obtain()
  File "/usr/lib/python3.9/site-packages/setuptools/config/expand.py", line 423, in _get_package_dir
    self()
  File "/usr/lib/python3.9/site-packages/setuptools/config/expand.py", line 413, in __call__
    self._dist.set_defaults(name=False)  # Skip name, we can still be parsing
  File "/usr/lib/python3.9/site-packages/setuptools/discovery.py", line 353, in __call__
    self._analyse_package_layout(ignore_ext_modules)
  File "/usr/lib/python3.9/site-packages/setuptools/discovery.py", line 387, in _analyse_package_layout
    or self._analyse_flat_layout()
  File "/usr/lib/python3.9/site-packages/setuptools/discovery.py", line 444, in _analyse_flat_layout
    return self._analyse_flat_packages() or self._analyse_flat_modules()
  File "/usr/lib/python3.9/site-packages/setuptools/discovery.py", line 450, in _analyse_flat_packages
    self._ensure_no_accidental_inclusion(top_level, "packages")
  File "/usr/lib/python3.9/site-packages/setuptools/discovery.py", line 480, in _ensure_no_accidental_inclusion
    raise PackageDiscoveryError(cleandoc(msg))
setuptools.errors.PackageDiscoveryError: Multiple top-level packages discovered in a flat-layout: ['pyngrok', 'temp].

To avoid accidental inclusion of unwanted files or directories,
setuptools will not proceed with this build.

If you are trying to create a single distribution with multiple packages
on purpose, you should not rely on automatic discovery.
Instead, consider the following options:

1. set up custom discovery (`find` directive with `include` or `exclude`)
2. use a `src-layout`
3. explicitly set `py_modules` or `packages` with a list of names

To find more information, look for "package discovery" on setuptools docs.

ERROR Backend subprocess exited when trying to invoke get_requires_for_build_wheel

Steps to Reproduce

mkdit temp python3 -sBm build -w --no-isolation

Expected Behavior

temporary crated directories or files should not affect build.

alexdlaird commented 6 months ago

Yes, look like this was broken when we migrated to pyproject.toml recently. Auto-discovery works fine in almost all cases, but not if you have multiple directories that might bet picked up as parts of the project. It could be fixed by simply adding:

[tool.setuptools]
package-dir = {"" = "pyngrok"}
alexdlaird commented 6 months ago

Fix for this has been merged to main.