niess / python-appimage

AppImage distributions of Python
https://python-appimage.readthedocs.io/en/latest/
GNU General Public License v3.0
170 stars 24 forks source link

[question] Support for relative path based requirements #75

Closed dotzborro closed 2 months ago

dotzborro commented 4 months ago

Is there a way to put requirements as paths relative to the AppDir, or relative to the directory from which python-appimage was executed?

E.g. following works

/absolute/path/to/project

But it requires to know the absolute path. What I would like to achieve is to pull "local" package that isn't available through git or pip - it's just directory, e.g. ./path/to/project and then let python-appimage install it.

Currently, the pip is executed in temporary directory, thus it won't work with paths relative to the original CWD.

I was thinking of abusing the local+ hack. It currently seems to work only with installed packages, for which find_spec succeeds. It doesn't succeed with path. Following hack makes it work:

                  elif requirement.startswith('local+'):
                      name = requirement[6:]
                      find_result = find_spec(name)
                      if find_result.origin is not None:
                          source = find_result.origin
                      elif os.path.exists(os.path.join(pwd, name)):
                          source = os.path.join(pwd, name)
                      else:
                          raise RuntimeError("failed to find requirement " + requirement)
                      if source.endswith('/__init__.py'):
                          source = os.path.dirname(source)

However, I'm not sure if this is the best way to achieve what I want.

I would appreciate some guidance. If the solution requires coding, I will open PR.

niess commented 4 months ago

Hello @dotzborro,

the local+ feature is a user contribution that I do not use. Now, given my understanding of the problem, your hack looks good to me. It should not modify the original behaviour. Moreover, it explicitly checks that the requirement is found.

Another possibility would be not to use a temporary directory when building the AppDir. But, it might have side effects. In addition, I like that everything gets cleaned when resuming from the temporary directory.

Thus, if you like to submit your hack as a PR, I am fine with that.