简体   繁体   中英

Flask blueprint as a package | setuptools

I have a flask blueprint that I'm pushing to GitHub as a separate repo. Then I install it via

pip install git@httpps://....

I get the package in my venv and it's all good I can import code etc.

However there is an issue. I don't see HTML/CSS/js files that are visible on GitHub.

I found similar errors on here but the solutions that I tested don't work. Maybe there is an error in my folder structure (if so how to do it correctly? flask needs to see them too) maybe it's something different.

Here is my folder structure all of the folders have init .py

src
   updater
      SWupdater
      templates
        static
           js
             *.js
           css
             external_css
                  *.css
             *.css
           images
            *.jpg 
        SWupdater
            *.html

This is my setup without names/descriptions etc

setuptools.setup(
    packages=setuptools.find_packages(where='src', exclude=["*.tests", "*.tests.*"]),
    package_dir={"updater": "src/updater"},
    zip_safe=False,
    include_package_data=True,
    install_requires=[],
    classifiers=[],
    python_requires='>=3.7'
)

What I've tried to do in my setup.py

-added package_data

package_data={"updater/SWupdater/templates": ["SWUpdater/*"],
               "updater/SWupdater/templates/static":["css/*", "images/*", "js/*"]},

-added include_package_data

include_package_data=True,

-a combination of package_data/include -line order combination (one higher one lower)

I do not build this package, I only push it to GitHub and install it into my venv

For anyone looking for answers.

  • you don't need package_data in setup.py
  • you need manifest.in

In my case I've created manifest with this line

recursive-include src\updater\SWupdater\templates\* .

to include all html/css/js files

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM