praiskup / argparse-manpage

Automatically build man-pages for your Python project
Apache License 2.0
40 stars 22 forks source link

How to build man pages when the script requires the current package? #111

Open rrthomas opened 2 months ago

rrthomas commented 2 months ago

I am trying to switch from an old setup.py setup to pure pyproject.toml (thanks for making this possible!) for PSPDFUtils.

The commands I'm trying to make man pages for are standard entry points in my package. With setup.py this works fine; with pure pyproject.toml, I get this error:

Failed to build pspdfutils
  error: subprocess-exited-with-error

  × Building wheel for pspdfutils (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [78 lines of output]
      No `packages` or `py_modules` configuration, performing automatic discovery.
      `flat-layout` detected -- analysing .
      discovered packages -- ['psutils', 'psutils.command']
      running bdist_wheel
      running build
      running build_py
      running build_manpages
      generating epsffit.1
      Traceback (most recent call last):
        File "/home/rrt/Software/psutils/.tox/py310/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/home/rrt/Software/psutils/.tox/py310/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/home/rrt/Software/psutils/.tox/py310/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 251, in build_wheel
          return _build_backend().build_wheel(wheel_directory, config_settings,
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 410, in build_wheel
          return self._build_with_temp_dir(
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 395, in _build_with_temp_dir
          self.run_setup()
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 1, in <module>
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/setuptools/__init__.py", line 104, in setup
          return distutils.core.setup(**attrs)
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 184, in setup
          return run_commands(dist)
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 200, in run_commands
          dist.run_commands()
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
          self.run_command(cmd)
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/setuptools/dist.py", line 967, in run_command
          super().run_command(command)
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/tmp/pip-build-env-nm5m55mz/normal/lib/python3.10/site-packages/wheel/bdist_wheel.py", line 368, in run
          self.run_command("build")
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/setuptools/_distutils/cmd.py", line 316, in run_command
          self.distribution.run_command(command)
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/setuptools/dist.py", line 967, in run_command
          super().run_command(command)
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/setuptools/_distutils/command/build.py", line 132, in run
          self.run_command(cmd_name)
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/setuptools/_distutils/cmd.py", line 316, in run_command
          self.distribution.run_command(command)
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/setuptools/dist.py", line 967, in run_command
          super().run_command(command)
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/build_manpages/build_manpages.py", line 151, in run
          self.run_command(DEFAULT_CMD_NAME)
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/setuptools/_distutils/cmd.py", line 316, in run_command
          self.distribution.run_command(command)
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/setuptools/dist.py", line 967, in run_command
          super().run_command(command)
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/build_manpages/build_manpages.py", line 127, in run
          parser = get_parser(data['import_type'], data['import_from'], data['objname'], data['objtype'], data.get('prog', None))
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/argparse_manpage/tooling.py", line 66, in get_parser
          return get_parser_from_module(import_from, objname, objtype, prog=prog)
        File "/tmp/pip-build-env-nm5m55mz/overlay/lib/python3.10/site-packages/argparse_manpage/tooling.py", line 28, in get_parser_from_module
          mod = importlib.import_module(module)
        File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
          return _bootstrap._gcd_import(name[level:], package, level)
        File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
        File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
        File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
        File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
        File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
        File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
        File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
        File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
        File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
        File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
        File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
      ModuleNotFoundError: No module named 'psutils'

As we can see, it's not finding psutils. I'm not sure why it works with the setup.py setup but not pyproject.toml.

I'm sorry if this isn't an argparse problem, but it seemed to me that it would be a fairly common problem (that is, wanting to use argparse to make man pages for scripts that require the current package), and I can't see anything in the argparse documentation about it.

rrthomas commented 2 months ago

Just to check that it's not the particularity of one project, I tried with https://github.com/rrthomas/rpl and had the same problem. (I appreciate that this is another of my projects, so it could still be something I'm doing wrong!)

praiskup commented 1 month ago

Thank you for the report. Indeed, this seems like something everyone wants to do when using pyproject+argparse-manpage.. but I don't understand why this is happening.

It seems that psutils is not on the PYTHONPATH. Could setup.py implicitly add the current working directory there, but that's not done by pyproject?

How do you execute the build?

rrthomas commented 1 month ago

I use python -m build. My diagnosis of the immediate problem is the same as yours, and like you I speculated that the path was being set up differently in the two cases; I've not yet had time to probe further.