Skip to content

Commit

Permalink
move errpy source under pyre directory
Browse files Browse the repository at this point in the history
Summary:
this diff moves errpy from `fbcode/python/errpy` to `fbcode/tools/pyre/source/errpy`, allowing Pyre to use it directly as a dependency instead of pulling from opam

the changes I've made to get errpy to build using dune in our internal environment are noted with comments

this should allow errpy API changes to be handled in pyre immediately, without needing an OSS release + opam update and without breaking the buck tests

Reviewed By: stroxler

Differential Revision: D58110305

fbshipit-source-id: 225ede1fc997bfe86927d96fbbbdb7c5e42fb78c
  • Loading branch information
yangdanny97 authored and facebook-github-bot committed Jun 14, 2024
1 parent 2d6f6d0 commit 5a4d1a3
Show file tree
Hide file tree
Showing 247 changed files with 259,309 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[source.crates-io] # @oss-disable
replace-with = "vendored-sources" # @oss-disable

[source.vendored-sources] # @oss-disable
directory = "../../../third-party/rust/vendor" # @oss-disable
5 changes: 5 additions & 0 deletions source/errpy/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[source.crates-io] # @oss-disable
replace-with = "vendored-sources" # @oss-disable

[source.vendored-sources] # @oss-disable
directory = "../../../../../third-party/rust/vendor" # @oss-disable
37 changes: 37 additions & 0 deletions source/errpy/.github/workflows/cargo_vendor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
on:
push:
branches:
- main
name: cargo vendor and commit
run-name: cargo vendor 🚚 on - ${{ github.event.head_commit.message }}
jobs:
cargo_vendor:
runs-on: ubuntu-latest
steps:
- name: Delete release branch
uses: dawidd6/action-delete-branch@v3
with:
soft_fail: true # set to true so that if the branch doesn't exist action doesnt fail
branches: release
- uses: actions/checkout@v2
- uses: dtolnay/rust-toolchain@stable
- run: cargo vendor vendor_external
- name: Create .cargo dir
run: |
mkdir -p .cargo
- name: Create cargo config
shell: bash
run: |
cat << EOF > .cargo/config.toml
[source.crates-io]
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "vendor_external"
EOF
- name: commit to 'new' release branch
uses: EndBug/add-and-commit@v9.1.1
with:
new_branch: release
author_name: GitHub Action
author_email: action@github.com
1 change: 1 addition & 0 deletions source/errpy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_build/
29 changes: 29 additions & 0 deletions source/errpy/.ocamlformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
assignment-operator=end-line
break-cases=all
break-fun-decl=fit-or-vertical
break-infix=fit-or-vertical
break-infix-before-func
break-separators=after
break-sequences
dock-collection-brackets=true
doc-comments=before
exp-grouping=preserve
field-space=tight-decl
if-then-else=fit-or-vertical
indicate-nested-or-patterns=unsafe-no
let-and=sparse
let-binding-spacing=sparse
margin=100
ocp-indent-compat
parens-tuple=multi-line-only
parens-tuple-patterns=multi-line-only
sequence-style=terminator
sequence-blank-line=preserve-one
single-case=sparse
space-around-lists=false
space-around-records
space-around-variants
type-decl=sparse
wrap-comments
wrap-fun-args=false
parse-docstrings
76 changes: 76 additions & 0 deletions source/errpy/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to make participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies within all project spaces, and it also applies when
an individual is representing the project or its community in public spaces.
Examples of representing a project or community include using an official
project e-mail address, posting via an official social media account, or acting
as an appointed representative at an online or offline event. Representation of
a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at <opensource-conduct@fb.com>. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
36 changes: 36 additions & 0 deletions source/errpy/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Contributing to Errpy

## Issues

We use GitHub issues to track public bugs. Please ensure your description is
clear and has sufficient instructions to be able to reproduce the issue.
We want to make contributing to this project as easy and transparent as
possible.

## Contributor License Agreement ("CLA")

In order to accept your pull request, we need you to submit a CLA. You only need
to do this once to work on any of Facebook's open source projects.

Complete your CLA here: <https://code.facebook.com/cla>. If you have any questions,
please drop us a line at cla@fb.com.

You are also expected to follow the [Code of Conduct](CODE_OF_CONDUCT.md),
so please read that if you are a new contributor.

## Developing Errpy

Unfortunately at the moment it is difficult to build Errpy because we
are still in the process of open-sourcing a dependency,
[ocamlrep](https://github.com/facebook/ocamlrep). It is possible to build,
but requires cloning `ocamlrep` and setting paths appropriately.

If you are interested in working on Errpy, please file an issue and we'll
work on the docs for this, in the meantime we are focused on getting
`ocamlrep` into the Rust repository in crates.io so that the build will be
come standard.

## License

By contributing to Pyre, you agree that your contributions will be licensed
under the LICENSE file in the root directory of this source tree.
37 changes: 37 additions & 0 deletions source/errpy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# @generated by autocargo from //tools/pyre/source/errpy:[ffi_ocaml,print_ast,print_cst]

[package]
name = "ffi_ocaml"
version = "0.0.0"
edition = "2021"
repository = "https://github.com/facebook/errpy"
license = "MIT"

[lib]
path = "ffi_ocaml.rs"
test = false
doctest = false
crate-type = ["lib", "staticlib"]

[[bin]]
name = "print_ast"
path = "print_ast.rs"

[[bin]]
name = "print_cst"
path = "print_cst.rs"

[dependencies]
bstr = { version = "1.4.0", features = ["serde", "std", "unicode"] }
clap = { version = "3.2.25", features = ["derive", "env", "regex", "unicode", "wrap_help"] }
itertools = "0.11.0"
num_enum = { version = "0.5", default-features = false }
ocamlrep = { path = "vendor/ocaml/interop/ocamlrep" }
ocamlrep_ocamlpool = { path = "vendor/ocaml/interop/ocamlrep_ocamlpool" }
phf = { version = "0.11", features = ["macros"] }
regex = "1.9.2"
rust_to_ocaml_attr = { path = "vendor/ocaml/interop/rust_to_ocaml/rust_to_ocaml_attr" }
serde = { version = "1.0.185", features = ["derive", "rc"] }
thiserror = "1.0.49"
tree-sitter = "0.20.8"
tree_sitter_python = { path = "vendor/tree-sitter-python" }
21 changes: 21 additions & 0 deletions source/errpy/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Meta Platforms, Inc. and affiliates.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
58 changes: 58 additions & 0 deletions source/errpy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

# Errpy: An Error Recovering Rust Python Parser

This is a new project to provide an error-recovering Python parser, implemented
in Rust based on tree-sitter. Our short-term goal is to use it in the [pyre
type checker](https://github.com/facebook/pyre-check), in order to provide
better IDE features.

## License

Errpy is licensed under the MIT license.

## Building
Errpy depends upon the following:
* Ocaml
* Dune
* Rust
* Cargo

### Platform
ERRPY is verified as being buildable on Linux on OCaml 4.14.0

### Installing Ocaml and Dune
Install `opam` and run `opam switch install "4.14.0"`

## Usage
It is recommended to use dune as your build system. To use errpy in your dune project, you can add errpy to the libraries stanza in your dune file. For example,

```
(library
(name mylib)
(libraries errpy))
```

### For local development
If you want to test your changes to errpy locally and use them in another OCaml project (.e.g. Pyre) you can try the following,

First clone the repo with: `$ git clone https://github.com/facebook/errpy.git`

Or use `$ git clone --branch release https://github.com/facebook/errpy.git` if you're operating within an `offline` rust enviroment.

```
... make the required changed ...
$ cd errpy
$ dune build @install # Build the errpy library
$ dune test # Run tests
$ opam pin add errpy . -n # pin opam to errpy
$ opam install errpy --verbose # install local build as errpy in opam
```

## Formatting
When making Ocaml changes you can run `ocamlformat` in order to ensure code is
formatted in a conistent manner. This is invoked as follows:
```
$ dune build @fmt
$ dune promote
```
Loading

0 comments on commit 5a4d1a3

Please sign in to comment.