Is it okay to change a source code I haven't written? - python

I only started coding a couple months ago and I'm developing an App with Python and KivyMD.
There is a StringProperty in one of KivyMD's classes that I want to change and only managed to do it by changing the source code.
So I wondered how the community sees this. I mean, when I get a job and I see myself in this situation, it would be okay to do it?

Fork the repo, make your changes and use changed code in your project. As stated:
If you wish to contribute, the project's coding style is available there as well.
So, try to follow that code style and create a pull request afterward. If that PR is accepted, then you don't need to use your repo for your project in the future, just the original.

when I get a job and I see myself in this situation, it would be okay to do it?
Almost certainly not. The reason being: modifying the source code on your local machine is no use to anyone but yourself. In a work environment, everyone is going to need those changes (unless you're just debugging) and asking your colleagues to copy and paste your custom library file around would quickly turn into a nightmare.
Your question really needs the example of what you're trying to achieve because I'd be surprised if KivyMD has been written in a way that means you can't just sub-class the class you want to change and change the StringProperty that way.
It may well be that you want to do something that cannot be achieved without modifying the source like you say, at which point your will have to fork the repository and add your changes to it.

Related

Comment / documentation as metadata

If I type-annotate my code properly, and use something like Pylance in my IDE, when I hover over a method or function I get helpful information about that code's 'signature': the variables it expects, their types, and what I can expect from that code in terms of a response. All that is great, and I have come to rely on it in my daily coding activities.
Anyway, I was reviewing some old code of mine, and was trying to make sense of it after 18+ months (I'm sure I'm alone in that, right? lol). And although I had commented the code in question back then, looking at it now I found the comments to actually clutter things up, instead of being very helpful.
So it got me to thinking: what if there were some sort of plugin or code-assistant library that, when I hovered over a section of code, not only gave me the code's signature/type annotation info, but also gave me the documentation for that particular section? I could potentially make the comments much longer and clearer without having to worry about code bloat, or its visual impact.
tldr;
is there a way to make my comments be metadata instead of having to be embedded in the code itself?

Structure of a python project that is not a package

If you search over the internet about python project structures, you will find some articles about python package structure. Based on it, What I want to know is if there is any kind of instructions for creating structure for python projects that isn't packages, that is, projects that the code is the end code it self?
For example, I created a package that handles some requests of some specific endpoints. This package will serve the main code that will handle the data fetched by this package. The main code is not a package, that is, it don't have classes and __init__ files, because in this software layer, there will be no necessity of code reuse. Instead, the main code relate straight to the end it self.
Is there any instructions for it?
It would be good to see the structure itself instead of reading the description of it - it can help visualize the problem and answer properly to your case 😉
projects that isn't packages, that is, projects that the code is the end code it self
In general, I would say you should always structure your code! And by telling that, I mean exactly the work with the modules/packages. It is needed mostly to sperate the responsibilities and to introduce things that can be reused. It also gives the possibility to find things easier/faster instead of going through the unstructured tones of the code.
Of course, as I said, it is a general thought and as far as you are experienced you can experiment with the structure to find the best one for the project which you are working on. But without any structure, you won't survive in a bigger project (or the life will be harder than you want).

Auto code intelligence in Python and Pycharm

I am wrting a Python application for the first time and I am using Pycharm as the slected IDE. One thing that I notice I can;t see all classses and methods for the object I am using. I have coded with intelligIdea to code Scala and Java as well. They are easier to code since code intelligence is really handy but In Python it is not convineit..
suppose I am writing
divs=innerTree.cssselect('div.story-body__inner')
when I write innerTree. Pycharm doesnt suggest cssseelct while I used to write Scala/Java with the same Idea, they suggested all available accesible classes.
Is thet any problem with my IDEA?
There are a few of possible reasons:
innerTree doesn't actually have a cssselect method. Seems obvious, but this one catches me out more often than I'd like to admit.
PyCharm doesn't know what innerTree is an instance of.
You need to clear PyCharm's cache and restart. Which is pretty much the "have you tried turning it off and on again?" of PyCharm.
Side note, you can also use IntelliJ to do everything that PyCharm does. It's a bit harder to set up, but it's easier that switching back and forth i.m.o.

wx.DirDialog and App Store Sandboxing

As I understand with a sandboxing that Apple added you can no longer write outside your sandbox, but using the NSOpenPanel you can ask the user to specify the directory and let you write there. For example, there is this wrapper to simplify things: https://github.com/leighmcculloch/AppSandboxFileAccess
But I have a python app using wx, which I need to extend to support this, but as I understand wx.DirDialog doesn't have anything like this. https://wxpython.org/Phoenix/docs/html/wx.DirDialog.html?highlight=dirdialog#wx-dirdialog
Is there some other class for this?
P.S. I'm quite new to the wx+python so maybe there is some other option like integrating those Obj-c classes and using them instead of DirDialog? Although I would like to avoid it if possible

How do I use the wx.lib.docview package?

I'm currently working on a simple wxPython app that's essentially document based. So far I've been manually implementing the usual open/save/undo/redo etc etc stuff.
It occurred to me that wxPython must have something to help me out and after a bit of searching revealed the docview package.
At this point though I'm just not quite sure how to hook everything up and get things started. Anyone got any good links or hints about places to start?
The docs seems to be a little thin about this and Robin Dunn's wxPython book doesn't really cover this package at all.
You might take a look at the docviewdemo.py from the wxPython Docs and Demos:
on my machine they are located:
C:\Program Files\wxPython2.8 Docs and Demos\samples\pydocview\
C:\Program Files\wxPython2.8 Docs and Demos\samples\docview\
In addition to the ones mentioned, there is quite an extensive example docview/pydocview in the samples\ide. If you want it to run you will have to make a few code corrections (I have submitted a ticket that outlines the fixes at trac.wxwidgets.org #11237). It is pretty complex but I found it handy to figure out how to do some more complex things. For example, samples\ide\activegrid\tools\ProjectEditor.py is built from scratch and has undo support etc rather than just relying on a control that does everything for you already. That way you can see how things are supposed to be done at the detailed level. The documentation is rather useless in that regard.
If you have decided against using docview/pydocview I have a spreadsheet application built on wxPython that you may find useful as an example. While it does not implement a document view framework it does have some characteristics of it and I've implemented an undo/redo system. Check it out at http://www.missioncognition.net/pysheet/ I'm currently working on a pydocview based app so I expect that to be up on my site eventually.

Categories

Resources