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

Convert plcc.py into a Python package #121

Closed
StoneyJackson opened this issue Apr 21, 2024 · 3 comments · Fixed by #122
Closed

Convert plcc.py into a Python package #121

StoneyJackson opened this issue Apr 21, 2024 · 3 comments · Fixed by #122
Labels

Comments

@StoneyJackson
Copy link
Member

To help with redesigns, it would be helpful to organize functionality across multiple files (making clear the boundaries and independence of components). Converting plcc.py into a package would help with this and gets us closer to #119 .

This would change the way you call it. Currently, as a script, we call it like this...

$ python3 path/to/plcc.py

Once converted into a package, we would call it like this...

$ python3 -m plcc

This requires that it's parent directory is in Python's path (PYTHONPATH). After #119 , this is automatic. Until then, the PLCC scripts can set this just before calling plcc, something like this

PYTHONPATH=/path/to/parent/of/plcc python3 -m plcc

PLCC's scripts can do this by using relative paths from their current location as described in #120 .

Code impact

The codebase would need to be reorganized as follows:

plcc/                      Rename src/ to plcc/
    bin/                    Move scripts (scan, parse, etc.) to bin/
    lib/                     Move Std/ and lib/jackson/*.jar here.
    __init__.py        Makes plcc/ a Python package.
    __main__.py     Rename plcc.py as __main__.py which makes plcc/ executable.
    ...                       Other Python scripts are organized under plcc/ .

Scripts and main.py (currently plcc.py) would need to update the way they find the location of resources (e.g., Std/).
Scripts would need to be updated to set PYTHONPATH and CLASSPATH correctly.

User impact

This would break existing PLCC installations as LIBPLCC would point to src/ which no longer exists.
Users would need to reinstall PLCC when they upgrade.

StoneyJackson added a commit that referenced this issue Apr 22, 2024
BREAKING CHANGE:

plcc is now a Python package, and plcc.py has been removed.
So plcc.py can no longer be called directly like this

    python3 path/to/plcc.py grammar

Instead, use plcc like this

    plcc grammar

---

This commit restructures the PLCC codebase into that of a
conventional Python project. This should make it easier to
redesign the internal structure of PLCC, making it easier to
maintain and add new functionality. It should also help us
prepare to distribute PLCC through PyPI, making it easier
to install. Here is a summary of changes.

- Convert plcc.py into python package plcc
- Remove environment variable LIBPLCC
- Move src/Std/ to src/
- Move lib/jackson to src/lib/jackson
- Move src/ to plcc/bin/
- Pull common functionality of scripts into plcc/bin/__init__.bash

---

Related Issues

- Related to #119
- Closes #121
- Closes #120
@jashelio
Copy link
Collaborator

I played around with these Python features a bit. On the one hand, I read that init.py has not been required since Python3.3. On the other hand, I suggest it be used to do the necessary imports, whereas main.py contains the simple code line(s) to start everything running. No biggie; just my preference.

@StoneyJackson
Copy link
Member Author

@jashelio

Wow, didn't know __init__.py was no longer required. Thanks for letting me know. Based on some quick reads, I don't get the impression that they want everyone to stop using it. At this point, we don't use them to control imports, just to signal that a directory is really a Python package. So we could remove them.

I added __main__.py to allow the plcc package to be "executable". That is, so that we can run python3 -m plcc. Currently __main__.py is the old plcc.py. The goal, after this change, is to start breaking down and organizing functionality into more independent packages and modules leaving a relatively thin, bootstrapping __main__.py. I think this matches your preference. Let me know if I miss understood.

StoneyJackson added a commit that referenced this issue Apr 28, 2024
BREAKING CHANGE:

plcc is now a Python package, and plcc.py has been removed.
So plcc.py can no longer be called directly like this

    python3 path/to/plcc.py grammar

Instead, use plcc like this

    plcc grammar

---

This commit restructures the PLCC codebase into that of a
conventional Python project. This should make it easier to
redesign the internal structure of PLCC, making it easier to
maintain and add new functionality. It should also help us
prepare to distribute PLCC through PyPI, making it easier
to install. Here is a summary of changes.

- Convert plcc.py into python package plcc
- Remove environment variable LIBPLCC
- Move src/Std/ under src/plcc (the PLCC Python package)
- Move lib/jackson under src/plcc (the PLCC Python package)
- Pull common functionality of scripts into common.bash

---

Related Issues

- Related to #119
- Closes #121
- Closes #120
Copy link

🎉 This issue has been resolved in version 8.0.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

2 participants