Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python modifications #111

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Python modifications #111

wants to merge 2 commits into from

Conversation

gorimaaa
Copy link
Contributor

@gorimaaa gorimaaa commented Feb 17, 2025

Description

Following #109 #109
I added the modifications as asked :

  • A file named data.json get all the data in _data. We can now check if the path is in data.json, if it is we get the data associated (that were usually in _data/path)
  • getNodeByPath is now usable with the package "kulya_python"
    If there is any error left, or misunderstanding from my side please let me know.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Copy link
Member

@ZibanPirate ZibanPirate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome work @gorimaaa ! and you even went ahead and published the package 🚀

i added couple of comments, feel free to merge this PR now and address them in a separate follow-up PR if you want

thanks again for the PR i'm learning Python along with you now 🙏

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to commit this file (and also kulya_python-1.6-py3-none-any.whl) ?

ideally we want to generate them and publish them in a Github CI Action

if they are not mandatory to be committed, then let's remove them for now, and worry about publishing the package in a follow-up PR.

Issues = "https://github.com/dzcode-io/kuliya/issues"

[tool.hatch.build.targets.wheel]
only-include = ["src/kulya_python", "data"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the "data" folder here is only used during build time right? and not actually published as part of the package code?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also not commit this file? and generate it on the fly in CI? and also locally when you build the package

self.nameAr = nameAr
self.nameEn = nameEn
self.nameFr = nameFr
self.univ = univ
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have .univ field?

def getNameFr(self):
return self.nameFr

def getUniv(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have getUniv method?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we not commit the __pycache__ folder?

Essientially, it converts the JSON data into a Node object.
"""
def getNodeByPath(path: str) -> Node:
if DEVELOPMENT_MODE:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is clever, but generally we want to avoid bloating our package with files it does not need. for instance, a consumer of this package will never use directoryToOneJsonFile but they will still download this piece of code regardless, which is not ideal.

an alternative solution is, move the directoryToOneJsonFile to a seperate non-published directory (eg: src/build/utils.py) and then:

  • in development, you would need to run this in watch mode (it watches ../data for changes and re-run, maybe using nodemon)
  • in CI, we run this once before publishing the package (to prepare the json once)

think of it more or less like the JS implementation where we have a script that prepares the data.json

targetFile.write(file.read())
targetFile.write(",")
file.close()
targetFile.write('"":{}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writing the json format by hand is error prune, maybe we can use a more rebust solution by using the existing json module, where:

  • we would have a local jsonData variable as an empty array, that we then add nodes into
  • then we json.dump it to targetFile

this way we guarantee we have a valid and escaped json file, and as a bonus we have a nice formatted file ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants