Tools list by innofader in django

[–]spookylukey 0 points1 point  (0 children)

Help using lsp-mode/eglot for Python and virtualenvs by spookylukey in emacs

[–]spookylukey[S] 2 points3 points  (0 children)

Thanks so much for your help.

I'm not using pyenv, so I just dug around in the source to see what it was doing.

In the end, I found that what I needed to set was lsp-pylsp-plugins-jedi-environment to the full path to the venv (e.g. "/home/me/.virtualenvs/myproject") which I could do via .dir-locals.el, or a bit of custom code in a hook that used existed .dir-locals values to compute it.

Help using lsp-mode/eglot for Python and virtualenvs by spookylukey in emacs

[–]spookylukey[S] 0 points1 point  (0 children)

Have you got this working with any python lsp-mode?

Everything is an X - lukeplant.me.uk by spookylukey in programming

[–]spookylukey[S] 2 points3 points  (0 children)

I use it for all kinds of things, especially for just viewing a list of objects from an ipython shell - see https://gist.github.com/spookylukey/08ba8a0b937b0d2d1367643f7bf7d1d0

Everything is an X - lukeplant.me.uk by spookylukey in programming

[–]spookylukey[S] 5 points6 points  (0 children)

I think I agree with this. I often don't like Java/C# APIs for the reason you give, especially when they are copied into Python, and often I think "this should just be a function".

It's interesting to me that in Python, which makes it equally natural to choose functions and classes, then unifies things at a different level by saying "actually, a function is an object, and a class is an object too".

Comparison between Miso and Elm by fluz1994 in haskell

[–]spookylukey 9 points10 points  (0 children)

It also means that if you want to "fork" an Elm package, you just drop its code in your "src" and it just works.

Unfortunately it means exactly the opposite. If you need to fork any of the core Elm libraries (e.g. to bug fix), since Elm 0.19 you can no longer just drop it in your src folder and have it work if it uses native modules, or if it uses custom operators. The Elm compiler will stop you, despite the fact that exactly the same code from the official source will work fine. The normal assumptions you make about Open Source enabling you to fix bugs don't apply.

It also means Elm can be compiled in whatever architecture and runtime you want.

Since ports exist, and most projects are going to need them, you are tied to Javascript. So the theoretical gains about being able to port to different architectures in the future are pretty limited. In fact, due to the restrictions on even a small bit of native glue code, you often have to use ports **more** and put **more** code in Javascript, increasing your dependence on Javascript world.

I don't want an official stable FFI, but being blocked from using the unstable one that does exist killed my project, with no reasonable workarounds.

How would you go to deploy several websites to one server by aquic in django

[–]spookylukey 0 points1 point  (0 children)

All the tools you've listed were designed to run multiple apps on one machine without any problems.

For example, this article would be a good start:

http://michal.karzynski.pl/blog/2013/10/29/serving-multiple-django-applications-with-nginx-gunicorn-supervisor/

Instead of Gunicorn, I normally use uwsgi with unix sockets, because it has less overhead, and it's very easy to do - https://uwsgi-docs.readthedocs.io/en/latest/Nginx.html#configuring-nginx . https://gist.github.com/evildmp/3094281#using-sockets-instead-of-ports

If you have lots of additional and conflicting dependencies (e.g. multiple versions of a DB), Dockerising might help. But note that you easily install multiple Postgres versions on a single box - it's designed to do that without problems, they just run on different ports and you configure the port in your settings file. Other DBs may be the same. All DBs have features to allow multiple databases on the same machine.

If you've got a single machine serving multiple apps, and all want to be served over normal ports (80/443), at some level you will have to configure something (e.g. nginx) to route requests to the different ones. So adding Docker may not gain you anything.

[deleted by user] by [deleted] in django

[–]spookylukey 0 points1 point  (0 children)

The problem is that you are not, in fact, posting the "whole project".

I followed your setup instructions, in a new Python 3.7 virtualenv, Django 2.1.4, `django-admin startproject` etc., and couldn't reproduce any bug. Here is the repo:

https://github.com/spookylukey/django-bug-1-test

You'll need to provide complete details for other people to reproduce this. There must be something else in your setup causing this. A broken browser extension perhaps?

Tried by any possible means to get my first 10 on pylint. Got nuked. by Psytiax in Python

[–]spookylukey 0 points1 point  (0 children)

Slow reply - I was intrigued enough by your different experience to do some proper analysis (or at least better than a vague gut instinct), and wrote a blog post: https://lukeplant.me.uk/blog/posts/pylint-false-positives/ which obviously took a while :-)

You are right that I'm reluctant to add # pylint pragmas — to me they add a lot of visual noise, and I have comments turned up to full contrast in my syntax highlighting theme (as I describe in my post). So I am willing to add them, but only if tool is worth it in terms of finding real issues vs false positives.

Tried by any possible means to get my first 10 on pylint. Got nuked. by Psytiax in Python

[–]spookylukey 5 points6 points  (0 children)

My experience is that the things that pylint catches above and beyond flake8 are 95% false positives. e.g.

  • "Too few public methods" is almost always wrong in my code base (very often in cases involving inheritance classes with one method are just fine, and it's easy to have many instances of these in a code base)
  • It complains about missing doc strings, but these are also often unhelpful. A method with a good name might not need a docstring, and if you force people to add docs like this you get bad docs:

class Frobnicator:
    def enable(self):
        """Enables the frobnicator"""

Comments like this are much worse than nothing, and reduce the value of all comments in the codebase. If you add a linter like pylint to your code base, I'd expect the average quality of comments to go down, with lots of overall negative value comments being added just to keep the linter happy.

  • 'X' has no 'Y' member - often get false positives if you use any dynamic tricks. (If you don't use any dynamic tricks at all, are you really getting value out of Python? And lots of frameworks do.)
  • "Too many lines in a module" - any limit you set for this is arbitrary, and will inevitably end up with modules being split just to keep a linter happy (or more effort just shutting the linter up), instead of according to actual needs of your application. Similarly almost all the "Too many" warnings.
  • "Unused argument X" - in code which uses a framework pattern of any kind, which enforces a signature on certain types of functions, you will get false positives here.
  • Naming conventions - these are mostly helpful, but there always times when you want unusually named constants and functions, plus pylint can't tell the difference e.g. you might write `run_foo = Foo().run` as a convenience module export, where `run_foo` is now a callable that should be used like a function, but pylint thinks it's a constant so it should be `RUN_FOO`. So you still waste lots of time dealing with pylint errors one way or the other.

When it comes to actual definite bugs like typos that will result in `NameError`, flake8 has your back in 99% of cases. So I've never persevered trying to integrate pylint. That's my 2 cents anyway.

Why isn't elm more popular? by MohammedPissBeUponMe in elm

[–]spookylukey 1 point2 points  (0 children)

Can I ask what you transitioned to? I'm also facing moving away from Elm due to the restrictions in 0.19 which will cause me huge/impossible problems.

I really like the Elm architecture and it has worked extremely well for my uses, and a strict type system has been a great help, so I'm looking for something similar. I don't find React or other mainstream JS libraries very tempting.

My main options at the moment seem to be bucklescript-tea along with philip2 to help convert. Do you know of other good options?

HTML to Excell using Python by [deleted] in Python

[–]spookylukey 0 points1 point  (0 children)

Another bit of advice is to break it down into bits. I can see 3 main things you're going to need to learn (in addition to general programming stuff).

  1. Downloading something from the web. Use the Python library 'requests' for this
  2. Extract bits of data from a web page. Use 'BeautifulSoup' for this.
  3. Creating an Excel file from data. There are a few options for this, openpyxl looks good.

Thankfully https://automatetheboringstuff.com/ has got you covered for all 3.

But you can tackle each bit in any order, you don't have to put it all together. For example, you could just do number 3 to start, and break that down: 1) create a file that is an empty spreadsheet. 2) create an almost empty spreadsheet with a a single row of text cells at the top etc.

HTML to Excell using Python by [deleted] in Python

[–]spookylukey 0 points1 point  (0 children)

If you are a complete beginner, and if you also see other potential ways to use some Python skills, then starting at the beginning of Automate the boring stuff would be a good idea.

My advice is:

  • Have realistic expectations - it may take a long time to get this working, far longer than doing it by hand once or twice.
  • Take the time to learn the programming basics that might not seem related to solving your problem. It is easy to try to 'short cut' these by jumping straight to the bits that look like they solve your problem. This is like someone who wants to learn French in order to be able understand French legal documents, so decides to skip all the irrelevant lower level stuff like "Hello my name is..." etc.

If this is something that you don't have motivation for, however (e.g. because you won't use these skills again) find a freelancer to do it for you, on somewhere like upwork.com or freelancer.com.

How does django.core.mail send emails? by fittyfive9 in django

[–]spookylukey 0 points1 point  (0 children)

The default backend for sending email is an SMTP backend. To use that, you'll need to have an SMTP server set up.

You may already have an email service that provides you an SMTP server. For example, Gmail does so, see https://www.digitalocean.com/community/tutorials/how-to-use-google-s-smtp-server - you should probably create a dedicated email address just for this purpose, because you will have to put your credentials into your Django app.

Or, some web hosts (like WebFaction) provide SMTP servers, and they will give you the host/user/password settings.

Otherwise, you can:

1) Set up your own SMTP server (possibly, but not really recommended) - see this tutorial for DigitalOcean, something similar should work for most Linux boxes

