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

build: initial support for poetry build tool #4513

Merged
merged 10 commits into from
Jun 11, 2024

Conversation

MatriQ
Copy link
Contributor

@MatriQ MatriQ commented May 19, 2024

Description

This PR is just adding poetry configurations in pyproject.toml so that we can use poety to easily manage the environment, as well as a little of README.md.

Fixes # (issue)

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update, included: Dify Document
  • Improvement, including but not limited to code refactoring, performance optimization, and UI/UX improvement
  • Dependency upgrade

How Has This Been Tested?

This change doesn't bring out any changes of code, and I have tested with generic poetry commands.

  • TODO

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
  • optional I have made corresponding changes to the documentation
  • optional I have added tests that prove my fix is effective or that my feature works
  • optional New and existing unit tests pass locally with my changes

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. 🐍 python Pull requests that update Python code 📚 documentation Improvements or additions to documentation labels May 19, 2024
@bowenliang123
Copy link
Contributor

bowenliang123 commented May 20, 2024

How to guarantee the [tool.poetry.dependencies] settings align to requireiments.txt? As well as the poetry.lock lock file to the requireiments.txt?

@MatriQ
Copy link
Contributor Author

MatriQ commented May 20, 2024

How to guarantee the [tool.poetry.dependencies] settings align to requireiments.txt? As well as the poetry.lock lock file to the requireiments.txt?

Hi @bowenliang123 , in current stage. we can use poetry add command to keep dependencies consistency as I mentioned in README.md:
image

In the future, I'd like to suggest that remove requirements.txt and requirements-dev.txt and entirely use poetry to manage dependencies.

@bowenliang123
Copy link
Contributor

Can you figure out at least one way in CI jobs to making sure poetry dependency list satisfying the existed requirements.txt ?

I'm against setting the removal the requirements.txt as final target, considering the following facts:

  1. requirements.txt is generally used out of box with python and pip
  2. poetry is just one of the build systems with dependencies management
  3. For the runtime usage, the build system does not bring any benefits , while it causes reversed dependencies on poetry to the runtime base, like in docker images.

@@ -0,0 +1 @@
3.10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is unnecessary, as the pyporject.toml has set the required minimum python version.
Also, dify API module is tested on Python 3.10 and 3.11 in CI jobs.
If this is for local development only, please do not submit to the commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm facing the following issue with 3.11, hence I thought Dify doesn't support 3.11:
image

However, I will remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem you listed is not caused by python 3.11 , I think.
And it should be fixed in #4517, bumping yfinance on minor verions.
Please rebase to the latest commit and check again.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an perfect example for inconsistency of your poetry dependencies and the required dependencies from requirements.txt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@MatriQ
Copy link
Contributor Author

MatriQ commented May 20, 2024

Can you figure out at least one way in CI jobs to making sure poetry dependency list satisfying the existed requirements.txt ?

I'm against setting the removal the requirements.txt as final target, considering the following facts:

  1. requirements.txt is generally used out of box with python and pip
  2. poetry is just one of the build systems with dependencies management
  3. For the runtime usage, the build system does not bring any benefits , while it causes reversed dependencies on poetry to the runtime base, like in docker images.

This PR is just for providing another for developers to manage dependencies, it doesn't impact unit tests, CI and product env. As for your objections, I'd like to discuss with you in another PR(not created yet).

@bowenliang123
Copy link
Contributor

bowenliang123 commented May 20, 2024

This PR is just for providing another for developers to manage dependencies, it doesn't impact unit tests, CI and product env. As for your opsitions, I'd like to discuss with you in another PR(not created yet).

The introduced support for a new build system should at least respect and align with the existing core mechanisms. Otherwise, it will puzzle the users with the issues caused by inconsistencies in dependencies(which happen often), as the de-facto two different dependencies are listed in the Dify API module.

@MatriQ
Copy link
Contributor Author

MatriQ commented May 20, 2024

This PR is just for providing another for developers to manage dependencies, it doesn't impact unit tests, CI and product env. As for your opsitions, I'd like to discuss with you in another PR(not created yet).

The introduced support for a new build system should at least respect and align with the existing core mechanisms. Otherwise, it will puzzle the users with the issues caused by inconsistencies in dependencies(which happen often), as the de-facto two different dependencies are listed in the Dify API module.

