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

Refactoring setup.py to enable dry pip install #82

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Yomguithereal
Copy link

@Yomguithereal Yomguithereal commented Feb 28, 2019

Hello dragnet team. Thanks for your work.

I am submitting this PR as a conversation opener about pip installations. Currently, since the setup.py script relies on having already installed lxml, Cython &numpy, and a lot of persons aren't able to just do pip install dragnet and have it work. See #81 for instance.

This PR therefore leverages techniques found on this SO post and ideas from scipy etc. to make a dry pip install dragnet work even if the required deps were not installed in an earlier command.

It works on my end on a macOS python 3.6.5, but unfortunately I can't easily test this for further cases. So I was wondering what you think of it and if it could be of interest to you that we try and implement those workarounds or if just a patch to the documentation about pip installs would be enough.

Have a good day

ext_modules = [
Extension('dragnet.lcs',
sources=["dragnet/lcs.pyx"],
include_dirs=[get_include()],
sources=["dragnet/lcs.cpp"],
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this work without checking in the generated C++ files?

Copy link
Author

Choose a reason for hiding this comment

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

I am not sure what you mean. Writing this is in fact unrolling what the cythonize function does under the hood with source names etc.

Copy link
Contributor

@b4hand b4hand Apr 3, 2019

Choose a reason for hiding this comment

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

Yeah, but I didn't see any call to cythonize so I wasn't sure if it was still generating those files or if those files needed to be checked in to be found.

I've seen other projects just check in the generated files to avoid using cythonize during setup.py. The downside is you have to remember to update those before checking in and it makes the diffs larger.

Copy link
Author

Choose a reason for hiding this comment

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

Oh. I see now. I did not understand "checking" this way, hence the confusion.

Copy link
Contributor

@b4hand b4hand Apr 11, 2019

Choose a reason for hiding this comment

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

When I run on a completely clean virtualenv:

pip install git+https://github.com/Yomguithereal/dragnet.git@setup-build-enhancements

The command fails, and I see the following error:

  clang: error: no such file or directory: 'dragnet/lcs.cpp'
  clang: error: no input files
  error: command 'clang' failed with exit status 1

This means that the .cpp files need to be generated before the Extension commands can be called. I'm not opposed to pregenerating the .cpp files, but then we need to ensure they are regenerated after any changes to the .pyx files.

@b4hand
Copy link
Contributor

b4hand commented Apr 3, 2019

I'll confirm this works from a clean pip install using this branch and then merge.

ext_modules = [
Extension('dragnet.lcs',
sources=["dragnet/lcs.pyx"],
include_dirs=[get_include()],
sources=["dragnet/lcs.cpp"],
Copy link
Contributor

@b4hand b4hand Apr 11, 2019

Choose a reason for hiding this comment

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

When I run on a completely clean virtualenv:

pip install git+https://github.com/Yomguithereal/dragnet.git@setup-build-enhancements

The command fails, and I see the following error:

  clang: error: no such file or directory: 'dragnet/lcs.cpp'
  clang: error: no input files
  error: command 'clang' failed with exit status 1

This means that the .cpp files need to be generated before the Extension commands can be called. I'm not opposed to pregenerating the .cpp files, but then we need to ensure they are regenerated after any changes to the .pyx files.

@Yomguithereal
Copy link
Author

Would a commit hook fit the bill? Or would a command to run when releasing a version be better?

@b4hand
Copy link
Contributor

b4hand commented Apr 16, 2019

I'd prefer a release script than a commit hook. Commit hooks are hard to manage and there's no guarantee that people use them on forks, etc.

@Yomguithereal
Copy link
Author

Would something of the kind (the build.sh script) work?

@b4hand
Copy link
Contributor

b4hand commented Apr 17, 2019

Yes, that looks reasonable, but I want to hold off on merging until the current release is settled since this changes the way the package is built.

@Yomguithereal
Copy link
Author

Fair enough. Tell me if I can be of any assistance in the future.

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.

2 participants