Skip to content

Instantly share code, notes, and snippets.

@jugmac00
jugmac00 / main.py
Last active July 21, 2022 17:20
get some infos about the PPas of a team
"""
Usage:
- create and activate a virtual env
- `pip install launchpadlib`
- run `python main.py https://launchpad.net/~deadsnakes`
API:
https://launchpad.net/+apidoc/devel.html
@jugmac00
jugmac00 / a_run.py
Last active December 14, 2021 08:51
pluggy - different signature problem
# packages is a list of packages, created from the configuration object (config.job.packages),
# but also external plugins can extend this list
# so I need something like this here
packages = list(itertools.chain(*pm.hook.lpcraft_install_packages()))
packages_cmd = ["apt", "install", "-y"] + packages
emit.progress("Installing system packages")
with emit.open_stream(f"Running {packages_cmd}") as stream:
proc = instance.execute_run(
# pi_approx.py
from math import pi
def approximate_pi(iteration_count: int) -> float:
sign, result = 1, 0.0
for at in range(iteration_count):
result += sign / (2 * at + 1)
sign *= -1
return result * 4
tox on  rewrite [$?] via 🐍 v2.7.17
❯ tox4 -r -e flake8
flake8: remove tox env folder /home/jugmac00/Projects/tox/.tox/4/flake8
flake8: install_deps> python -I -m pip install flake8-bugbear==20.11.1 flake8-comprehensions==3.3.1 flake8-pytest-style==1.3 flake8-spellcheck==0.23 flake8-unused-arguments==0.0.6 flake8==3.8.4
flake8: commands[0]> flake8 src tests docs
src/tox/pytest.py:66:1: PT004 fixture 'ensure_logging_framework_not_altered' does not return anything, add leading underscore
src/tox/pytest.py:111:1: PT004 fixture 'check_os_environ_stable' does not return anything, add leading underscore
src/tox/pytest.py:118:1: PT004 fixture 'no_color' does not return anything, add leading underscore
src/tox/pytest.py:274:1: PT004 fixture 'enable_pep517_backend_coverage' does not return anything, add leading underscore
src/tox/pytest.py:565:1: PT005 fixture '_invalid_index_fake_port' returns a value, remove leading underscore
@jugmac00
jugmac00 / gist:ebfba2234fe059b293086bb76177adfe
Created November 7, 2020 09:05
error compiling python 3.9
❯ ./configure --with-pydebug --enable-shared
❯ make -j2 -s
Python build finished successfully!
❯ ./python
./python: error while loading shared libraries: libpython3.9d.so.1.0: cannot open shared object file: No such file or directory
This is reproducible on Linux (Ubuntu 18.04) with the `enable-shared` option.
@jugmac00
jugmac00 / simple_cache.py
Last active October 10, 2020 10:31
simple cache
from time import sleep
cache = dict()
def get_data():
if not cache.get("items"):
sleep(10) # simulates waiting for data
items = ["a", "b", "c"]
cache["items"] = items
branch: 3.9.0b5
@jugmac00
jugmac00 / conftest.py
Created July 9, 2020 14:02
Zope and pytest
import os
import os.path
import sys
import gocept.httpserverlayer.plonetestingzope as gc_httpserverlayer_zope
import gocept.selenium
import plone.testing.layer
import plone.testing.zodb
import plone.testing.zope as plone_testing_zope
import Products.MailHost.tests.testMailHost
@jugmac00
jugmac00 / factory.py
Created June 25, 2020 12:24
converting the type comments in this module to annotations with com2ann breaks the code, cf. postponed evaluation of annotations
from typing import Optional
from typing import List
class Pizza:
def __init__(self, ingredients=None):
# type: (Optional[List[str]]) -> None
if ingredients is None:
self.ingredients = []
else:
self.ingredients = ingredients
diff --git a/Grammar/Grammar b/Grammar/Grammar
index 170518af74..25067147bf 100644
--- a/Grammar/Grammar
+++ b/Grammar/Grammar
@@ -138,7 +138,7 @@ not_test: 'not' not_test | comparison
comparison: expr (comp_op expr)*
# <> isn't actually a valid comparison operator in Python. It's here for the
# sake of a __future__ import described in PEP 401 (which really works :-)
-comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
+comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'~='|'in'|'not' 'in'|'is'|'is' 'not'