rootCircle / codemark-cli

CLI app for Codemark for HOF v4.0
https://devfolio.co/projects/codemark-251c
Apache License 2.0
6 stars 5 forks source link

Add support for signup using cli #1

Closed rootCircle closed 8 months ago

rootCircle commented 9 months ago

Motivation

User signup is still not supported at all, from the CLI.

Possible Steps

AnuraagReddy123 commented 9 months ago

Hey if this issue is available can I work on it? Also is there a deadline to finish this issue?

rootCircle commented 9 months ago

Sure! Go ahead with it! Ping me if you need any help!

There won't be any deadline, but try to keep us updated with the progress! Generally, if you're inactive for >3~4 days, chances are some other people might get assigned with the issue!

That being said, I wish you all the best :+1:

AnuraagReddy123 commented 9 months ago

Thank you so much! I will keep you posted!

rootCircle commented 8 months ago

Hi @AnuraagReddy123, are you facing in any difficulty setting up the environment or having any trouble implementing the feature, please do let me know! Maybe I can help!

AnuraagReddy123 commented 8 months ago

Hey @rootCircle, I tried to run the project but I am facing an error: ModuleNotFoundError: No module named 'codemark.secrets'. I guess there is supposed to be another file called secrets. Here is the entire error message:

Traceback (most recent call last): File "\?\D:\anaconda3\envs\codemark-cli\Scripts\codemark-script.py", line 33, in sys.exit(load_entry_point('codemark', 'console_scripts', 'codemark')()) File "\?\D:\anaconda3\envs\codemark-cli\Scripts\codemark-script.py", line 25, in importlib_load_entry_point return next(matches).load() File "D:\anaconda3\envs\codemark-cli\lib\importlib\metadata.py", line 77, in load module = import_module(match.group('module')) File "D:\anaconda3\envs\codemark-cli\lib\importlib__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 843, in exec_module File "", line 219, in _call_with_frames_removed File "d:\coding\hacktober2023\codemark-cli\codemark\scripts\cm_cli.py", line 2, in import codemark.get File "d:\coding\hacktober2023\codemark-cli\codemark\get.py", line 1, in import codemark.firebase.database as FireDB File "d:\coding\hacktober2023\codemark-cli\codemark\firebase\database.py", line 30, in import codemark.secrets ModuleNotFoundError: No module named 'codemark.secrets'

Also unrelated but what is pip install --editable? I had only used pip install so far and usually downloaded all the dependencies, from requirements.txt

rootCircle commented 8 months ago

Yes! You presumed it right

The project requires some setup, try following docs/FIREBASE_SETUP.md and docs/INSTALL.md

Tell me if you face any difficulty, setting those up, for the time being, you can skip the openai and web3storage things(refer link above for details) and put in dummy values.

AnuraagReddy123 commented 8 months ago

Are those links working? They are broken I think image Did you mean to link this? https://github.com/rootCircle/codemark-cli/issues/4

rootCircle commented 8 months ago

So, sorry for that. Here the absolute URLs

https://github.com/rootCircle/codemark-cli/blob/main/docs/FIREBASE_SETUP.md

https://github.com/rootCircle/codemark-cli/blob/main/docs/INSTALL.md

4

Yes!

AnuraagReddy123 commented 8 months ago

So I was able to install codemark but I get this new error when i run codemark --help

Traceback (most recent call last):
  File "D:\anaconda3\envs\codemark-cli\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "D:\anaconda3\envs\codemark-cli\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "D:\anaconda3\envs\codemark-cli\Scripts\codemark.exe\__main__.py", line 4, in <module>
  File "D:\Coding\Hacktober2023\codemark-cli\codemark\scripts\cm_cli.py", line 2, in <module>
    import codemark.get
  File "D:\Coding\Hacktober2023\codemark-cli\codemark\get.py", line 1, in <module>
    import codemark.firebase.database as FireDB
  File "D:\Coding\Hacktober2023\codemark-cli\codemark\firebase\database.py", line 21, in <module>
    import pyrebase
  File "D:\anaconda3\envs\codemark-cli\lib\site-packages\pyrebase\__init__.py", line 1, in <module>
    from .pyrebase import initialize_app
  File "D:\anaconda3\envs\codemark-cli\lib\site-packages\pyrebase\pyrebase.py", line 23, in <module>
    import python_jwt as jwt
  File "D:\anaconda3\envs\codemark-cli\lib\site-packages\python_jwt\__init__.py", line 9, in <module>
    from jwcrypto.jws import JWS, JWSHeaderRegistry
  File "D:\anaconda3\envs\codemark-cli\lib\site-packages\jwcrypto\jws.py", line 7, in <module>
    from jwcrypto.jwa import JWA
  File "D:\anaconda3\envs\codemark-cli\lib\site-packages\jwcrypto\jwa.py", line 8, in <module>
    from cryptography.exceptions import InvalidSignature
  File "D:\anaconda3\envs\codemark-cli\lib\site-packages\cryptography\exceptions.py", line 9, in <module>
    from cryptography.hazmat.bindings._rust import exceptions as rust_exceptions
pyo3_runtime.PanicException: Python API call failed

I followd all the steps to set up the secrets.py and service-account-file.json. Not sure if Github has a Dm option but I can share those files if you want to have a look at them

rootCircle commented 8 months ago

Thanks for pointing it out!

I assume you have the service-account-file.json in codemark/firebase/res directory right?

I might require some extra information to debug the issue!

Can you tell me your Python version?

python3 --version

Your operating system?

Check if poetry update fixes that for you?

Check if poetry run codemark --help run or not?

AnuraagReddy123 commented 8 months ago

python version: 3.10.13 Operating System: Windows 10

Poetry was not working for me. It gives me this error on running poetry install

Installing dependencies from lock file

Package operations: 7 installs, 1 update, 0 removals

  • Installing future (0.18.3)
  • Installing ply (3.8)
  • Installing google-gax (0.12.5)
  • Installing grpc-google-logging-v2 (0.8.1)
  • Installing grpc-google-pubsub-v1 (0.8.1)
  • Installing gax-google-logging-v2 (0.8.3)
  • Installing gax-google-pubsub-v1 (0.8.3)
  • Updating rapidfuzz (2.15.1 -> 3.3.1)

  CalledProcessError

  Command '['D:\\anaconda3\\envs\\codemark-cli\\python.exe', '-m', 'pip', 'uninstall', 'rapidfuzz', '-y']' returned non-zero exit status 2.

  at D:\anaconda3\envs\codemark-cli\lib\subprocess.py:526 in run
       522│             # We don't call process.wait() as .__exit__ does that for us.
       523│             raise
       524│         retcode = process.poll()
       525│         if check and retcode:
    →  526│             raise CalledProcessError(retcode, process.args,
       527│                                      output=stdout, stderr=stderr)
       528│     return CompletedProcess(process.args, retcode, stdout, stderr)
       529│
       530│

The following error occurred when trying to handle this error:

  EnvCommandError

  Command ['D:\\anaconda3\\envs\\codemark-cli\\python.exe', '-m', 'pip', 'uninstall', 'rapidfuzz', '-y'] errored with the following return code 2

  Output:
  Found existing installation: rapidfuzz 2.15.1
  Uninstalling rapidfuzz-2.15.1:
    Successfully uninstalled rapidfuzz-2.15.1
  ERROR: Exception:
  Traceback (most recent call last):
    File "D:\anaconda3\envs\codemark-cli\lib\site-packages\pip\_internal\cli\base_command.py", line 180, in exc_logging_wrapper 
      status = run_func(*args)
    File "D:\anaconda3\envs\codemark-cli\lib\site-packages\pip\_internal\commands\uninstall.py", line 110, in run
      uninstall_pathset.commit()
    File "D:\anaconda3\envs\codemark-cli\lib\site-packages\pip\_internal\req\req_uninstall.py", line 432, in commit
      self._moved_paths.commit()
    File "D:\anaconda3\envs\codemark-cli\lib\site-packages\pip\_internal\req\req_uninstall.py", line 278, in commit
      save_dir.cleanup()
    File "D:\anaconda3\envs\codemark-cli\lib\site-packages\pip\_internal\utils\temp_dir.py", line 173, in cleanup
      rmtree(self._path)
    File "D:\anaconda3\envs\codemark-cli\lib\site-packages\pip\_vendor\tenacity\__init__.py", line 291, in wrapped_f
      return self(f, *args, **kw)
    File "D:\anaconda3\envs\codemark-cli\lib\site-packages\pip\_vendor\tenacity\__init__.py", line 381, in __call__
      do = self.iter(retry_state=retry_state)
    File "D:\anaconda3\envs\codemark-cli\lib\site-packages\pip\_vendor\tenacity\__init__.py", line 327, in iter
      raise retry_exc.reraise()
    File "D:\anaconda3\envs\codemark-cli\lib\site-packages\pip\_vendor\tenacity\__init__.py", line 160, in reraise
      raise self.last_attempt.result()
    File "D:\anaconda3\envs\codemark-cli\lib\concurrent\futures\_base.py", line 451, in result
      return self.__get_result()
    File "D:\anaconda3\envs\codemark-cli\lib\concurrent\futures\_base.py", line 403, in __get_result
      raise self._exception
    File "D:\anaconda3\envs\codemark-cli\lib\site-packages\pip\_vendor\tenacity\__init__.py", line 384, in __call__
      result = fn(*args, **kwargs)
    File "D:\anaconda3\envs\codemark-cli\lib\site-packages\pip\_internal\utils\misc.py", line 130, in rmtree
      shutil.rmtree(dir, ignore_errors=ignore_errors, onerror=rmtree_errorhandler)
    File "D:\anaconda3\envs\codemark-cli\lib\shutil.py", line 750, in rmtree
      return _rmtree_unsafe(path, onerror)
    File "D:\anaconda3\envs\codemark-cli\lib\shutil.py", line 615, in _rmtree_unsafe
      _rmtree_unsafe(fullname, onerror)
    File "D:\anaconda3\envs\codemark-cli\lib\shutil.py", line 620, in _rmtree_unsafe
      onerror(os.unlink, fullname, sys.exc_info())
    File "D:\anaconda3\envs\codemark-cli\lib\shutil.py", line 618, in _rmtree_unsafe
      os.unlink(fullname)
  PermissionError: [WinError 5] Access is denied: 'D:\\anaconda3\\envs\\codemark-cli\\Lib\\site-packages\\~apidfuzz\\distance\\metrics_cpp_avx2.cp310-win_amd64.pyd'

  at D:\anaconda3\envs\codemark-cli\lib\site-packages\poetry\utils\env\base_env.py:363 in _run
      359│                 output = subprocess.check_output(
      360│                     cmd, stderr=stderr, env=env, text=True, **kwargs
      361│                 )
      362│         except CalledProcessError as e:
    → 363│             raise EnvCommandError(e, input=input_)
      364│
      365│         return output
      366│
      367│     def execute(self, bin: str, *args: str, **kwargs: Any) -> int:
rootCircle commented 8 months ago

Seems like anaconda env issue, haven't tested it in CLI app in conda env.

Possibly might be attributed to #3.

Check if this works?

git checkout 1841600cb9d261d0ee51b34199c25258508a0fee
git checkout -b testing-branch
pip3 install -e .
codemark --help
rootCircle commented 8 months ago

PermissionError: [WinError 5] Access is denied: 'D:\anaconda3\envs\codemark-cli\Lib\site-packages\~apidfuzz\distance\metrics_cpp_avx2.cp310-win_amd64.pyd'

git checkout main

I believe that running as admin or deleting that file might fix the issue! (it won't break a thing) After deleting, cd into root directory and then again run poetry install

rootCircle commented 8 months ago

If case both doesn't solve the issue then try installing the python from python.org official website and then try to use it. Your system's python is linked to that of conda environment, which although should not be an issue imo, but it is.

Do, let me know if none of them work!

AnuraagReddy123 commented 8 months ago

So for people in the future: I uninstalled all of my python installations and reinstalled them again. And I am running VS code in administrator now Python version: 3.10.0 I avoided anaconda this time, created a virtual environment using the command python -m venv venv Then I followed the steps:

pip install poetry
poetry install

I got this error

Traceback (most recent call last):
  File "C:\Users\Anuraag Reddy\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main    return _run_code(code, main_globals, None,
  File "C:\Users\Anuraag Reddy\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "D:\Coding\Hacktober2023\codemark-cli\venv\Scripts\poetry.exe\__main__.py", line 4, in <module>
  File "D:\Coding\Hacktober2023\codemark-cli\venv\lib\site-packages\poetry\console\application.py", line 11, in <module>
    from cleo.application import Application as BaseApplication
  File "D:\Coding\Hacktober2023\codemark-cli\venv\lib\site-packages\cleo\application.py", line 12, in <module>        
    from cleo.commands.completions_command import CompletionsCommand
  File "D:\Coding\Hacktober2023\codemark-cli\venv\lib\site-packages\cleo\commands\completions_command.py", line 10, in <module>
    from cleo import helpers
  File "D:\Coding\Hacktober2023\codemark-cli\venv\lib\site-packages\cleo\helpers.py", line 5, in <module>
    from cleo.io.inputs.argument import Argument
  File "D:\Coding\Hacktober2023\codemark-cli\venv\lib\site-packages\cleo\io\inputs\argument.py", line 5, in <module>  
    from cleo.exceptions import CleoLogicError
  File "D:\Coding\Hacktober2023\codemark-cli\venv\lib\site-packages\cleo\exceptions\__init__.py", line 3, in <module> 
    from cleo._utils import find_similar_names
  File "D:\Coding\Hacktober2023\codemark-cli\venv\lib\site-packages\cleo\_utils.py", line 8, in <module>
    from rapidfuzz.distance import Levenshtein
ModuleNotFoundError: No module named 'rapidfuzz'

I installed rapidfuzz using pip install rapidfuzz and got this warning:

Collecting rapidfuzz
  Obtaining dependency information for rapidfuzz from https://files.pythonhosted.org/packages/81/3f/e08d377a5368402d7fef9931e43af4776d493d881f44e5c750d21505f0d1/rapidfuzz-3.3.1-cp310-cp310-win_amd64.whl.metadata
  Using cached rapidfuzz-3.3.1-cp310-cp310-win_amd64.whl.metadata (11 kB)
Using cached rapidfuzz-3.3.1-cp310-cp310-win_amd64.whl (1.8 MB)
Installing collected packages: rapidfuzz
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
cleo 2.0.1 requires rapidfuzz<3.0.0,>=2.2.0, but you have rapidfuzz 3.3.1 which is incompatible.
Successfully installed rapidfuzz-3.3.1

Then I ran poetry install again and finally it works now! But I am not sure about that warning, you can look into it codemark --help works now!

rootCircle commented 8 months ago

Hi @AnuraagReddy123, I am glad that it works now! And sorry that you had to go through all those pain. I will surely try to get resolved before an upcoming release! As my prime development environment is Linux, I need some time replicating those issues in Windows!

Regarding running as admin thing, can you confirm if this works even without admin also or not, please?

AnuraagReddy123 commented 8 months ago

I just ran poetry install now (not in adminstrator mode) and this was the output

Installing dependencies from lock file

No dependencies to install or update

Installing the current project: codemark (0.2.2)

so probably it works now..? I can uninstall the venv and try again but that would again be a long task 😅. I will do it if you want me to check now

rootCircle commented 8 months ago

No, it's fine! :+1: You really did a great job at handling those issues!

AnuraagReddy123 commented 8 months ago

Just a heads up I got this warning on running poetry install when I synced the latest commits

Warning: poetry.lock is not consistent with pyproject.toml. You may be getting improper dependencies. Run `poetry lock [--no-update]` to fix it.
rootCircle commented 8 months ago

Just run poetry update, it will fix it!

AnuraagReddy123 commented 8 months ago

The register function works now image image However on logging in I get an error

[INFO] Initializing Configurations for User
Enter Email : testing321@testing.com
Enter Password : 
[SUCCESS] Logined Successfully!
Traceback (most recent call last):
  File "D:\Coding\Hacktober2023\codemark-cli\venv\lib\site-packages\firebase_admin\db.py", line 929, in request
    return super(_Client, self).request(method, url, **kwargs)
  File "D:\Coding\Hacktober2023\codemark-cli\venv\lib\site-packages\firebase_admin\_http_client.py", line 119, in request       
    resp.raise_for_status()
  File "D:\Coding\Hacktober2023\codemark-cli\venv\lib\site-packages\requests\models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://codemark-cli-default-rtdb.firebaseio.com/users.json?equalTo=%22testing321@testing.com%22&orderBy=%22email%22

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Coding\Hacktober2023\codemark-cli\codemark\firebase\database.py", line 199, in getdataOrderEqual
    out = db.reference(child).order_by_child(ordervar).equal_to(equalvar).get()
  File "D:\Coding\Hacktober2023\codemark-cli\venv\lib\site-packages\firebase_admin\db.py", line 621, in get
    result = self._client.body('get', self._pathurl, params=self._querystr)
  File "D:\Coding\Hacktober2023\codemark-cli\venv\lib\site-packages\firebase_admin\_http_client.py", line 131, in body
    resp = self.request(method, url, **kwargs)
  File "D:\Coding\Hacktober2023\codemark-cli\venv\lib\site-packages\firebase_admin\db.py", line 931, in request
    raise _Client.handle_rtdb_error(error)
firebase_admin.exceptions.InvalidArgumentError: Index not defined, add ".indexOn": "email", for path "/users", to the rules     

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Coding\Hacktober2023\codemark-cli\venv\Scripts\codemark", line 6, in <module>
    sys.exit(cli())
  File "D:\Coding\Hacktober2023\codemark-cli\venv\lib\site-packages\click\core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "D:\Coding\Hacktober2023\codemark-cli\venv\lib\site-packages\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "D:\Coding\Hacktober2023\codemark-cli\venv\lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "D:\Coding\Hacktober2023\codemark-cli\venv\lib\site-packages\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "D:\Coding\Hacktober2023\codemark-cli\venv\lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "D:\Coding\Hacktober2023\codemark-cli\codemark\scripts\cm_cli.py", line 28, in init
    codemark.initialise.initApp()
  File "D:\Coding\Hacktober2023\codemark-cli\codemark\initialise.py", line 20, in initApp
    if initialiseCred():
  File "D:\Coding\Hacktober2023\codemark-cli\codemark\initialise.py", line 50, in initialiseCred
    user_content = db.getdataOrderEqual("users", "email", email)
  File "D:\Coding\Hacktober2023\codemark-cli\codemark\firebase\database.py", line 208, in getdataOrderEqual
    print_error(e)
  File "D:\Coding\Hacktober2023\codemark-cli\codemark\utils.py", line 98, in print_error
    message = "[ERROR] " + message
TypeError: can only concatenate str (not "InvalidArgumentError") to str
rootCircle commented 8 months ago

Index not defined, add ".indexOn": "email", for path "/users", to the rules => For this go to realtime database, section then rules

{
  "rules": {
    "assignments" :{
      ".indexOn":["batch_id", "assignment_id"],
    },
    "submissions" : {
      ".indexOn":["student_id", "submission_id"],
    },
    "users" : {
      ".indexOn" : ["email"],
    },
    "students" : {
      ".indexOn" : ["email"],
    },
    "plagcache" : {
      ".indexOn" : ["assignment_id"],
    },

    ".read": "true",  // 2023-5-22
    ".write": "true",  // 2023-5-22
  }
}

Also,

In codemark/utils.py, Line no. 94

-  message = "[ERROR] " + message
+  message = "[ERROR]" + str(message) 
AnuraagReddy123 commented 8 months ago

Made the required changes. Now the following error comes up. image I guess it is because the new user is not being registered in the realtime database image

rootCircle commented 8 months ago

Also, just to let you know there are some extra info to be filled in Real-time DB Firebase when registering. Refer users and students in https://github.com/rootCircle/codemark-cli/blob/main/Schemas/dummy_data.json.

For implementing them, try using https://github.com/rootCircle/codemark-cli/blob/c000fd2fb7309c0a05e25598a639fbdc3edd770a/codemark/firebase/database.py#L115

rootCircle commented 8 months ago

Made the required changes. Now the following error comes up. I guess it is because the new user is not being registered in the realtime database

It's because it can't find the user with email testing123@testing.com in users and students collection in firebase db

https://github.com/rootCircle/codemark-cli/blob/c000fd2fb7309c0a05e25598a639fbdc3edd770a/codemark/initialise.py#L50

Implementing the one above, might help resolving the issue.

AnuraagReddy123 commented 8 months ago

Is the student_id autogenerated or will the student enter it during registration? Also what is batch_id? I think I am more or less done. Any idea how to fix this?

Another collection is being formed with a random name This is the code I have written

db.pushData('users/'+email.replace('.', '_'), user_config)
db.pushData('students/'+student_id, student_config)

Similarly for students collection

rootCircle commented 8 months ago

Is the student_id autogenerated or will the student enter it during registration? Also what is batch_id? I think I am more or less done. Any idea how to fix this?

They(student_id) will a random identifier, not exposed to end user and hence auto-generated. (submit.py file has angenerate_hash() method, maybe that can help!) For batch ID, for now you can enumerate the list of batches in the class by batch_name, and let user choose the batch_id

Another collection is being formed with a random name This is the code I have written

For that, you don't need to pass in the emails and student_id as the keys actually! Being a sample schema, that was for test purposes only.

- db.pushData('users/'+email.replace('.', '_'), user_config)
- db.pushData('students/'+student_id, student_config)
+ db.pushData('users', user_config)
+ db.pushData('students', student_config)

For this check if atleast login and get etc works or not!

Just for Knowledge : [no need to implement thing down below]

For what, you want to achieve : In codemark/firebase/database.py, you will need to

-    def pushData(self, child, details):
+   def pushData(self, child, key, details):
        """
        Writes data to FirebaseDB
        :param child: The address to the node on which data has to be written
                    If one has created a table named Institute and another sub-table inside
                    the table say named Students.Idea being, at a time all students of same
                    branch name is to be put at one branch.
                    So every new entry is defined by a random set of character allocated on data creation.
                    This key(random set of character) can be fetched using getdataOrderEqual function and
                    getting the keys of returned dictionaries. Each keys point of its own location
                    in database.
        :param details: Data-Type-Dictionary All the details in form of dictionary, one want to push
        :return: True : If data is successfully written
                 None : If some error arises
        """
        try:
 -           results = db.reference(child).push(details)
 +          results = db.reference(child).child(key).push(details) 
            return True

And hence then your calls might change to

db.pushData('users', email.replace('.', '_'), user_config)
db.pushData('students', student_id, student_config)
AnuraagReddy123 commented 8 months ago

\ \ \ It works now! 🥳

Works for professors too

However I can't login using professor email

rootCircle commented 8 months ago

It works now! 🥳

Great work @AnuraagReddy123 :tada: :tada: You can create an PR to this repo, and then we can review the code!

However I can't login using professor email

It's more because, login support for professor isn't implemented yet! (TBC in #2)

AnuraagReddy123 commented 8 months ago

Thanks! I have made the pull request