Skip to content

Build documentation without the compiled extension #11

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

Merged
merged 9 commits into from
Nov 27, 2017
Merged

Conversation

encukou
Copy link
Member

@encukou encukou commented Nov 24, 2017

This rabbit hole turned out deeper than expected, but I managed to mock out _ldap so that documentation can be built without a C compiler.
All the magic is documented.

C code had the only list of LDAP_* constants python-ldap used. I turned that into a Python file, and generated a .h from it.

@encukou encukou mentioned this pull request Nov 25, 2017
21 tasks
@encukou
Copy link
Member Author

encukou commented Nov 25, 2017

Autodoc is working as it should, see e.g. ldap-controls

@encukou encukou closed this Nov 25, 2017
@encukou encukou reopened this Nov 25, 2017
@tiran
Copy link
Member

tiran commented Nov 25, 2017

I'll review this PR later today. It's rather big.

Copy link
Member

@tiran tiran left a comment

Choose a reason for hiding this comment

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

I like how you generate the header file.

Some minor style nit picks.

UPDATE: I compared vars(_ldap) of this PR and master. They both contain the same set of keys. The values for constants are equal, too.

obj = PyUnicode_FromString(LDAP_CONTROL_ASSERT);
PyDict_SetItemString( d, "CONTROL_ASSERT", obj );
Py_DECREF(obj);
#define check_result() { \
Copy link
Member

Choose a reason for hiding this comment

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

I don't like this kind of macros. It's confusing whenever a macro picks up values from the outer scope. Please either pass result in the function check(result);or rewrite the few calls to if (PyModule_AddIntConstant(m, "OPT_ON", 1)) return -1;

IIRC some compilers do not like a semicolon after a block {...};. This could be a problem with MSVC.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I'll write out the error checking. (but I prefer an explicit != 0 if what I'm checking isn't a straightforward Boolean.)

Wrapped the macros in do {...} while (0).

)


def write_header():
Copy link
Member

Choose a reason for hiding this comment

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

It does a bit more than just writing the header :)

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 don't understand the comment. It dumps to stdout in C header format, nothing more :)
I've renamed it to print_header to point out the output is not configurable.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, you refer to C header. I though that you were referring to file header Generated with: .... Forget what I said. :)


/* Convert an LDAP error into an informative python exception */
PyObject*
LDAPerror( LDAP *l, char *msg )
Copy link
Member

Choose a reason for hiding this comment

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

Is this a straight copy from the other file?

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, except whitespace and a comment.

git diff HEAD^{/Refactor}~:Modules/errors.c HEAD^{/Refactor}:Modules/constants.c

Copy link
Member

Choose a reason for hiding this comment

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

+1

(cool git magic)

@@ -0,0 +1,402 @@
"""Definitions for constants exported by OpenLDAP
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a shebang, please?

Copy link
Member Author

Choose a reason for hiding this comment

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

Should I? As a Linux packager, I have a bias against executable files in /usr/lib.
The module is intended to be run as python Lib/ldap/constants.py > Modules/constants_generated.h, and that doesn't need a shebang.

These were created only as:
forward = {}
reverse = {0: None}

The only use was the function LDAPconstant, equivalent to:

    def LDAPconstant(i):
        return reverse.get(i, i)

It looks like these were prepared for a better future, but python-ldap
has gone for years or decades without needing to actually use them.
Remove both dictionaries and the function.
…te C

Modules/errors.{c,h} are merged into Modules/constants.{c,h}

The function LDAPerror_TypeError is moved to common.{c,h}, as it's not
concerned with LDAPError.

Add a new Python module, ldap.constants, to keep information about
all OpenLDAP constants that we know about, including those that aren't
available in the OpenLDAP used.

Generate a C header file, Modules/constants_generated.h, from this information.
(Checking generated files into Git is better avoided, but it's much
more straightforward than generating the file from setup.py.)

Use proper error checking when adding the constants.
This involves a fake _ldap module and carefully bootstrapping
ldap.__init__ (which imports * from _ldap).
The default should be pretty enough.
@codecov
Copy link

codecov bot commented Nov 27, 2017

Codecov Report

Merging #11 into master will decrease coverage by 1.35%.
The diff coverage is 74.31%.

@@            Coverage Diff             @@
##           master      #11      +/-   ##
==========================================
- Coverage   62.35%   60.99%   -1.36%     
==========================================
  Files          45       46       +1     
  Lines        4370     4369       -1     
  Branches      737      749      +12     
==========================================
- Hits         2725     2665      -60     
- Misses       1337     1390      +53     
- Partials      308      314       +6
Impacted Files Coverage Δ
Modules/functions.c 61.66% <ø> (ø) ⬆️
Modules/ldapcontrol.c 50.59% <ø> (ø) ⬆️
Modules/message.c 32.53% <ø> (ø) ⬆️
Modules/options.c 34.42% <ø> (ø) ⬆️
Lib/ldap/constants.py 0% <0%> (ø)
Modules/ldapmodule.c 80.95% <0%> (-9.53%) ⬇️
Modules/constants_generated.h 100% <100%> (ø)
Modules/LDAPObject.c 54.01% <25%> (-0.26%) ⬇️
Modules/constants.c 47.05% <47.05%> (-51.62%) ⬇️
Modules/common.c 83.33% <71.42%> (-16.67%) ⬇️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a72aaac...5cbbc49. Read the comment docs.

@tiran
Copy link
Member

tiran commented Nov 27, 2017

Awesome, LGTM! 💯

@encukou encukou merged commit 4431a30 into master Nov 27, 2017
@encukou encukou deleted the read-the-docs branch November 28, 2017 10:58
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.

2 participants