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

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

Merged
merged 6 commits into from
Jan 17, 2021

Conversation

groodt
Copy link
Contributor

@groodt groodt commented Jan 10, 2021

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
.gitignore Show resolved Hide resolved
.travis.yml Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
setup.py Show resolved Hide resolved
@groodt groodt changed the title PEP-517 support (add pyproject.toml) PEP-517 and PEP-518 support (add pyproject.toml) Jan 10, 2021
Copy link
Member

@yurymalkov yurymalkov left a comment

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?

setup.py Show resolved Hide resolved
@groodt
Copy link
Contributor Author

groodt commented Jan 11, 2021

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
Member

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

@dyashuni
Copy link
Contributor

Sure, I'll check it.

@dyashuni
Copy link
Contributor

dyashuni commented Jan 13, 2021

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
Copy link
Contributor Author

groodt commented Jan 13, 2021

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.

setup.py Show resolved Hide resolved
setup.py Show resolved Hide resolved
setup.py Show resolved Hide resolved
.travis.yml Show resolved Hide resolved
python_bindings/tests/bindings_test.py Show resolved Hide resolved
python_bindings/tests/bindings_test_labels.py Show resolved Hide resolved
Copy link
Member

@yurymalkov yurymalkov left a comment

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
Contributor

Good changes, thank you very much @groodt!

@dyashuni
Copy link
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
Copy link
Contributor Author

groodt commented Jan 15, 2021

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.

README.md Outdated Show resolved Hide resolved
@dyashuni
Copy link
Contributor

python3 setup.py sdist

It fixes the issue, thank you @groodt !

Copy link
Contributor

@dyashuni dyashuni left a comment

Choose a reason for hiding this comment

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

@groodt Thank you!

Copy link
Member

@yurymalkov yurymalkov left a comment

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
Copy link
Contributor Author

groodt commented Jan 17, 2021 via email

@yurymalkov
Copy link
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
Copy link
Contributor Author

groodt commented Jan 17, 2021

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
Member

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

@groodt
Copy link
Contributor Author

groodt commented Jan 28, 2021

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

@yurymalkov
Copy link
Member

@groodt
Done! Thanks!

@groodt
Copy link
Contributor Author

groodt commented Jan 29, 2021

@groodt
Done! Thanks!

Awesome! Thanks again!

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