Forum Archive

Hackathon Challenge set by ccc (started new thread)

Phuket2

@ccc, I have some questions. I hope you don't mind I started a new thread here. Was not sure we're to put it, Pythonista or General. So to be safer I put it here.

Hackathon Challange: write code that uses the Python inspect module to find all the functions and methods in the ui module and auto generate a ui.py file that has those same functions and modules stubbed out (with pass statement) such that an editor like sublime or PyCharm on Windoze or a real computer (e.g. Mac) will do autocompletion on all functions and methods of Pythonista ui code. All winning entries must 1) deliver correct code completion for all ui methods and functions, 2) pass all PyCharm PEP8 compliance tests (esp. line length) and 3) be posted in a GitHub repo by 8am Eastern time on Monday 14 Dec 2015 time. If there are multiple entries that pass the above tests then the shortest number of (nonblank) lines of code wins.

Can you complete the challenge?!?

Phuket2

@ccc, some stupid questions. I have never participated in such a thing before.
1. Eastern time, which eastern time? Is gmt offset better?
2. Ok, we create a repo, is suppose to be private/public. How do we infom you of the repo? Just a post here? Somehow that does not seem right.

omz

Am I qualified to enter? ;)

Anyway, here's a start:

ui_stub_generator.py [Gist]

Phuket2

@omz , lol. I have almost finished mine. I h think I have done a good job. I will not look at yours yet, I want to finish 100% on my own first. It's taken me many hours, I am sure it took you all of 5 mins 😭
But you know @ccc, is very correct. That's why I have taken so long, I keep revising.

MartinPacker

As @ccc is a fellow IBMer :-) I understand his meaning of Eastern to be "East Coast USA" i.e. 5 hours behind GMT.

(Mentioning IBM as we have a variant of English all our own - as do most large organisations.) :-)

ccc

As a Native New Yorker, Eastern Standard Time or Eastern Daylight Time (don't axe me to define the difference!) is New York Time. I was actually going to put Swiss Time because that home for me. But what I was really after was to give everyone all of Sunday to complete their work. Anyway, you have until 8am New York Time to get it done. You can use http://worldtimeserver.com or the iOS Clock app to calculate your local time. As Martin sayz, we at IBM live this on a weekly basis and many IBMers have the muscle memory to be able tell you the current time in Bejing, Bangalore, New York, and Silicon Valley without pausing. International is part of who we are.

The repo should be open. You can drop the URL here in this thread.

@omz of course you are eligible to participate!! I like @Phuket2 will avoid looking at other submissions while I work on my own.

Rule 0 was implied in the initial write up: you must use the inspect module to get the structure of the ui module.

There are two PEP8 rules that your output is allowed to break: you can put pass on the same line as the preceding line and you don't need blank lines if you don't want them.

Thus you could have:

i_will_survive = True
class DarkStar(object):
    def __init__(self): pass
    def draw(self): pass
class TheOtherOne(): pass
the_eleven = 11
ccc

Oh... I forgot, you need the variables in addition to the classes, functions, and methods to really get full auto completion.

Phuket2

@ccc , I am in the dark already.
Variables?
def _bind_action(v, action_str, f_globals, f_locals, attr_name='action'):
pass
If I have the above, does that mean I have variables? Sorry as I say, first time for me.

dgelessus

There. (It's meant to generate a stub for _ui. The ui module is written in Python and can be copied over from the app.)

ccc

I will try to roll away the dew...

I meant module level variables that type ahead in Pythonista would suggest like: ui.ACTIVITY_INDICATOR_STYLE_WHITE_LARGE.

Tizzy

GLHF! I'm lost however.

@ccc are you one of the IBM devs working on iOS enterprise apps?

Phuket2

Lol, I am still going....but @omz whatever score you get from @ccc would be -2 , 😜

Phuket2

Ok, my one is here
I didn't exactly follow the challenge. But I am glad it's finished, can look at the other ones now.

Phuket2

@omz , the -2 is not about your submission, but about the edge cases in ui.py etc.... 😜
But out of interest, is the convert tabs tools menu item a call to inspect.cleandoc()?
In an ideal world, would you run that over your modules such as ui and dialogs when you publish, or do you do something else?

JonB

@Phuket2 I believe convert tabs uses this:
editor.open_file(os.path.abspath(os.path.join(sys.executable,'../pythonista_reindent.py')))

Phuket2

@JonB, ok thanks. Just doing this challenge got me thinking. I guess the best is not to think too much 😁 I learnt along time ago never to trust your input. But I had sort had forgotten that lesson. Learning and re-learning 👍

Phuket2

@JonB , sorry was a stupid question. I see now inspect.cleandoc() works on docstrings not the document/module

omz

out of interest, is the convert tabs tools menu item a call to inspect.cleandoc()?

It's more or less what @JonB said.

In an ideal world, would you run that over your modules such as ui and dialogs when you publish, or do you do something else?

I don't really use anything to auto-format my code, I just try to make it look nice while I write it. I don't think any of my own Python code is PEP-8-compliant (I prefer tabs instead of spaces, and don't care that much about line length).

Webmaster4o

@omz said:

I don't really use anything to auto-format my code, I just try to make it look nice while I write it. I don't think any of my own Python code is PEP-8-compliant (I prefer tabs instead of spaces, and don't care that much about line length).

I break the exact same rules as you do in my code :) @ccc sometimes creates pull requests on my code just to shorten line lengths

ccc

LOL... https://www.python.org/dev/peps/pep-0008/#a-foolish-consistency-is-the-hobgoblin-of-little-minds I have a little mind.

Remember, as the repo owner, you are always free to reject pull requests. ;-)

Phuket2

@Webmaster4o , you have to love it though 😀 @ccc beats me up on all sorts of what I thought was small stuff. But in the end it really has helped me. Well let's say helping....

Webmaster4o

@ccc but they're almost always things I want but didn't bother to do.

Phuket2

@ccc we need to see your repo within the next hour and half 😱

Phuket2

@ccc , do we get to see your repo?

ccc

So... I was not able to complete the hackathon myself. Year end at work is keeping me totally occupied so I got the first 30% done but had to abandon the effort. I will try to create another hackathon topic in the new year when I have more time to devote to it.

Phuket2

@ccc , that's a shame. But I understand. Was looking fwd to see what you had done. I know, I lost the plot somewhere 😁 It was still fun doing it though.
Look fwd to the next one in the new year

Webmaster4o

@ccc New hackathon topic: a fake ui module that actually makes Tkinter calls, but allows you to run UI scripts on a desktop computer! (This is unrealistic, but I'd love this support)

Phuket2

@Webmaster4o , I am sure it would been a challenging and may daunting for the best of the guys here. And a bit more than a part time thing. At least I think. But I think with the inclusion of the objc_util that ship has well and truly sailed.

But I used to think the same. Would so cool to have this ui on the Mac. I understand the cross platform needs, but from what I have seen briefly playing with TKinter, it's ugly. Not inspiring at all to build an interface. And compared to the ui module it's so convoluted.

I think if ui was available on macs as we see it here, would be a huge hit given that it didn't have to be cross platform. Even on Pcs for that matter. I just think that if was ever done, should be seperate projects with a shared interface. Not all these compromises to have a shared code base. They just don't seem to turn out right. Maybe there others on the market that are more elegant than I have seen.

But with a ui module style interface, I think it would be a death blow for AppleScript. It's amazing Python is sitting there in the background on macs and people resort to AppleScript.

Oh well, that's my 2 cents worth. So not just running Pythonista scripts on the Mac, but to give the Mac users a reason to want to use and learn Python without thinking they are stuck in a console . Very in appealing thought, also makes Python seem old and antiqued and should be only used by techie guys.

Webmaster4o

Tkinter doesn't look too bad on mac, I think it just looks crappy on a Windows/linux machine.

ccc

The way to get started is to pick just one class out of the UI module and implement that. Afterward, you will have a much better sense of the degree of difficulty and you will also have a demo to convince others to join your effort.

Webmaster4o

yeah. Right now I've got two other projects that are as much as I can handle (A chatbot, and an PHP API for retrieving my grades from my school's servers), but I'll consider this once I finish with these projects.