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
Please enter at least three characters to search
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

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Type Variance in Java and Kotlin
  • Using Python Libraries in Java
  • Why Database Migrations Take Months and How to Speed Them Up
  • Start Coding With Google Cloud Workstations

Trending

  • Doris: Unifying SQL Dialects for a Seamless Data Query Ecosystem
  • Developers Beware: Slopsquatting and Vibe Coding Can Increase Risk of AI-Powered Attacks
  • My LLM Journey as a Software Engineer Exploring a New Domain
  • Medallion Architecture: Efficient Batch and Stream Processing Data Pipelines With Azure Databricks and Delta Lake
  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
Likes (1)
Comment
Save
Tweet
Share
1.4K 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
  • Using Python Libraries in Java
  • Why Database Migrations Take Months and How to Speed Them Up
  • Start Coding With Google Cloud Workstations

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and 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:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!