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

PyPI #119

Open
StoneyJackson opened this issue Apr 21, 2024 · 7 comments
Open

PyPI #119

StoneyJackson opened this issue Apr 21, 2024 · 7 comments

Comments

@StoneyJackson
Copy link
Member

If we distributed PLCC through PyPI then installing PLCC would become...

$ pip install plcc

And no one needs to set environment variables (e.g., LIBPLCC). All Python scripts can find the resource that they need (e.g., Std/) relative to their location (__file__). We might need to reimplement the PLCC scripts (e.g., parse, scan, etc.) in Python. This could have the added benefit of making them platform independent.

@jashelio
Copy link
Collaborator

jashelio commented Apr 21, 2024 via email

@StoneyJackson
Copy link
Member Author

@jashelio Should be possible. Something like:

$ python3 -m pip install --user plcc

This I based on this: https://packaging.python.org/en/latest/tutorials/installing-packages/#installing-to-the-user-site

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
@AksharP5
Copy link
Collaborator

AksharP5 commented Apr 26, 2024

@StoneyJackson

Everything I have learned about how to package to PyPi, and what I have so far:

  1. Create an account on PyPi
  2. Verify account
  3. Create a setup.py file in the root
  4. pip install setuptools
  5. Fill setup.py out with required information, this is what I have so far for this, may need to be altered:
from setuptools import setup

with open('README.md') as f:
    long_description = f.read()

setup(
    name='plcc',
    version='7.0.0',
    description='A Programming Language Compiler Compiler',
    long_description=long_description,
    long_description_content_type='text/markdown',
    url='https://github.com/ourPLCC/plcc',
    author="Akshar Patel", #placeholder name
    author_email='aksharcommit@gmail.com', #placeholder email
    license='GPL 3',
    # Derived requirements from pip3 freeze, but some of these may or may not be needed, and additional ones may be missing
    install_requires=[
        'argcomplete==3.3.0',
        'click==8.1.7',
        'pipx==1.5.0',
        'userpath==1.9.2'],
    classifiers=[
        'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
        'Operating System :: OS Independent',
        'Intended Audience :: Education', 
        'Programming Language :: Python',
        'Programming Language :: Python :: 3 :: Only',
        'Natural Language :: English',
        'Programming Language :: Java',
        'Programming Language :: Java :: 17'
    ] # May need to add more programming language classifiers as it states in the README.md that 
      # plcc works with python>=3.5 and java>=11

      # Can also add entrypoints here, basically map a command to a specific function in a file, will likely need to import the file 
      # in the __init__.py file, this could look something like this:
      # entry_points={
      #     'console_scripts': ['plcc=plcc.__main__.py:main']
      # }
)
  1. pip3 install wheel (try --user if it doesnt work) - Needed for next step
  2. python setup.py sdist bdist_wheel - Creates a build and dist folder
  3. pip install --upgrade twine --user - Used to package and upload dist/ folder to pypi
  4. twine upload dist/* - will ask for the pypi account credentials
  5. Package should be available to download via pip3 after these steps (Hopefully)

@StoneyJackson
Copy link
Member Author

@AksharP5 Good stuff!

Based on https://packaging.python.org/ I get the impression we should be using pyproject.toml. True?

@AksharP5
Copy link
Collaborator

AksharP5 commented Apr 26, 2024

@StoneyJackson

setup.py is fine to use instead of pyproject.toml I believe it is the older method (This is based on git-keeper), however pyproject.toml seems to be the newer standardized format so we can use that. Using poetry for this may be helpful, https://github.com/python-poetry/poetry

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
@StoneyJackson
Copy link
Member Author

Python is beautiful. It's packaging ecosystem is not. It looks like things have improved changed since last I looked at it. Here are some readings that I found that might be useful to others, and might help provide a background if we ever reevaluate this decision later (and we probably will need to).

Based on the above (and maybe a few I didn't capture), here is my summary.

  • There are an insane number of packaging tools in the Python ecosystem.
  • pyproject.toml is the standard that everyone is trying to support. There are several PEPs that have standardized most if not all of it.
  • setuptools was the first packaging tool. It has the largest marketshare. But it's lacking; that's why there are so many other tools.
  • Poetry has the the second largest marketshare. It was using pyproject.toml before it was fully standardized. Now they are working to support the newest standards. It's been a couple of years. There is progress. But they are not done.
  • Of the other tools, PDM and Hatch seam to be "doing it right". PDM is especially standards oriented.

My conclusion? Use pyproject.toml following modern standards. Use PDM for now. If Poetry comes up to standards, consider moving to it.

Note, even if we don't start publishing to PyPI, we still need a place to specify development and runtime dependencies, and pyproject.toml is a good place to do it.

@StoneyJackson
Copy link
Member Author

PR #129 is becoming unwieldily. So I'm down scoping it. It will no longer attempt to distribute plcc through PyPI. But I think this is still a good goal. I'm moving the to-do list that was to here, so we don't lose it.

  1. Add the version number in pyproject.toml to the bumpfile list for semantic release.
  2. Add version="8.0.0" in src/plcc/init.py and use it in src/plcc/main.py to report the version. ("This is the way" https://stackoverflow.com/questions/30159202/how-pip-determine-a-python-package-version)
  3. Add src/plcc/init.py to bumpfile list.
  4. Create PyPI and PyPI test account.
  5. Connect this to PyPI.
  6. Add pdm commands to CI to push to PyPI (see https://pdm-project.org/latest/usage/advanced/#use-pdm-in-continuous-integration)
  7. Update install docs
  8. Update GitPod and devel docs

StoneyJackson added a commit that referenced this issue May 1, 2024
Adopt Technologies:

* PDM - "A modern Python package and dependency manager supporting
the latest PEP standards."
* pyproject.toml - Used by PDM to manage project dependencies and metadata.
* pytest - A nice modern unit testing framework for python.

Reorganized tests, and removed local-min-max test.
They were breaking and are VERY slow. They were intended to mimic
those that run in CI. But those are passing.

Added bin/test/units.bash to run unit tests. Place unit tests in tests/unit/.

No longer supporting python < 3.9.

---

Related to #119
Closes #131

Thanks to
Co-authored-by: Akshar Patel <aksharpatel1233@gmail.com>
He performed the initial research for pyproject.toml
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

No branches or pull requests

3 participants