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

Add eachdist.py to simplify build. #291

Merged
merged 24 commits into from
Dec 10, 2019

Conversation

Oberon00
Copy link
Member

@Oberon00 Oberon00 commented Nov 15, 2019

Quoting from CONTRIBUTING.md:

To quickly get up and running, you can use the scripts/eachdist.py tool that
ships with this project. First create a virtualenv and activate it.
Then run python scripts/eachdist.py develop to install all required packages
as well as the project's packages themselves (in --editable mode).
You can then run scripts/eachdist.py test to test everything or
scripts/eachdist.py lint to lint everything (fixing anything that is auto-fixable).

Of course the script works on both Windows and Linux (py > sh 😄). I encourage you to try it out.

PS: Yes, I know that I created "an ad-hoc, informally-specified, bug-ridden, slow implementation of half of" xargs find -exec.

Excluding `build` for black isn't a great idea when travis is checking
out under `/home/travis/build/open-telemetry`.
@codecov-io
Copy link

codecov-io commented Nov 15, 2019

Codecov Report

Merging #291 into master will increase coverage by 0.14%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #291      +/-   ##
==========================================
+ Coverage   85.74%   85.88%   +0.14%     
==========================================
  Files          33       33              
  Lines        1613     1630      +17     
  Branches      181      182       +1     
==========================================
+ Hits         1383     1400      +17     
  Misses        182      182              
  Partials       48       48
Impacted Files Coverage Δ
...app/src/opentelemetry_example_app/flask_example.py 100% <0%> (ø) ⬆️
...src/opentelemetry/ext/opentracing_shim/__init__.py 95.86% <0%> (+0.17%) ⬆️
...xt-jaeger/src/opentelemetry/ext/jaeger/__init__.py 85.18% <0%> (+0.18%) ⬆️
...ry-ext-wsgi/src/opentelemetry/ext/wsgi/__init__.py 90.54% <0%> (+0.26%) ⬆️
...ts/src/opentelemetry/ext/http_requests/__init__.py 89.18% <0%> (+0.3%) ⬆️
opentelemetry-sdk/src/opentelemetry/sdk/util.py 85.88% <0%> (+0.34%) ⬆️
...opentelemetry/sdk/context/propagation/b3_format.py 84.61% <0%> (+0.61%) ⬆️
...ry-sdk/src/opentelemetry/sdk/resources/__init__.py 70.83% <0%> (+2.65%) ⬆️

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 3d441b1...ac4174b. Read the comment docs.

First, black already parsers .gitignore, so no need for the exclude
option in pyproject.toml (apart from checked in generated files). The
problem with this is that .gitignore has `build/` in it already and
black does not take into account the root of the git repository, but
instead seems to apply the ignore patterns to the path that results from
the command line arguments (be that relative or absolute).
@Oberon00 Oberon00 added the build & infra Issues related to build & infrastructure. label Nov 18, 2019
@Oberon00
Copy link
Member Author

Oberon00 commented Nov 22, 2019

DO NOT MERGE yet: eachdist.py lint/test miss most the examples currently (because they have no setup.py/pyproject.toml)

Fixed in ea07bd6

