how does relocated_files work together with resour...
# general
g
how does relocated_files work together with resources? in 2.16.0dev it just worked, now (in 2.16.0 and 2.17.0) it says "the pex_binary target transitively depends on the below...."
Copy code
resources(
    sources = ["./**/*"],
    dependencies = [":js_libs"]
)

relocated_files(
    name = "js_libs",
    src = "src/js_libs",
    dest = "src/tuhls/core/static",
    files_targets = ["src/js_libs/alpinejs.3.10.3.min.js"],
)
b
They get turned into files during the relocation (in pants parlance) 😞 Look up "experimental_wrap_as_resources" for how to turn them back.
This is something that's plagued me for a year and a half. If I ever get the time and energy, we have an idea for how to solve it, but it's admittedly quite involved
g
ok, thx josh, i will try this 🙂
am i doing something wrong?
Copy code
resources(
    dependencies = [":wrapped_js_libs"],
    sources = ["**/*"],
)

experimental_wrap_as_resources(
    name = "wrapped_js_libs",
    inputs = [":relocated_js_libs"],
)

relocated_files(
    name = "relocated_js_libs",
    src = "src/js_libs",
    dest = "src/tuhls/core/static",
    files_targets = ["src/js_libs"],
)
but i cant see the js files in the pex. but as i include all resources i can see the static folder and the BUILD file from it in the pex file
b
What is the pex target definition?
g
Copy code
python_sources(
    name = "src",
    dependencies = [
        "./base",
        "./app",
        "./css",
        "src/tuhls/core",
        "src/tuhls/dashboard",
        "src/tuhls/icons",
    ],
)

pex_binary(
    name = "manage_dev_pex",
    dependencies = [
        ":src",
        "3rdparty/python:reqs#django-extensions",
        "3rdparty/python:reqs#Werkzeug",
    ],
    entry_point = "manage.py",
    execution_mode = "venv",
    layout = "loose",
)
but im pretty sure this is not a possible problem because files gets included as soon as im manualy dropping files into that static folder
ok, one step closer. my build file for the js resources used
resources(sources = ["*.js"])
now im using
files(sources = ["*.js"])
in 2.16.0dev it worked with resources.
relocated_files
was able to move the things arround now it only works with
files
but now theres a new problem 🙂 the files are now in the pex, but in the wrong location. and im not able to move it exactly to where they should be. the tree structure in my pex (simplified) looks like this
Copy code
- .bootstrap
- .deps
- __pex__
- marla
- tuhls
  - core
    - static
- utils
and when i try to move the dependent files like so
Copy code
relocated_files(
    name = "relocated_files",
    src = "src/js_libs",
    dest = "src/tuhls/core/static",
    files_targets = ["src/js_libs"],
)
the new tree looks like this
Copy code
- .bootstrap
- .deps
- __pex__
- marla
- src
  - tuhls
    - core
      - static
- tuhls
  - core
    - static
  - utils
so i thought this could be an easy one and changed my relocated_files to
Copy code
relocated_files(
    name = "relocated_files",
    src = "src/js_libs",
    dest = "tuhls/core/static",
    files_targets = ["src/js_libs"],
)
with the result: NoSourceRootError: No source root found for
tuhls/core/static
. either theres something broken in my head or in pants. maybe in booth, idk, im lost :D
b
Sorry, I’m a bit lost with your file structure too. What’s your source repo structure? That is, which BUILD files are where? (Btw as a general thing, it might be simpler to work out how to get this going with a super simple example that’s just a single Python file, and single JS file, and then shuffle them around until you get things working and understand the mechanics (and/or find bugs). And then apply that to the more complicated real repo)
g
the problem is it worked until the upgrade 😉 so yes, there is no simple repo available because im using pants since over 1 year
b
Right. I’m suggesting creating a smaller repo explicitly for the purpose of teasing out the bugs/issues.
g
and something wired is happening after the upgrade from 2.16.0dev to 2.16.0 or 2.17.0
im pretty sure im able to replicate this in a smaller repo
b
Yep, that would be great! It would help work out if there’s a bug here and if there is, serve as a reproducer for it, to make debugging and verifying easier.
g
i have reduced the whole pile of stuff to this simple repo in which im able to reproduce the behavior: https://github.com/thelittlebug/pants__reproduce_relocated_files_anomaly
👍 1
b
Thanks for the start of a simpler reproduction. You'll get more and faster help if you reduce it as much as possible, e.g. preferably as few BUILD/other files as possible. (Sorry for being a bit unhelpful here, but Pants is entirely volunteer-driven.) That said, now that you've got a simpler reproduction, if you don't get much help here in Slack, feel free to file a bug https://github.com/pantsbuild/pants/issues/new/choose so that it's listed somewhere more persistently (but of course, as above, the simpler it is, the quicker/better the help/fixes 😄 )
g
yeah, i finally discovered that too ^^ a pro tip: reducing the repo is faster than rephrasing the questions/effects and so on i learned something allready 🙂
b
If you file a bug with the before/after I'll that a look. Note you can run
PANTS_VERSION=2.16.0 pants ...
To override the version. Makes it easy to compare from the terminal 🙂
👍 1