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

[CT-2027] [Feature] Standardize setup.py across adapter repos #80

Open
3 tasks done
dbeatty10 opened this issue Feb 3, 2023 · 7 comments
Open
3 tasks done

[CT-2027] [Feature] Standardize setup.py across adapter repos #80

dbeatty10 opened this issue Feb 3, 2023 · 7 comments
Labels
type:task Eng-driven work

Comments

@dbeatty10
Copy link
Contributor

Is this your first time submitting a feature request?

  • I have read the expectations for open source contributors
  • I have searched the existing issues, and I could not find an existing issue for this feature
  • I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion

Describe the feature

Loving the changes that @mikealfare made to setup.py in Redshift.

It seems like we should standardize and make similar changes in the other adapters!

I'm not sure if they would apply to Postgres or not 🤷 -- someone would need to assess:

Bonus suggestion:

  • put the definition of setup.py here and then just use that to stamp out instances for each adapter

Describe alternatives you've considered

We could allow the structure and contents of setup.py to drift. But I don't think it's necessary for them to drift. After a detailed assessment, nearly everything I saw was undifferentiated across adapters.

Who will this benefit?

One benefit:

  • My assumption is that some maintainers of the adapters listed here largely take their setup.py from an adapter maintained by dbt Labs, and it would be nice for them to get the "latest and greatest" version.

Another benefit:

Are you interested in contributing this feature?

Happy to help however -- pretty easy to open PRs for these

Anything else?

See below for a templated version of setup.py (that may itself be stale already 🤷). It would be very easy to convert this for usage by Copier, Cruft, Cookiecutter, Cookieninja, etc.

Cookiecutter template for

setup.py

#!/usr/bin/env python
import sys

if sys.version_info < (3, 7):
    print("Error: dbt does not support this version of Python.")
    print("Please upgrade to Python 3.7 or higher.")
    sys.exit(1)


try:
    from setuptools import find_namespace_packages
except ImportError:
    print("Error: dbt requires setuptools v40.1.0 or higher.")
    print('Please upgrade setuptools with "pip install --upgrade setuptools" and try again')
    sys.exit(1)


from pathlib import Path
from setuptools import setup


# pull the long description from the README
README = Path(__file__).parent / "README.md"


# used for this adapter's version and in determining the compatible dbt-core version
VERSION = Path(__file__).parent / "dbt/adapters/{{ cookiecutter.directory_name }}/__version__.py"


def _plugin_version() -> str:
    """
    Pull the package version from the main package version file
    """
    attributes = {}
    exec(VERSION.read_text(), attributes)
    return attributes["version"]


def _core_patch(plugin_patch: str):
    """
    Determines the compatible dbt-core patch given this plugin's patch

    Args:
        plugin_patch: the version patch of this plugin
    """
    pre_release_phase = "".join([i for i in plugin_patch if not i.isdigit()])
    if pre_release_phase:
        if pre_release_phase not in ["a", "b", "rc"]:
            raise ValueError(f"Invalid prerelease patch: {plugin_patch}")
        return f"0{pre_release_phase}1"
    return "0"


# require a compatible minor version (~=) and prerelease if this is a prerelease
def _core_version(plugin_version: str = _plugin_version()) -> str:
    """
    Determine the compatible dbt-core version given this plugin's version.

    We assume that the plugin must agree with `dbt-core` down to the minor version.

    Args:
        plugin_version: the version of this plugin, this is an argument in case we ever want to unit test this
    """
    try:
        major, minor, plugin_patch = plugin_version.split(".")
    except ValueError:
        raise ValueError(f"Invalid version: {plugin_version}")

    return f"{major}.{minor}.{_core_patch(plugin_patch)}"


setup(
    name="{{ cookiecutter.project_name }}",
    version=_plugin_version(),
    description="The {{ cookiecutter.platform_short_name }} adapter plugin for dbt",
    long_description=README.read_text(),
    long_description_content_type="text/markdown",
    author="dbt Labs",
    author_email="info@dbtlabs.com",
    url="[https://github.com/dbt-labs/{{](https://github.com/dbt-labs/%7B%7B) cookiecutter.project_name }}",
    packages=find_namespace_packages(include=["dbt", "dbt.*"]),
    include_package_data=True,
    install_requires=[
        f"dbt-core~={_core_version()}",
    ],
    zip_safe=False,
    classifiers=[
        "Development Status :: 5 - Production/Stable",
        "License :: OSI Approved :: Apache Software License",
        "Operating System :: Microsoft :: Windows",
        "Operating System :: MacOS :: MacOS X",
        "Operating System :: POSIX :: Linux",
        "Programming Language :: Python :: 3.7",
        "Programming Language :: Python :: 3.8",
        "Programming Language :: Python :: 3.9",
        "Programming Language :: Python :: 3.10",
        "Programming Language :: Python :: 3.11",
    ],
    python_requires=">=3.7",
)
@dbeatty10 dbeatty10 added type:enhancement New feature request triage:product In Product's queue labels Feb 3, 2023
@github-actions github-actions bot changed the title [Feature] Standardize setup.py across adapter repos [CT-2027] [Feature] Standardize setup.py across adapter repos Feb 3, 2023
@jtcohen6 jtcohen6 added type:task Eng-driven work and removed triage:product In Product's queue type:enhancement New feature request labels Feb 3, 2023
@emmyoop
Copy link
Member