@@ -3,21 +3,7 @@ line-length = 79
exclude = '''
(
/(
Copy link
Contributor

@lzchen lzchen Dec 3, 2019

Choose a reason for hiding this comment

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

If I understand correctly, this file is for excluding certain folders from being checked with black. We are removing these because the tox will run the eachdist.py script (which will only run on folders specified in eachdist.ini), instead of running black directly correct? For cases when I want to fix the lint directly myself without running tox, will changing this file effect that?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, running black directly vs eachdist.py makes no difference at all. This was removed because black already checks .gitignore and so the lines were just redundant. This is actually a change independent from the rest of this PR and could be merged separately.

@@ -0,0 +1,10 @@
pylint~=2.3
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this file have the word constraints in it as well? dev-constraints.txt maybe? Due to use using it as constraints in tox.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, if you use the install --with-dev-deps or develop commands, it will be used as a requirements file.

-c dev-requirements.txt
sphinx
sphinx-rtd-theme
sphinx-autodoc-typehints
opentracing~=2.2.0
Deprecated>=1.2.6
Copy link
Contributor

Choose a reason for hiding this comment

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

How come no -c dev-requirements.txt for testenv:py37-tracecontext?

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems that environment doesn't use any requirement that is listed in dev-requirements. Also, because the dev-requirements file is used for installing too (#291 (comment)), I didn't want to include all that.

This project uses [`tox`](https://tox.readthedocs.io) to automate some aspects
To quickly get up and running, you can use the `scripts/eachdist.py` tool that
ships with this project. First create a virtualenv and activate it.
Then run `python scripts/eachdist.py develop` to install all required packages
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the difference between python scripts/eachdist.py develop and python scripts/eachdist.py install --editable?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is an alias for install --editable --with-dev-deps --eager-upgrades (see

editable=True, with_dev_deps=True, eager_upgrades=True
)

Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

This is awesome, it makes writing code so much easier!

Just a non-blocking suggestion and it would be nice to have an example of how to use exec, I ended up digging through the test file to figure out what format was expecting.

@Oberon00
Copy link
Member Author

Oberon00 commented Dec 6, 2019

@codeboten

Just a non-blocking suggestion and it would be nice to have an example of how to use exec, I ended up digging through the test file to figure out what format was expecting.

This was actually bugging me too, so I took the time and documented exec properly (including two examples) in 487a600.

$ scripts/eachdist.py exec --help
usage: eachdist.py exec [-h] [--all [ALLFORMAT]] [--allsep ALLSEP]
                        [--allowexitcode ALLOWEXITCODE] [--mode MODE]
                        format

Run a command according to the `format` argument for each or all targets.

This is an advanced command that is used internally by other commands.

For example, to install all distributions in this repository
editable, you could use:

    scripts/eachdist.py exec "python -m pip install -e {}"

This will run pip for all distributions which is quite slow. It gets
a bit faster if we only invoke pip once but with all the paths
gathered together, which can be achieved by using `--all`:

    scripts/eachdist.py exec "python -m pip install {}" --all "-e {}"

The sortfirst option in the DEFAULT section of eachdist.ini makes
sure that dependencies are installed before their dependents.

Search for usages of `parse_subargs` in the source code of this script
to see more examples.

This command first collects target paths and then executes
commands according to `format` and `--all`.

Target paths are initially all Python distribution root paths
(as determined by the existence of setup.py, etc. files).
They are then augmented according to the section of the
`PROJECT_ROOT/eachdist.ini` config file specified by the `--mode` option.

The following config options are available (and processed in that order):

- `extraroots`: List of project root-relative glob expressions.
  The resulting paths will be added.
- `sortfirst`: List of glob expressions.
  Any matching paths will be put to the front of the path list,
  in the same order they appear in this option. If more than one
  glob matches, ordering is according to the first.
- `subglob`: List of glob expressions. Each path added so far is removed
  and replaced with the result of all glob expressions relative to it (in
  order of the glob expressions).

After all this, any duplicate paths are removed (the first occurrence remains).

positional arguments:
  format                Format string for the command to execute.

                        The available replacements depend on whether `--all` is specified.
                        If `--all` was specified, there is only a single replacement,
                        `{}`, that is replaced with the string that is generated from
                        joining all targets formatted with `--all` to a single string
                        with the value of `--allsep` as separator.

                        If `--all` was not specified, the following replacements are available:

                        - `{}`: the absolute path to the current target in POSIX format
                          (with forward slashes)
                        - `{rel}`: like `{}` but relative to the project root.
                        - `{raw}`: the absolute path to the current target in native format
                          (thus exactly the same as `{}` on Unix but with backslashes on Windows).
                        - `{rawrel}`: like `{raw}` but relative to the project root.

                        The resulting string is then split according to POSIX shell rules
                        (so you can use quotation marks or backslashes to handle arguments
                        containing spaces).

                        The first token is the name of the executable to run, the remaining
                        tokens are the arguments.

                        Note that a shell is *not* involved by default.
                        You can add bash/sh/cmd/powershell yourself to the format if you want.

                        If `--all` was specified, the resulting command is simply executed once.
                        Otherwise, the command is executed for each found target. In both cases,
                        the project root is the working directory.

optional arguments:
  -h, --help            show this help message and exit
  --all [ALLFORMAT]     Instead of running the command for each target, join all target
                        paths together to run a single command.

                        This option optionally takes a format string to apply to each path. The
                        available replacements are the ones that would be available for `format`
                        if `--all` was not specified.

                        Default ALLFORMAT if this flag is specified: `{rel}`.
  --allsep ALLSEP       Separator string for the strings resulting from `--all`.
                        Only valid if `--all` is specified.
  --allowexitcode ALLOWEXITCODE
                        The given command exit code is treated as success and does not abort execution.
                        Can be specified multiple times.
  --mode MODE, -m MODE  Section of config file to use for target selection configuration.
                        See description of exec for available options.

You're welcome!

@toumorokoshi toumorokoshi added needs reviewers PRs with this label are ready for review and needs people to review to move forward. PR:please merge This PR is ready to be merged by a Maintainer (has enough valid approvals, successful build, etc.) and removed needs reviewers PRs with this label are ready for review and needs people to review to move forward. labels Dec 9, 2019
@a-feld a-feld removed their request for review December 10, 2019 00:55
Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

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

This is a huge improvement, and will make developing with multiple packages in the same repo much easier. I'm taking some of the script on faith here, and didn't do an exhaustive review, but it did work as advertised when I tested it.

Comment on lines +101 to +104
pylint
flake8
isort
black
Copy link
Member

Choose a reason for hiding this comment

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

These are listed in dev-requirements, why duplicate them here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because dev-requirements has more requirements than each tox environment on its own. That's why it's used with -c so that only the version requirements are taken, but the targets are not automatically installed. I only moved the versions out of the toxfile with this. If I used -r, it would install unnecessary packages for each target (e.g. we don't need pytest or sphinx for the lint toxenv).

Comment on lines +115 to +117
sphinx
sphinx-rtd-theme
sphinx-autodoc-typehints
Copy link
Member

Choose a reason for hiding this comment

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

Same question

sphinx-rtd-theme~=0.4
sphinx-autodoc-typehints~=1.10.2
pytest!=5.2.3
pytest-cov>=2.8
Copy link
Member

Choose a reason for hiding this comment

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

I understand these were moved from tox.ini, but what do you think about using the latest version of build tools instead of pinning these? It does mean dealing with some build unpredictability, but prevents us having to make big changes to update these packages later.

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 think we should at least have >= requirements (although the minimum version would be very low due to Python 3.4 support most of the time, at least for requirements we use on Python != 3.7). I'm fine with removing upper bounds though.

scripts/eachdist.py Show resolved Hide resolved
for subdir in rootpath.iterdir():
if not subdir.is_dir():
continue
if subdir.name.startswith(".") or subdir.name.startswith("venv"):
Copy link
Member

Choose a reason for hiding this comment

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

Using gitignore or similar seems like a better long term solution here.

Copy link
Member Author

Choose a reason for hiding this comment

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

True, actually since Python already supports globbing (and it's already used in that script), that should be a relatively simple change.

@c24t c24t merged commit b25af7f into open-telemetry:master Dec 10, 2019
@Oberon00 Oberon00 deleted the eachdist-script branch December 10, 2019 08:51
@c24t c24t mentioned this pull request Dec 10, 2019
@c24t c24t removed the PR:please merge This PR is ready to be merged by a Maintainer (has enough valid approvals, successful build, etc.) label Dec 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build & infra Issues related to build & infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants