|
| 1 | +Python Package Compatibility Guidelines |
| 2 | +======================================= |
| 3 | + |
| 4 | +This document uses terminology (MUST, SHOULD, etc) from `RFC 2119`_. |
| 5 | + |
| 6 | +.. _RFC 2119: https://www.ietf.org/rfc/rfc2119.txt |
| 7 | + |
| 8 | +---------- |
| 9 | +Background |
| 10 | +---------- |
| 11 | + |
| 12 | +Incompatibilities between packages published on the `Python Package Index (PyPI)`_ |
| 13 | +have been a long standing issue. Diamond dependencies are a common problem where |
| 14 | +a package or application has dependencies that are, themselves, dependant on |
| 15 | +incompatible versions of shared packages. |
| 16 | + |
| 17 | +.. _Python Package Index (PyPI): https://pypi.org/ |
| 18 | + |
| 19 | +Incompatibilities between packages can occur when: |
| 20 | + |
| 21 | +- A package makes breaking API changes and doesn't follow `Semantic Versioning`_ |
| 22 | +- A package has a pinned dependency version which conflicts with other dependencies. |
| 23 | +- A package depends on outdated dependencies. |
| 24 | +- A package is dependent on deprecated dependencies. |
| 25 | + |
| 26 | +.. _Semantic Versioning: https://semver.org/ |
| 27 | + |
| 28 | +This guide is a list of best practices that Python package authors can follow |
| 29 | +to help reduce future incompatibilities. Google-sponsored projects are expected |
| 30 | +to follow these guidelines but other projects may benefit from them as well. |
| 31 | + |
| 32 | +----- |
| 33 | +Tools |
| 34 | +----- |
| 35 | + |
| 36 | + To detect and prevent version incompatibilities between Google Open Source Python |
| 37 | + packages, we provide a set of tooling to ensure we are compatible with |
| 38 | + ourselves. Our tools are as follows: |
| 39 | + |
| 40 | +Dependency Compatibility Dashboard |
| 41 | +---------------------------------- |
| 42 | + |
| 43 | +The `dashboard`_ shows the compatibility status of a list of Google sponsored Open Source |
| 44 | +Python packages. |
| 45 | + |
| 46 | +.. _dashboard: https://googlecloudplatform.github.io/cloud-opensource-python/ |
| 47 | + |
| 48 | +Badge Server |
| 49 | +------------ |
| 50 | + |
| 51 | +The badge server runs checks and generates an svg format badge image to show the |
| 52 | +status of a given package. Supported usage includes: |
| 53 | + |
| 54 | +- Self compatibility (the package has internally consistent dependencies) |
| 55 | +- Google-wise compatibility (the package is compatible with other Google packages) |
| 56 | +- Dependency version status (the package does not rely on obsolete dependencies) |
| 57 | +- One badge for all of the checks above |
| 58 | + |
| 59 | +For more details please refer to `here`_. |
| 60 | + |
| 61 | +.. _here: https://github.com/GoogleCloudPlatform/cloud-opensource-python/tree/master/badge_server |
| 62 | + |
| 63 | +---------------------- |
| 64 | +Python Packaging Rules |
| 65 | +---------------------- |
| 66 | + |
| 67 | +Package Versioning |
| 68 | +------------------ |
| 69 | + |
| 70 | +We should use semantic versioning for all Google OSS Python distribution |
| 71 | +packages. Semantic versioning requires that given a version number |
| 72 | +`MAJOR.MINOR.PATCH`, increment the: |
| 73 | + |
| 74 | + * MAJOR version when you make incompatible API changes. |
| 75 | + * MINOR version when you add functionality in a backwards-compatible manner. |
| 76 | + * PATCH version when you make backwards-compatible bug fixes. |
| 77 | + |
| 78 | +Requirements: |
| 79 | + |
| 80 | +- `GA(Generally Available)`_ libraries must conform to semantic versioning. |
| 81 | +- Non-GA libraries should use major version 0, and be promoted to 1.0 when reaching GA. |
| 82 | +- Non-GA libraries could be excluded from semver stability guarantees. |
| 83 | +- Dropping support for a Python major version(e.g. Python 2) should result in a major version increment |
| 84 | + |
| 85 | +.. _GA(Generally Available): https://cloud.google.com/terms/launch-stages |
| 86 | + |
| 87 | +Dependencies |
| 88 | +------------ |
| 89 | + |
| 90 | +**1. Specify dependency version using closed ranges** |
| 91 | + |
| 92 | +- Minor or patch versions shouldn’t be used as an upper bound for 1st party dependencies unless the dependency is not GA. |
| 93 | +- Specific versions can be excluded if they are known to be incompatible. e.g. google-cloud-pubsub >= 0.1.1 !=2.0.0 !=2.0.1 |
| 94 | +- Specific versions may be specified if a package exists as a wrapper around another. |
| 95 | + |
| 96 | +**2. Avoid depending on unstable release version dependencies** |
| 97 | + |
| 98 | +- It’s not recommended to depend on non-GA packages. |
| 99 | +- Avoid depending on pre-release, post-release and development release versions. |
| 100 | +- GA packages must not depend on non-GA packages. |
| 101 | + |
| 102 | +**3. Version range upper bound should be updated when there is a newer version available as soon as possible.** |
| 103 | + |
| 104 | +- We allow a 30 day grace period for package owners to migrate to support new major version bump of the dependencies. |
| 105 | + |
| 106 | +**4. Minimize dependencies** |
| 107 | + |
| 108 | +- Packages should use Python built-in modules if possible. e.g. logging, unittest |
| 109 | + |
| 110 | +**5. Never vendor dependencies** |
| 111 | + |
| 112 | +Vendoring means having a copy of a specific version of the dependencies and ship it together with the library code. |
| 113 | + |
| 114 | +Release and Support |
| 115 | +------------------- |
| 116 | + |
| 117 | +- Major version bumps should be rare |
| 118 | +- Minimize the cost for users to go from one major version to another. |
| 119 | +- Support every semver-major HEAD of every package that is 1.0+ for at least one year. |
| 120 | +- Dropping support for any older version should be semver-major. |
| 121 | + |
| 122 | +--------------- |
| 123 | +GA Requirements |
| 124 | +--------------- |
| 125 | + |
| 126 | +The GA requirements are validated using the `github badge`_ service, so the badge |
| 127 | +should be green before any GA launch. |
| 128 | + |
| 129 | +- Packages must be self compatible |
| 130 | +If package A has dependencies B and C, and they require different versions |
| 131 | +of dependency D, package A is not self compatible. Packages that are not internally |
| 132 | +compatible will have conflicts with all the rest of the packages in the world. |
| 133 | + |
| 134 | +- Packages must be google-wise compatible |
| 135 | +It’s required for any new package owned by Google to be compatible with all the other Google Python packages. So that using any combination of Google Python packages will not cause any conflicts during installation or failures during runtime. |
| 136 | + |
| 137 | +- Packages must support latest version of its dependencies |
| 138 | + |
| 139 | +.. _github badge: https://github.com/GoogleCloudPlatform/cloud-opensource-python/blob/master/badge_server/README.rst |
0 commit comments