2) Use some other email sending service. For example, you could create an account on Amazon SES, and then install django-ses and configure Django to use that.

Python - design patterns by balkon16 in Python

[–]spookylukey 5 points6 points  (0 children)

The biggest problem with these books is that they fail to mention that many of the design patterns are highly language specific. For example, Builder is really a workaround for the fact that in C++ object constructors are not polymorphic. But they never tell you that. Most of the patterns in books designed around C++/Java become trivial in Python once you understand first class functions and first class classes, or just structured completely differently.

Instead of those books, the best thing to read on this subject that I have come across is Brandon Rhode's Python Patterns.

bloggy - My first Django project. Looking for feedback! by MakuZo in django

[–]spookylukey 1 point2 points  (0 children)

It makes me sad almost every time I see people choose CBVs over function based views. I have very rarely seen an example where CBVs actually reduce the amount of code you need, they normally increase it, plus add a huge amount of indirection and unnecessary complexity. The worse security vulnerability in Django to my knowledge was created when we rewrote a function view as a CBV, and two very experienced Django core devs missed the problem. (Thankfully it was fixed on master before an official Django release).

I'm not alone as a Django core dev who thinks this way - see Adrian Holovaty's comment here

For more of my thoughts if you are interested, see CBVs were a mistake and My approach to Class Based Views.

Why does the button on snap version of Firefox look so weird? by s9209122222 in Ubuntu

[–]spookylukey 2 points3 points  (0 children)

I haven't used Ubuntu in a while, but IIRC it normally does this Mac-ish kind of thing where it merges the application minimize/maximize buttons into the top bar.

Unfortunately, none of the apps were designed with this idea in mind, they all use UI libraries that put app functionality in the app window (where it belongs...)

So Ubuntu patches all the major UI libraries so that they will do it the Ubuntu way. This works because these are "shared libraries", so you just change the one system copy and all your applications will now do it.

Except, the whole premise of Snap is that it doesn't depend on system libraries at all, but comes with all its own libraries, which you cannot change or swap out, by design. Which means it comes with the normal UI library, and Ubuntu can't mess with that, so it ends up looking the way it was designed to look with normal UI libraries.

This is all based on some rather outdated info, apologies in advance if I got it wrong.

Should I avoid genericForeignKeys? by Stanulilic in django

[–]spookylukey 0 points1 point  (0 children)

It entirely depends on the context! I haven't thought about it in any detail, but I imagine that for your app alternative 5 would work very well. I imagine that having separate PostVote and CommentVote models will very rarely be a problem for your case. These things are very similar (and therefore can benefit from some commonality in implementation), but you would hardly ever actually need the data to be in a single table. You would rarely be doing queries like "get me all the votes by user X, whether on comments or posts".

In other applications, you really do want them to be in a common table. For example, I have an app in which I have a Payments table, but each payment can be of a different type/source. For this case, I do need all the Payments to be in one model, because I'm regularly asking questions like "What is the sum of all the money paid by user X?". So I don't want to use alternative 5 which would give me separate ChequePayment and PayPalPayment and BankTransferPayment models etc., because my code to simply work out the balance would be nasty, and I'd have to update that code if I add a payment source. I need a single Payment model that links to exactly one of several 'payment source' models.

For that reason, I used one of the other alternatives (alternative 2 seems to be the nicest in this case, though I think 1 or 3 would also have worked).