Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile() failure when run via mpremote mount on Pico #19

Open
jfbauer432 opened this issue Aug 12, 2023 · 0 comments
Open

compile() failure when run via mpremote mount on Pico #19

jfbauer432 opened this issue Aug 12, 2023 · 0 comments

Comments

@jfbauer432
Copy link

I ran into am issue when using utemplate on a Raspberry Pi Pico. I was using the mpremote command with the mount option. Something like

mpremote mount . run main.py

If you are nor familiar with that, it has the Pico mount a directory ('.' in this case) on the host and then run code from there. Using this you can run your code without having to upload to the Pico first.

It fails in source.py at the

for l in self.file_in:

line with an

TypeError: 'RemoteFile' object isn't iterable.

I presume that files opened on the host are of type RemoteFile and that you can't just iterate over each line like it was a local file. I quick fix is to make the following change

     def compile(self):
         self.header()
-        for l in self.file_in:
-            self.parse_line(l)
+        try:
+            for l in self.file_in:
+                self.parse_line(l)
+        except TypeError:
+            lines = self.file_in.readlines()
+            for l in lines:
+                self.parse_line(l)
         self.close_literal()
         return self.seq

It is a bit slow but it works -- maybe I should just always upload to the Pico :-)

Due to the above error, it created but did not finish writing the .py version of the template file (it only had the initial comment line). So later runs try to import it and they fail in compiled.py when trying to access the .render attribute AttributeError: 'module' object has no attribute 'render'. It might be helpful to others in the future, it that could be caught and a better error presented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant