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

Swap Packaging to Poetry #60

Merged
merged 9 commits into from
Mar 28, 2022
Merged

Swap Packaging to Poetry #60

merged 9 commits into from
Mar 28, 2022

Conversation

sneakers-the-rat
Copy link
Collaborator

@sneakers-the-rat sneakers-the-rat commented Jan 20, 2022

re: #59

Some light maintenance, updating from the old setuptools format to new pyproject.toml format using Poetry.

  • main thing is removal of setup.py and requirements.txt, instead we have pyproject.toml and poetry.lock. pyproject is the project description that contains everything that setup.py does (i was careful to keep it as similar as possible to the existing one while also adding version constraints that allow a successful build/install), and the poetry.lock contains the exact specification of what to install
  • I bumped up the minimum python from 3.5 to 3.6.1 edit:3.7 to be able to install a few packages, both 3.5 and 3.6 are EOL and we should probably deprecate3.
  • The only thing I didn't preserve is the check for tegra in platform(), because I wasn't sure exactly where in the platform string it shows up and platform() is sorta a mash of several other environment markers, but if we know that it's relatively easy to spec with Poetry.
  • I'm sure y'all will have some deeper wisdom than I about tensorflow, I just used the default version specifier ("^2.7.0") but that can be relaxed/tightened/etc. as needed.

Also

  • added some type hints to the DLCLive class which was bothering me to not have tab completion when i've been using it lol
  • DLCLive object tries to mutate something that is by default a tuple, which should cause an error if anyone tries to use tflite and dynamic (instead of warning and repairing as is intended)
  • Using Pathlib to resolve the path and check that it exists when loading configuration, this gives more helpful error messages bc people know where DLC is looking in their filesystem/resolves ambiguity of relative paths re: dlc_live.init_inference throwing error #56 (comment)
  • added a CITATION.cff file <3

Runs fine in a venv,
python==3.7.12

Packages:

>>> poetry show
absl-py                      1.0.0     Abseil Python Common Libraries, see https://github.com/abseil/abseil-py.
astunparse                   1.6.3     An AST unparser for Python
cached-property              1.5.2     A decorator for caching properties in classes.
cachetools                   4.2.4     Extensible memoizing collections and decorators
certifi                      2021.10.8 Python package for providing Mozilla's CA Bundle.
charset-normalizer           2.0.10    The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet.
colorcet                     3.0.0     Collection of perceptually uniform colormaps
flatbuffers                  2.0       The FlatBuffers serialization format for Python
gast                         0.4.0     Python AST that abstracts the underlying Python version
google-auth                  2.3.3     Google Authentication Library
google-auth-oauthlib         0.4.6     Google Authentication Library
google-pasta                 0.2.0     pasta is an AST-based Python refactoring library
grpcio                       1.43.0    HTTP/2-based RPC framework
h5py                         3.1.0     Read and write HDF5 files from Python
idna                         3.3       Internationalized Domain Names in Applications (IDNA)
importlib-metadata           4.8.3     Read metadata from Python packages
keras                        2.7.0     Deep learning for humans.
keras-preprocessing          1.1.2     Easy data preprocessing and data augmentation for deep learning models
libclang                     12.0.0    Clang Python Bindings, mirrored from the official LLVM repo: https://github.com/llvm/llvm-project/tree/main/clang/bindings/python, to make the installation process easier.
markdown                     3.3.6     Python implementation of Markdown.
numexpr                      2.8.1     Fast numerical expression evaluator for NumPy
numpy                        1.18.5    NumPy is the fundamental package for array computing with Python.
oauthlib                     3.1.1     A generic, spec-compliant, thorough implementation of the OAuth request-signing logic
opencv-python                4.5.5.62  Wrapper package for OpenCV python bindings.
opt-einsum                   3.3.0     Optimizing numpys einsum function
packaging                    21.3      Core utilities for Python packages
pandas                       1.1.5     Powerful data structures for data analysis, time series, and statistics
param                        1.12.0    Make your Python code clearer and more reliable by declaring Parameters.
pillow                       8.4.0     Python Imaging Library (Fork)
protobuf                     3.19.3    Protocol Buffers
py-cpuinfo                   5.0.0     Get CPU info with pure Python 2 & 3
pyasn1                       0.4.8     ASN.1 types and codecs
pyasn1-modules               0.2.8     A collection of ASN.1-based protocols modules.
pyct                         0.4.8     Python package common tasks for users (e.g. copy examples, fetch data, ...)
pyparsing                    3.0.6     Python parsing module
python-dateutil              2.8.2     Extensions to the standard Python datetime module
pytz                         2021.3    World timezone definitions, modern and historical
requests                     2.27.1    Python HTTP for Humans.
requests-oauthlib            1.3.0     OAuthlib authentication support for Requests.
rsa                          4.8       Pure-Python RSA implementation
ruamel.yaml                  0.17.20   ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order
ruamel.yaml.clib             0.2.6     C version of reader, parser and emitter for ruamel.yaml derived from libyaml
six                          1.16.0    Python 2 and 3 compatibility utilities
tables                       3.6.1     Hierarchical datasets for Python
tensorboard                  2.7.0     TensorBoard lets you watch Tensors Flow
tensorboard-data-server      0.6.1     Fast data loading for TensorBoard
tensorboard-plugin-wit       1.8.1     What-If Tool TensorBoard plugin.
tensorflow                   2.7.0     TensorFlow is an open source machine learning framework for everyone.
tensorflow-estimator         2.7.0     TensorFlow Estimator.
tensorflow-io-gcs-filesystem 0.23.0    TensorFlow IO
termcolor                    1.1.0     ANSII Color formatting for output in terminal.
tqdm                         4.62.3    Fast, Extensible Progress Meter
typing-extensions            4.0.1     Backported and Experimental Type Hints for Python 3.6+
urllib3                      1.26.8    HTTP library with thread-safe connection pooling, file post, and more.
werkzeug                     2.0.2     The comprehensive WSGI web application library.
wrapt                        1.13.3    Module for decorators, wrappers and monkey patching.
zipp                         3.6.0     Backport of pathlib-compatible object wrapper for zip files

- main thing is removal of setup.py and requirements.txt, instead we have pyproject.toml and poetry.lock. pyproject is the project description that contains everything that setup.py does (i was careful to keep it as similar as possible to the existing one while also adding version constraints that allow a successful build/install), and the poetry.lock contains the exact specification of what to install
- I bumped up the minimum python from 3.5 to 3.6.1 to be able to install a few packages, both 3.5 and 3.6 are EOL and we should think of bumping this up further.

Also
- added some type hints to the DLCLive class which was bothering me to not have tab completion when i've been using it lol
- DLCLive object tries to mutate something that is by default a tuple, which should cause an error if anyone tries to use tflite and dynamic (instead of warning and repairing as is intended)
- Using Pathlib to resolve the path and check that it exists when loading configuration, this gives more helpful error messages bc people know where DLC is looking in their filesystem/resolves ambiguity of relative paths
- added a CITATION.cff file <3
- removed pip install requirements
- removed pytest tests (i don't see any!?)
- installing package and running test from already checked-out copy rather than pip installing from git://
- the packaging script doesn't look like it's doing anything, but i'd be happy to write one that autodeploys on tagged commits to master
…d then call it when doing the tests

- also install and run using poetry because windows paths are an abominable hell
- tensorflow 2.7 only support python >3.7
…e because it gets instantiated before the check happens whether it should be saved or not.

also limited tf versions for python <3.7 because it has to like do the ridiculous pip thing where it downloads all of them for some reason
@sneakers-the-rat
Copy link
Collaborator Author

uh so it turns out that the test function downloads the video but then it just streams the raw video from github anyway because the video file string that's passed is just the url

url_link = "https://github.com/DeepLabCut/DeepLabCut-live/blob/master/check_install/dog_clip.avi?raw=True"
urllib.request.urlretrieve(url_link, "dog_clip.avi")
video_file = os.path.join(url_link, "dog_clip.avi")

- also cleaned up file handling in test function. Previously the video file was downloaded and not used, and lots of implicit paths that seem to be causing people trouble when running it.
@sneakers-the-rat
Copy link
Collaborator Author

OK damn that was harder than i thought it was gonna be, but packaging should be a bit neater now.

supporting 3.6 was causing a huge amount of problems and making pip spend hours trying to install all the possible versions of things, it's EOL anyway so I dropped it, but we can make it technically allowed if ya want, tho the tests need some more work to run :)

also fixes test errors in 36e9d08 from trying to open tk without xvfb.

The two gh actions seem to overlap, but keepin em in there for now.

@MMathisLab MMathisLab requested a review from gkane26 January 20, 2022 09:55
@MMathisLab
Copy link
Member

Hey! question, as I am new to Poetry (looks awesome); how can I use ./reinstall.sh (as no temp wheels I guess?); or what is the best way to install branch with Poetry?

@sneakers-the-rat
Copy link
Collaborator Author

that numpy ~1.18 sticks out like a sore thumb and really pins a lot of other packages down/complicates build, i tried to keep it bc it had been mentioned in prior issues and etc, but any reason why we shouldn't try and catch up?

@sneakers-the-rat
Copy link
Collaborator Author

sneakers-the-rat commented Jan 20, 2022

Hey! question, as I am new to Poetry (looks awesome); how can I use ./reinstall.sh (as no temp wheels I guess?); or what is the best way to install branch with Poetry?

sry didn't refresh. is that script for like a development environment? like keeping the running version in sync as you change code? the generic way is to poetry shell from the root directory which is effectively a venv, then poetry install, so each new interpreter (or I guess import or w/e) should read from the local install.

that's a replacement for a pip install -e kind of env,
you can also use pip in the same way since the pyproject.toml is standard, so just instead of doing the build step you can pip uninstall . && pip install .

the more explicit dependency spec makes it much easier for pip and poetry to verify the environment is as it should be, so repeatedly doing "poetry install" also works without much overhead lol.

or lmk if I've missed the purpose of that script ❤️

edit: their docs are actually really good imo and basically always have them open when I'm mashing at my versions https://python-poetry.org/docs/cli/

@MMathisLab MMathisLab requested review from jeylau and MMathisLab and removed request for gkane26 March 21, 2022 13:58
@MMathisLab MMathisLab added the enhancement New feature or request label Mar 21, 2022
@MMathisLab
Copy link
Member

MMathisLab commented Mar 21, 2022

Hey @sneakers-the-rat just so I undetstand, poetry would replace pypi packaging fully then (i.e., I wouldn't push to pypi packages such that pip install deeplabcut-live works), or both can co-exist?

@sneakers-the-rat
Copy link
Collaborator Author

Hey @sneakers-the-rat just so I undetstand, poetry would replace pypi packaging fully then (i.e., I wouldn't push to pypi packages such that pip install deeplabcut-live works), or both can co-exist?

it would replace setuptools packaging, but you would still be able to publish to pypi : poetry build makes a wheel and then poetry publish uploads to pypi. in either case you can still install with pip, which when installing from source just reads the requirements from pyproject.toml or installs a wheel as usual

@MMathisLab MMathisLab merged commit ce8e96a into master Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants