Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Migrate Apps from setup.py to pyproject.toml #999

Open
swainn opened this issue Dec 8, 2023 · 3 comments
Open

[FEATURE] Migrate Apps from setup.py to pyproject.toml #999

swainn opened this issue Dec 8, 2023 · 3 comments
Assignees
Milestone

Comments

@swainn
Copy link
Member

swainn commented Dec 8, 2023

Is your feature request related to a problem? Please describe.

The setup.py is being phased out in favor of the more standardized pyproject.toml.

Describe the solution you'd like

We should migrate apps to pyproject.toml. The tethys install command is already compatible pyproject.toml (it uses pip install -e . instead of setup.py develop).

Describe alternatives you've considered

N/A - pyproject.toml is the standard recommended build configuration file for Python modules.

Additional context

@swainn swainn self-assigned this Dec 8, 2023
@swainn swainn added this to the Version 4.3 milestone Dec 8, 2023
@swainn swainn removed this from the Version 4.3 milestone Apr 26, 2024
@swainn swainn added this to the Version 5.0 milestone Jul 19, 2024
@sdc50
Copy link
Member

sdc50 commented Nov 14, 2024

It looks like the latest version of pip will no longer work with our setup.py. From what I can tell it creates a temporary virtual environment to build the package, but only installs what is listed in requires of the pyproject.toml (or just setuptools by default). The result is that when it tries to run the setup.py it fails because it can't import tethys_apps in the build environment:

from tethys_apps.app_installation import find_all_resource_files
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [23 lines of output]
      Traceback (most recent call last):
        File "/Users/rditlsc9/conda/envs/tethys-install/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
          ~~~~^^
        File "/Users/rditlsc9/conda/envs/tethys-install/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ~~~~^^^^^^^^^^^^^^^^^^^^^^^^
        File "/Users/rditlsc9/conda/envs/tethys-install/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
        File "/private/var/folders/57/2pp3zbc93qd62k1qw1pmq9tcmw_trg/T/pip-build-env-xgtfiz_g/overlay/lib/python3.13/site-packages/setuptools/build_meta.py", line 334, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=[])
                 ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/57/2pp3zbc93qd62k1qw1pmq9tcmw_trg/T/pip-build-env-xgtfiz_g/overlay/lib/python3.13/site-packages/setuptools/build_meta.py", line 304, in _get_build_requires
          self.run_setup()
          ~~~~~~~~~~~~~~^^
        File "/private/var/folders/57/2pp3zbc93qd62k1qw1pmq9tcmw_trg/T/pip-build-env-xgtfiz_g/overlay/lib/python3.13/site-packages/setuptools/build_meta.py", line 522, in run_setup
          super().run_setup(setup_script=setup_script)
          ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/57/2pp3zbc93qd62k1qw1pmq9tcmw_trg/T/pip-build-env-xgtfiz_g/overlay/lib/python3.13/site-packages/setuptools/build_meta.py", line 320, in run_setup
          exec(code, locals())
          ~~~~^^^^^^^^^^^^^^^^
        File "<string>", line 2, in <module>
      ModuleNotFoundError: No module named 'tethys_apps'
      [end of output]

@sdc50
Copy link
Member

sdc50 commented Nov 14, 2024

There are two possible solutions. One is that we make tethys-platform available on PyPI so that we can add it as a build requirement for Tethys apps.

The other is that we just add the find_all_resoures_files function to the setup.py scaffold so it doesn't have to import anything.

It could look something like this:

setup.py

from pathlib import Path
from setuptools import setup, find_namespace_packages


def find_all_resource_files(app_package, app_root):
    relative_to = Path(f"{app_root}/{app_package}")
    resources = []
    for resource_type in ('templates', 'public', 'workspaces'):
        for path, __, filenames in (relative_to / resource_type).walk():
            resources.extend([str(Path(path).relative_to(relative_to) / filename) for filename in filenames])
    return resources


# -- Apps Definition -- #
app_package = 'my_app'
package_namespace = 'tethysapp'
release_package = f'{package_namespace}-{app_package}'

# -- Python Dependencies -- #
dependencies = []

# -- Get Resource File -- #
resource_files = find_all_resource_files(
    app_package, package_namespace
)

setup(
    name=release_package,
    packages=find_namespace_packages(),
    package_data={'': resource_files},
)

pyproject.toml

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[package]
version = '0.0.1'
description = ''
long_description = ''
keywords = ''
author = ''
author_email = ''
url = ''
license = ''
include_package_data = true
zip_safe = false
install_requires = []

@sdc50 sdc50 modified the milestones: Version 5.0, Version 4.3 Nov 14, 2024
@sdc50
Copy link
Member

sdc50 commented Nov 14, 2024

We wither need to fix this for 4.3 or pin pip to an older version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants