Skip to main content

A script to fetch and save course activities from myrpl.ar

Project description

myrpl-cli

Build Status License

myrpl-cli is a command-line interface tool for fetching and saving course activities from myrpl.ar.

What does it do?

  • ๐Ÿชจ Tired of copying and pasting your code between your IDE and RPL like a caveman?

    Well I've got the answer for you! Fetch your activities with myrpl fetch, solve them and upload them once with myrpl submit when you're done

  • โŒ› Exhausted of waiting whole seconds for running tests that should take milliseconds?

    Well I've got the answer for you! Run your tests locally with myrpl test

  • ๐Ÿ’ฆ Got a thing for slick CLI tools?

    While myrpl can't help you with your fantasies, it can certainly make your workflow smoother and more enjoyable. ๐Ÿ˜

๐Ÿ› ๏ธ Installation

Install the package globally using pipx:

pipx install myrpl-cli

Now you can use the myrpl command! ๐ŸŽ‰

๐Ÿ“š Usage

To use myrpl-cli, you need a bearer token for authentication. You can provide this token either as an environment variable (even within a .env file) or as a command-line argument.

1. ๐Ÿ”‘ Logging In

Before fetching course activities, you need to log in and store your credentials securely. Use the login command:

myrpl login

This will prompt you for your username/email and password and store your credentials securely in an encrypted file. You'll also be asked for a passphrase to encrypt said file.๐Ÿ”’ NOTE: Each time you use myrpl you'll be prompted for the passphrase.

You can always overwrite the stored credentials by running the login command again

2. ๐ŸŽ“ Fetching course activities

First, cd into the directory where you want your courses and activities stored

To fetch activities for a specific course:

myrpl fetch <course_id>

This will create a file structure in the current working directory like follows:

./
โ”œโ”€โ”€ courses/
โ”œโ”€โ”€ {course 1}/
โ”œโ”€โ”€ {category 1}/
โ”‚   โ”œโ”€โ”€ description.txt
โ”‚   โ”œโ”€โ”€ {activity 1}/
โ”‚   โ”‚   โ”œโ”€โ”€ description.md
โ”‚   โ”‚   โ”œโ”€โ”€ unit_test.py
โ”‚   โ”‚   โ””โ”€โ”€ main.py
โ”‚   โ”œโ”€โ”€ {activity 2}/
โ”Š   โ”Š

3. ๐Ÿง‘โ€๐Ÿ’ป Getting some actual work done

  • cd into any activity
  • Launch your IDE of choice. eg.: code . for VS Code
  • You can see the activity's description, initial code and unit tests
  • Write your code and run the tests using myrpl test or just pytest

๐Ÿ›ก๏ธ (Optional) Setting up the bearer token

Option 1: Set an environment variable

export MYRPL_BEARER_TOKEN=your_bearer_token_here

Option 2: Provide the token as a command-line argument (see examples below)

โ“ Getting help

For general help:

myrpl --help

For help with the a specific command:

myrpl <command> --help

๐Ÿ—๏ธ Project Structure

myrpl-cli/
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ myrpl_cli/
โ”œโ”€โ”€ __init__.py
โ”œโ”€โ”€ api.py
โ”œโ”€โ”€ credential_manager.py
โ”œโ”€โ”€ main.py
โ””โ”€โ”€ myrpl.py

๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป Development

To set up the development environment:

  1. Install all dependencies
poetry install
  1. And pre-commit hooks:
pre-commit install
  1. Activate the virtual environment:
poetry shell
  1. Off you go! ๐Ÿš€

๐Ÿงช Tests

Use pytest to run the project's tests

Use act for running the github workflow locally

๐Ÿ“โœ… Linting & Formatting

I chose ruff for linting + formatting

PD: I use the Ruff VS Code extension, but you do you

๐Ÿ—บ๏ธ Roadmap

  • [x] Implement basic authentication functionality
  • [x] Fetch course activities
  • [x] Store credentials securely for reuse
  • [x] Fetch latest submission
  • [ ] Implement hidden file .pyc download via submission abuse (branch: feature/hidden_file_decompilation)
  • [ ] Implement hidden file decompilation for python version agnostic test execution
  • [ ] Implement activity submission (myrpl submit)
  • [ ] Implement course/category/activity progress (myrpl status)
  • [ ] Remove annoying keyring passphrase
  • [ ] Enhance test coverage
  • [ ] VS Code extension (?)
  • [ ] Add support for additional programming languages (idk if actually necessary)

Please note that this roadmap is subject to change and may be updated based on user feedback and my own time ๐Ÿ˜

How does myrpl-cli fetch hidden files and decompiles them? (incoming feature)

I ran into a problem where I couldn't run a unit_test because the "grafo" library was missing.

So, what could I do?

I started trying to get the content of the grafo library, obviously

I ended up with this code snippet, which I ran on myrpl.ar:

import grafo
import base64


def vertex_cover_min(_):
	print("#startgrafocontent")
	with open(grafo.__file__, "rb") as gf:
		content = gf.read()
		encoded_content = base64.b64encode(content).decode("utf-8")
		print(encoded_content)
	print("#endgrafocontent")

	return []

In the future this can be easily automated with the submission API

This ends up spitting into the submission's stdout the base64 encoded contents of the grafo.pyc file.

From there I could easily import the Grafo class into python. But, .pyc files are python version specific, so I could only run them inside Python 3.10.0. Boooringg

So, time to decompile ๐Ÿ˜ˆ

I finally found pycdc, which unfortunately has to be make compiled (that'll make things harder when integrating with myrpl-cli later on)

pycdc then spat the following to stdout:

# Source Generated with Decompyle++
# File: grafo.pyc (Python 3.10)


class Grafo:
	def __init__(self, es_dirigido, vertices_init=(False, [])):
		self.vertices = {}
		for v in vertices_init:
			self.vertices[v] = {}
		self.es_dirigido = es_dirigido

	def __contains__(self, v):
		return v in self.vertices


# and so on...

So, now comes the time to integrate this into myrpl-cli, which poses a challenge in itself.

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

๐Ÿ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

Where does the name come from?

It's actually 'My RPL' backwards. No, wait...

๐Ÿ‘ฅ Authors

  • tcorzo ๐Ÿง‘๐Ÿพโ€๐Ÿฆฒ

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

myrpl_cli-1.0.0.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

myrpl_cli-1.0.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file myrpl_cli-1.0.0.tar.gz.

File metadata

  • Download URL: myrpl_cli-1.0.0.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for myrpl_cli-1.0.0.tar.gz
Algorithm Hash digest
SHA256 cea2128f9bd70f8ff29080d9274f84485b19a8aebd891eadefdad4a577769ed6
MD5 0de9690b7d2199771d0f14acfd5fbabe
BLAKE2b-256 88ab260d746bcdd64663cfe1a914a3e65eb7d12649988e530f0a5fd2fa409052

See more details on using hashes here.

Provenance

The following attestation bundles were made for myrpl_cli-1.0.0.tar.gz:

Publisher: release.yml on tcorzo/myrpl-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file myrpl_cli-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: myrpl_cli-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for myrpl_cli-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4715d9675ad19a15691461ee99fadb942600d2a37a3a99bfa3714ad1e08bb36e
MD5 315c25f631087d6c0002ac62b6dfc4d6
BLAKE2b-256 8c11bac352001fcc8764c232486c1872bc2f576268b32f8646adb448828d5acc

See more details on using hashes here.

Provenance

The following attestation bundles were made for myrpl_cli-1.0.0-py3-none-any.whl:

Publisher: release.yml on tcorzo/myrpl-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page