Skip to content

Python3 - Pipenv für die virtuelle Entwicklungsumgebung

Python3
  • Python hat ein wirklich sehr groß entwickeltes Ökosystem, mit ganz vielen Tools, die man erst mal finden muss und dann im zweiten Step auch nutzen können muss.

    Hier geht es heute um pipenv

    01b9dc8f-34ae-4a32-b18a-5e06df39e960-grafik.png

    Installation

    sudo apt install pipenv
    

    Virtuelle Umgebung anlegen

    Wir wechseln ins Projektverzeichnis

    cd /home/$USER/projekt1
    

    Die Entwicklungsumgebung anlegen

    pipenv --python 3.8
    

    Die Entwicklungsumgebung starten

    frank@frank-MS-7C37:~/restic_ui$ pipenv shell
    Spawning environment shell (/bin/bash). Use 'exit' to leave.
    frank@frank-MS-7C37:~/restic_ui$ . /home/frank/.local/share/virtualenvs/restic_ui-RwXjz-0W/bin/activate
    (restic_ui-RwXjz-0W) frank@frank-MS-7C37:~/restic_ui$ pipenv
    Usage: pipenv [OPTIONS] COMMAND [ARGS]...
    
    Options:
      --where          Output project home information.
      --venv           Output virtualenv information.
      --py             Output Python interpreter information.
      --envs           Output Environment Variable options.
      --rm             Remove the virtualenv.
      --bare           Minimal output.
      --completion     Output completion (to be eval'd).
      --man            Display manpage.
      --three / --two  Use Python 3/2 when creating virtualenv.
      --python TEXT    Specify which version of Python virtualenv should use.
      --site-packages  Enable site-packages for the virtualenv.
      --version        Show the version and exit.
      -h, --help       Show this message and exit.
    
    
    Usage Examples:
       Create a new project using Python 3.6, specifically:
       $ pipenv --python 3.6
    
       Install all dependencies for a project (including dev):
       $ pipenv install --dev
    
       Create a lockfile containing pre-releases:
       $ pipenv lock --pre
    
       Show a graph of your installed dependencies:
       $ pipenv graph
    
       Check your installed dependencies for security vulnerabilities:
       $ pipenv check
    
       Install a local setup.py into your virtual environment/Pipfile:
       $ pipenv install -e .
    
       Use a lower-level pip command:
       $ pipenv run pip freeze
    
    Commands:
      check      Checks for security vulnerabilities and against PEP 508 markers
                 provided in Pipfile.
      clean      Uninstalls all packages not specified in Pipfile.lock.
      graph      Displays currently–installed dependency graph information.
      install    Installs provided packages and adds them to Pipfile, or (if none
                 is given), installs all packages.
      lock       Generates Pipfile.lock.
      open       View a given module in your editor.
      run        Spawns a command installed into the virtualenv.
      shell      Spawns a shell within the virtualenv.
      sync       Installs all packages specified in Pipfile.lock.
      uninstall  Un-installs a provided package and removes it from Pipfile.
      update     Runs lock, then sync.
    
  • Ich ko... immer, wenn ich mein VSCodium neu installieren muss. Das größte Problem dabei ist immer, das ich fast immer vergesse den Python Interpreter zu setzen.

    "CTRL+SHIFT+P" and choose the correct python interpreter.

    46f85075-4dbc-414c-94c2-abc5bb6009b6-grafik.png

    Danach startet das Python Programm auch wieder aus der richtigen Entwicklungsumgebung 🙂

  • Django - Webframework

    Python3 django python3
    1
    2
    0 Stimmen
    1 Beiträge
    145 Aufrufe
    Niemand hat geantwortet
  • Restic UI - Changelog

    Angeheftet Restic UI restic-ui python3 pyqt5
    3
    0 Stimmen
    3 Beiträge
    364 Aufrufe
    FrankMF
    v1.5.0 - Release for restic v0.14.0 with compression and migration tool
  • Python3 - QT_QPA_PLATFORM

    Python3 pyqt5 python3
    2
    2
    0 Stimmen
    2 Beiträge
    405 Aufrufe
    FrankMF
    Nachdem ich ja mittlerweile schon lange weder auf Cinnamon bin, hatte ich nach einem Update von VSCodium wieder ein anderes Design. Ok, schauen wir rein. (venv) frank@frank-MS-7C37:~/restic-ui-public$ env | grep "QT" QT_ACCESSIBILITY=1 QT_QPA_PLATFORMTHEME=qt5ct Wenn ich das auf QT_QPA_PLATFORMTHEME=gnome3 ändere, sieht es wie auf meinem Linux Mint Cinnamon Desktop aus.
  • Python3 - subprocess.run

    Python3 python3
    2
    0 Stimmen
    2 Beiträge
    277 Aufrufe
    FrankMF
    Ich möchte das Thema noch mal ausgraben. Bin beim Recherchieren über diese Links gestolpert, die mein Interesse geweckt haben. https://security.openstack.org/guidelines/dg_avoid-shell-true.html https://bandit.readthedocs.io/en/latest/plugins/b603_subprocess_without_shell_equals_true.html Da ich aktuell nur eine Desktop Anwendung entwickle, ist das Thema Sicherheit nicht ganz so wichtig, weil wer hackt sich schon selber!? Aber, da man ja nie weiß, wie so ein Tool evt. mal benutzt wird, sollte man von Anfang an auf ein paar Dinge achten. Ok, schauen wir uns das mal genauer an. Link 1 - shell=True Ich kopiere mal das Beispiel aus dem Link. def count_lines(website): return subprocess.check_output('curl %s | wc -l' % website, shell=True) Ok, das Problem ist shell=True Ein Beispiel aus meinem Projekt result = subprocess.run(['restic', '-r', backup_data[row].repository, 'stats'], input=pass_word.pw[0], capture_output=True, text=True) Gesetzt wird der in meinem Beispiel nicht. Besuchen wir mal die Webseite vom subprocess.run https://docs.python.org/3/library/subprocess.html?highlight=subprocess run#subprocess.run Wenn ich das jetzt richtig verstehe, subprocess.run(args, *, stdin=None, input=None, stdout=None, stderr=None, capture_output=False, shell=False, cwd=None, timeout=None, check=False, encoding=None, errors=None, text=None, env=None, universal_newlines=None, **other_popen_kwargs) dann ist standardmäßig shell=False gesetzt. Damit ist das in meinem Projekt kein Problem. Link 2 - B603: subprocess_without_shell_equals_true Ein Tool auf gitlab.com wirft Security Warnings aus, dabei war diese. Schauen wir mal, was uns das sagen möchte. Python possesses many mechanisms to invoke an external executable. However, doing so may present a security issue if appropriate care is not taken to sanitize any user provided or variable input. Ok, es geht also um die Prüfung von Eingaben bzw. Variablen. Der Merksatz "Keine Benutzereingabe wird ungeprüft übernommen!" ist doch mit das Wichtigste, wenn man irgendwas programmiert. Nochmal mein Beispiel von oben. result = subprocess.run(['restic', '-r', backup_data[row].repository, 'stats'], input=pass_word.pw[0], capture_output=True, text=True) Ich übergebe dem Prozess einige Eingaben / Variablen. backup_data[row].repository pass_word.pw[0] Lesen wir wieder ein wenig in der Dokumentation von subprocess.run args is required for all calls and should be a string, or a sequence of program arguments. Providing a sequence of arguments is generally preferred, as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names). If passing a single string, either shell must be True (see below) or else the string must simply name the program to be executed without specifying any arguments. Das Wichtigste in Kürze Providing a sequence of arguments is generally preferred Der Aufruf von subprocess.run erwartet als erste Übergabe args subprocess.run(args, *, .... Mein Beispiel result = subprocess.run(['restic', '-r', backup_data[row].repository, 'stats'], .... Das zwischen den eckigen Klammern ist args. Laut der Anleitung ist es empfohlen, das als ein Argument zu übergeben, also so. Somit ist dafür gesorgt, das das Modul die Argumente selbst ein wenig "überwacht". as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names). Somit hätten man schon mal was für sie "Sicherheit" getan. args = ['restic', '-r', backup_data[row].repository, 'stats'] result = subprocess.run(args, .... Man sollte trotzdem auf diese beiden Variablen * backup_data[row].repository * pass_word.pw[0] ein Auge behalten. Ich denke, das habe ich in meinem Projekt eingehalten, indem ich Pfadangabe mit den Systemwerkzeugen auswählbar mache, keine Texteingaben! Passwörter und andere Bezeichnung werden mit regex auf korrekte Eingaben geprüft usw. Fazit Wieder viel gelernt und ich denke, es passt so weit alles. Bei der ganzen Spielerei, dann noch entdeckt, das ich im Code dieses Argument drin hatte. check=False Das ist aber Standard, somit kann das weg. Habe das im kompletten Projekt dann entfernt und mir fällt gerade auf, da der Code immer gleich ist, muss das jetzt eigentlich alles in eine Funktion Mal auf die ToDo-Liste drauf schreiben.
  • Python3 - String-Operatoren

    Python3 python3
    1
    0 Stimmen
    1 Beiträge
    170 Aufrufe
    Niemand hat geantwortet
  • Python3 - subprocess.Popen

    Python3 restic python3
    1
    0 Stimmen
    1 Beiträge
    335 Aufrufe
    Niemand hat geantwortet
  • Python3 - JSON

    Python3 python3
    3
    1
    0 Stimmen
    3 Beiträge
    260 Aufrufe
    FrankMF
    [image: 1603645936018-ede1a88a-5183-4f85-a602-27650362d532-grafik.png] Die Backups sollen Namen haben, also habe ich das erweitert. Jetzt sollen diese als Liste rechts angezeigt werden. Das mache ich wie folgt. for key in backups: print(backups[key]['name'], key) liste = backups[key]['name'] + " ID: " + key self.listWidget.addItem(liste) Mittels des Keys kann ich auf den Namen zugreifen und die Liste damit füllen. Aktuell habe ich noch den Key hinten angefügt, weil ich noch keine Idee habe, wie ich die Backups anders verarbeiten soll. Aber, Stück für Stück. Der Backup-Name wird nach Auswahl in der Statusbar angezeigt. So weit klappt das so wie ich mir das vorstelle. Für heute ist Feierabend
  • Python3 - RegEx für ein LineEdit

    Python3 pyqt5 python3
    2
    1
    0 Stimmen
    2 Beiträge
    222 Aufrufe
    FrankMF
    Gut, Menschen die mich kennen, wissen das IPv6 nicht so mein Spezialgebiet ist. Es hilft aber nichts, auch damit muss man sich beschäftigen Es war etwas schwierig was Passendes zu finden, aber ich denke das hier ist ganz gut. Ob es alle Möglichkeiten bei IPv6 beinhaltet, weiß ich nicht zu 100%. Hier eine Seite, wo ich was Passendes gefunden habe. https://ihateregex.io/expr/ipv6/ Code # regex für IPv6 reg_ex = QRegExp('^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$') input_validator = QRegExpValidator(reg_ex, self.lineedit2_ipv6) self.lineedit2_ipv6.setValidator(input_validator) Ein paar Test von mir ergaben, das es so aussieht als wenn es funktioniert