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

make installation with pip possible #11

Closed
mwermelinger opened this issue Feb 24, 2023 · 14 comments
Closed

make installation with pip possible #11

mwermelinger opened this issue Feb 24, 2023 · 14 comments
Assignees
Labels
effort: high These issues require the most work priority: medium type: enhancement Improve an existing feature
Milestone

Comments

@mwermelinger
Copy link
Member

Find out how to make a pip package and add allowed to the Python Package Index.

@mwermelinger mwermelinger added type: enhancement Improve an existing feature priority: medium labels Feb 24, 2023
@mwermelinger mwermelinger added this to the Version 1.0 milestone Feb 24, 2023
@mwermelinger mwermelinger self-assigned this Feb 24, 2023
@mwermelinger
Copy link
Member Author

@mwermelinger
Copy link
Member Author

mwermelinger commented Mar 5, 2023

  • The sample files could be moved to a tests folder that isn't included in the distribution
  • the code could be split into multiple files e.g. language.py, check.py, ...
  • Since pip will install any dependant packages, we could use TOML instead of JSON
  • pytype could also be automatically installed for Python 3.10
  • would default config still be retrieved in the same way (ie from same folder)?

@densnow densnow mentioned this issue Dec 3, 2023
4 tasks
@mwermelinger
Copy link
Member Author

mwermelinger commented Dec 23, 2023

allowed is now on TestPyPi but not yet working. TestPyPi uses 2FA, so a project can't be published with username/pwd; only with an API token or a trusted publisher like GitHub Actions. The steps were:

  1. Tell poetry the URL of the repo to publish to: poetry config repositories.testpypi https://test.pypi.org/legacy/
  2. Log into my TestPyPi account and create an API token pypi-...
  3. Tell poetry it should publish using that token: poetry config http-basic.testpypi __token__ pypi-...
  4. Bump up the version number in pyproject.toml because the same version can't be published twice. I'm using developmental versions.
  5. Build and publish to TestPyPi: poetry publish --build -r testpypi

To test the installation, I created and activated a new venv with Python 3.10, and ran pip install -i https://test.pypi.org/simple/ allowed==1.2.0.dev1 but got installation issues. Apparently TestPyPi doesn't include a recent ipython, and for some reason installing pytype complains that it can't satisfy setuptools > 40.8, even though the venv has `setuptools 65.5. I hope it works with the real PyPi.

Commenting out both dependencies in pyproject.toml makes pip install work. However, the built wheel only has the allowed.py file and not the configuration files. Several things to do:

  • include configuration files in the installation
  • skip installation of pytype on Windows – see dependency specifiers
  • make allowed an executable that can be called from command line – is it this?
  • make allowed look into its own folder for the configuration files
  • Do a simpler README for PyPi that doesn't have local links (which won't work on PyPi)

@mwermelinger
Copy link
Member Author

It seems it's possible to leave the dependencies in pyproject.toml and do pip install --no-deps -i ..., to avoid trying installing dependencies that may not exist on TestPyPi.

@densnow
Copy link
Contributor

densnow commented Dec 24, 2023

Here is some documentation that might also be useful for skipping pytype installation on windows: Using environment markers and Environment markers

Something like the following in pyproject.toml could work

[tool.poetry.dependencies]
#...
pytype = { version = "^2023.11.29", markers = "platform_system != 'Windows'" }

For making allowed an executable see scripts. It looks like an entry point to allowed must be defined E.g a main() or run() function, then something like the following could be added to the TOML

[tool.poetry.scripts]
allowed = 'allowed:main'

@mwermelinger
Copy link
Member Author

  • I managed to make paddles pip'able. I think we need a subfolder allowed/ with the .py and .json files and an empty __init__.py.
  • The installation can be done locally, without going through TestPyPi, withpip path/to/allowed_project. This allows to check things before putting on TestPyPi and then on PyPi.
  • allowed works if IPython and pytype aren't present, so we could for the moment leave it to the user to install those if they wish. Those dependencies could move to the development group.

@mwermelinger mwermelinger modified the milestones: 23J release, 24J release Jan 8, 2024
@mwermelinger mwermelinger added the effort: high These issues require the most work label Jan 9, 2024
@scmmmh
Copy link

scmmmh commented Jan 15, 2024

Just a few notes on publishing PyPi packages easily:

I've built and published a number of CLI applications over the years, so if you have any questions, please just tag me in (@scmmmh).

@mwermelinger
Copy link
Member Author

mwermelinger commented Feb 9, 2024

To check pip installation locally, change to a folder outside the repo, e.g. your home folder. Then:

  • create a virtual env, e.g. python3.10 -m venv ~/testenv
  • activate it, e.g. . ~/testenv/bin/activate
  • install allowed: pip install ~/dsa-ou/allowed
  • try it out, e.g. allowed ~/dsa-ou/allowed/sample.ipynb -c tm112.json or python -m allowed ~/dsa-ou/....
  • do pip install '/Users/.../dsa-ou/allowed[ipython]' (can't use ~) and check again the sample notebook
  • finally do pip install '/Users/.../dsa-ou/allowed[pytype]' and check again sample notebook with -m option

@mwermelinger
Copy link
Member Author

@densnow I've put allowed on PyPi. It can be installed in 4 ways:

  • pip install allowed
  • pip install 'allowed[ipython]'
  • pip install 'allowed[pytype]'
  • pip install 'allowed[all]' to install both

Could you try the latter in a new virtual env on Windows? Let me know if pytype is installed or not. Thanks. If it's all fine, I will update the installation instructions and then merge the branch for this issue into main.

@densnow
Copy link
Contributor

densnow commented Feb 9, 2024

@mwermelinger After running the command pip install 'allowed[all]' in a brand new venv on Windows 10, pytype was not installed.

@densnow
Copy link
Contributor

densnow commented Feb 9, 2024

@mwermelinger If allowed is now on Pypi, it would be nice to have --version and -v commands to print the version (and quickly check if it is installed). Also I noticed when the usage instructions are printed there is reference to allowed.py rather than allowed which might not make sense in the new context.

@mwermelinger
Copy link
Member Author

Thanks for checking. Good point about the version. But where does the usage refer to allowed.py? If I type allowed -h I don't see it. But if I type python -m allowed -h then the usage mentions __main__.py. I'll fix these things before merging.

@densnow
Copy link
Contributor

densnow commented Feb 9, 2024

My mistake, I thought the usage message was written in the code somewhere, but It seems to be generated by argparser when an unknown or missing argument is given.

The message was printed when I tried allowed --version

@mwermelinger
Copy link
Member Author

mwermelinger commented Feb 9, 2024

  • update installation.md
  • see if there's a way for argparser to not display __main__.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: high These issues require the most work priority: medium type: enhancement Improve an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants