Python Changes are not loaded Local Dev Environment Using Vagrant - OSX

Unfortunately, no. This thread references a development environment.

thanks for your answer

i tried bench migrate command, and yes, python changes was loaded after bench migrate. But this is not solution for me. Bench migrate took few minutes. Its too long in developing.

@janecek.mato Can you share your site_config.json file? I’m convinced that you’re not in developer mode.

Sorry, I meant development environment.

Did you guys mean in normal development environment if I make a change in python file it will immediately reloaded on server without having to run stopping bench and run bench start again ?

@tmatteson we was talking about that :slight_smile:

{
"db_name": "1bd3e0294da19198",
"db_password": "tkoAXvsa0SbaJgPa",
"developer_mode": 1,
"encryption_key": "9Y33YeW-WzRs4f70vDAmacVcWPhUH5PHXVaMNZpcmIk=",
"host_name": "http://127.0.0.1:8016",
"limits": {
 "space_usage": {
  "backup_size": 3.0,
  "database_size": 24.38,
  "files_size": 1.0,
  "total": 28.38
 }
}
}

@janecek.mato I know! I don’t know what else it could be. This is exactly that behavior which is why I’m so confused. To be clear it should be in site_config.json, not common_site_config.json

@pipech Yes, when you make changes to python, it works that way, at least on localhost. You can set up remote editing packages with your text editor to make changes to an offsite/cloud server. I know these is available for Atom and VSCode at the very least, it’s usually a combination of mate/rmate and ftp.

@tmatteson

{
 "db_name": "at_local", 
 "db_password": "X0hZFoK0gwme2xBi", 
 "db_type": "mariadb", 
 "developer_mode": 1, 
 "encryption_key": "eXQBTWa4furPQNbBGwgtQCi7xxCBB89RNmqttrP2F9w=", 
 "limits": {
  "space_usage": {
   "backup_size": 4.0, 
   "database_size": 26.44, 
   "files_size": 5.0, 
   "total": 35.44
  }
 }
}

These are basically the same. The DB type shouldn’t be a variable that effects this. You have run bench disable-production, right? I think I suggested that already.

Well, I got exactly same behavior as OP.

I’m using Docker on Windows 10 and have turn on developer mode on site.

Can it be because of share resource ?

In my setup Apps folder and Sites folder has been share from Docker to host OS.

when i run this command, i get error, but it is maybe because of in vagrant is not production setted, like nginx and etc…

 frappe@ubuntu:~/frappe-bench$ sudo bench disable-production
Traceback (most recent call last):
  File "/usr/local/bin/bench", line 11, in <module>
    load_entry_point('bench', 'console_scripts', 'bench')()
  File "/home/frappe/.bench/bench/cli.py", line 40, in cli
    bench_command()
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/.bench/bench/commands/utils.py", line 152, in disable_production
    disable_production(bench_path='.')
  File "/home/frappe/.bench/bench/config/production_setup.py", line 64, in disable_production
    reload_nginx()
  File "/home/frappe/.bench/bench/config/production_setup.py", line 142, in reload_nginx
    subprocess.check_output(['sudo', find_executable('nginx'), '-t'])
  File "/usr/lib/python2.7/subprocess.py", line 567, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
TypeError: execv() arg 2 must contain only strings

Did you share folder from Vagrant to Host?

@pipech yes, but i tried also change file right in vagrant throgh pycharm remote host connection. And it was same. Maybe pycharm is problem.

I don’t think it’s pycharm problem since I using VScode.

Have you tried not sharing folder and change file through remote host connection or even change file using text editor on server?

no, because without shared folder, have vagrant no value for me

Remove host_name line from your site_cong.json photo above

Try bench disable-production not sudo bench disable-production
Not sure why you would want to do this?

Just edit site_config.json file in aton

After python changes try:
sudo service nginx restart
sudo supervisorctl restart all

Hope that this is a relevant answer as I have lost my glasses today and am having to guess most of what I read in this thread. Its all a blur :slight_smile:

I just tried not sharing folder in my setup (Docker on Windows 10).

When I made change to python file using bash text editor (nano) it automatically detect change !!

07:22:47 web.1            |  * Detected change in '/home/frappe/bench/apps/erpnext/erpnext/selling/doctype/customer/customer.py', reloading
07:22:47 web.1            | INFO:werkzeug: * Detected change in '/home/frappe/bench/apps/erpnext/erpnext/selling/doctype/customer/customer.py', reloading
07:22:48 web.1            |  * Restarting with inotify reloader
07:22:49 web.1            |  * Debugger is active!
07:22:49 web.1            |  * Debugger PIN: 923-896-094

So I think the problem might be because shared folder.
@janecek.mato Could you confirm this by not sharing folder and change file through remote host connection or even change file using text editor on server using vagrant ?

If it is problem with shared folder we can narrow the problem and tried to fix this.

Never mind that just tried again with shared folder it still works.

But it won’t works with change made using VSCode.
So could you try making change using bash text editor ?

According to this Flask Auto Reload Is Not Detecting Changes in a VM

I manage to make Frappe detect change from changing.

/apps/frappe/frappe/apps.py

by adding reloader_type='stat', to run_simple command

The downside seems to be it used more battery according to Werkzeug manual

def serve(port=8000, profile=False, no_reload=False, no_threading=False, site=None, sites_path='.'):
    global application, _site, _sites_path
    _site = site
    _sites_path = sites_path

    from werkzeug.serving import run_simple

    if profile:
            application = ProfilerMiddleware(application, sort_by=('cumtime', 'calls'))

    if not os.environ.get('NO_STATICS'):
            application = SharedDataMiddleware(application, {
                    '/assets': os.path.join(sites_path, 'assets'),
            })

            application = StaticDataMiddleware(application, {
                    '/files': os.path.abspath(sites_path)
            })

    application.debug = True
    application.config = {
            'SERVER_NAME': 'localhost:8000'
    }

    in_test_env = os.environ.get('CI')
    if in_test_env:
            log = logging.getLogger('werkzeug')
            log.setLevel(logging.ERROR)

    run_simple('0.0.0.0', int(port), application,
            reloader_type='stat',
            use_reloader=False if in_test_env else not no_reload,
            use_debugger=not in_test_env,
            use_evalex=not in_test_env,
            threaded=not no_threading)
1 Like

@System19 I tried remove host_name in site.config.json, everythink is still same. _

But @pipech solution defintelly solved my problem
open:

/apps/frappe/frappe/apps.py

and add to run_simple command

reloader_type='stat', 

thank you

Great to hear that the issue has been resolved. I actually wrote that Vagrant tutorial a few years back so it needs updating. It looks like it has received a few updates from other users which is cool but until it gets a proper rewrite I would recommend also looking at:

Which is a much more up to date vagrant setup install script.

1 Like

A great Centos7 ERPNext Vagrant box can be found here:
https://app.vagrantup.com/pegastechs/boxes/erpnext_centos
@pegastechs do a great job of scripting the install process. Very simple from start to finish. Slightly different technique to the one in the tutorial. By reading the @digiThinkIT and @pegastechs install and vagrant files I learnt a lot. Cheers.

Thanks, maybe will be good add this to main vagrant tutorial, for others.

I will definitelly try it. Now will be developing much faster.