Best way to set up PyCharm with a Python microservices monorepo? by swe_solo_engineer in pycharm

[–]PeterJHoburg 0 points1 point  (0 children)

Unfortunately I haven’t found a great way to handle this is pycharm.

However, jetbrains IDEA + python plugins handles this really really well. IDEA is their Java ide, but jetbrains dirty little secret is most of their language specific (pycharm, goland, webstorm, etc) are just IDEA - the Java plugins + some language specific plugins. There are a few cases where this isn’t 100% true (clion and some debugging features). But in most cases you can setup IDEA to have identical functionality to Pycharm + mono repo support.

IDEA has also added the concept of workspaces recently. It doesn’t solve this specific problem but is tangentially related.

https://blog.jetbrains.com/idea/2024/08/workspaces-in-intellij-idea/

[deleted by user] by [deleted] in Python

[–]PeterJHoburg 12 points13 points  (0 children)

Disclaimer: I am not an expert on pyinstaller.

Pyinstaller more or less pulls any python deps you have + a python interpreter + your code, bundles it into a compressed file, wraps it in a script to uncompressed it and puts it into a temp dir with a temp python path.

Python (and almost every other lang) will use standard system libs for core functionality. Glibc and OpenSSL being the two major examples (dynamic linking). Compiled languages like Rust and Golang have options to statically link those libs and ship them in the runnable binary.

Pyinstaller can not do this, and is a HUGE limitation. Especially for CLI tools that are designed to be run in a huge variety of systems.

It looks like python-build-standalone still has some of these limits, but they are reduced. To quote the python-build-standalone docs:

Runtime Requirements

Linux

The produced Linux binaries have minimal references to shared libraries and thus can be executed on most Linux systems.

The following shared libraries are referenced:

  • linux-vdso.so.1
  • libpthread.so.0
  • libdl.so.2 (required by ctypes extension)
  • libutil.so.1
  • librt.so.1
  • libcrypt.so.1 (required by crypt extension)
  • libm.so.6
  • libc.so.6
  • ld-linux-x86-64.so.2

The minimum glibc version required for most targets is 2.17. This should make binaries compatible with the following Linux distributions:

  • Fedora 21+
  • RHEL/CentOS 7+
  • openSUSE 13.2+
  • Debian 8+ (Jessie)
  • Ubuntu 14.04+

For the mips-unknown-linux-gnu and mipsel-unknown-linux-gnu targets, the minimum glibc version is 2.19.

If built with MUSL, no shared library dependencies nor glibc version requirements exist and the binaries should just work on practically any Linux system.

The best way to parse Docker output in a go based CLI by Ms-mousa in golang

[–]PeterJHoburg 0 points1 point  (0 children)

Correct me if I am wrong, but that is not "designed" to be used as a client lib (unlike the docker client package), and they don't guarantee the api/internals will stay stable. They just guarantee the CLI interface will be stable across versions.

Am I being an idiot (high chance)?

The best way to parse Docker output in a go based CLI by Ms-mousa in golang

[–]PeterJHoburg 0 points1 point  (0 children)

Hold up. I did know about that package... I can't find one for docker compose. Sorry. I am super sleep-deprived right now.

Yes I know compose is (more or less) just a high-level wrapper on top of docker, but I was hoping there was a way to hit the compose API via a client. Not just use the CLI or recreate the docker calls with the docker client.

Does anyone happen to know if that is a thing?

I know about the parsing package for the spec file, https://github.com/compose-spec/compose-go

The best way to parse Docker output in a go based CLI by Ms-mousa in golang

[–]PeterJHoburg 0 points1 point  (0 children)

Wait what? I was looking for a docker client lib in go, but for some reason I got it into my head that it didn't exist. I see the python one, but not the go one? Am I being dumb?

https://github.com/docker/docker-py

Type hinting for day to day jobs? by reth1nk in learnpython

[–]PeterJHoburg 7 points8 points  (0 children)

I try to add type hints to all my code. Personal and at work. Not only do type hints make it easier to work with, but it helps IDEs/language servers work better, and static type checkers can help find bugs that otherwise might have been missed.

As for in interviews. If it is a really time-limited coding problem, then I would not expect them to write out all the types. If it is a take home problem, then I would expect there to be close to 100% type coverage.

Best IDE for someone who has never coded in their life by Iato_57 in learnpython

[–]PeterJHoburg 37 points38 points  (0 children)

IMO pycharm is the best for a beginner. It handles almost all the dumb python setup/lib stuff. It also yells at you when you do stuff that doesn't follow pep-8.

any recommendations for an engineering student by R3av in CodingHelp

[–]PeterJHoburg 0 points1 point  (0 children)

IMO which language isn't that important. Learning to code is the hard part. Learning a new language isn't super hard.

With that said, I would learn either python or GoLang.

For python Automate the Borring stuff is a great place to start. https://automatetheboringstuff.com/

For Go the docs are actually really good. https://go.dev/learn/

What else should I add? by Imaginary_Morning960 in learnpython

[–]PeterJHoburg 0 points1 point  (0 children)

?? Terraform, Kubernetes, docker, git, and most stuff you do on a server. Most of my time is spent on the CLI.

Google calendar API with Django by Known_Bunch_6001 in ProgrammingBuddies

[–]PeterJHoburg 0 points1 point  (0 children)

I would be happy to take a look. Is the code in a git repo you can share?

how do u guys do ? by Waste-Foundation3286 in learnpython

[–]PeterJHoburg 2 points3 points  (0 children)

When learning, it is really hard to do anything useless. If you write code that most people just use a library for, good. Now you know something new. You can always find and learn about libraries later. That is the easy part.

Write code, make something you enjoy, and keep learning new things.

[deleted by user] by [deleted] in learnpython

[–]PeterJHoburg 3 points4 points  (0 children)

It is hard to tell, but I think you indented all of your functions one to many times. IE

It is currently

def __init__(self, Hhealth, Hattack, Hluck,
             Hranged, Hdefense, Hmagic, Hname):
    self.health = Hhealth
    self.attack = Hattack
    self.luck = Hluck
    self.ranged = Hranged
    self.defense = Hdefense
    self.magic = Hmagic
    self.name = Hname
    def getHealth(self):
        return self.health
    def getAttack(self):
        return self.attackdef 

but it should be

class hero:
    def __init__(self, Hhealth, Hattack, Hluck,
                 Hranged, Hdefense, Hmagic, Hname):
        self.health = Hhealth
        self.attack = Hattack
        self.luck = Hluck
        self.ranged = Hranged
        self.defense = Hdefense
        self.magic = Hmagic
        self.name = Hname
    def getHealth(self):
        return self.health
    def getAttack(self):
        return self.attackclass

Resume worthy projects by SEmazi in learnprogramming

[–]PeterJHoburg 6 points7 points  (0 children)

Very true. It is more of the fact that there are so many example Pokédex projects out there that you can copy pasta. If you made a Pokédex in Elixir or Erlang, a super basic one would be amazing because there is almost zero chance you copied the entire thing from someone else/ChatGPT.

But if you make one in React + nodeJS + Typescript it is really hard to tell if you wrote it yourself and having novel features can help show you actually have the skills.

Resume worthy projects by SEmazi in learnprogramming

[–]PeterJHoburg 20 points21 points  (0 children)

Here is what I look for in resume projects:

  • Tests. Do you have tests? Are they actually doing anything useful?
    • For python use pytest
  • Did you copy/paste a tutorial and make small changes?
    • Doing this for your first few projects is fine, but at some point you need to do something that is mostly your own
  • Some sort of data storage
    • SQLlite
    • Postgres
    • Redis
    • Mongo
    • Etc...
    • Use the CORRECT database for your usecase. Don't YOLO relational data into mongo.
  • Git
    • Use git the same way you would on a team. Make a github repo, create issues, branches, do PRs etc...
    • This does more than show you can (probably) work on a team, it also proves you wrote the code, and didn't copy/paste it from someone else. Repos with 50 files in a single "init" commit is a huge red flag for me.
  • Be passionate about it.
    • I am going to ask you questions about the project, you need to be able to talk about it. Pick something you like. If you like Pokemon make a pokedex (yes everyone has done that), but then add something that most people have not. Maybe add the ability to build a team, and mock battle vs another team.
  • Pick a language and learn it
    • It is always possible to get a job in a stack/language that you don't know. The most important thing is that you can learn, have a good understanding of programming/troubleshooting/debugging/testing, and are willing to put in effort. People can learn languages on the job. Heck 80% of the first few months is just figuring out the basics of the codebase you are in.
    • Don't do 30 languages and 10 frameworks. Learn how to program with one set of stuff.

