Compare commits

...
2 Commits
3 changed files with 89 additions and 1 deletions
+3 -1
View File
@@ -10,7 +10,7 @@ working across different projects via [VisualMode](https://www.visualmode.dev/).
For a steady stream of TILs, [sign up for my newsletter](https://visualmode.kit.com/newsletter). For a steady stream of TILs, [sign up for my newsletter](https://visualmode.kit.com/newsletter).
_1851 TILs and counting..._ _1853 TILs and counting..._
See some of the other learning resources I work on: See some of the other learning resources I work on:
@@ -1111,6 +1111,7 @@ If you've learned something here, support my efforts writing daily TILs by
- [Make Secure Temp File For Atomic Write](python/make-secure-temp-file-for-atomic-write.md) - [Make Secure Temp File For Atomic Write](python/make-secure-temp-file-for-atomic-write.md)
- [Override The Boolean Context Of A Class](python/override-the-boolean-context-of-a-class.md) - [Override The Boolean Context Of A Class](python/override-the-boolean-context-of-a-class.md)
- [Parse Relative Time To datetime Object](python/parse-relative-time-to-datetime-object.md) - [Parse Relative Time To datetime Object](python/parse-relative-time-to-datetime-object.md)
- [Publish A Package To A Test Env As A Dry Run](python/publish-a-package-to-a-test-env-as-a-dry-run.md)
- [Reclassify Certain Packages As Dev Dependencies](python/reclassify-certain-packages-as-dev-dependencies.md) - [Reclassify Certain Packages As Dev Dependencies](python/reclassify-certain-packages-as-dev-dependencies.md)
- [Resurface Exceptions Swallowed By Click Under Test](python/resurface-exceptions-swallowed-by-click-under-test.md) - [Resurface Exceptions Swallowed By Click Under Test](python/resurface-exceptions-swallowed-by-click-under-test.md)
- [Select Implementation With Class Registry](python/select-implementation-with-class-registry.md) - [Select Implementation With Class Registry](python/select-implementation-with-class-registry.md)
@@ -1260,6 +1261,7 @@ If you've learned something here, support my efforts writing daily TILs by
- [Read-Only Models](rails/read-only-models.md) - [Read-Only Models](rails/read-only-models.md)
- [Rebuild Tailwind Bundle For Dev Server](rails/rebuild-tailwind-bundle-for-dev-server.md) - [Rebuild Tailwind Bundle For Dev Server](rails/rebuild-tailwind-bundle-for-dev-server.md)
- [Remove A Database Column From A Table](rails/remove-a-database-column-from-a-table.md) - [Remove A Database Column From A Table](rails/remove-a-database-column-from-a-table.md)
- [Remove Blank Values From A Hash](rails/remove-blank-values-from-a-hash.md)
- [Remove The Default Value On A Column](rails/remove-the-default-value-on-a-column.md) - [Remove The Default Value On A Column](rails/remove-the-default-value-on-a-column.md)
- [Render An Alternative ActionMailer Template](rails/render-an-alternative-action-mailer-template.md) - [Render An Alternative ActionMailer Template](rails/render-an-alternative-action-mailer-template.md)
- [Render The Response Body In Controller Specs](rails/render-the-response-body-in-controller-specs.md) - [Render The Response Body In Controller Specs](rails/render-the-response-body-in-controller-specs.md)
@@ -0,0 +1,35 @@
# Publish A Package To A Test Env As A Dry Run
As I was preparing to register a new Python package with PyPI and release my
first version cut, I felt like there were a lot of unknowns. Is my package's
name going to be valid? How will the package appear in PyPI? Did I configure
everything correctly? Etc.
It turns out that PyPI has a great way of answering a lot of these questions.
There is a [`test.pypi.org`](https://test.pypi.org/) site that parrots the
publishing flow of `pypi.org`. This makes for a great target to do a dry-run
publishing of a package.
First, I had to go through the same registration flow and 2FA setup as when I
registered with `pypi.org`.
Second, I deviated from my tag and CI-triggered publishing flow by instead doing
a one-off run of the `uv publish` command. That requires an API token which I
generated in the web UI for `test.pypi.org`. I added that to my env as
`TEST_PYPI_TOKEN`.
I then ran the following command:
```bash
uv publish --publish-url https://test.pypi.org/legacy/ --token "$TEST_PYPI_TOKEN"
```
When this first ran for [`py-vmt`](https://github.com/jbranchaud/py-vmt), I got
an error back from the publishing API telling me the package name is too similar
to an existing package. I then had to make a few updates across the project to
rename the published package name to `visualmode-tracker`. Running the `uv
publish` command again worked with the updated name.
I was then able to go into the web UI and verify everything looked as expected.
I now have the confidence to publish this thing for real to `pypi.org`.
+51
View File
@@ -0,0 +1,51 @@
# Remove Blank Values From A Hash
Ruby's [`Enumerable`](https://docs.ruby-lang.org/en/master/Enumerable.html) has
a method `#compact` that will remove `nil` values from `Enumerable` objects like
hashes and arrays.
```ruby
> { one: nil, two: 2, three: "" }.compact
=> {two: 2, three: ""}
> [nil, 2, ""].compact
=> [2, ""]
```
That is often what I want because I'm thinking in terms of values being either
`nil` or valid value.
Sometimes I want to remove all _blank_ values, not just the `nil` ones. This
happens in a Rails context like in a controller when dealing with parameters
from a request -- a form field was left blank (`""`) or no options were picked
from the multi-select (`[]`).
Rails adds
[`#compact_blank`](https://api.rubyonrails.org/classes/Enumerable.html#method-i-compact_blank)
to `Enumerable` to support these cases. Consider that `#compact` corresponds to
`#nil?` where as `#compact_blank` corresponds to `#blank?`.
Here is the example hash pulled from the docs:
```ruby
> { a: "", b: 1, c: nil, d: [], e: false, f: true }.compact
=> {a: "", b: 1, d: [], e: false, f: true}
> { a: "", b: 1, c: nil, d: [], e: false, f: true }.compact_blank
=> {b: 1, f: true}
```
I might want to `compact_blank` a set of search parameters coming from the
client before passing it into my search service:
```ruby
class BooksController < BaseController
def search
@results = SearchService.call(search_params.compact_blank)
end
private
def search_params
params.permit(...)
end
end
```