Page MenuHomeSoftware Heritage

Move static folder out of the Python tree
ClosedPublic

Authored by anlambert on Fri, Jan 10, 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
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

anlambert created this revision.Fri, Jan 10, 3:02 PM
anlambert updated this revision to Diff 8934.Fri, Jan 10, 3:35 PM

Update: Fix tests execution with tox

anlambert planned changes to this revision.Fri, Jan 10, 4:00 PM

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 data_files from setuptools instead.

anlambert updated this revision to Diff 8941.Fri, Jan 10, 5:46 PM

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.Fri, Jan 10, 5:49 PM
anlambert edited the summary of this revision. (Show Details)
anlambert edited the summary of this revision. (Show Details)Mon, Jan 13, 1:48 PM
vlorentz added inline comments.
swh/web/tests/conftest.py
59
static_dir = os.path.join(sys.prefix, 'share/swh/web/static')
59

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

anlambert added inline comments.Mon, Jan 13, 2:05 PM
swh/web/tests/conftest.py
59

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.

anlambert updated this revision to Diff 8948.Mon, Jan 13, 2:11 PM

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

vlorentz added inline comments.Mon, Jan 13, 2:18 PM
swh/web/tests/conftest.py
59

There's an extra leading slash

anlambert updated this revision to Diff 8949.Mon, Jan 13, 2:24 PM

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

vlorentz accepted this revision.Mon, Jan 13, 2:42 PM
This revision is now accepted and ready to land.Mon, Jan 13, 2:42 PM
This revision was automatically updated to reflect the committed changes.