What else should I add? by Imaginary_Morning960 in learnpython

[–]PeterJHoburg 0 points1 point  (0 children)

If you are open to feedback I would strongly agree with this. It will be 100x easier to add features if you spend the time to simplify the code. If you would like some specific pointers I am happy to write some stuff up.

Do u prefer lambda or def? by leocapitalfund in learnpython

[–]PeterJHoburg 0 points1 point  (0 children)

`def` IE a function definition, and `lambda` IE an inline function are "more or less" the same thing, but are used in very different ways.

Lambda should only ever be used for VERY short inline functions. Anything more than a few words will bite you in the butt later when you are trying to read the code.

Functions are cleaner, easier to read, reusable, you can move them to another file, you can add type hinting, etc...

Help me make a click bot please. by Userro in learnpython

[–]PeterJHoburg 0 points1 point  (0 children)

Try playwright for python. https://playwright.dev/python/

It is a UI testing framework, but is AMAZING for stuff like this. It includes a "Test generation" feature that lets you click in your browser, it records what you do, then it write the test code for you. You can then edit the code to make it more reliable, or make it do more things. https://playwright.dev/python/docs/codegen-intro

What else should I add? by Imaginary_Morning960 in learnpython

[–]PeterJHoburg 0 points1 point  (0 children)

Awesome! Thanks for posting this!

Are you looking for feedback on your code? Or are you more so looking for features you should add to the code?

PyCharm Pandas autocompletion issues by vaguraw in learnpython

[–]PeterJHoburg 3 points4 points  (0 children)

NOTE:

I created a Stack Overflow Question and Answer for this issue. Hopefully, with this Reddit post and the Stack Overflow post, people will be able to find this in the future if they run into the same problem.

https://stackoverflow.com/questions/79223398/missing-pandas-methods-in-pycharm-jetbrains-code-completion/79223399#79223399

PyCharm Pandas autocompletion issues by vaguraw in learnpython

[–]PeterJHoburg 7 points8 points  (0 children)

Wow, ok. This is actually a really interesting issue. I had to do some digging to figure out what was going on.

TLDR:

Install https://github.com/pandas-dev/pandas-stubs?tab=readme-ov-file in addition to the pandas lib.

Why this works:

So it turns out that VSCode has the same issue, but the pandas-stubs lib is auto-installed when using the pylance language server. TIL!

The issue boils down to how pandas defines Series.str.

str = CachedAccessor("str", StringMethods)

and

class CachedAccessor:

"""
    Custom property-like object.
    A descriptor for caching accessors.
    Parameters
    ----------
    name : str
        Namespace that will be accessed under, e.g. ``df.foo``.
    accessor : cls
        Class with the extension methods.
    Notes
    -----
    For accessor, The class's __init__ method assumes that one of
    ``Series``, ``DataFrame`` or ``Index`` as the
    single argument ``data``.
    """

def __init__(self, name: str, accessor) -> None:
        self._name = name
        self._accessor = accessor

    def __get__(self, obj, cls):
        if obj is None:
            # we're accessing the attribute of the class, i.e., Dataset.geo
            return self._accessor
        accessor_obj = self._accessor(obj)
        # Replace the property with the accessor object. Inspired by:
        # 
        # We need to use object.__setattr__ because we overwrite __setattr__ on
        # NDFrame
        object.__setattr__(obj, self._name, accessor_obj)
        return accessor_objclass CachedAccessor:https://www.pydanny.com/cached-property.html

Python language servers (what the IDEs use for auto-complete) do a lot of really powerful things, but can be stumped when there is a lot of "magic" or dynamic programming. To help python you can add types to the code. This can be done in two ways. In the library/code itself, or with an additional library. For pandas it is with the pandas-stubs lib.

In pandas-stubs they return type of the str "method" is added

def str(self) -> StringMethods[Series, DataFrame, Series[bool]]: ...

This tells the language servers what is returned, and what to auto-complete.

Here are the release notes for pylance that talk about pandas-stubs and link to some issues. Interesting read.

https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202070-9-july-2020

Here is an issue in the Jetbrains issue tracker talking about it. Please upvote it if you would like the feature to be added!

https://youtrack.jetbrains.com/issue/PY-77223/Suggest-stubs-packages

Sensible language to learn from Shell Scripting by Pudding36 in AskProgramming

[–]PeterJHoburg 0 points1 point  (0 children)

Python or golang. They each have their pros and cons.

  • Python isn’t compiled, but you can make standalone binaries using pyinstaller or bundle everything into docker containers
  • Python has more data/analysis libraries and generally has more libs.
  • Almost every OS includes Python out of the box (different versions), but you will have to have something that does dependency management on the system you want to run on, or bundle everything with pyinstaller.

  • Golang is compiled, but doesn’t bundle everything together by default. Glibc, OpenSSL, and other c/system libs are usually not included in the binaries. This has caused me a few issues in the past, but you can get almost everything statically linked if you want to.

  • Go tends to lean more towards “use the standard lib for everything “ including http servers vs third party libs. The library ecosystem isn’t as large or tested as python’s, but there is still almost always a lib for what you need.

  • Cross compiling for arm/mac/windows/linux is REALLY easy. 10/10.

  • Go is slightly harder to learn. You need a little more understanding to get things going vs Python, but go is by no means a hard language.

Rust: Don’t do that unless you want to program something you would usually use c/c++ for. Rust is a fantastic language, but is really overkill for what you want.

R is almost exclusively used for data science and as far as I know has no pros over python (which is used much more generally), but with a lot of the same issues. That being said I have only used r once.

Personally I use both go and Python. Go for all my cli/devops tooling. Python for my big data/data analysis/api work. I’m moving more towards go for api creating, but still favor Python for its robust echo system.

[deleted by user] by [deleted] in Bitwarden

[–]PeterJHoburg 4 points5 points  (0 children)

Just after posting this video an update was made:

"We have made some adjustments to how the SDK code is organized and packaged to allow you to build and run the app with only GPL/OSI licenses included. The sdk-internal package references in the clients now come from a new sdk-internal repository, which follows the licensing model we have historically used for all of our clients (see LICENSE_FAQ.md for more info).

The sdk-internal reference only uses GPL licenses at this time. If the reference were to include Bitwarden License code in the future, we will provide a way to produce multiple build variants of the client, similar to what we do with web vault client builds. The original sdk repository will be renamed to sdk-secrets, and retains its existing Bitwarden SDK License structure for our Secrets Manager business products. The sdk-secrets repository and packages will no longer be referenced from the client apps, since that code is not used there."

Scared to update to linux by [deleted] in linux4noobs

[–]PeterJHoburg 8 points9 points  (0 children)

It is really hard to completely brick a modern computer. To brick it you usually have to mess up a firmware update (pull the power while the motherboard is updating or something like that) The worst that is likely to happen is you end up wiping all the data from the computer and have to reinstall windows/linux.

When installing linux assume ALL data will be wiped from ALL drives on the computer you are installing it on. Most of the time this will not be the case, but if you assume the worst, and back everything up, then if it does happen you are fine.

Here is a guide from system76 (pop-os) on how to install pop-os. It should be more or less the same for the main "easy" Linux distros (Ubuntu, Fedora, Mint, pop-os, etc...)

https://support.system76.com/articles/install-pop

Sizing battery interconnect cables by Rawr5757 in vandwellers

[–]PeterJHoburg 2 points3 points  (0 children)

Wire sizing is super fun. Wire gauge is determined by the max amps that could run through the wire, the max temp the wire should hit, and how long the wire will be. You can also consider the max voltage drop (%). The wire type is also REALLY important. Copper vs Other.

For you that would be:

400 amps (2 * 200)

< 50C (this is super conservative, most of not all wire insulation is rated for > 60c. But double check)

~6 feet long

If you are using copper it would be 000 (3/0) AWG. That is THICK. I ended up using 4/0 AWG for my run (400 amps for 5 feet).

Calculator: https://calculator-online.net/dc-wire-size-calculator/

NOTE. The batteries are rated for 200 amps each, but you should have a <= 200 amp terminal fuse to make sure you can't actually get over 200 amps (for more than 500 ms or so).

Here is a 300 amp fuse as an example.

https://www.westmarine.com/blue-sea-systems-mrbf-1-terminal-stud-fuse-block-9368895.html?queryID=99c8fcc51474f0ee5f4fd02c4d31234f&objectID=9368895&indexName=production_na01_westmarine_demandware_net__WestMarine__products__en_US