DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Enterprise AI Trend Report: Gain insights on ethical AI, MLOps, generative AI, large language models, and much more.

2024 Cloud survey: Share your insights on microservices, containers, K8s, CI/CD, and DevOps (+ enter a $750 raffle!) for our Trend Reports.

PostgreSQL: Learn about the open-source RDBMS' advanced capabilities, core components, common commands and functions, and general DBA tasks.

AI Automation Essentials. Check out the latest Refcard on all things AI automation, including model training, data security, and more.

Related

  • Type Variance in Java and Kotlin
  • Black Box Tester in Python
  • Modern Python: Patterns, Features, and Strategies for Writing Efficient Code (Part 1)
  • API Appliance for Extreme Agility and Simplicity

Trending

  • API Appliance for Extreme Agility and Simplicity
  • Some Thoughts on Bad Programming Practices
  • DZone's Article Submission Guidelines
  • Getting Started With NCache Java Edition (Using Docker)
  1. DZone
  2. Coding
  3. Languages
  4. From Kotlin Scripting to Python

From Kotlin Scripting to Python

I recently moved away from Kotlin Scripting to Python. In this post, I want to explain my reasons and document the migration.

By 
Nicolas Fränkel user avatar
Nicolas Fränkel
DZone Core CORE ·
Mar. 11, 24 · Tutorial
Like (1)
Save
Tweet
Share
1.0K Views

Join the DZone community and get the full member experience.

Join For Free

GitHub offers a way to customize one's profile by allowing one to create a README in a specific repository, named as your profile, e.g., nfrankel/nfrankel. A couple of years ago, I automated the update of my GitHub profile with up-to-date info: my latest blog posts, my upcoming talks, and the last recorded YouTube talk. I took the time to document how to do it on this blog.

At the time, I chose Kotlin scripting because I was proficient enough in Kotlin, but I wanted to learn the scripting part. Over the years, I became more and more dissatisfied with the solution. I recently moved away from Kotlin Scripting to Python. In this post, I want to explain my reasons and document the migration.

The Previous Situation

First things first, I'm a big proponent of Kotlin; my issues were in other areas.

When I first developed the code, I had the feeling that Kotlin scripting was an unloved child. The documentation is pretty straightforward about it:

Kotlin scripting is Experimental. It may be dropped or changed at any time. Use it only for evaluation purposes. We appreciate your feedback on it in YouTrack.

Get started with Kotlin custom scripting

I didn't pay much attention then, believing it was temporary. The problem is that the status has stayed the same over two years. At some point, an experiment either graduates or the product is dropped. But Kotlin's scripting stays in an intermediate Schrödinger state, neither really living nor truly dead.

Kotlin scripting allows dependencies via in-file annotations. Here's a dependency to the Freemarker templating engine:

@file:DependsOn("org.freemarker:freemarker:2.3.32")


Dependabot and Renovate are bots that can regularly check dependencies for updates. Renovate manages more ecosystems than Dependabot, e.g., Docker Compose, but still doesn't handle Kotlin scripting. It's a vicious circle because since not many use Kotlin scripting, it doesn't support it, and since it doesn't, not many use it. The consequence is that I had to check dependencies by myself regularly.

The final problem in my setup was entirely unrelated to Kotlin scripting but was the push to change anyway. I had put the script inside the magic GitHub repo. For this reason, the GitHub history contained daily README commits sprinkled with dependency upgrades and my changes.

The Target Setup

I put the code in a different repo than the profile one. I now have two repositories:

  • nfrankel: the target repo with the README
  • nfrankel-update: the repo hosting the script

It fixes the latest issue I mentioned above.

I chose Python because I used it for simple scheduled jobs in the last couple of years, and I'm happy enough about the results. A simple search pointed me to the following dependencies:

  • requests to send HTTP requests
  • PyYAML to parse YAML payloads
  • Jinja2 for the templating engine

I manage them via Poetry. Renovate manages Poetry; it takes care of my first concern.

What the code does is precisely the same. It's about reading posts from this blog's RSS feed, talks from my underlying blog repo, and videos from YouTube.

Challenge

During the migration, I had a couple of hiccups, but the biggest challenge was committing to another repository.

Most GitHub actions either don't touch the repository hosting the action at all or commit to it and it only. In my case, I'm decoupling the script and the repo it acts upon:

Kotlin
 
jobs:
  update:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repo                                 #1
        uses: actions/checkout@v4
      - name: Checkout profile repo                         #2
        uses: actions/checkout@v4
        with:
          repository: nfrankel/nfrankel
          path: nfrankel
          token:  ${{ secrets.NFRANKEL_GITHUB_TOKEN }}      #3
# Set up and run the script here
      - name: Commit README and push                        #4
        uses: EndBug/add-and-commit@v9
        with:
          cwd: './nfrankel'
          add: README.adoc
          default_author: github_actions
          message: Automatically update README.adoc


  1. Check out current repo, the one hosting the script
  2. Checkout profile repo in a sub-directory
  3. Use an explicit GitHub token
  4. Commit the README and push it to the profile repo

The magic happens in step 3 above. By default, GitHub allows you to commit to the repo of the action. When one wants to commit to other repos, one needs to have a regular token, the same one you'd use outside of GitHub. Besides, you must set the token in the checkout step, not the commit step. The rest is usual.

Conclusion

In this post, I've explained why and how I migrated from Kotlin scripting to Python. In my context, the latter is a better fit than the former. It will be the case until JetBrains commits to Kotlin scripting.

The complete source code for this post can be found on GitHub.

To Go Further

  • Get started with Kotlin custom scripting
  • Poetry
  • Checkout multiple repos (nested)
  • Automatic token authentication
Kotlin (programming language) Python (language) Data migration

Published at DZone with permission of Nicolas Fränkel, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Type Variance in Java and Kotlin
  • Black Box Tester in Python
  • Modern Python: Patterns, Features, and Strategies for Writing Efficient Code (Part 1)
  • API Appliance for Extreme Agility and Simplicity

Partner Resources


Comments

ABOUT US

  • About DZone
  • Send feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: