Fork me on GitHub
#clojure-europe
<
2020-12-10
>
slipset06:12:25

Morning. December is really showing itself from its worst side this year. Dark and grey every day.

orestis07:12:29

Yeah it’s not helping with the 2020 blues. Gray and cold and dark and wet here in Copenhagen

slipset07:12:21

One of the things I enjoy the least with maintaining OSS is the actual release process. The pains involve updating a bunch of files with the correct version, especially random version strings in Readmes and tagging, How do you manage these things?

orestis07:12:28

I still have Reseda under just a git sha because I can’t be bothered to figure out Clojars and bundling Cljs stuff.

orestis07:12:51

I think you can do something like this in a GitHub action?

javahippie07:12:30

In comparison to Javas public Maven Repo, releasing to Clojars is “relatively” simple and straightforward, but I still have to google every time what the steps were.

javahippie07:12:48

@orestis do you want the GitHub Action to do the bundling, or also the “pushing to Clojars” part?

dharrigan07:12:42

Good Morning!

orestis07:12:37

@javahippie I’ve no clue, haven’t thought about it! We’re using a GitHub action for doing releases of our software on elastic beanstalk on AWS, and the pattern there is that on every commit to master it will run a build and upload an artifact to S3, but the deployment action is meant to be run on purpose by a human.

orestis07:12:54

It works well but I’m not sure how it would apply to Clojars etc.

javahippie08:12:05

If your environment variables are right, you could push to Clojars with a leiningen plugin in the action. But I am too paranoid to store my Clojars Credentials in GitHub, so I release manually every time

ordnungswidrig08:12:08

Updating the Readme should include more than the version (otherwise no reason for a release, right?). For the reference to the latest version on clojar I used the embedded SVG which is nasty but maybe the best you can do? When it comes to published documentation you can used a preprocessor of any kind to do text replacement in the most simple case.

synthomat08:12:24

good morning!

simongray08:12:15

good morning

simongray08:12:16

@orestis I feel ya. Supposedly it’ll be like this the rest of the year.

simongray08:12:31

the weather, I mean.

plexus08:12:53

Good morning!

slipset08:12:04

@ordnungswidrig re updating the readme, that kind’a depends I guess. If your current version is 1.2.3-SNAPSHOT, then I guess you can let PR’s update the readme with any new functionality you need/want to document. And then on release you change the version to 1.2.3 , publish, and update the version to 1.2.4-SNAPSHOT (not that I’m doing that).

slipset08:12:26

Also, one could imagine that more finegrained docs live other places than in the readme.

thomas08:12:31

morning lovely people!

slipset08:12:26

Had a lovely start today with 45 mins of the Defn podcast on my ears while on my ballance rollers.

😂 3
plexus09:12:36

For the lambda island libraries we update anything that looks like a deps.edn or leiningen version vector/map for the current project to the version number that is being released, and commit that before the release. This way it always shows the most recently released version on github, and it shows the version you are looking at in cljdoc.

ordnungswidrig09:12:11

That’s neat. But honestly the need for prgrammatic creation of a regex is on the edge of what I consider to be comfortable with 😛

ordnungswidrig09:12:49

These are the dirty secrets of our industry I guess.

borkdude10:12:51

@ordnungswidrig Are you talking about regal in general?

plexus10:12:42

I think in this case I could have still quite easily written these regexes directly. It would be a lot more concise but harder to maintain.

borkdude10:12:16

I think the idea of regal is pretty great. For perf reasons I would probably generate the regexes in a REPL session and then inline them manually. They don't need to be evaluated each time I run my code. But I will keep the original regal expression around because it's way more readable.

ordnungswidrig10:12:16

@borkdude no, but the need to construct regexes is always kind of edgy, isn’t it?

ordnungswidrig10:12:47

I mean regex as data compared to regex as a dsl (“actual regexes” 🙂 🤷

plexus10:12:52

This is what that regex compiles to

#"lambdaisland/kaocha(\s+\{\s*:mvn/version\s+\")[^\"]+(\"\s*\})"

plexus10:12:20

not sure what you're saying @ordnungswidrig? would you consider regex in general a smell or red flag?

ordnungswidrig10:12:12

well, regex are fine (unless you’re trying to parse HTML with it). But constructing regex via something like regal should be kind of a last resort when you really need it. I think the actual string regex representation is fine and way more readable in almost any case.

borkdude10:12:35

How is one giant string more readable than information around each sub-string?

borkdude10:12:19

btw, there are also parser combinator libraries for clojure that let you parse strings with good performance, similar to spec (but then designed for actual text)

borkdude10:12:03

btw, I have also created documented regexes by just giving names to each sub-part and then using re-pattern and str to create it, just for readability. or little functions to create the sub-parts based on some dynamic input

ordnungswidrig10:12:24

Yeah, I’ve used that before and I totally see the use case for “AST”-based regex creation. But for the daily simpler cases foo-bar: (\d+)-(\w+) I strongly prefer the string over a clojure reresentation of it. 😉

plexus10:12:33

I'm quite comfortable writing plain old regex so I don't use regal myself that often. Regal came about when I was working on this: https://github.com/lambdaisland/trikl/blob/trikl1/src/lambdaisland/trikl1/specs.clj here the benefits are multiple, I can define each sub section separately, can validate subparts as well as the combined versions, and I can generate each as needed in my tests

genRaiy11:12:41

morning

☀️ 6
simongray11:12:40

Regular string regex would be perfect for 99.9% of use cases if whitespace was ignored when compiling the pattern the same way it’s ignored in pretty much every other compiled language. The syntax is simple and easy to grasp. The only real problem is that fact that there is no obvious way to semantically partition the patterns you write when spaces are considered part of the pattern.

borkdude11:12:16

string concat + re-pattern

simongray11:12:04

I guess, but then you lose out on the niceties of regex literals

borkdude11:12:40

#=(re-pattern (str ....)) 👿

simongray11:12:14

not good enough

simongray11:12:33

regex literals are great because they are different from strings and this can be reflected in syntax highlighting and the quality of life feature of not having to double escape a bunch of stuff (another common issue with regex readability).

simongray11:12:19

I guess with a suitably clever macro you can accomplish many great things, but it would be a lot nicer to just be able to ignore whitespace…

simongray11:12:24

Yeah, in regex in many other languages you have to double escape every escaped character like \s \n \t etc.

plexus11:12:35

Ruby has a modifier for ignoring whitespace

/regex
some more regex
.../x

simongray11:12:51

hm, if Ruby can have it why can’t we!?

plexus11:12:40

Turns out we do!

(re-find #"(?x) hello world" "helloworld")

🎉 12
🕺 6
plexus11:12:13

who knew?? 😄

simongray11:12:22

oooooh! well, then I was grumpy for nothing

borkdude11:12:39

Very simple solution:

(require '[clojure.string :as str])

(defn regex [& parts]
  (-> (str/join parts)
      (re-pattern)))

(def re (regex #"\w+" #"bar"))

(prn re)

(prn (re-matches re "foobar"))

borkdude11:12:11

This now allows you to document each part:

(def re (regex #"\w+" ;; match leading char
               #"bar" ;; match bar
               ))

❤️ 3
borkdude11:12:20

with still syntax highlighting

simongray11:12:18

that’s actually pretty good too since it allows comments, but I think my personal preference would just be using that x flag

borkdude11:12:35

I think Java regexes also allow comments.

borkdude11:12:55

(?#comment)

simongray11:12:14

hm interesting

simongray11:12:49

well, that was a mind-expanding 10 minutes on this channel 🙂

borkdude11:12:10

I haven't been able to figure out a working example though ;)

slipset11:12:05

The wonders of #clojure-europe 🙂

ordnungswidrig15:12:04

Advanced regexes are advanced. “Lookbehind Zero-Length Assertions” is burned into my memory from my times as a perl developer

ordnungswidrig15:12:38

> (?<!a)b matches a “b” that is not preceded by an “a”, using negative lookbehind.

ordnungswidrig15:12:45

That can become handy.

ordnungswidrig15:12:36

Also forward references are neat: > If forward references are supported, the regex (\2two|(one))+ matches oneonetwo.

ordnungswidrig15:12:51

But honestly I would not know by heard what of this funky stully is supported by Java.

dominicm16:12:25

Java's regex is very powerful, and it has 2 engines with different performance characteristics dependent on your regex.

ordnungswidrig18:12:40

I didn’t know that.

plexus20:12:12

Yeah pro tip if you're looking for the docs on Clojure regexes, look for the javadoc for Pattern. Very comprehensive! https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/regex/Pattern.html

✔️ 12