/srv/irclogs.ubuntu.com/2020/07/21/#smooth-operator.txt

jammorning all05:09
Chipacagoooooooooooooooooooooooooooooooooooooooood  morning!09:10
jammorning Chipaca . it seems Guido was against main scripts inside packages09:11
jamI'm not sure why they created __main__.py then.09:11
Chipacajam: is this related to the 'cannot import commands' thing?09:19
jamChipaca, yes. You can see my investigation on mattermost, but basically when running the primary script09:20
jamyour __name__ is __main__ which means you aren't part of a __package__09:20
Chipacafacubatista: I just opened latest/beta, and moved latest/edge to it, so people can use that and we can open master to edge in due course09:21
Chipacajam: lol09:21
Chipacajam: another LOL is that jujuignores aren't gitignores09:23
jamChipaca, probably closer to bzr ignores I would guess09:24
Chipacaand the only gitignore python implementations seem to be terrible09:24
Chipacae.g. https://github.com/mherrmann/gitignore_parser09:24
Chipaca'A spec-compliant gitignore parser for Python'09:24
jamChipaca, also, something to consider, one reason git ignores work well, is because you can create an exception with an explicit 'git add' but you can't do that for charms unless we have some sort of manifest09:25
Chipacahas an open issue about 'foo' matching 'barfoo'09:25
Chipacaand the author says "I have no idea LOL"09:25
jamChipaca, I have no idea... always a good response :)09:25
Chipacaand it has no tests09:25
Chipacaeven though it's based on a different project that does has tests, but hasn't seen work in years09:25
Chipaca(to the point that it's only been tested on 3.5)09:25
Chipacaand that summarises how far i got yesterday before hating the world and going to sleep :)09:26
jamChipaca, don't hate the world, hate the... players ?09:27
Chipacajam: I shall hate the world, by the power of synecdoche!09:28
Chipacagoing back to jujuignore, it's a SMOP to translate https://github.com/juju/charm's jujuignore.go (and jujuignore_test.go) to python for our use09:32
Chipacabut I don't think I can make it for release09:32
Chipacaso I propose we look for a .jujuignore and bail out if it exists09:32
jamChipaca, so what about .gitignore ?09:33
jamSwitch and use 'git ls' ?09:33
jamor just do .jujuignore but otherwise add everything since that matches juju deploy ?09:33
Chipacajam: well, that's the other approach09:34
Chipacai was thinking of getting .gitignore parsing to work, which should be a day of work on top of one of the se projects09:34
Chipacathese*09:34
jamChipaca, I'd go for 'juju deploy' over most other things, because that is setting the precedence09:34
* jam goes to make coffee09:34
Chipacafair09:35
Chipacaok, let's do that09:35
Chipacai should be able to do that :)09:35
Chipacai don't think i can do that and 'charmcraft init' in four days though :)09:35
jamChipaca, can you split off pieces that I can help with?09:41
jameg, the jujuignore parser I could do while you focus on other things09:41
Chipacajam: you also have plenty on your plate already :)09:41
jamChipaca, indeed, but charmcraft release happens frist09:42
jamfirst09:42
Chipacajam: ok let's do it09:45
jamChipaca, ok, I'll put together a jujuignore.py for charmcraft09:46
Chipacameanwhile i'll poke the init beast09:50
Chipacafacubatista: WRT --system, it's *probably* easier to try with --system and if it fails try again without09:51
Chipacajam, facubatista: meeting10:02
Chipacajam: in setup.py, set zip_safe=False10:17
Chipacawe can sort out the why and the how later :)10:18
jamChipaca, to make it do what? It still doesn't solve the problem that you can't run "python ./charmcraft' because the import paths are wrong10:21
jamYou *can* run python -m charmcraft for whatever reason10:21
Chipacajam: ah, for 'python setup.py install' to work, i meant10:21
jamChipaca, does zip_safe=false actually fix that? It seems like you still wouldn't have a 'charmcraft' you could drop in your path10:21
Chipacawork as in result in a working 'charmcraft' script10:21
Chipacait does fix that, yes10:22
Chipacathat's the only difference between what 'setup.py install' and 'pip install' does10:22
Chipacajam: python ./charmcraft  (and just 'python charmcraft') work as long as your PYTHONPATH includes .10:24
Chipacajam: (which it shouldn't by default)10:24
jamChipaca, but isn't that bad behavior?10:24
jamChipaca, so my goal was to 'build something' and then symlink a 'charmcraft' into my 'bin' directory so I can just run it10:25
jamthat feels like something that should work10:25
jamif zip_safe=false gets us there, that seems ek10:25
jamok10:25
Chipacajam: zip_safe=False gets you a charmcraft script in the venv's bin, which you should be able to symlink10:25
Chipacai haven't tried that10:26
jamChipaca, I just did and it works10:27
jamwell, with venv active, let me try without10:27
jamyep10:27
Chipacaterrible news then10:27
Chipaca:)10:27
Chipacajam: getting __main__.py to dtrt when it can find itself but not the package is a matter of tweaking sys.path, which is ugly but ok10:28
Chipacaand if we do that we might be able to move the entry point to that? dunno :)10:28
Chipacaat which point we get eggs back10:29
Chipacabut, not for now10:29
Chipacanow, for init10:29
jamzip_safe does what I wanted10:29
jamand is small10:29
facubatista¡Muy buenos días a todos!11:35
facubatistaChipaca, ok with edge->beta, thanks11:36
Chipacaoh drat, lunch11:44
Chipacafacubatista: buen día seor!11:44
Chipacabut also, lunch11:44
Chipacasiiigh12:45
facubatistaChipaca, ?13:18
Chipacafacubatista: sigh13:18
Chipacafacubatista: :)13:19
Chipacalittle frustrations with jinja13:19
facubatista:)13:19
jamChipaca, what's wrong with jinja ?14:17
jamfacubatista, reviewed your 'release' pr. I had a couple questions about divergence from snapcraft's CLI.14:17
jamIf it is intentional, then go with it.14:17
Chipacajam: it prunes the last \n when generating a file, and i hadn't spotted the option to turn that off :)14:17
jamChipaca, https://stackoverflow.com/questions/36870953/jinja2-how-to-remove-trailing-newline14:18
jamit seems '-%' the '-' is relevant14:18
jamChipaca, and/or 'trim_blocks=True' 'lstrip_blocks=True' (or false) in Python14:20
Chipacajam: nah, it was the keep_trailing_newline option on the environment i was missing14:20
Chipacanot in th eblocks14:20
Chipaca's all sorted now :)14:20
jamChipaca, as long as there is yet-another-way to do it14:20
jam:)14:20
* jam aways14:21
Chipacathose options you mentio are about trimming the whitespace around {%s, as opposed to trimming the whitespace at the bottom of the file14:21
Chipacaanyway, yeah, all sorted14:21
Chipacaalso i can't type14:21
Chipacajam: the problem about "No module named 'charmcraft.commands'" kept on bugging me, but i figured it out: eggs don't like new-style namespace packages14:39
Chipacajam: easiest fix for our woes: drop an __init__.pu in charmcraft/commands/14:40
Chipacafacubatista: is there a reason for not having that __init__ beyond "wasn't needed"?14:40
Chipacajam: an __init__.py probably works better14:40
Chipacathan a .pu14:41
Chipacawhat even is a pu14:41
Chipacano don't answer14:41
facubatistaChipaca, I used that __init__.py so you can do this elegant thing in main.py:14:43
facubatistafrom charmcraft.commands import version, build, store14:43
facubatista        store.ReleaseCommand, store.StatusCommand,14:43
Chipacafacubatista: which __init__.py?14:44
* Chipaca puzzled14:44
facubatistacharmcraft.commands.store14:44
facubatistaoh, wait14:44
facubatistayou mean charmcraft/commands/__init__.py ?14:44
Chipacayes14:44
facubatistathere's not such thing14:44
Chipacaexactly14:44
Chipacaand that breaks things :)14:44
Chipacanothing serious i don't think, but it does14:45
Chipacafacubatista: that's why 'python setup.py install' doesn't work14:45
facubatistaChipaca, it's not needed theorically14:45
Chipacafacubatista: because that builds an egg, and eggs don't like new-style namespace packages14:45
facubatistastupid rotten eggs14:45
Chipacabah, it's supposed to be fixed in https://bugs.python.org/issue17633 but something's still off14:46
Chipacabecause just dropping __init__.py in there fixes it :)14:46
Chipacafacubatista: the other alternative is zip_safe=False on setup.py/setup, but that's less nice i think14:47
facubatistaChipaca, I just did ./setup.py install --prefix=/tmp/foo14:50
facubatistawhich left me a lib/python3.8/site-packages/charmcraft-0.2.0-py3.8.egg in that dir14:50
facubatistaI unzipped that egg14:50
facubatistaand it has all the files ok in it14:50
Chipacafacubatista: yes. But try running the script that you get from that install.14:50
Chipacayou get14:51
ChipacaModuleNotFoundError: No module named 'charmcraft.commands'14:51
Chipacafrom ...charmcraft.egg/charmcraft/main.py14:51
Chipacaline 2514:51
Chipacawhich was puzzling because that comes right after 'from charmcraft import __version__'14:51
Chipacaand commands is right there in the egg14:52
facubatistaChipaca, actually, https://paste.ubuntu.com/p/xzPhxjXgQN/14:52
Chipacafacubatista: i'm assuming prefix=/tmp/foo means you're not getting the egg added to your import path14:53
Chipacafacubatista: so try again with PYTHONPATH=/the/charmcraft.egg14:53
facubatista11:53:38|facundo@blackfx:/tmp/foo$ PYTHONPATH=lib/python3.8/site-packages/ bin/charmcraft14:53
facubatista  File "/tmp/foo/lib/python3.8/site-packages/charmcraft-0.2.0-py3.8.egg/charmcraft/main.py", line 25, in <module>14:54
facubatistaModuleNotFoundError: No module named 'charmcraft.commands'14:54
Chipacak14:54
Chipacafacubatista: so that's what jam spotted yesterday, and is fixed by making commands not be a namespace package14:57
facubatistaChipaca, ok14:59
Chipacafacubatista: (please confirm) :)15:00
facubatistaChipaca, confirm what? that it works? or that the theory is solid? I don't know enough of that corner, don't want to spend a couple of hours reading about it unless necessary15:00
Chipacafacubatista: that dropping an __init__.py into commands makes it work15:01
Chipacafacubatista: but, eh, we can dig next week or the other15:01
Chipacaor i can propose a pr, innit15:01
Chipacajust a silly thing really, it was bugging me15:01
facubatistaChipaca, I don't care about it, people should be using snapcraft or the branch from github :p15:02
facubatistas/snapcraft/the snap/15:02
facubatistaChipaca, and IMO nobody should never ever do "sudo pip install"15:02
Chipacapip install would've worked because it doesn't make eggs :)15:03
facubatistaI wonder why :)15:03
Chipacafacubatista: i agree, but i also don't want things to break in strange ways15:04
facubatistaChipaca, more reasons! is adding quirks to our code good for the corner case of somebody installing running setup.py?15:04
facubatistaChipaca, as you wish15:04
Chipacafacubatista: we can't control how peple use our stuff :-)15:04
Chipacawe can only control what happens when they do15:04
facubatistaChipaca, but we have to prioritize where we invest our scarce time15:05
* Chipaca invests it in diophantine equations15:05
* facubatista invests in elephants equestrianism15:06
alejdgHello everyone, I'd like to know if there's an alternative for unitdata.kv in the operator framework. If not what is the best way to save information pertinent to units15:28
Chipacaalejdg: I'm afraid I don't know what unitdata.kv is15:34
Chipacaalejdg: how would you do the thing in the absence of the operator framework?15:35
alejdgChipaca: hey, this is what I'm referring to: https://charm-helpers.readthedocs.io/en/latest/api/charmhelpers.core.unitdata.html15:36
Chipacaalejdg: that sounds like something you'd do using  _stored = StoredState()  on the charm class15:38
Chipacaalejdg: not sure doing deltas of config is a good pattern, but if you need to do it that's how you'd go about it15:38
Chipacathat'll give you per unit stored state. In the class's __init__ you'd do e.g. self._stored.set_default("some-kv", {}), and then you'd use self._stored["some-kv"] in the hook handlers15:40
alejdgnice I'll try that15:40
alejdgI'm doing that with some config data that comes from a relation.15:41
alejdgmaybe there's a better practice for it?15:41
Chipacaalejdg: and you definitely need to react to _changes_ to that data, as opposed to the data itself?15:41
alejdgChipaca: That data doesn't change once the relation has sent it15:44
Chipacaalejdg: ah so you're not looking for the "delta these things" feature, just the storing the data for later use?15:45
Chipacathen _stored is definitely what you want :-)15:46
alejdggotcha, thanks a lot!15:46
Chipacaalejdg: the 'set_default' thing is possibly the only non-obvious bit of it, where if you forget to do that and instead do the more obvious self._stored["some-kv"] = {}  in the __init__, then you're overwriting it every time15:57
crodriguezHow do I add an event? I added in init `self.framework.observe(self.on.restart_iscsi_services, self.on_restart_iscsi_services)`, I have a function defined `def on_restart_iscsi_services(self, event):`, and I added an actions.yaml file with `restart-iscsi-services` in it. But I get the error that `  File "./src/charm.py", line 47, in __init__17:37
crodriguez    self.framework.observe(self.on.restart_iscsi_services, self.on_restart_iscsi_services)17:37
crodriguezAttributeError: 'CharmEvents' object has no attribute 'restart_iscsi_services'`17:37
crodriguezI was looking at the example from https://github.com/openstack-charmers/charm-ceph-iscsi and they didn't add anything else than that for their actions17:38
crodriguezI want a user to be able to do : juju run-action restart-iscsi-services17:38
facubatistacrodriguez, let me see18:01
crodriguezfacubatista, jam told me it is because I'm missing _action at the end18:09
facubatistacrodriguez, oh, right, I didn't remember that18:09
crodriguezthere's not really an easy way to know that lol18:10
facubatistacrodriguez, our documentation status makes me sad18:10
crodriguezme too :/18:11
crodriguezanother question :) is there an easy way to set some configuration parameters as mandatory? Wondering if there is a reusable component somewhere or if I should code it myself18:11
facubatistaI don't think there's anything in the operator for that18:28
crodriguezok. Is there a way to stop the code execution after setting "self.unit.status = BlockedStatus" ?18:37
crodriguezthe charm keeps on executing so the status gets cleared up really quickly18:37
facubatista"return"?18:45
facubatistacrodriguez, I mean, if you set to blocked, and right away you do something and it gets unblocked it's fine, right?18:45
facubatistaor if you go to blocked and want to stop doing things until another event arrives, just return to exit the method?18:46
crodriguezah yeah I guess I could true/false on the check_mandatory_config function, and then exit on_install() with return depending on the result19:30
crodriguezSo in reactive I would do something like event A triggers B, when B completed -> trigger C, etc. and that way I would avoid having a really long function doing B+C. Can I do the same with the framework.observe?19:44
crodriguezcurrently I have on.config_changed -> render_config . I would like to trigger something when render_config is completed19:45
facubatistacrodriguez, have a function that does B, then another function that does C; then create a function that is hooked to event A, which calls B() and then C()20:38
facubatistaI mean, it's something that can be solved simply enough at a Python level, doesn't need to have infrastructure for it20:39
crodriguezyeah it can be. I just got used to set states in reactive and triggers things with these states, I was wondering if there is an equivalent here20:43
crodriguezfacubatista, I see options to set active, maintenance, blocked, but no option to set a charm in error state ? https://github.com/canonical/operator/blob/master/ops/model.py#L77021:23
Chipacacrodriguez: exiting with failure does that22:02
Chipacai don't think you can 'set' error state otherwise22:02
Chipacabut i'm no expert :)22:03
facubatistajam, ^ :)22:19
facubatistacrodriguez, sorry, I was off already22:20
facubatista(didn't see your message before)22:20
crodriguezoh hey :) no problem, notifications aren't great on my side neither. I think it would be good to be able to set an error state sometimes. It allows to set a message more explicit than "config-changed failed"22:47

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!