Monday, 24 July 2023

How to properly capture library / package version in my package when using pyproject.toml to build

I have moved away from a setup.py file to build my packages / libraries to fully using pyproject.toml. I prefer it overall, but it seems that the version placed in the pyproject.toml does not propagate through the build in any way. So I cannot figure out how to inject the package version -- or any other metadata provided in the pyproject.toml -- into my package.

A google search led me to this thread, which had some suggestions. They all seemed like hacks, but I tried this one because it seemed best:

from pip._vendor import tomli ## I need to be backwards compatible to Python 3.8

with open("pyproject.toml", "rb") as proj_file:
    _METADATA = tomli.load(proj_file)

DESCRIPTION = _METADATA["project"]["description"]
NAME = _METADATA["project"]["name"]
VERSION = _METADATA["project"]["version"]

It worked fine upon testing, but I did not test robustly enough: once I tried to install this in a fresh location / machine, it failed because the pyproject.toml file is not part of the package installation. (I should have realized this.)


So, what is the right / best way to provide metadata, like the package version, to my built package? I need the following requirements:

  1. I only want to provide the information once, in the pyproject.toml. (I know that if I need to repeat a value, at some point there will be a mismatch.)
  2. I want the information to be available to the end user, so that someone who installs the package can do something like mypackage.VERSION from her interactive Python session.
  3. I want to only use pyproject.toml and Poetry / PDM. (I actually use PDM, but I know that Poetry is more popular. The point is that I don't want a setup.py or setup.cfg hack. I want to purely use the new way.)


from How to properly capture library / package version in my package when using pyproject.toml to build

Sunday, 23 July 2023

Does partytown support smartlook? Problelm in integrating smartlook with partytown

I am trying to integrate smartlook using partytown using this code:

<script type='text/javascript'>
  window.smartlook||(function(d) {
    var o=smartlook=function(){ o.api.push(arguments)},h=d.getElementsByTagName('head')[0];
    var c=d.createElement('script');o.api=new Array();c.async=true;c.type='text/partytown';
    c.charset='utf-8';c.src='https://web-sdk.smartlook.com/recorder.js';h.appendChild(c);
    })(document);
    smartlook('init', PROJECT_KEY, { region: REGION });
</script>

it does not give any errors but does not show anything on the smartlook is there something wrong I am doing?

I have addes this code before all of the headers

 <script type="module">
      import { partytownSnippet } from "@builder.io/partytown/integration";
      const snippetText = partytownSnippet();
      const el = document.createElement("script");
      el.innerText = snippetText;
      document.head.appendChild(el);
    </script>

I have added this to scripts in package.json:

"scripts": {
    "partytown": "partytown copylib public/~partytown"
  },


from Does partytown support smartlook? Problelm in integrating smartlook with partytown

Missing HTTPOnly Cookies at HTTP Request from child iFrame

Browser (Chrome) doesn't set HttpOnly cookies from child iframe

I have a parent webpage with a child iframe:

Parent at https://sub1.some-domain.com
Child at <iframe src="https://sub2.some-domain.com"> (inside of parent)

From Parent I do POST request to the API "https://ift.tt/kcwCvjU".
Below is the response Headers:

Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: https://sub1.some-domain.com
Set-Cookie:
 payload-name=payload-value;
 max-age=30;
 domain=some-domain.com;
 path=/;
 secure;
 samesite=none;
 httponly
    

Afterwards,
from the Iframe I do GET request to "https://ift.tt/kcwCvjU".
Expectation: Browser to include Httponly cookies payload-name=payload-value; into the request.

Result: Httplonly cookies not included for unknown reason.
BTW, I included "withCredentials" property into JS Http request, so this couldn't be a problem.



from Missing HTTPOnly Cookies at HTTP Request from child iFrame