Skip to content

PEP-517 and PEP-518 support (add pyproject.toml)#274

Merged
yurymalkov merged 6 commits into
nmslib:developfrom
groodt:groodt-pyproject-toml
Jan 17, 2021
Merged

PEP-517 and PEP-518 support (add pyproject.toml)#274
yurymalkov merged 6 commits into
nmslib:developfrom
groodt:groodt-pyproject-toml

Conversation

@groodt

@groodt groodt commented Jan 10, 2021

Copy link
Copy Markdown
Contributor

Closes: #269 #177

hnswlib does not use the recommended packaging approach for pybind11.
https://pybind11.readthedocs.io/en/stable/compiling.html#setup-helpers-pep518

The pyproject.toml file can specify the requirements necessary for the build backend (setuptools in this case) that are installed before the actual build takes place.

This should also make it easier to start packaging wheels etc if this project moves to a more modern packaging approach.

@groodt groodt changed the base branch from master to develop January 10, 2021 10:10
This was referenced Jan 10, 2021
Comment thread .gitignore
Comment thread .travis.yml
Comment thread setup.py Outdated
Comment thread setup.py
@groodt groodt changed the title PEP-517 support (add pyproject.toml) PEP-517 and PEP-518 support (add pyproject.toml) Jan 10, 2021

@yurymalkov yurymalkov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cool! Thanks!
I wonder, will the current script (https://github.com/nmslib/hnswlib/blob/develop/Makefile) work for publishing pip packages?

Comment thread setup.py
@groodt

groodt commented Jan 11, 2021

Copy link
Copy Markdown
Contributor Author

I wonder, will the current script (https://github.com/nmslib/hnswlib/blob/develop/Makefile) work for publishing pip packages?

Yes, in this PR, the project will still publish an "sdist" (source distribution), not a "wheel" (binary distribution). However, now the "sdist" will be built correctly by consumers of this package without having to manually install pip install pybind11 numpy setuptools into their environment beforehand when the legacy fallback behavior of pip is removed.

Compare what happens with pip install . of the develop branch and pip install hnswlib==0.4.0:

Using legacy setup.py install for hnswlib, since package 'wheel' is not installed.

This message no longer appears if you try the install into a clean virtualenv of this branch.

You will see the PEP-517 behavior kick in:

**Building wheels for collected packages: hnswlib
  Building wheel for hnswlib (PEP 517) ... done**

@yurymalkov

Copy link
Copy Markdown
Member

Got it! Thanks! I'll check it and merge. @dyashuni can you please also check?

@dyashuni

Copy link
Copy Markdown
Contributor

Sure, I'll check it.

@dyashuni

dyashuni commented Jan 13, 2021

Copy link
Copy Markdown
Contributor

Currently in the travis we build hnswlib twice. When we run python -m pip install at an installation phase and python setup.py test at a test phase. I wonder why python setup.py test rebuilds the lib if it is installed.
Link to travis logs: https://travis-ci.org/github/nmslib/hnswlib/jobs/753778781

@groodt

groodt commented Jan 13, 2021

Copy link
Copy Markdown
Contributor Author

Currently in the travis we build hnswlib twice. When we run python -m pip install at an installation phase and python setup.py test at a test phase. I wonder why python setup.py test rebuilds the lib if it is installed.
Link to travis logs: https://travis-ci.org/github/nmslib/hnswlib/jobs/753778781

Yes. I didn't really want to mention it, but setup.py test is also deprecated: pypa/setuptools#1878

I've made some changes to fix this in the latest commit. See: 467c98f

Essentially, this project can do with a bit of refactoring in the way that it is packaged and the Python coding conventions to make it follow best-practices a bit.

I can raise a few more PRs to propose some changes in future if I find some time and if the project is interested.

Comment thread setup.py
Comment thread setup.py
Comment thread setup.py
Comment thread .travis.yml
Comment thread python_bindings/tests/bindings_test.py
Comment thread python_bindings/tests/bindings_test_labels.py
@groodt groodt requested a review from yurymalkov January 13, 2021 21:23

@yurymalkov yurymalkov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me!

@dyashuni

Copy link
Copy Markdown
Contributor

Good changes, thank you very much @groodt!

@dyashuni

Copy link
Copy Markdown
Contributor

One thing to mention, now in Makefile python3 setup.py sdist doesn't work if pybind11 is not installed.

What is the best way to handle it @groodt ? Add an additional target in Makefile that will allow a user to install all required packages to build sdist, for example, pip3 install pybind11 numpy setuptools ?

@groodt

groodt commented Jan 15, 2021

Copy link
Copy Markdown
Contributor Author

One thing to mention, now in Makefile python3 setup.py sdist doesn't work if pybind11 is not installed.

Ah, you are correct. My apologies. I should have checked. Yes, these new PEP standards do encourage more publishing of wheels than sdist. We don't need to make this change now (or ever).

At least this inconvenience is only for the package uploader to PyPI, which is presumably a limited number of people.

There is an official PEP517 builder that supports both sdist and wheels, see: https://github.com/pypa/build

I'll make this change to the Makefile shortly.

@groodt groodt requested a review from yurymalkov January 15, 2021 04:05
Comment thread README.md Outdated
@dyashuni

Copy link
Copy Markdown
Contributor

python3 setup.py sdist

It fixes the issue, thank you @groodt !

@dyashuni dyashuni left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@groodt Thank you!

@yurymalkov yurymalkov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great! Do you plan add something to this PR?

@groodt

groodt commented Jan 17, 2021 via email

Copy link
Copy Markdown
Contributor Author

@yurymalkov

Copy link
Copy Markdown
Member

Cool! Thank you so much!
Also thanks to @dyashuni for reviewing!

@yurymalkov yurymalkov merged commit 65a5f28 into nmslib:develop Jan 17, 2021
@groodt groodt deleted the groodt-pyproject-toml branch January 17, 2021 21:33
@groodt

groodt commented Jan 17, 2021

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews @yurymalkov @dyashuni

Is there likely to be a new release to PyPI anytime soon or are there more features waiting to land on develop?

@yurymalkov

Copy link
Copy Markdown
Member

Yes, we plan to release soon, there are significant changes.
Most likely, the following week.

@groodt

groodt commented Jan 28, 2021

Copy link
Copy Markdown
Contributor Author

@yurymalkov No rush, just checking in, but any news on the next release date?

@yurymalkov

Copy link
Copy Markdown
Member

@groodt
Done! Thanks!

@groodt

groodt commented Jan 29, 2021

Copy link
Copy Markdown
Contributor Author

@groodt
Done! Thanks!

Awesome! Thanks again!

amodhakal pushed a commit to amodhakal/hnswlib that referenced this pull request Apr 20, 2026
PEP-517 and PEP-518 support (add pyproject.toml)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants