Python icon indicating copy to clipboard operation
Python copied to clipboard

ci: Consolidate requirements into `pyproject.toml`

Open CaedenPH opened this issue 3 years ago • 13 comments

Describe your change:

Consolidate the requirements into pyproject.toml https://pip.pypa.io/en/stable/reference/build-system/pyproject-toml/

  • [ ] Add an algorithm?
  • [x] Fix a bug or typo in an existing algorithm?
  • [ ] Documentation change?

Checklist:

  • [x] I have read CONTRIBUTING.md.
  • [x] This pull request is all my own work -- I have not plagiarized.
  • [x] I know that pull requests will not be merged if they fail the automated tests.
  • [x] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • [x] All new Python files are placed inside an existing directory.
  • [x] All filenames are in all lowercase characters with no spaces or dashes.
  • [x] All functions and variable names follow Python naming conventions.
  • [x] All function parameters and return values are annotated with Python type hints.
  • [x] All functions have doctests that pass the automated testing.
  • [x] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • [x] If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

CaedenPH avatar Oct 23 '22 14:10 CaedenPH

@cclauss Never used pyproject.toml, so expecting lots of changes

CaedenPH avatar Oct 23 '22 14:10 CaedenPH

We could also move our codespell, mypy, and pyupgrade args from .pre-commit into pyproject.toml.

Please run https://pypi.org/project/validate-pyproject to validate the file and let's add that tool to pre-commit.

cclauss avatar Oct 23 '22 15:10 cclauss

We might run into trouble consolidating our pytest args because our GitHub Actions run it two different ways. So that might be difficult to express.

cclauss avatar Oct 23 '22 15:10 cclauss

We could also move our codespell, mypy, and pyupgrade args from .pre-commit into pyproject.toml.

Please run https://pypi.org/project/validate-pyproject to validate the file and let's add that tool to pre-commit.

How would this be done?

CaedenPH avatar Oct 23 '22 15:10 CaedenPH

The only benefit we get in using pyproject.toml is to have a central place for configuration. We don't need the project declaraction, build system, dependencies.

Build system is used to provide a backend like poetry, flit or setuptools to actually build the Python package (wheels). For our use case, requirements.txt is actually the best option instead of declaring it in pyproject.toml. Otherwise, users will be required to install using pip install . which installs the dependencies along with the package (remember this is not a package) and the egg info. Project declaration is not useful as it's used to provide metadata information for PyPi. I guess it was added to declare the dependencies which as mentioned not useful. Adding the authors field is a bit misleading as this is a work of all the contributors.

dhruvmanila avatar Oct 23 '22 16:10 dhruvmanila

Let's use maintainers rather than authors... https://peps.python.org/pep-0621/#authors-maintainers

Would we be able to use pip install . or probably better pip install --editable . in our GitHub Actions?

Could pip install git+https://github.com/TheAlgorithms/Python.git be made to work?

cclauss avatar Oct 23 '22 16:10 cclauss

As I said, this won't work as TheAlgorithms/Python is not a "Python package", you cannot install it as it's not even structured like a standard package. I don't really see why you're wasting time in this.

dhruvmanila avatar Oct 23 '22 17:10 dhruvmanila

OK... So now pip seems to be installing all of our dependencies and dev-dependencies. It is pytest that seems broken.

cclauss avatar Oct 23 '22 17:10 cclauss

Now it seems to be working end-to-end without the need for requirements.txt!!

cclauss avatar Oct 23 '22 17:10 cclauss

Please rebase.

cclauss avatar Oct 29 '22 13:10 cclauss

Please rebase.

Done

CaedenPH avatar Oct 29 '22 15:10 CaedenPH

I don't really recommend defining dependencies in pyproject.toml file as this is not a Python package. It doesn't make sense to define them there. We can use pyproject.toml to define all the tool configs though, but we should be using requirements.txt to define the dependencies.

dhruvmanila avatar Oct 29 '22 17:10 dhruvmanila

I fail to understand the logic. pip knows how to install project dependencies from two different file types. Why does it matter whether this is a package or not?

cclauss avatar Oct 29 '22 21:10 cclauss