Let's back up a step: it's not clear to me what the goal here is. I assume to write an extension that can be installed using wee_extension?
If so, users.extensions is not really the best place to put unit extensions for the reasons you have discovered. The installer would have to parse the file, adding what it needs. Instead, it's usually done by whatever driver, service, or search-list extension you are writing. If you have none, then just introduce a skeletal service to do the job. It would be so skeletal it would not even bind to any events. Its sole job is to set up the units. For example, *user.urad.py <http://user.urad.py>:* import weewx.engine # uRADMon weewx.units.obs_group_dict['uvolt'] = 'group_volt' weewx.units.obs_group_dict['ucpm'] = 'group_sievert' weewx.units.obs_group_dict['uvoc'] = 'group_ppm' weewx.units.obs_group_dict['uco2'] = 'group_ppm' weewx.units.obs_group_dict['uch2o'] = 'group_ppm' weewx.units.obs_group_dict['upm25'] = 'group_mgram' weewx.units.obs_group_dict['uptime'] = 'group_elapsed' weewx.units.obs_group_dict['upres'] = 'group_pressure' weewx.units.obs_group_dict['utemp'] = 'group_temperature' weewx.units.obs_group_dict['uhum'] = 'group_percent' # USUnits would be ???? weewx.units.USUnits['group_sievert'] = 'microsievert' weewx.units.USUnits['group_ppm'] = 'ppm' weewx.units.USUnits['group_mgram'] = 'microgram' weewx.units.MetricUnits['group_sievert'] = 'microsievert' weewx.units.MetricUnits['group_ppm'] = 'ppm' weewx.units.MetricUnits['group_mgram'] = 'microgram' weewx.units.MetricWXUnits['group_sievert'] = 'microsievert' weewx.units.MetricWXUnits['group_ppm'] = 'ppm' weewx.units.MetricWXUnits['group_mgram'] = 'microgram' weewx.units.default_unit_format_dict['microsievert'] = '%.0f' weewx.units.default_unit_format_dict['ppm'] = '%.1f' weewx.units.default_unit_format_dict['microgram'] = '%.0f' weewx.units.default_unit_label_dict['microsievert'] = ' \xc2\xb5Sv/h' weewx.units.default_unit_label_dict['ppm'] = ' ppm' weewx.units.default_unit_label_dict['microgram'] = ' \xc2\xb5g/m\xc2\xb3' class LoadURad(weewx.engine.StdService): pass Now add user.urad.LoadURad to the list of services to be run. It doesn't really matter where, but let's add it to the data_services. [Engine] [[Services]] # This section specifies the services that should be run. They are # grouped by type, and the order of services within each group # determines the order in which the services will be run. prep_services = weewx.engine.StdTimeSynch data_services = user.urad.LoadURad process_services = weewx.engine.StdConvert, weewx.engine.StdCalibrate, weewx.engine.StdQC, weewx.wxservices.StdWXCalculate archive_services = weewx.engine.StdArchive restful_services = weewx.restx.StdStationRegistry, weewx.restx.StdWunderground, weewx.restx.StdPWSweather, weewx.restx.StdCWOP, weewx.restx.StdWOW, weewx.restx.StdAWEKAS report_services = weewx.engine.StdPrint, weewx.engine.StdReport Now when the WeeWX engine starts up, it will load the service and, with it, your unit extensions, making them ready to use. The above example assumes you have no service or driver at all, so we made up a minimal one. Of course, if part of your package is to install a "real" service, that's the place to do the unit extensions. OTOH, if I've completely misunderstood your question, then I apologize. Please clarify and let's try again. -tk On Sun, Mar 4, 2018 at 8:30 PM, Glenn McKechnie <[email protected]> wrote: > Hi All, > > http://weewx.com/docs/customizing.htm#customizing_units > > I've reread the docs above and I've succesfully added what I need (as > per the attachment) and integrated them into weewx using > user/extension.py > Because they ran to more than a couple of extra lines I added them to > their own file and have sourced that from user/extensions.py using > import user.extensions_urad . The separate page seemed a tidier way > of packaging them up, whether for an install or uninstall. > > The question is, how to reference them once they are transferred via > wee_extension? I have the service written and installable, I can copy > this new file 'extensions_urad.py' file over. But how do I add the > required import statement, other than manually of course. This step > alludes me. > > Is this within the scope of wee_extension? > What have I missed, or what's a work around, or an alternative? > > The weewx doc linked above suggests that there may be another way, > where these can be included with weewx.conf - but also mentions that > this feature is on the todo list. > > For context, it's for generating the following page... > http://203.213.243.61/weewx/uradmon/index.html > > using one of these... > https://www.uradmonitor.com/products/?sel=4 > > Cheers > Glenn > > rorpi - read only raspberry pi & various weewx addons > https://github.com/glennmckechnie >