emmyoop commented May 30, 2023

Part of these updates should include visiting the conditionals in setup.py per dbt-labs/dbt-snowflake#633

@DustinMoriarty
Copy link

If setup.py is being overhauled, why not just switch to pyproject.toml and maybe also switch to python poetry at the same time?

@dbeatty10
Copy link
Contributor Author

@DustinMoriarty we're definitely interested in switching to pyproject.toml 🤩 We have some light discussion in dbt-labs/dbt-core#5696 and dbt-labs/dbt-core#4674 related to that switch. I think this will happen, and it's just a matter of when.

We'd consider Poetry separately. We last discussed this in dbt-labs/dbt-core#4446, which has since gone stale and subsequently closed. We'd invite you to comment on that closed issue and we can re-open it for further discussion. I just added a comment here.

@DustinMoriarty
Copy link

@dbeatty10 : I would definitely recommend poetry for any project, especially one that is refactoring it's build tools. I would be happy to help with the migration if you want. I have migrated quite a few projects to poetry. It is not nearly as big of a change as you would think. It is not a breaking change because the build output meets the same PEP standards. The project just becomes easier to manage.

@mikealfare mikealfare transferred this issue from dbt-labs/dbt-core Feb 13, 2024
@benc-db
Copy link

benc-db commented Feb 27, 2024

We (Databricks) have a stale PR in our repo for doing exactly this. It's mostly never gotten merged because I waffled about if we're ok with more fragmentation for people who might work across the ecosystem.

@benc-db
Copy link

benc-db commented Feb 27, 2024

In other words, would strongly appreciate the move to modern build tools. Poetry's value is maybe more debatable, but I'd love to consolidate all our python config into a pyproject.toml.

@dbeatty10
Copy link
Contributor Author

We migrated to hatch in #17 for this repo.

dbt-postgres has an example pyproject.toml.

When we do the same for the other adapters maintained by dbt Labs, then this issue will be resolved.

mikealfare pushed a commit that referenced this issue Jan 20, 2025
#80)

* Merge `main` into `1.0.latest` (#46)

* Slack message for failed nightly runs (#41)

* Add Redshift parameter to create tables with backup option specified (#42)

* Update impl and adapters to support backup parameter

* Add test files

* Add test files

* Add PR link to Changelog

* Add EOF newlines

* Debug and split test into two separate cases

* Add contributor info

Co-authored-by: Jeremy Cohen <jeremy@dbtlabs.com>

* Bumping version to 1.0.0rc2 (#45)

* Bumping version to 1.0.0rc2

* Update changelog

Co-authored-by: Github Build Bot <buildbot@fishtownanalytics.com>
Co-authored-by: Jeremy Cohen <jeremy@dbtlabs.com>

Co-authored-by: Dan Bryan <dlb8685@gmail.com>
Co-authored-by: Jeremy Cohen <jeremy@dbtlabs.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Github Build Bot <buildbot@fishtownanalytics.com>

* [Backport] Bumping version to 1.0.0 (#47) (#48)

* Bumping version to 1.0.0 (#47)

Co-authored-by: Github Build Bot <buildbot@fishtownanalytics.com>

* Update CHANGELOG.md

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Github Build Bot <buildbot@fishtownanalytics.com>

* Fix package version (#49)

* using string interpoloation to gather correct pointer for dbt-core tests against release branches

* created new job for gha to grab correct version of dbt-core to test branch against

* minor update

* adding Get dbt-core-version step to integration.yaml

* modifying version parameters

* change for integration testing

* updating file

* readding pull_request_target now that tests pass

* make nit: suggested changes

* testing conditional logic in integration.yml

* updating test names

* creating main.yml versions of new condtional steps for dbt-version gather

* trying different version of test v.2

* v.3 of conditional mix of original version of tests and leah logic

* adding comment and changelog entry

* changes made after review by @VersusFacit and @kwigley

* name change

* minor updates

* updating name of version ref

* name change of dbt-version step to dbt-core-ref to be more descriptive iof where version is coming from

* Update test_backup_table_option.py

* Update test_backup_table_option.py

* reseting file that shouldn't of been changed

Co-authored-by: leahwicz <60146280+leahwicz@users.noreply.github.com>
Co-authored-by: Dan Bryan <dlb8685@gmail.com>
Co-authored-by: Jeremy Cohen <jeremy@dbtlabs.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Github Build Bot <buildbot@fishtownanalytics.com>
mikealfare pushed a commit that referenced this issue Jan 23, 2025
Co-authored-by: Mila Page <versusfacit@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:task Eng-driven work
Projects
None yet
Development

No branches or pull requests

6 participants