Is there a way to delete priv files only in _build?

So I have created an Elixir application which uses erlport to connect with Python. Everything works well there. Now, some stuff of the Python code must be ran on an ARM architecture to even compile while my machine on which I develop is x86_64.

What I’ve done is created a mock file which overrides them to not produce an error on a non-ARM architecture which is great.

But I want those files to not ship with my application while in production.

Initially I got an idea that I could just use this at the beggining of my application before the erlport is called:

  defp delete_rpi() do
    if Mix.env == :prod do
      [:code.priv_dir(:pheed_the_pi), "python", "RPi"]
      |> Path.join()
      |> IO.inspect(label: "This is my path")
      |> File.rm_rf()
      |> IO.inspect(label: "Deletion status")
    end
  end

And the response is:

This is my path: "/home/zastrix/Documents/Personal/Phoenix/pheed_the_pi/_build/prod/lib/pheed_the_pi/priv/python/RPi"
Deletion status: {:ok,
 ["/home/zastrix/Documents/Personal/Phoenix/pheed_the_pi/_build/prod/lib/pheed_the_pi/priv/python/RPi",
  "/home/zastrix/Documents/Personal/Phoenix/pheed_the_pi/_build/prod/lib/pheed_the_pi/priv/python/RPi/pwm.py",
  "/home/zastrix/Documents/Personal/Phoenix/pheed_the_pi/_build/prod/lib/pheed_the_pi/priv/python/RPi/__init__.py",
  "/home/zastrix/Documents/Personal/Phoenix/pheed_the_pi/_build/prod/lib/pheed_the_pi/priv/python/RPi/GPIO.py"]}

And it seems that it only deleted those files under my _build folder… but that’s not what happens. It also deletes the files in the source code in the priv folder.

Meaning if I delete: _build/prod/lib/pheed_the_pi/priv/python/RPi via File.rm_rf/1 I as well delete: priv/python/RPi.

Is there any way for me to exclude the deletion of priv/python/RPior even exclude the folder during compilation?

Edit:

For now I have made a workaround by adding priv/python/RPi to .gitignore, moved it a folder up and using this Elixir code:

  defp delete_rpi() do
    [:code.priv_dir(:pheed_the_pi), "python", "RPi"]
    |> Path.join()
    |> File.rm_rf()

    if Mix.env != :prod do
      destination =
        [:code.priv_dir(:pheed_the_pi), "python", "RPi"]
        |> Path.join()

        [:code.priv_dir(:pheed_the_pi), "RPi"]
        |> Path.join()
        |> File.cp_r(destination)
    end
  end

But this is not a good solution as then on every update of the code I’d have to manually copy from the ignored folder to the folder up.

Solution explanation:
I’ve kept the code in priv/python which I am using for debugging and development but made the application copy it to .python where it will delete the RPi module data if necessary:

Tweaked the previous function:

  defp setup_python!() do
    destination =
      [File.cwd!(), ".python"]
      |> Path.join()

    [:code.priv_dir(:pheed_the_pi), "python"]
      |> Path.join()
      |> File.cp_r(destination)

    if Mix.env == :prod do
        [destination, "RPi"]
        |> Path.join()
        |> File.rm_rf()
    end
  end

And calling the module like so:

  def start() do
    path = [
      File.cwd!(), ".python"
    ] |> Path.join() |> IO.inspect(label: "Python priv path")

    {:ok, pid} = :python.start_link([{:python_path, to_charlist(path)}])

    pid
  end

Okay so apparently the priv under build is linked to the priv under the source code. Doing:

$ readlink -f _build/prod/lib/pheed_the_pi/priv/python/RPi
I got:
/home/zastrix/Documents/Personal/Phoenix/pheed_the_pi/priv/python/RPi.

And when manually deleting the folder under build the source code folder deletes as well.

I can’t seem to create any Elixir code which could unlink these two.

If you only need those files for development, then you could just not put them in priv but in a totally different folder. That way they won’t be included in your _build folder and also not in a potential release.

Well, that’s a bit of a problem. I did move them for now but that’s an optimal solution as then I can’t properly debug those files. I need to have those files where the rest of my Python code. I can’t get to the answer of which folder to change them. The lib folder isn’t coped in the _build so I can’t have them deleted. I have written my current setup under the edit field but that is, as I have said there, not a really good solution as I have to code on one place and run, debug on the other.

Edit:

That is, if I move only those files, I will have to change their references, thus changing the references when it is ran on production making that code crash due to invalid references.

I think we need a bit more information here:

  1. How does the file structure look like in your priv folder and how does differ between dev and prod?
  2. How do you run your code in production?

I’m going to give a solution because this did give me an intial idea.

When the app is starting I’d copy my priv/python code (with RPi) to a .python folder which is git-ignored and then I would delete the RPi from there if needed and load my modules from .python.

This way I can keep my code in priv/python (I want to keep it here in case I build the code for release (I want to make sure they are kept)) even with RPi but essentially not have RPi in production.