Page MenuHomeSoftware Heritage

Move static folder out of the Python tree
ClosedPublic

Authored by anlambert on Jan 10 2020, 3:02 PM.

Details

Summary

It does not contain Python files but rather Javascript and CSS source files generated by webpack
but also image files and fonts. So it seems a better practice to move this folder at the root of the repository.

That diff moves the folder to the root of the repository and fixes the paths referencing it.

In order to generate the same distribution wheel as before, I added a little hack
in setup.py in order to add the static folder in the swh/web directory: a
symlink is created before calling the setup function and removed afterwards.

I do not really like that but I did not find another way to do so.

Update: No more dirty hack, I managed to use data_files from setuptools

After this change, static assets will be deployed to /usr/share/swh/web/static/ in production
environment so the puppet configuration will have to be updated before deployment.

Related to T2155

Diff Detail

Repository
rDWAPPS Web applications
Branch
move-assets-and-static
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 10051
Build 14880: Cypress tests for swh-web diffsJenkins
Build 14879: tox-on-jenkinsJenkins
Build 14878: arc lint + arc unit

Event Timeline

Update: Fix tests execution with tox

In order to generate the same distribution wheel as before, I added a little hack
in setup.py in order to add the static folder in the swh/web directory: a
symlink is created before calling the setup function and removed afterwards.

I do not really like that but I did not find another way to do so.

Let's try if we can use [[ https://docs.python.org/3/distutils/setupscript.html#installing-additional-files | data_files ]] from setuptools instead.

Update:

  • use data_files parameter from setuptools to bundle static assets generated by webpack instead of using a dirty hack in setup.py
  • do not move the assets folder after all as the files are not generated and it will be easier to grep its content
anlambert retitled this revision from Move assets and static folders out of the Python tree to Move static folder out of the Python tree.Jan 10 2020, 5:49 PM
anlambert edited the summary of this revision. (Show Details)
vlorentz added inline comments.
swh/web/tests/conftest.py
58
static_dir = os.path.join(sys.prefix, 'share/swh/web/static')
58

Or static_dir = pkg_resources.resource_string('swh.web', 'static')

swh/web/tests/conftest.py
58

Right ! The pkg_resources approach does not seem to work after a quick test as it will try to locate resources inside the module folder but data files are located in a different one. So I will go for the classic os.path.join approach.

Update: Address @vlorentz comments (use proper paths manipulation)

swh/web/tests/conftest.py
58

There's an extra leading slash

Update: Remove leading slashes in os.path.join operations.

This revision is now accepted and ready to land.Jan 13 2020, 2:42 PM