I normally code in Sublime (now using VSCode more often) & that’s pretty comfortable for me. However for Anvil, I’ve been coding right on the site. I hate the experience & feel there has to be a better way.
I do use GIT & know that Anvil uses it by default too. In an ideal world I’d write the code in my system & deploy to Anvil. however I then can’t test/access built-in, anvil features like app secrets.
How does everyone else do it? Or do you just code on the site too?
For me when a server module is not fully visible on the screen is time to use PyCharm. I defined an environment with 2-space tabs so it doesn’t re-format the code.
There are problems with a few resources, like raw SQL and importing server modules from other dependency apps, but I can often find a workaround. I can usually get the imports to work, and I can create a very small server module to run SQL queries when the larger module needs it.
I create a test script that starts an uplink connection and uses the classes and functions defined in the server modules. Then I test large server modules on my computer and the forms from the client.
It could be better, but I got used to the little problems and it doesn’t bother me much.
This has been interesting feedback! We’re focused on making the Anvil editor the best place to edit Anvil apps, but one of the benefits of Git access is that you can use a workflow like this if you want to.
Unofficial suggestion, while I’m mulling this over: Have you or anyone here tried an auto-synchronisation script? You could try running something like this (don’t try it if you’re not familiar with what it does - ideally tag a version as a backup before trying it):
while true ; do
git commit -a --amend -m 'Saved from local machine' && git push --force-with-lease
This will automatically commit any changes you make and push them up to Anvil, every two seconds (provided you haven’t made any modifications in the IDE - the --force-with-lease prevents blind overwriting). This would mean you can edit locally and by the time you’ve flipped to the browser to refresh the page, your changes will have uploaded. (When you make changes in the IDE you’ll have to Ctrl+C this script, git pull them down, and then restart it. You could try making it more clever but do be careful…) I’m always interested to see people’s favourite Anvil workflows, so if this works for you, please do let us know…
Since I don’t know what’s cached and not automatically reloaded on the ide, I always refresh the page and reopen the app between the second and third step.
The IDE won’t know to auto-reload an app you’ve just pushed from Git - but it will detect and prevent conflicts when you save. So if you’ve pushed a new version, you might as well refresh - else the IDE will make you do it
(These days, just hitting the Refresh button returns you to the same app you were editing. This should make that step more comfortable…)
[quote=“stefano.menci, post:2, topic:2096”]
There are problems with a few resources, … but I can often find a workaround[/quote]
Same. Though for me, using anvil is a matter of efficiency over building django sites. Finding workarounds is proving to be inefficient & worse still; something I can’t delegate.
[quote=“stefano.menci, post:2, topic:2096”]
I create a test script that starts an uplink connection and uses the classes and functions defined in the server modules. Then I test large server modules on my computer and the forms from the client.[/quote]
I never thought to use uplink. If it helps me get user data & app secrets on my local machine while developing & then I can just push the final version to Anvil, that would be big. Thanks
I suppose that this method would make it easier to autosync as I save code. However I’m still wrapping my mind around how to write code which would work on my local machine or on the anvil platform.
On my machine I often read local files (like config files). On the Anvil platform, I would use the built in database, user & app secrets to store much of what I need. Though I can’t reference those things when I’m coding on my local machine. Stefano has suggested uplink, which might help. I haven’t wrapped my mind around how to implement that across all projects without writing something custom for each project.
I replaced the local files with one KeyValue table shared by all the apps. The table has two columns: key (string) and value (json). I can use app_tables.KeyValue.search('app1 configuration') to get the whole app configuration as a json object both on the server side and on an uplink module. Couldn’t be easier.
So far I have used secrets only for SQL queries. it is possible to whitelist my IP address and get access to SQL from uplink modules, but I didn’t ask for it because it feels safer, so I don’t need to use secrets either. For the time being the few times I need to use SQL from an uplink module I do it with a small module dedicated to the SQL queries.
Another problem I had to solve was the import of the dependencies. When that happens I put the import in a try except and when it doesn’t work it means I’m on an uplink and try with the path that works here.
One addition to this topic, that debugging is also could be an important feature, which I cannot do in Anvil site, but I can via VSCode!
I’m also using VSCode (as formerly I used sublime as well and VSCode build on sublime), which makes code editing much easier. I can also use debug in VS which I’m doing when I run my server code on my computer via uplink.
I would love to see a VSCode plugin for Anvil, so it could be fully integrated and get benefits from a good IDE.
Still, using the website is something I like time to time, but most cases I would work offsite with an IDE.
Similarly like Arduino manage it, you can get the right plugins to work offsite via VSCode or stick to the online hosting version as you wish.
Admittedly this is a repo that is basically written for my use and I have not made much effort to make it easier to use… sorry about that…
But, it does allow me to basically do a lot of things on my laptop instead of a browser:
It has auto-correct using anvil’s documentation and also uses PyCharm’s incredible ability to link everything together so I can find code easily
I can run pytest on client and server classes and functions
It has its own database so I don’t need to interfere with the website
there are two scripts that download and upload updated code to and from anvil.works from my laptop
I can use git on my pytests
it uses anvil.yaml to generate an alternative sqlite database that is used on the laptop
most of anvil’s calls are mocked or filled out with code that can be run on the laptop
every form can be also pytested because the form’s yaml is used to generate the form’s class
ok, having said that, there is a modification to the anvil code that I need to do to run it on the laptop. That is
from portable_meeting import Meeting
from client_code.portable_meeting import Meeting
from anvil import dict
I can’t seem to get pytest to recognize the same directory structure as the anvil site so I have to add the except part for the laptop.
And I need to import my own dict function to convert a row into a dictionary.
AND I have to remember to use row.update(…) instead of row[‘column1’] = x
and that’s it.