0

I have a Python project which displays some information in the browser and uses bootstrap and D3 to do so. Right now, I'm simply including bootstrap.min.css and d3.v5.min.js in the source code repository, add them to the package_data in setup.py, and update them as new versions are released. This is rather ugly of course.

I'd like to specify bootstrap and D3 as a dependency in setup.py; any hint on how this could be possible?

Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
  • may be using data files ? https://docs.python.org/2/distutils/setupscript.html#distutils-additional-files – Sreyas Jul 18 '18 at 06:46
  • @Sreyas Well, the files are of course specified in `setup.py` _somehow_ so they get installed at all; in my case as `package_data`. I still need to keep them in the repo though. Clarified in the question. – Nico Schlömer Jul 18 '18 at 06:49
  • Do you mean you want the files be downloaded while installing this package? Actually I don't this is a good idea as in this case this package won't be able to installed offline. Maybe a better choice is add some code in your `setup.py` to automatically download these files while packaging. So that the built wheel contains everything you need and files get update automatically when you release a new version. – Sraw Jul 18 '18 at 06:54
  • Well, if you install something you need to be online anyways, right? I'm never packaging all of my Python dependencies either. – Nico Schlömer Jul 18 '18 at 06:57
  • If you expect your users to be online to begin with, you could point to a CDN instead. If for some reason you don't want to serve those libraries through a CDN, you will need to require some kind of front-end dependency management package on the target system. If you can assume that, then you can override `build` or `build_ext` (or some other fitting build step that pip goes through) class in the `cmdclass` argument to `setup` to install these front-end deps via yarn/npm/whatever. – Thtu Jul 18 '18 at 07:03
  • 1
    How about detecting and downloading files manually in `setup.py`? Those code will be executed while installing. – Sraw Jul 18 '18 at 07:05
  • @Sraw Yes, it'll have to be something like that. One problem (perhaps not related to this question exactly) is that I'll require `requests` at installation time, but there's no way to specify them yet (see [this question](https://stackoverflow.com/questions/51323748/setup-py-add-dependencies-required-for-installation)). – Nico Schlömer Jul 18 '18 at 07:08
  • 1
    `requests` is one of the dependencies of `pip`. So if user use `pip install ...` to install your package, it should have `requests`. – Sraw Jul 18 '18 at 07:21
  • https://github.com/pypa/pip/tree/master/src/pip/_vendor/requests – Sraw Jul 18 '18 at 07:22

0 Answers0