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

Revised setup.py and minor fixes in kernels. #89

Merged
merged 16 commits into from
Nov 27, 2017
Merged

Revised setup.py and minor fixes in kernels. #89

merged 16 commits into from
Nov 27, 2017

Conversation

JSKenyon
Copy link
Collaborator

@JSKenyon JSKenyon commented Nov 7, 2017

This should be a more general approach to setup which removes the Cython dependency. Assigning @gijzelaerr to check if this is more acceptable from a packaging perspective. Behaviour is modelled on rasterio, one of the more successful repositories I could find which also uses Cython. Default behaviour is to use .c and .cpp files instead of Cythonising. Will Cythonise locally if Cython is installed. This should be "safe" behaviour.

@JSKenyon
Copy link
Collaborator Author

Ok, @o-smirnov. I think this is ready to be merged.

@o-smirnov
Copy link
Collaborator

Has @gijzelaerr done a review?

@JSKenyon
Copy link
Collaborator Author

Not as far as I know. I have tested it to the best of my ability, so I think it works. The docs will become consistent with the new approach when it gets merged. It would be cool if @gijzelaerr could weigh in and let me know if the changes will make packaging it easier.

setup.py Outdated
import numpy as np
except ImportError:
log.critical("Numpy and its headers are required to run setup(). Exiting.")
sys.exit(1)
Copy link
Member

Choose a reason for hiding this comment

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

don't raise exceptions or exit manually in the setup script. It should still be possible to run the setup.py script without any of the dependencies installed.

Copy link
Collaborator 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 I understand. Surely installation will fail if you have unmet dependencies?

Copy link
Member

@gijzelaerr gijzelaerr Nov 23, 2017

Choose a reason for hiding this comment

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

well how is somebody going to be able to say what the dependencies are if the setup.py script fails to parse if the dependencies are not installed?

setup.py Outdated
except ImportError:
cythonize = None

include_path = np.get_include()
Copy link
Member

Choose a reason for hiding this comment

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

probably best to just make this an empty array if numpu is not installed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The whole installation will bomb without numpy - I don't think the .c and .cpp files can compile without those numpy headers.

Copy link
Member

@gijzelaerr gijzelaerr Nov 23, 2017

Choose a reason for hiding this comment

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

opening, reading, parsing the setup.py file doesn't mean you are also actually installing the project.

setup.py Outdated
"Programming Language :: Python",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Scientific/Engineering :: Astronomy"],
author='Jonathan Kenyon',
author_email='[email protected]',
license='GNU GPL v3',
cmdclass={'install': custom_install},
Copy link
Member

Choose a reason for hiding this comment

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

I think this is very scary, a custom install command class that calls a python executable to add some arguments to the build_ext step. There must be a better way to do this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am open to suggestions. We are very much at the edge of my familiarity.

Copy link
Member

Choose a reason for hiding this comment

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

@gijzelaerr This is the kind of thing that anyone with a python package that builds an extension will run into at some point. its a chicken and egg scenario -- you need numpy/tensorflow/something to build your extension, but its not installed yet, so it needs to be put in install_requires so that numpy/tensorflow/something gets installed. But the setup.py script tries to build the extension first.

Hence:

Until the above is fixed in some satisfactory way, deferred extension builds via sub-classing build_ext is the way to solve the chicken and egg scenario. See the datastax python driver setup.py, for example.

Copy link
Member

Choose a reason for hiding this comment

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

what are you trying to accomplish? What happens if you remove the custom install cmdclass?

Copy link
Member

@sjperkins sjperkins Nov 23, 2017

Choose a reason for hiding this comment

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

In fact, it looks like PEP 518 has made it into pip pypa/pip#4144. A cursory read suggests one needs a pyproject.toml to specify build dependencies and break the chicken and egg links.

Copy link
Member

Choose a reason for hiding this comment

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

but that probably doesnt help @JSKenyon very much at the moment.

The changes I suggest is:

  • Don't exit on the failing numpy import
  • If you can't populate the list for now, create an empty list. Specify numpy as a build dependency in setup.py.
  • Don't call an external python interpreter, that looks like a a recipe for problems. Can't that flags be set somewhere internal?

@JSKenyon
Copy link
Collaborator Author

JSKenyon commented Nov 23, 2017 via email

@JSKenyon
Copy link
Collaborator Author

JSKenyon commented Nov 23, 2017

@gijzelaerr I have made some changes that seem to work. Would you mind reviewing setup.py again? Not sure what the review procedure is. Do I dismiss the previous one?

@JSKenyon
Copy link
Collaborator Author

Thanks. Didn't know that was valid syntax.

@gijzelaerr
Copy link
Member

it looks like the SharedArray dependency has the same issue:

Collecting sharedarray (from cubical==0.9.2)
  Downloading SharedArray-2.0.3.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/qs/hpsrfjwx0313rdk2t7jj2ddw0000gn/T/pip-build-v99tMq/sharedarray/setup.py", line 23, in <module>
        import numpy
    ImportError: No module named numpy

Has this been reported upstream?

@JSKenyon
Copy link
Collaborator Author

JSKenyon commented Nov 23, 2017

@gijzelaerr It has not, but I feel you are in a better position to explain precisely what is wrong. Thus far, I have only worked around the dependencies. @o-smirnov you know the provenance of SharedArray more than I do. Any ideas?

@sjperkins
Copy link
Member

SharedArray is running into the exact same problem that you are now :-)

@sjperkins
Copy link
Member

@gijzelaerr
Copy link
Member

ok tried this on my mac but getting stuck at compiling casacore. I'll only be able to continue this on sunday.

@JSKenyon
Copy link
Collaborator Author

@gijzelaerr No stress - you are on holiday. I was expecting this to be ignored for a while. Enjoy Bahrain!

@gijzelaerr
Copy link
Member

gijzelaerr commented Nov 23, 2017

i'm actually working from here, but the middle-eastern weekend just started :)

@o-smirnov
Copy link
Collaborator

Issue 1 reported! ddboline/shared-array#1

@sjperkins
Copy link
Member

@JSKenyon Try the sjp-rev-setup branch. The taste of dark chocolate is pleasing to me.

@JSKenyon
Copy link
Collaborator Author

@sjperkins Seems good, though Cython was not a problem - it doesn't need to be installed. It will be used if it is, otherwise it will default to using the bundled .c and .cpp files. @gijzelaerr Feel free to have a look at @sjperkins approach when you get a moment (zero pressure) and see if it meets with your approval. I found this yesterday. If it seems ok, might be another way to break the np.get_include() problem.

@sjperkins
Copy link
Member

sjperkins commented Nov 24, 2017

@gijzelaerr
Copy link
Member

for me this installs in a clean virtualenv with and without --system-site-packages. I think it is good to go.

@gijzelaerr
Copy link
Member

gijzelaerr commented Nov 26, 2017

i've made a package of this branch and uploaded it to KERN-dev and KERN-3 as 0.9.2.1, it seems to work. If you make a new release I'll update the package to that release.

So your docker instructions now are:

FROM kernsuite/base:3
RUN docker-apt-install cubical

@o-smirnov o-smirnov merged commit 3b39dd1 into master Nov 27, 2017
@JSKenyon JSKenyon deleted the rev-setup branch December 4, 2017 11:30
@o-smirnov
Copy link
Collaborator

Can we revisit the issue of whether the *.c files need to be checked into the repository? @gijzelaerr it was at your instigation, wasn't it? Since it's auto-generated code, it feels a bit weird checking them in. Also makes for massive git diffs, making it harder to get an overview of commits. Cannot we generate them when shipping the package?

@gijzelaerr
Copy link
Member

The Cython peeps recommend bundling your tarball with the generated C code so you don't depend on Cython. if you think it is easier to only upload upon a release then i guess it is okay, but i'm quite sure people are going to forget.

@o-smirnov
Copy link
Collaborator

but i'm quite sure people are going to forget.

But that's easy to catch -- the package doesn't build, we're alerted, we fix the tarball. This only happens once in a while, when we release, right?

Whereas having the .c files checked in is just daily misery.

@gijzelaerr
Copy link
Member

ok lets see what happens :)

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.

4 participants