Currently, the only supported build system is still not changed. the dependencies in pyproject.toml will be kept update from requirements.txt. So there won't introduce any new issues from this PR.

@takatost
Copy link
Collaborator

Hi @bowenliang123, is it possible to migrate to poetry in the future? Actually, currently lint and test are using poetry's configuration file, while package dependencies are using pip. I hope in the future we can consolidate everything with poetry, and poetry can parallelize the dependency fetching process to speed up package installation.

@bowenliang123
Copy link
Contributor

bowenliang123 commented May 20, 2024

Hi @bowenliang123, is it possible to migrate to poetry in the future? Actually, currently lint and test are using poetry's configuration file, while package dependencies are using pip. I hope in the future we can consolidate everything with poetry, and poetry can parallelize the dependency fetching process to speed up package installation.

Hi @takatost , I am always open to modern build systems like hatch or poetry. All I want to prevent is the inconsistency of dependencies, especially we don't have our decisions in the choice of build system.

@loganclark360
Copy link

loganclark360 commented May 20, 2024 via email

@loganclark360
Copy link

loganclark360 commented May 20, 2024 via email

@loganclark360
Copy link

loganclark360 commented May 20, 2024 via email

@bowenliang123
Copy link
Contributor

I'm suggesting the following changes in this PR to meet the baseline of acceptance for initial support for poetry build system.

  1. change the PR title build: initial support for poetry build tool
  2. add CI job to check poetry.lock file aligned to the dependency list of [tool.poetry.dependencies] in pyproject.toml, by using poetry check
  3. add CI job in api-tests.yml workflow to install dependencies via poetry and run all through all the tests

These actions still don't guarantee the poetry dependencies aligned to requirements.txt, but it should be good enough for initial support. The dependency list of [tool.poetry.dependencies] in pyproject.toml requires more polishment in version declaration like preferring ^ operator rather than >= + <, which could be done in the future.

WDYT? @takatost @MatriQ

@MatriQ
Copy link
Contributor Author

MatriQ commented May 21, 2024

I'm suggesting the following changes in this PR to meet the baseline of acceptance for initial support for poetry build system.

  1. change the PR title build: initial support for poetry build tool
  2. add CI job to check poetry.lock file aligned to the dependency list of [tool.poetry.dependencies] in pyproject.toml, by using poetry check
  3. add CI job in api-tests.yml workflow to install dependencies via poetry and run all through all the tests

These actions still don't guarantee the poetry dependencies aligned to requirements.txt, but it should be good enough for initial support. The dependency list of [tool.poetry.dependencies] in pyproject.toml requires more polishment in version declaration like preferring ^ operator rather than >= + <, which could be done in the future.

WDYT? @takatost @MatriQ

It's ok for me. But I'd like to get opinion from @takatost

@MatriQ MatriQ force-pushed the chore/poetry-support branch 5 times, most recently from a77ade4 to ac63620 Compare May 25, 2024 06:43
@MatriQ MatriQ changed the title chore: support poetry build: initial support for poetry build tool May 26, 2024
@MatriQ MatriQ requested a review from bowenliang123 May 26, 2024 03:35
Copy link
Contributor

@bowenliang123 bowenliang123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall. It covers the tests with dependencies installed by peotry. cc @takatost
Minor optional suggestions:

  1. use poetry style version specification like ^ rather than >= + < for readability and maintainability
  2. use actions-poetry v3
  3. basic info of [tool.poetry] should be updated as
  • name: dify-api
  • version: 0.6.8
  • authors: Dify with its official email

@MatriQ MatriQ requested a review from bowenliang123 May 26, 2024 16:54
takatost
takatost previously approved these changes Jun 11, 2024
Copy link
Collaborator

@takatost takatost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 11, 2024

[tool.poetry]
name = "dify-api"
version = "0.6.8"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
version = "0.6.8"
version = "0.6.10"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. It's best to update to the latest dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

pytest-benchmark = "^4.0.0"
pytest-env = "^1.1.3"
pytest-mock = "^3.14.0"
jinja2 = "^3.1.2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jinjia2 has been removed from development dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@takatost takatost merged commit f62f71a into langgenius:main Jun 11, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 documentation Improvements or additions to documentation lgtm This PR has been approved by a maintainer 🐍 python Pull requests that update Python code size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants