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

Switch to setup.cfg from setup.py. #129

Merged
merged 3 commits into from
Oct 28, 2021
Merged

Switch to setup.cfg from setup.py. #129

merged 3 commits into from
Oct 28, 2021

Conversation

clokep
Copy link
Member

@clokep clokep commented Oct 20, 2021

  • Updates setup.cfg (which we were already using for flake8) to include the metadata from setup.py.
  • Includes a pyproject.toml.
  • Updates the releasing instructions to use build (and upload wheels).
  • Switches tox to use isolated builds (which are recommended, I think?)

@clokep clokep requested a review from a team October 20, 2021 16:06
@clokep
Copy link
Member Author

clokep commented Oct 20, 2021

I tested running tox and go through the build process (up to the actual upload) and things seem OK.

Copy link
Contributor

@reivilibre reivilibre left a comment

Choose a reason for hiding this comment

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

Thanks for making a good example. I think it paints a good picture.

Comment on lines -53 to -55
test_require=[
"matrix-synapse",
],
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see this having been copied over, but I think that's fine because this is only part of python setup.py test from what I can tell?

Copy link
Member Author

Choose a reason for hiding this comment

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

I should have mentioned that, good catch!

As far as I can tell this was for python setup.py test, but I don't think that would work properly with the Twisted bits anyway.

In tox we run via trial, but seem to missing docs on how to run tests manually.

@@ -1,5 +1,6 @@
[tox]
envlist = packaging, pep8, py35, py36, py37, py38
isolated_build = True
Copy link
Contributor

Choose a reason for hiding this comment

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

For onlookers who didn't know what this meant (me!):

Activate isolated build environment. tox will use a virtual environment to build a source distribution from the source tree. For build tools and arguments use the pyproject.toml file as specified in PEP-517 and PEP-518. To specify the virtual environment Python version define use the isolated_build_env config section.

tox

Comment on lines +4 to +6
version = attr: ldap_auth_provider.__version__
description = An LDAP3 auth provider for Synapse
long_description = file: README.rst
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm really liking attr: and file: rather than our (nice, but not really belonging in a config file) exec_file and read_file.

(I also believe I read somewhere that setuptools doesn't actually execute the code, it reads it from the AST.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this is the main improvement IMO.

@clokep clokep marked this pull request as ready for review October 20, 2021 18:35
@reivilibre
Copy link
Contributor

Actually I might request a change because of this:

matrix-synapse-ldap3 on  clokep/build [?] is 📦 vattr: ldap_auth_provider.__version__ via 🐍 v3.9.5 
$ pip install -e .
ERROR: File "setup.py" not found. Directory cannot be installed in editable mode: /home/rei/work/matrix-synapse-ldap3
(A "pyproject.toml" file was found, but editable mode currently requires a setup.py based build.)

I think this means we need to add a stub as setup.py:

from setuptools import setup
setup()

That does the job for me.

Am I missing a workaround?

Copy link
Contributor

@reivilibre reivilibre left a comment

Choose a reason for hiding this comment

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

as above (or workaround needed, preferably documented)

@reivilibre
Copy link
Contributor

Hm, actually, before posting that, I only upgraded setuptools thinking that would do the trick.
But actually, upgrading pip seems to get me there.

Can we perhaps get into a habit of documenting that this command is the first one that you want to run in your venv:
pip install -U pip setuptools?

I note that, although it seems to install, pip reports this:

  Installing build dependencies ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... done
->Build backend does not support editables, falling back to setup.py egg_info.
  Preparing metadata (setup.py) ... done

(emphasis mine)

I don't know if that's cause for concern (probably not; it's not in red or anything), but thought it was worth noting.

@callahad
Copy link

Yep. You need pip 21.1 (2021-04-24) for editable installs in projects with only setup.cfg files, or pip 21.3 (2021-10-11) for standardized, PEP 660 support for editable installs for any project that uses pyproject.toml and a compatible build backend.

@clokep
Copy link
Member Author

clokep commented Oct 21, 2021

Can we perhaps get into a habit of documenting that this command is the first one that you want to run in your venv:
pip install -U pip setuptools?

I usually upgrade pip every time it yells at me for being out of date FWIW...

@reivilibre
Copy link
Contributor

I usually upgrade pip every time it yells at me for being out of date FWIW...

I don't even know how to get pip to yell at me for being out of date. I just tried installing a package and it didn't mention that pip was old. (I was not on the latest pip at the time. :/)

I think it's worth dropping a line in with that upgrade command? I think that should catch everything.
Otherwise it's not obvious what's going wrong (I guess this situation will change over time, but I imagine I'm not the only one who is brand new to all this?).

@clokep
Copy link
Member Author

clokep commented Oct 22, 2021

I usually upgrade pip every time it yells at me for being out of date FWIW...

I don't even know how to get pip to yell at me for being out of date. I just tried installing a package and it didn't mention that pip was old. (I was not on the latest pip at the time. :/)

It happens automatically for me, I get a message like:

image

I think it's worth dropping a line in with that upgrade command? I think that should catch everything. Otherwise it's not obvious what's going wrong (I guess this situation will change over time, but I imagine I'm not the only one who is brand new to all this?).

We don't have directions anywhere to install it as editable, so I don't think there's a place to include this. The normal installation instructions should be fine without upgrading pip and I do not wish to complicate them.

@reivilibre
Copy link
Contributor

reivilibre commented Oct 22, 2021

It happens automatically for me, I get a message like:

image

Hm, I haven't seen that.

I think it's worth dropping a line in with that upgrade command? I think that should catch everything. Otherwise it's not obvious what's going wrong (I guess this situation will change over time, but I imagine I'm not the only one who is brand new to all this?).

We don't have directions anywhere to install it as editable, so I don't think there's a place to include this.

That's a shame, but OK, we'll figure it out when we cross it.

The normal installation instructions should be fine without upgrading pip and I do not wish to complicate them.

If I don't upgrade Pip, I get this very unhelpful error:

Processing /home/rei/work/matrix-synapse-ldap3
  Installing build dependencies ... done
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib/python3.9/tokenize.py", line 392, in open
        buffer = _builtin_open(filename, 'rb')
    FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-req-build-xgug4xmd/setup.py'
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-req-build-xgug4xmd/

@clokep
Copy link
Member Author

clokep commented Oct 26, 2021

@reivilibre I'm unsure if there are changes you'd like me to make or not now! I agree that's an unhelpful error, but I'm not sure many people will be installing this in edit-mode.

@reivilibre
Copy link
Contributor

@reivilibre I'm unsure if there are changes you'd like me to make or not now! I agree that's an unhelpful error, but I'm not sure many people will be installing this in edit-mode.

The above error is for non-editable mode. I think it would be worth at least mentioning a minimum supported Pip version? I know this isn't exactly our main project, but these kinds of weird errors are tricky for Python strangers and especially since we're aware of them, 6 words along the line of 'Pip x.y or newer is needed.' (in the bullet point where we mention installing into a virtualenv) might just be what someone needs to figure this out.

@clokep
Copy link
Member Author

clokep commented Oct 27, 2021

@reivilibre I'm unsure if there are changes you'd like me to make or not now! I agree that's an unhelpful error, but I'm not sure many people will be installing this in edit-mode.

The above error is for non-editable mode. I think it would be worth at least mentioning a minimum supported Pip version? I know this isn't exactly our main project, but these kinds of weird errors are tricky for Python strangers and especially since we're aware of them, 6 words along the line of 'Pip x.y or newer is needed.' (in the bullet point where we mention installing into a virtualenv) might just be what someone needs to figure this out.

Yes, that makes sense. It wasn't clear to me that this was for a normal install.

Copy link
Contributor

@reivilibre reivilibre left a comment

Choose a reason for hiding this comment

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

Thank you!

@clokep clokep merged commit 9b2530e into main Oct 28, 2021
@clokep clokep deleted the clokep/build branch October 28, 2021 11:06
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.

3 participants