astral-sh / packse

Python packaging scenarios
Apache License 2.0
93 stars 9 forks source link

templates/package: fix template to use triple quotes #175

Closed BurntSushi closed 4 months ago

BurntSushi commented 4 months ago

I noticed that when using a requirement like

c<2.0.0 ; sys_platform == 'linux'

then the single quotes seem to get rewritten as double quotes. And since the TOML template just prints the value as-is without any escaping, it ends up producing an invalid TOML file.

I do wonder whether a better fix here would be to abdicate templates and use a proper TOML serializer from an in-memory data structure, but this fix is probably good enough for now. Namely, we use triply quoted TOML strings. The only way this can go wrong is if the requirement contains three single quotes in succession.

BurntSushi commented 4 months ago

It took me a fair bit of time to figure out that poetry run pytest --snapshot-update was what I needed to run to update the snapshots. Is there a place in the docs where it would make sense to document this command?

(This might have just been ecosystem ignorance on my part. What actually took me a bit to figure out was that syrupy was what was doing the snapshotting. This was surprisingly difficult to difficult to discover because import syrupy never occurs anywhere.)

BurntSushi commented 4 months ago

It also seems to have updated a snapshot on my local system in a way that differs from CI. In particular, I had to back this snapshot update out (test_index.ambr):

@@ -1,12 +1,11 @@
 # serializer version: 1
 # name: test_index_down
   dict({
-    'exit_code': 0,
+    'exit_code': 1,
     'stderr': '''
-      Stopping server with pid [PID]...
-      Stopped server!
+      Server looks shutdown already.

     ''',
     'stdout': '',
   })
 # ---
BurntSushi commented 4 months ago

I've added a very lightweight CONTRIBUTING.md file to document some of my learnings here.